Logo coherent WaveBurst  
Library Reference Guide
Logo
HistoryLine.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  HistoryLine.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 "HistoryLine.hh"
37 #include <iostream>
38 #include <string.h>
39 #include "TDatime.h" // [0.94.01]
40 
41 CWB::HistoryLine::HistoryLine(char* Type, char* Comment, char* History){
42  TTimeStamp CreationTT;
43 
44  Init();
45  CreationDate_Sec = CreationTT.GetSec();
46  CreationDate_NSec = CreationTT.GetNanoSec();
47  TypeSet(Type);
48  CommentSet(Comment);
49  HistorySet(History);
50 }
51 
52 CWB::HistoryLine::HistoryLine(const HistoryLine& HistoryLine) : TObject(HistoryLine) {
53  this->TypeLength = HistoryLine.TypeLength;
54  this->CommentLength = HistoryLine.CommentLength;
55  this->HistoryLength = HistoryLine.HistoryLength;
56  this->Type = strdup(HistoryLine.Type);
57  this->Comment = strdup(HistoryLine.Comment);
58  this->History = strdup(HistoryLine.History);
59  this->SortOrder = HistoryLine.SortOrder;
60  this->AscendingOrder = HistoryLine.AscendingOrder;
61  this->CreationDate_Sec = HistoryLine.CreationDate_Sec;
62  this->CreationDate_NSec = HistoryLine.CreationDate_NSec;
63 }
64 
66  Destroy();
67 }
68 
69 void
71  TypeSet(Type);
72  CommentSet(Comment);
73  HistorySet(History);
74 }
75 
76 char*
78  TypeSet(Type);
79  return Type;
80 }
81 
82 char*
84  CommentSet(Comment);
85  return History;
86 }
87 
88 char*
90  HistorySet(History);
91  return History;
92 }
93 
94 char*
96  if (Type == NULL) return NULL;
97  else return strdup(Type);
98 }
99 
100 char*
102  if (Comment == NULL) return NULL;
103  else return strdup(Comment);
104 }
105 
106 char*
108  if (History == NULL) return NULL;
109  else return strdup(History);
110 }
111 
112 void
114  Print();
115 }
116 
117 void
119  cout << "Type : " << Type << endl;
120  cout << "Comment : " << Comment << endl;
121  cout << "History : " << History << endl;
122 }
123 
124 bool
126  return true;
127 }
128 
129 int
130 CWB::HistoryLine::Compare(const TObject* Obj) const {
131  int Result;
132 
133  switch(SortOrder) {
134  case InsertionOrder :
135  if (this->CreationDate_Sec < static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_Sec) Result = -1;
136  else if (this->CreationDate_Sec > static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_Sec) Result = 1;
137  else if (this->CreationDate_NSec < static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_NSec) Result = -1;
138  else if (this->CreationDate_NSec > static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_NSec) Result = 1;
139  else Result = 0;
140  case Alphabetical :
141  Result = strcmp(this->Type, static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->Type);
142  if (Result == 0) Result = strcmp(this->History, static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->History);
143  break;
144  default :
145 // HistoryLineException(kBreak, "CWB::HistoryLine::Compare", "Sort Order not supported XXX");
146  exit(1);
147  break;
148  }
149  return Result;
150 }
151 
154  if (SortOrder == ElementDate) this->SortOrder = InsertionOrder;
155  else this->SortOrder = SortOrder;
156  return this->SortOrder;
157 }
158 
161  return SortOrder;
162 }
163 
164 bool
166  if (SortOrder == InsertionOrder) return true;
167  else return false;
168 }
169 
170 bool
172  if (SortOrder == ElementDate) return true;
173  else return false;
174 }
175 
176 bool
178  if (SortOrder == Alphabetical) return true;
179  else return false;
180 }
181 
182 bool
184  AscendingOrder = true;
185  return AscendingOrder;
186 }
187 
188 bool
190  AscendingOrder = false;
191  return AscendingOrder;
192 }
193 
194 bool
196  return AscendingOrder;
197 }
198 
199 bool
201  return !AscendingOrder;
202 }
203 
204 TTimeStamp
206  TTimeStamp CreationTT(CreationDate_Sec, CreationDate_NSec);
207  return CreationTT;
208 }
209 
210 void
212  TypeLength = 0;
213  Type = NULL;
214  HistoryLength = 0;
215  History = NULL;
216  CommentLength = 0;
217  Comment = NULL;
220 }
221 
222 void
224  if (Type != NULL) delete Type;
225  if (History != NULL) delete History;
226  if (Comment != NULL) delete Comment;
227 }
228 
229 void
231  if (this->Type != NULL) delete this->Type;
232 
233  if (Type != NULL) {
234  TypeLength = strlen(Type) + 1;
235  this->Type = new char[TypeLength];
236  strcpy(this->Type, Type);
237  }
238  else {
239  TypeLength = 1;
240  this->Type = new char[1];
241  this->Type[0] = 0;
242  }
243 }
244 
245 void
247  if (this->Comment != NULL) delete this->Comment;
248 
249  if (Comment != NULL) {
250  CommentLength = strlen(Comment) + 1;
251  this->Comment = new char[CommentLength];
252  strcpy(this->Comment, Comment);
253  }
254  else {
255  HistoryLength = 1;
256  this->Comment = new char[1];
257  this->Comment[0] = 0;
258  }
259 }
260 
261 void
263  if (this->History != NULL) delete this->History;
264 
265  if (History != NULL) {
266  HistoryLength = strlen(History) + 1;
267  this->History = new char[HistoryLength];
268  strcpy(this->History, History);
269  }
270  else {
271  HistoryLength = 1;
272  this->History = new char[1];
273  this->History[0] = 0;
274  }
275 }
276 
277 void CWB::HistoryLine::Streamer(TBuffer &R__b)
278 {
279  // Stream an object of class HistoryLine.
280  TDatime CreationDatime;
281  TTimeStamp CreationTT;
282 
283  UInt_t R__s, R__c;
284  if (R__b.IsReading()) {
285  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
286  TObject::Streamer(R__b);
287  R__b >> TypeLength;
288  R__b >> HistoryLength;
289  delete [] Type;
290  Type = new char[TypeLength];
291  R__b.ReadFastArray(Type,TypeLength);
292  delete [] History;
293  History = new char[HistoryLength];
294  R__b.ReadFastArray(History,HistoryLength);
295  if (R__v > 1) {
296  R__b >> CommentLength;
297  delete [] Comment;
298  Comment = new char[CommentLength];
299  R__b.ReadFastArray(Comment,CommentLength);
300  R__b >> (Int_t&)SortOrder;
301  R__b >> AscendingOrder;
302  if (R__v == 1) {
303  CreationDatime.Streamer(R__b);
304  CreationTT.Set(CreationDatime.GetYear(), CreationDatime.GetMonth(), CreationDatime.GetDay(), CreationDatime.GetHour(), CreationDatime.GetMinute(), CreationDatime.GetSecond(), 0, true, 0);
305  CreationDate_Sec = CreationTT.GetSec();
306  CreationDate_NSec = CreationTT.GetNanoSec();
307  }
308  else {
309  R__b >> CreationDate_Sec;
310  R__b >> CreationDate_NSec;
311  R__b.CheckByteCount(R__s, R__c, CWB::HistoryLine::IsA());
312  }
313  }
314  else {
315  CommentLength = 0;
316  Comment = NULL;
319  CreationDate_Sec = CreationTT.GetSec();
320  CreationDate_NSec = CreationTT.GetNanoSec();
321  }
322  } else {
323  R__c = R__b.WriteVersion(CWB::HistoryLine::IsA(), kTRUE);
324  TObject::Streamer(R__b);
325  R__b << TypeLength;
326  R__b << HistoryLength;
327  R__b.WriteFastArray(Type,TypeLength);
328  R__b.WriteFastArray(History,HistoryLength);
329  R__b << CommentLength;
330  R__b.WriteFastArray(Comment,CommentLength);
331  R__b << (Int_t)SortOrder;
332  R__b << AscendingOrder;
333  R__b << CreationDate_Sec;
334  R__b << CreationDate_NSec;
335  R__b.SetByteCount(R__c, kTRUE);
336  }
337 }
338 
339 void
340 CWB::HistoryLine::HistoryLineException(int type, const char *location, const char *msgfmt, ...) {
341  cout << location << " " << msgfmt << endl;
342  exit(1);
343 }
344 
char * GetHistoryType()
Definition: HistoryLine.cc:95
bool IsSortOrderInsertion()
Definition: HistoryLine.cc:165
#define DEFAULT_SORT_ORDER
char * SetHistoryType(char *Type)
Definition: HistoryLine.cc:77
bool SetAscendingSortOrder()
Definition: HistoryLine.cc:183
virtual void Browse(TBrowser *b)
Definition: HistoryLine.cc:113
SortOrderType
bool SetDescendantSortOrder()
Definition: HistoryLine.cc:189
char * GetHistoryComment()
Definition: HistoryLine.cc:101
void HistoryLineException(int type, const char *location, const char *msgfmt,...)
Definition: HistoryLine.cc:340
bool GetDescendantSortOrder()
Definition: HistoryLine.cc:200
void TypeSet(char *Type)
Definition: HistoryLine.cc:230
SortOrderType GetSortOrder()
Definition: HistoryLine.cc:160
SortOrderType SetSortOrder(SortOrderType SortOrder)
Definition: HistoryLine.cc:153
bool GetAscendingSortOrder()
Definition: HistoryLine.cc:195
bool IsSortable() const
Definition: HistoryLine.cc:125
char * GetHistoryStr()
Definition: HistoryLine.cc:107
TTimeStamp GetCreationTimeStamp()
Definition: HistoryLine.cc:205
void SetHistory(char *Type, char *Comment, char *History)
Definition: HistoryLine.cc:70
bool IsSortOrderDate()
Definition: HistoryLine.cc:171
char * SetHistoryStr(char *History)
Definition: HistoryLine.cc:89
SortOrderType SortOrder
Definition: HistoryLine.hh:107
bool IsSortOrderAlphabetical()
Definition: HistoryLine.cc:177
strcpy(RunLabel, RUN_LABEL)
#define DEFAULT_ASCENDING
void HistorySet(char *History)
Definition: HistoryLine.cc:262
HistoryLine(char *Type=NULL, char *Comment=NULL, char *History=NULL)
Definition: HistoryLine.cc:41
char * SetHistoryComment(char *Comment)
Definition: HistoryLine.cc:83
Type
Definition: FrDisplay.cc:123
int Compare(const TObject *Obj) const
Definition: HistoryLine.cc:130
exit(0)
void CommentSet(char *Comment)
Definition: HistoryLine.cc:246