source: drsdaq/SlowData.cc@ 67

Last change on this file since 67 was 44, checked in by ogrimm, 15 years ago
Raw data format streamlined, revision tracking in run header
File size: 2.4 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); timeinfo = localtime(&rawtime);
30 snprintf(Filename,sizeof(Filename),"%s/%s_%d%02d%02d.slow",Direcory,Issuer,timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday);
31
32 if ((SlowdataFile = fopen(Filename, "a")) == NULL)
33 m->PrintMessage("Warning: Could not open slowdata file '%s' (%s)\n", Filename, strerror(errno));
34}
35
36//
37// Destructor
38//
39SlowData::~SlowData() {
40 if(SlowdataFile!=NULL && fclose(SlowdataFile)==-1)
41 m->PrintMessage("SlowData: Error, could not close slowdata file (%s)\n", strerror(errno));
42}
43
44//
45// Add a new entry to slow data file
46//
47bool SlowData::NewEntry(char *Variable) {
48
49 time_t RawTime;
50 struct tm *TM;
51 struct timeval Time;
52
53 time(&RawTime);
54 TM = localtime(&RawTime);
55 gettimeofday(&Time, NULL);
56 InternalCall = true;
57 NewEntryCalled = AddToEntry("\n%s-%s %lu %lu %d-%d-%dT%d:%d:%d ", Issuer, Variable, Time.tv_sec, Time.tv_usec, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec);
58 InternalCall = false;
59 return NewEntryCalled;
60}
61
62//
63// Add data to an open entry
64//
65bool SlowData::AddToEntry(char *Format, ...) {
66
67 char Textbuffer[MAX_COM_SIZE];
68 va_list ArgumentPointer;
69
70 if(SlowdataFile==NULL || (!NewEntryCalled && !InternalCall)) return false;
71
72 va_start(ArgumentPointer, Format);
73 vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
74 va_end(ArgumentPointer);
75
76 if(!InternalCall)
77 for(unsigned int i=0; i<strlen(Textbuffer); i++)
78 if (iscntrl(Textbuffer[i])) return false;
79
80 if(fprintf(SlowdataFile, "%s", Textbuffer) == -1) {
81 m->PrintMessage("SlowData: Error, could not write data to file (%s); closing file\n", strerror(errno));
82 fclose(SlowdataFile);
83 SlowdataFile = NULL;
84 return false;
85 }
86 fflush(SlowdataFile);
87 return true;
88}
Note: See TracBrowser for help on using the repository browser.