Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HistoryLine.cc
Go to the documentation of this file.
1 /***************************************************************************
2  HistoryLine.cpp - description
3  -------------------
4  begin : ven set 2 2005
5  copyright : (C) 2005 by Stefano Longo
6  email : Stefano.Longo@lnl.infn.it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "HistoryLine.hh"
19 #include <iostream>
20 #include <string.h>
21 #include "TDatime.h" // [0.94.01]
22 
23 CWB::HistoryLine::HistoryLine(char* Type, char* Comment, char* History){
24  TTimeStamp CreationTT;
25 
26  Init();
27  CreationDate_Sec = CreationTT.GetSec();
28  CreationDate_NSec = CreationTT.GetNanoSec();
29  TypeSet(Type);
30  CommentSet(Comment);
31  HistorySet(History);
32 }
33 
34 CWB::HistoryLine::HistoryLine(const HistoryLine& HistoryLine) : TObject(HistoryLine) {
35  this->TypeLength = HistoryLine.TypeLength;
36  this->CommentLength = HistoryLine.CommentLength;
37  this->HistoryLength = HistoryLine.HistoryLength;
38  this->Type = strdup(HistoryLine.Type);
39  this->Comment = strdup(HistoryLine.Comment);
40  this->History = strdup(HistoryLine.History);
41  this->SortOrder = HistoryLine.SortOrder;
42  this->AscendingOrder = HistoryLine.AscendingOrder;
43  this->CreationDate_Sec = HistoryLine.CreationDate_Sec;
44  this->CreationDate_NSec = HistoryLine.CreationDate_NSec;
45 }
46 
48  Destroy();
49 }
50 
51 void
52 CWB::HistoryLine::SetHistory(char* Type, char* Comment, char* History) {
53  TypeSet(Type);
54  CommentSet(Comment);
55  HistorySet(History);
56 }
57 
58 char*
60  TypeSet(Type);
61  return Type;
62 }
63 
64 char*
66  CommentSet(Comment);
67  return History;
68 }
69 
70 char*
72  HistorySet(History);
73  return History;
74 }
75 
76 char*
78  if (Type == NULL) return NULL;
79  else return strdup(Type);
80 }
81 
82 char*
84  if (Comment == NULL) return NULL;
85  else return strdup(Comment);
86 }
87 
88 char*
90  if (History == NULL) return NULL;
91  else return strdup(History);
92 }
93 
94 void
96  Print();
97 }
98 
99 void
101  cout << "Type : " << Type << endl;
102  cout << "Comment : " << Comment << endl;
103  cout << "History : " << History << endl;
104 }
105 
106 bool
108  return true;
109 }
110 
111 int
112 CWB::HistoryLine::Compare(const TObject* Obj) const {
113  int Result;
114 
115  switch(SortOrder) {
116  case InsertionOrder :
117  if (this->CreationDate_Sec < static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_Sec) Result = -1;
118  else if (this->CreationDate_Sec > static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_Sec) Result = 1;
119  else if (this->CreationDate_NSec < static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_NSec) Result = -1;
120  else if (this->CreationDate_NSec > static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->CreationDate_NSec) Result = 1;
121  else Result = 0;
122  case Alphabetical :
123  Result = strcmp(this->Type, static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->Type);
124  if (Result == 0) Result = strcmp(this->History, static_cast<HistoryLine*>(const_cast<TObject*>(Obj))->History);
125  break;
126  default :
127 // HistoryLineException(kBreak, "CWB::HistoryLine::Compare", "Sort Order not supported XXX");
128  exit(1);
129  break;
130  }
131  return Result;
132 }
133 
136  if (SortOrder == ElementDate) this->SortOrder = InsertionOrder;
137  else this->SortOrder = SortOrder;
138  return this->SortOrder;
139 }
140 
143  return SortOrder;
144 }
145 
146 bool
148  if (SortOrder == InsertionOrder) return true;
149  else return false;
150 }
151 
152 bool
154  if (SortOrder == ElementDate) return true;
155  else return false;
156 }
157 
158 bool
160  if (SortOrder == Alphabetical) return true;
161  else return false;
162 }
163 
164 bool
166  AscendingOrder = true;
167  return AscendingOrder;
168 }
169 
170 bool
172  AscendingOrder = false;
173  return AscendingOrder;
174 }
175 
176 bool
178  return AscendingOrder;
179 }
180 
181 bool
183  return !AscendingOrder;
184 }
185 
186 TTimeStamp
188  TTimeStamp CreationTT(CreationDate_Sec, CreationDate_NSec);
189  return CreationTT;
190 }
191 
192 void
194  TypeLength = 0;
195  Type = NULL;
196  HistoryLength = 0;
197  History = NULL;
198  CommentLength = 0;
199  Comment = NULL;
200  SortOrder = DEFAULT_SORT_ORDER;
201  AscendingOrder = DEFAULT_ASCENDING;
202 }
203 
204 void
206  if (Type != NULL) delete Type;
207  if (History != NULL) delete History;
208  if (Comment != NULL) delete Comment;
209 }
210 
211 void
213  if (this->Type != NULL) delete this->Type;
214 
215  if (Type != NULL) {
216  TypeLength = strlen(Type) + 1;
217  this->Type = new char[TypeLength];
218  strcpy(this->Type, Type);
219  }
220  else {
221  TypeLength = 1;
222  this->Type = new char[1];
223  this->Type[0] = 0;
224  }
225 }
226 
227 void
229  if (this->Comment != NULL) delete this->Comment;
230 
231  if (Comment != NULL) {
232  CommentLength = strlen(Comment) + 1;
233  this->Comment = new char[CommentLength];
234  strcpy(this->Comment, Comment);
235  }
236  else {
237  HistoryLength = 1;
238  this->Comment = new char[1];
239  this->Comment[0] = 0;
240  }
241 }
242 
243 void
245  if (this->History != NULL) delete this->History;
246 
247  if (History != NULL) {
248  HistoryLength = strlen(History) + 1;
249  this->History = new char[HistoryLength];
250  strcpy(this->History, History);
251  }
252  else {
253  HistoryLength = 1;
254  this->History = new char[1];
255  this->History[0] = 0;
256  }
257 }
258 
259 void CWB::HistoryLine::Streamer(TBuffer &R__b)
260 {
261  // Stream an object of class HistoryLine.
262  TDatime CreationDatime;
263  TTimeStamp CreationTT;
264 
265  UInt_t R__s, R__c;
266  if (R__b.IsReading()) {
267  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
268  TObject::Streamer(R__b);
269  R__b >> TypeLength;
270  R__b >> HistoryLength;
271  delete [] Type;
272  Type = new char[TypeLength];
273  R__b.ReadFastArray(Type,TypeLength);
274  delete [] History;
275  History = new char[HistoryLength];
276  R__b.ReadFastArray(History,HistoryLength);
277  if (R__v > 1) {
278  R__b >> CommentLength;
279  delete [] Comment;
280  Comment = new char[CommentLength];
281  R__b.ReadFastArray(Comment,CommentLength);
282  R__b >> (Int_t&)SortOrder;
283  R__b >> AscendingOrder;
284  if (R__v == 1) {
285  CreationDatime.Streamer(R__b);
286  CreationTT.Set(CreationDatime.GetYear(), CreationDatime.GetMonth(), CreationDatime.GetDay(), CreationDatime.GetHour(), CreationDatime.GetMinute(), CreationDatime.GetSecond(), 0, true, 0);
287  CreationDate_Sec = CreationTT.GetSec();
288  CreationDate_NSec = CreationTT.GetNanoSec();
289  }
290  else {
291  R__b >> CreationDate_Sec;
292  R__b >> CreationDate_NSec;
293  R__b.CheckByteCount(R__s, R__c, CWB::HistoryLine::IsA());
294  }
295  }
296  else {
297  CommentLength = 0;
298  Comment = NULL;
299  SortOrder = DEFAULT_SORT_ORDER;
300  AscendingOrder = DEFAULT_ASCENDING;
301  CreationDate_Sec = CreationTT.GetSec();
302  CreationDate_NSec = CreationTT.GetNanoSec();
303  }
304  } else {
305  R__c = R__b.WriteVersion(CWB::HistoryLine::IsA(), kTRUE);
306  TObject::Streamer(R__b);
307  R__b << TypeLength;
308  R__b << HistoryLength;
309  R__b.WriteFastArray(Type,TypeLength);
310  R__b.WriteFastArray(History,HistoryLength);
311  R__b << CommentLength;
312  R__b.WriteFastArray(Comment,CommentLength);
313  R__b << (Int_t)SortOrder;
314  R__b << AscendingOrder;
315  R__b << CreationDate_Sec;
316  R__b << CreationDate_NSec;
317  R__b.SetByteCount(R__c, kTRUE);
318  }
319 }
320 
321 void
322 CWB::HistoryLine::HistoryLineException(int type, const char *location, const char *msgfmt, ...) {
323  cout << location << " " << msgfmt << endl;
324  exit(1);
325 }
326 
char * GetHistoryType()
Definition: HistoryLine.cc:77
bool IsSortOrderInsertion()
Definition: HistoryLine.cc:147
bool IsSortable() const
Definition: HistoryLine.cc:107
#define DEFAULT_SORT_ORDER
char * SetHistoryType(char *Type)
Definition: HistoryLine.cc:59
bool SetAscendingSortOrder()
Definition: HistoryLine.cc:165
virtual void Browse(TBrowser *b)
Definition: HistoryLine.cc:95
SortOrderType
bool SetDescendantSortOrder()
Definition: HistoryLine.cc:171
char * GetHistoryComment()
Definition: HistoryLine.cc:83
void HistoryLineException(int type, const char *location, const char *msgfmt,...)
Definition: HistoryLine.cc:322
bool GetDescendantSortOrder()
Definition: HistoryLine.cc:182
int Compare(const TObject *Obj) const
Definition: HistoryLine.cc:112
void TypeSet(char *Type)
Definition: HistoryLine.cc:212
MDC Print()
SortOrderType GetSortOrder()
Definition: HistoryLine.cc:142
SortOrderType SetSortOrder(SortOrderType SortOrder)
Definition: HistoryLine.cc:135
bool GetAscendingSortOrder()
Definition: HistoryLine.cc:177
char * GetHistoryStr()
Definition: HistoryLine.cc:89
TTimeStamp GetCreationTimeStamp()
Definition: HistoryLine.cc:187
void SetHistory(char *Type, char *Comment, char *History)
Definition: HistoryLine.cc:52
bool IsSortOrderDate()
Definition: HistoryLine.cc:153
char * SetHistoryStr(char *History)
Definition: HistoryLine.cc:71
SortOrderType SortOrder
Definition: HistoryLine.hh:89
bool IsSortOrderAlphabetical()
Definition: HistoryLine.cc:159
strcpy(RunLabel, RUN_LABEL)
#define DEFAULT_ASCENDING
void HistorySet(char *History)
Definition: HistoryLine.cc:244
HistoryLine(char *Type=NULL, char *Comment=NULL, char *History=NULL)
Definition: HistoryLine.cc:23
char * SetHistoryComment(char *Comment)
Definition: HistoryLine.cc:65
Type
Definition: FrDisplay.cc:105
exit(0)
void CommentSet(char *Comment)
Definition: HistoryLine.cc:228