source: drsdaq/SlowData.cc@ 40

Last change on this file since 40 was 36, checked in by ogrimm, 16 years ago
Various changes, see History.txt
File size: 2.3 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 struct timeval Time;
50
51 gettimeofday(&Time, NULL);
52 InternalCall = true;
53 NewEntryCalled = AddToEntry("\n%s %s %lu %lu ", Issuer, Variable, Time.tv_sec, Time.tv_usec);
54 InternalCall = false;
55 return NewEntryCalled;
56}
57
58//
59// Add data to an open entry
60//
61bool SlowData::AddToEntry(char *Format, ...) {
62
63 char Textbuffer[MAX_COM_SIZE];
64 va_list ArgumentPointer;
65
66 if(SlowdataFile==NULL || (!NewEntryCalled && !InternalCall)) return false;
67
68 va_start(ArgumentPointer, Format);
69 vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
70 va_end(ArgumentPointer);
71
72 if(!InternalCall)
73 for(unsigned int i=0; i<strlen(Textbuffer); i++)
74 if (iscntrl(Textbuffer[i])) return false;
75
76 if(fprintf(SlowdataFile, "%s", Textbuffer) == -1) {
77 m->PrintMessage("SlowData: Error, could not write data to file (%s); closing file\n", strerror(errno));
78 fclose(SlowdataFile);
79 SlowdataFile = NULL;
80 return false;
81 }
82 fflush(SlowdataFile);
83 return true;
84}
Note: See TracBrowser for help on using the repository browser.