source: drsdaq/SlowData.cc@ 90

Last change on this file since 90 was 87, checked in by ogrimm, 16 years ago
Corrections in SlowData class
File size: 2.2 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
14//
15// Constructor: Open slow data file (filename generate using current date)
16//
17SlowData::SlowData(const char* IssuerName, const char* Direcory) {
18
19 time_t rawtime;
20 struct tm *timeinfo;
21 char Filename[MAX_PATH];
22
23 Issuer = IssuerName;
24 NewEntryCalled = false;
25 InternalCall = false;
26
27 time(&rawtime);
28 timeinfo = gmtime(&rawtime);
29 if(timeinfo->tm_hour>=13) rawtime += 12*60*60;
30 timeinfo = gmtime(&rawtime);
31 snprintf(Filename, sizeof(Filename), "%s/%s_%d%02d%02d.slow", Direcory, Issuer, timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday);
32
33 if ((SlowdataFile = fopen(Filename, "a")) == NULL) ErrorCode = errno;
34 else ErrorCode = 0;
35}
36
37//
38// Destructor
39//
40SlowData::~SlowData() {
41 if(SlowdataFile!=NULL) fclose(SlowdataFile);
42}
43
44//
45// Add a new entry to slow data file
46//
47bool SlowData::NewEntry(const 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 %d %d %d %d %d %d %d %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);
58 InternalCall = false;
59 return NewEntryCalled;
60}
61
62//
63// Add data to an open entry
64//
65bool SlowData::AddToEntry(const 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 ErrorCode = errno;
82 fclose(SlowdataFile);
83 SlowdataFile = NULL;
84 return false;
85 }
86 fflush(SlowdataFile);
87 ErrorCode = 0;
88 return true;
89}
Note: See TracBrowser for help on using the repository browser.