source: drsdaq/SlowData.cc@ 68

Last change on this file since 68 was 68, checked in by ogrimm, 15 years ago
Introduced dummy, zero initialized items in raw data format to align with MAGIC format ordering, changed date rollover to 13:00 UTC
File size: 2.5 KB
Line 
1/********************************************************************\
2
3 SlowData.cc
4
5 Class handling the writing of slow data. String to be written in the
6 slow data file are checked that they do not contain control characters.
7
8 Oliver Grimm
9
10\********************************************************************/
11
12#include "SlowData.h"
13#include "DAQReadout.h"
14
15//
16// Constructor: Open slow data file (filename generate using current date)
17//
18SlowData::SlowData(DAQReadout* DAQClass, const char* IssuerName, char* Direcory) {
19
20 time_t rawtime;
21 struct tm *timeinfo;
22 char Filename[MAX_PATH];
23
24 m = DAQClass;
25 Issuer = IssuerName;
26 NewEntryCalled = false;
27 InternalCall = false;
28
29 time(&rawtime);
30 timeinfo = gmtime(&rawtime);
31 if(timeinfo->tm_hour>=13) rawtime += 12*60*60;
32 timeinfo = gmtime(&rawtime);
33 snprintf(Filename,sizeof(Filename),"%s/%s_%d%02d%02d.slow",Direcory,Issuer,timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday);
34
35 if ((SlowdataFile = fopen(Filename, "a")) == NULL)
36 m->PrintMessage("Warning: Could not open slowdata file '%s' (%s)\n", Filename, strerror(errno));
37}
38
39//
40// Destructor
41//
42SlowData::~SlowData() {
43 if(SlowdataFile!=NULL && fclose(SlowdataFile)==-1)
44 m->PrintMessage("SlowData: Error, could not close slowdata file (%s)\n", strerror(errno));
45}
46
47//
48// Add a new entry to slow data file
49//
50bool SlowData::NewEntry(char *Variable) {
51
52 time_t RawTime;
53 struct tm *TM;
54 struct timeval Time;
55
56 time(&RawTime);
57 TM = localtime(&RawTime);
58 gettimeofday(&Time, NULL);
59 InternalCall = true;
60 NewEntryCalled = AddToEntry("\n%s %s %d %d %d %d %d %d %d %lu %lu", Issuer, Variable, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec, Time.tv_usec/1000, Time.tv_sec, Time.tv_usec);
61 InternalCall = false;
62 return NewEntryCalled;
63}
64
65//
66// Add data to an open entry
67//
68bool SlowData::AddToEntry(char *Format, ...) {
69
70 char Textbuffer[MAX_COM_SIZE];
71 va_list ArgumentPointer;
72
73 if(SlowdataFile==NULL || (!NewEntryCalled && !InternalCall)) return false;
74
75 va_start(ArgumentPointer, Format);
76 vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
77 va_end(ArgumentPointer);
78
79 if(!InternalCall)
80 for(unsigned int i=0; i<strlen(Textbuffer); i++)
81 if (iscntrl(Textbuffer[i])) return false;
82
83 if(fprintf(SlowdataFile, "%s", Textbuffer) == -1) {
84 m->PrintMessage("SlowData: Error, could not write data to file (%s); closing file\n", strerror(errno));
85 fclose(SlowdataFile);
86 SlowdataFile = NULL;
87 return false;
88 }
89 fflush(SlowdataFile);
90 return true;
91}
Note: See TracBrowser for help on using the repository browser.