/********************************************************************\ SlowData.cc Class handling the writing of slow data. String to be written in the slow data file are checked that they do not contain control characters. Oliver Grimm \********************************************************************/ #include "SlowData.h" #include "DAQReadout.h" // // Constructor: Open slow data file (filename generate using current date) // SlowData::SlowData(DAQReadout* DAQClass, const char* IssuerName, char* Direcory) { time_t rawtime; struct tm *timeinfo; char Filename[MAX_PATH]; m = DAQClass; Issuer = IssuerName; NewEntryCalled = false; InternalCall = false; time(&rawtime); timeinfo = localtime(&rawtime); snprintf(Filename,sizeof(Filename),"%s/%s_%d%02d%02d.slow",Direcory,Issuer,timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday); if ((SlowdataFile = fopen(Filename, "a")) == NULL) m->PrintMessage("Warning: Could not open slowdata file '%s' (%s)\n", Filename, strerror(errno)); } // // Destructor // SlowData::~SlowData() { if(SlowdataFile!=NULL && fclose(SlowdataFile)==-1) m->PrintMessage("SlowData: Error, could not close slowdata file (%s)\n", strerror(errno)); } // // Add a new entry to slow data file // bool SlowData::NewEntry(char *Variable) { struct timeval Time; gettimeofday(&Time, NULL); InternalCall = true; NewEntryCalled = AddToEntry("\n%s %s %lu %lu ", Issuer, Variable, Time.tv_sec, Time.tv_usec); InternalCall = false; return NewEntryCalled; } // // Add data to an open entry // bool SlowData::AddToEntry(char *Format, ...) { char Textbuffer[MAX_COM_SIZE]; va_list ArgumentPointer; if(SlowdataFile==NULL || (!NewEntryCalled && !InternalCall)) return false; va_start(ArgumentPointer, Format); vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer); va_end(ArgumentPointer); if(!InternalCall) for(unsigned int i=0; iPrintMessage("SlowData: Error, could not write data to file (%s); closing file\n", strerror(errno)); fclose(SlowdataFile); SlowdataFile = NULL; return false; } fflush(SlowdataFile); return true; }