Logo coherent WaveBurst  
Library Reference Guide
Logo
HistoryLogLine.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Stefano Longo, Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 /***************************************************************************
20  HistoryLogLine.cpp - description
21  -------------------
22  begin : ven set 2 2005
23  copyright : (C) 2005 by Stefano Longo
24  email : Stefano.Longo@lnl.infn.it
25  ***************************************************************************/
26 
27 /***************************************************************************
28  * *
29  * This program is free software; you can redistribute it and/or modify *
30  * it under the terms of the GNU General Public License as published by *
31  * the Free Software Foundation; either version 2 of the License, or *
32  * (at your option) any later version. *
33  * *
34  ***************************************************************************/
35 
36 #include "HistoryLogLine.hh"
37 
38 CWB::HistoryLogLine::HistoryLogLine(char* LogStr, TDatime* Time) {
39  TTimeStamp CreationTT;
40 
41  Init();
42  CreationDate_Sec = CreationTT.GetSec();
43  CreationDate_NSec = CreationTT.GetNanoSec();
44  if (Time != NULL) {
45  this->Date = Time->GetDate();
46  this->Time = Time->GetTime();
47  }
48  else {
49  TDatime tmpTime;
50  this->Date = tmpTime.GetDate();
51  this->Time = tmpTime.GetTime();
52  }
53 
54  if (LogStr != NULL) {
55  LogLength = strlen(LogStr) + 1;
56  Log = new char[LogLength];
57  strcpy(Log, LogStr);
58  }
59  else {
60  LogLength = 1;
61  Log = new char[1];
62  Log[0] = 0;
63  }
64 }
65 
67  TTimeStamp CreationTT;
68 
69  Init();
70  CreationDate_Sec = CreationTT.GetSec();
71  CreationDate_NSec = CreationTT.GetNanoSec();
72  this->Date = Date;
73  this->Time = Time;
74  if (LogStr != NULL) {
75  LogLength = strlen(LogStr) + 1;
76  Log = new char[LogLength];
77  strcpy(Log, LogStr);
78  }
79  else {
80  LogLength = 1;
81  Log = new char[1];
82  Log[0] = 0;
83  }
84 }
85 
86 CWB::HistoryLogLine::HistoryLogLine(const HistoryLogLine& LogLine) : TObject(LogLine) {
87  this->Date = LogLine.Date;
88  this->Time = LogLine.Time;
89  this->LogLength = LogLine.LogLength;
90  this->Log = strdup(LogLine.Log);
91  this->SortOrder = LogLine.SortOrder;
92  this->AscendingOrder = LogLine.AscendingOrder;
93  this->CreationDate_Sec = LogLine.CreationDate_Sec;
94  this->CreationDate_NSec = LogLine.CreationDate_NSec;
95 }
96 
98  Destroy();
99 }
100 
101 void
102 CWB::HistoryLogLine::SetLog(char* LogStr, TDatime* Time) {
103  delete Log;
104 
105  this->Date = Time->GetDate();
106  this->Time = Time->GetTime();
107  if (LogStr != NULL) {
108  LogLength = strlen(LogStr) + 1;
109  Log = new char[LogLength];
110  strcpy(Log, LogStr);
111  }
112  else {
113  LogLength = 1;
114  Log = new char[1];
115  Log[0] = 0;
116  }
117 }
118 
119 void
120 CWB::HistoryLogLine::SetLog(char* LogStr, int Date, int Time) {
121  delete Log;
122 
123  this->Date = Date;
124  this->Time = Time;
125  if (LogStr != NULL) {
126  LogLength = strlen(LogStr) + 1;
127  Log = new char[LogLength];
128  strcpy(Log, LogStr);
129  }
130  else {
131  LogLength = 1;
132  Log = new char[1];
133  Log[0] = 0;
134  }
135 }
136 
137 void
139  this->Date = Date;
140  this->Time = Time;
141 }
142 
143 void
145  this->Date = Time->GetDate();
146  this->Time = Time->GetTime();
147 }
148 
149 char*
151  delete this->Log;
152 
153  if (Log != NULL) {
154  LogLength = strlen(Log) + 1;
155  this->Log = new char[LogLength] + 1;
156  strcpy(this->Log, Log);
157  }
158  else {
159  LogLength = 1;
160  Log = new char[1];
161  Log[0] = 0;
162  }
163 
164  return Log;
165 }
166 
167 char*
169  return strdup(Log);
170 }
171 
172 int
174  return Date;
175 }
176 
177 int
179  return Time;
180 }
181 
182 TDatime*
184  return new TDatime(Date, Time);
185 }
186 
187 void
189  Print();
190 }
191 
192 void
194  TDatime tmpTime(Date, Time);
195  cout << "Log Time: " << tmpTime.GetDay() << "/" << tmpTime.GetMonth() << "/" << tmpTime.GetYear() << " - ";
196  cout << tmpTime.GetHour() << ":" << tmpTime.GetMinute() << ":" << tmpTime.GetSecond() << endl;
197  cout << Log << endl;
198 }
199 
200 bool
202  return true;
203 }
204 
205 int
206 CWB::HistoryLogLine::Compare(const TObject* Obj) const {
207  int Result;
208 
209  if (this->Date < static_cast<HistoryLogLine*>(const_cast<TObject*>(Obj))->Date) Result = -1;
210  else if (this->Date > static_cast<HistoryLogLine*>(const_cast<TObject*>(Obj))->Date) Result = 1;
211  else {
212  if (this->Time < static_cast<HistoryLogLine*>(const_cast<TObject*>(Obj))->Time) Result = -1;
213  else if (this->Time > static_cast<HistoryLogLine*>(const_cast<TObject*>(Obj))->Time) Result = 1;
214  else Result = strcmp(this->Log, static_cast<HistoryLogLine*>(const_cast<TObject*>(Obj))->Log);
215  }
216 
217  return Result;
218 }
219 
222  this->SortOrder = SortOrder;
223  return this->SortOrder;
224 }
225 
228  return SortOrder;
229 }
230 
231 bool
233  if (SortOrder == InsertionOrder) return true;
234  else return false;
235 }
236 
237 bool
239  if (SortOrder == ElementDate) return true;
240  else return false;
241 }
242 
243 bool
245  if (SortOrder == Alphabetical) return true;
246  else return false;
247 }
248 
249 bool
251  AscendingOrder = true;
252  return AscendingOrder;
253 }
254 
255 bool
257  AscendingOrder = false;
258  return AscendingOrder;
259 }
260 
261 bool
263  return AscendingOrder;
264 }
265 
266 bool
268  return !AscendingOrder;
269 }
270 
271 TTimeStamp
273  TTimeStamp CreationTT(CreationDate_Sec, CreationDate_NSec);
274  return CreationTT;
275 }
276 
277 void
279  LogLength = 0;
280  Log = NULL;
283 }
284 
285 void
287  if (Log != NULL) delete Log;
288 }
289 
290 void CWB::HistoryLogLine::Streamer(TBuffer &R__b)
291 {
292  // Stream an object of class HistoryLogLine.
293  TDatime CreationDatime;
294  TTimeStamp CreationTT;
295 
296  UInt_t R__s, R__c;
297  if (R__b.IsReading()) {
298  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
299  TObject::Streamer(R__b);
300  R__b >> Date;
301  R__b >> Time;
302  R__b >> LogLength;
303  delete [] Log;
304  Log = new char[LogLength];
305  R__b.ReadFastArray(Log,LogLength);
306  if (R__v > 1) {
307  R__b >> (Int_t&)SortOrder;
308  R__b >> AscendingOrder;
309  if (R__v == 1) {
310  CreationDatime.Streamer(R__b);
311  CreationTT.Set(CreationDatime.GetYear(), CreationDatime.GetMonth(), CreationDatime.GetDay(), CreationDatime.GetHour(), CreationDatime.GetMinute(), CreationDatime.GetSecond(), 0, true, 0);
312  CreationDate_Sec = CreationTT.GetSec();
313  CreationDate_NSec = CreationTT.GetNanoSec();
314  }
315  else {
316  R__b >> CreationDate_Sec;
317  R__b >> CreationDate_NSec;
318  }
319  R__b.CheckByteCount(R__s, R__c, CWB::HistoryLogLine::IsA());
320  }
321  else {
324  CreationDate_Sec = CreationTT.GetSec();
325  CreationDate_NSec = CreationTT.GetNanoSec();
326  }
327  } else {
328  R__c = R__b.WriteVersion(CWB::HistoryLogLine::IsA(), kTRUE);
329  TObject::Streamer(R__b);
330  R__b << Date;
331  R__b << Time;
332  R__b << LogLength;
333  R__b.WriteFastArray(Log,LogLength);
334  R__b << (Int_t)SortOrder;
335  R__b << AscendingOrder;
336  R__b << CreationDate_Sec;
337  R__b << CreationDate_NSec;
338  R__b.SetByteCount(R__c, kTRUE);
339  }
340 }
bool IsSortable() const
#define DEFAULT_SORT_ORDER
TTimeStamp GetCreationTimeStamp()
SortOrderType
SortOrderType GetSortOrder()
SortOrderType SetSortOrder(SortOrderType SortOrder)
TDatime * GetLogDatime()
void SetLogTime(int Date, int Time)
int Compare(const TObject *Obj) const
virtual void Browse(TBrowser *b)
char * SetLogStr(char *Log)
strcpy(RunLabel, RUN_LABEL)
#define DEFAULT_ASCENDING
SortOrderType SortOrder
HistoryLogLine(char *LogStr=NULL, TDatime *Time=NULL)
void SetLog(char *LogStr, TDatime *Time=NULL)