Logo coherent WaveBurst  
Library Reference Guide
Logo
History.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  History.cc - description
21  -------------------
22  begin : lun set 5 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 "History.hh"
37 #include "TRandom3.h"
38 #include <fstream>
39 #include "TFile.h"
40 #include "TTimeStamp.h"
41 #include <math.h>
42 
43 CWB::History::History(char** StageNames, int StageNumber, char** TypeNames, int TypeNumber, char* FilePrefix, bool HistoryModify) {
44  int i;
45  TTimeStamp CreationTT;
46 
47  Init();
48  CreationDate_Sec = CreationTT.GetSec();
49  CreationDate_NSec = CreationTT.GetNanoSec();
50 
51  if (StageNames != NULL) {
52  if (DuplicateNames(StageNames, StageNumber)) HistoryException(kBreak, "CWB::History::History", "Duplicate Stage Name");
53  for (i = 0; i < StageNumber; i++) {
54  if (StageNames[i] == NULL) HistoryException(kBreak, "CWB::History::History", "StageNames[%i] is NULL", i);
55  this->StageNames.AddLast(new TObjString(StageNames[i]));
56  }
57  }
58 
59  if (TypeNames != NULL) {
60  if (DuplicateNames(TypeNames, TypeNumber)) HistoryException(kBreak, "CWB::History::History", "Duplicate Type Name");
61  for (i = 0; i < TypeNumber; i++) {
62  if (TypeNames[i] == NULL) HistoryException(kBreak, "CWB::History::History", "TypeNames[%i] is NULL", i);
63  this->TypeNames.AddLast(new TObjString(TypeNames[i]));
64  }
65  }
66 
67  if (FilePrefix != NULL) this->FilePrefix.SetString(FilePrefix);
68  else this->FilePrefix.SetString("");
69 
70  this->HistoryModify = HistoryModify;
71 }
72 
73 CWB::History::History(const History& History) : TObject(History) {
74  int i;
75 
76  for (i = 0; i < History.StageNames.GetSize(); i++) {
77  this->StageNames.AddLast(new TObjString(*static_cast<TObjString*>(History.StageNames.At(i))));
78  }
79  for (i = 0; i < History.TypeNames.GetSize(); i++) {
80  this->TypeNames.AddLast(new TObjString(*static_cast<TObjString*>(History.TypeNames.At(i))));
81  }
82  for (i = 0; i < History.StageList.GetSize(); i++) {
83  this->StageList.AddLast(new HistoryStage(*static_cast<HistoryStage*>(History.StageList.At(i))));
84  }
85 
86  this->FilePrefix.SetString(History.FilePrefix.GetString().Data());
87  this->HistoryModify = History.HistoryModify;
88  this->SortOrder = History.SortOrder;
89  this->AscendingOrder = History.AscendingOrder;
90  this->CreationDate_Sec = History.CreationDate_Sec;
91  this->CreationDate_NSec = History.CreationDate_NSec;
92 }
93 
95  Destroy();
96 }
97 
98 bool
100  for (int i = 0; i < StageNames.GetSize(); i++) {
101  if (strcmp(Name, static_cast<TObjString*>(StageNames.At(i))->GetName()) == 0) return true;
102  }
103  return false;
104 }
105 
106 bool
108  char* StrApp;
109 
110  for (int i = 0; i < StageList.GetSize(); i++) {
111  StrApp = static_cast<HistoryStage*>(StageList.At(i))->GetName();
112  if (strcmp(StrApp, Name) == 0) {
113  //delete StrApp;
114  return true;
115  }
116  //delete StrApp;
117  }
118  return false;
119 }
120 
121 bool
123  return StageAllowed(Name);
124 }
125 
126 bool
128  for (int i = 0; i < TypeNames.GetSize(); i++) {
129  if (strcmp(Name, static_cast<TObjString*>(TypeNames.At(i))->GetName()) == 0) return true;
130  }
131  return false;
132 }
133 
134 void
135 CWB::History::SetStageNames(char** StageNames, int StageNumber) {
136  int i;
137  char* StrApp;
138  HistoryStage* tmpStage;
139 
140  if (StageNames == NULL) HistoryException(kBreak, "CWB::History::SetStageNames", "StageNames is NULL");
141 
142  this->StageNames.Delete();
143 
144  for (i = 0; i < StageNumber; i++) {
145  if (StageNames[i] == NULL) HistoryException(kBreak, "History:SetStageNames", "StageNames[%i] is NULL", i);
146  this->StageNames.AddLast(new TObjString(StageNames[i]));
147  }
148 
149  for (i =0; i < StageList.GetSize(); i++) {
150  //StrApp = static_cast<HistoryStage*>(StageList.At(i))->GetName();
151  tmpStage = static_cast<HistoryStage*>(StageList.At(i));
152  StrApp = tmpStage->GetName();
153  if (!NameAllowed(StrApp)) StageList.Remove(tmpStage);
154  delete StrApp;
155  }
156 }
157 
158 void
159 CWB::History::SetTypeNames(char** TypeNames, int TypeNumber) {
160  int i;
161  /*
162  REMOVED 03/05/2007
163  char* StrApp;
164  HistoryStage* tmpStage;
165  */
166 
167  if (TypeNames == NULL) HistoryException(kBreak, "CWB::History::SetTypeNames", "TypeNames is NULL");
168  this->TypeNames.Delete();
169 
170  for (i = 0; i < TypeNumber; i++) {
171  if (TypeNames[i] == NULL) HistoryException(kBreak, "History:SetTypeNames", "TypeNames[%i] is NULL", i);
172  this->TypeNames.AddLast(new TObjString(TypeNames[i]));
173  }
174 
175 /* WARNING : CHANGING A TYPE ON-THE-FLY ONLY AFFECT NEW HISTORY LINES */
176 /*
177  for (i =0; i < StageList.GetSize(); i++) {
178  tmpStage = static_cast<HistoryStage*>(StageList.At(i));
179  StrApp = tmpStage->GetType();
180  if (!TypeAllowed(StrApp)) StageList.Remove(tmpStage);
181  delete StrApp;
182  }*/
183 
184 }
185 
186 void
187 CWB::History::AddLog(char* Stage, char* Log, TDatime* Time) {
188  HistoryStage* TempStage;
189 
190  if (!StageAllowed(Stage)) HistoryException(kBreak, "CWB::History::AddLog", "Stage not allowed");
191 
192  if (!StageAlreadyPresent(Stage)) {
193  TempStage = new HistoryStage(TypeNames, Stage, NULL, Time);
194  TempStage->SetSortOrder(SortOrder);
195  if (AscendingOrder) TempStage->SetAscendingSortOrder();
196  else TempStage->SetDescendantSortOrder();
197  StageList.AddLast(TempStage);
198  //StageList.AddLast(new HistoryStage(TypeNames, Stage, NULL, Time));
199  }
200 
201  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
202  tmpStage->AddLog(Log, Time);
203 }
204 
205 void
206 CWB::History::AddLog(char* Stage, char* Log, int Date, int Time) {
207  HistoryStage* TempStage;
208 
209  if (!StageAllowed(Stage)) HistoryException(kBreak, "CWB::History::AddLog", "Stage not allowed");
210 
211  if (!StageAlreadyPresent(Stage)) {
212  TempStage = new HistoryStage(TypeNames, Stage, NULL, Date, Time);
213  TempStage->SetSortOrder(SortOrder);
214  if (AscendingOrder) TempStage->SetAscendingSortOrder();
215  else TempStage->SetDescendantSortOrder();
216  StageList.AddLast(TempStage);
217  //StageList.AddLast(new HistoryStage(TypeNames, Stage, NULL, Date, Time));
218  }
219 
220  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
221  tmpStage->AddLog(Log, Date, Time);
222 }
223 
224 void
225 CWB::History::AddHistory(char* Stage, char* Type, char* History, TDatime* Time) {
226  HistoryStage* TempStage;
227 
228  if (!StageAllowed(Stage)) HistoryException(kBreak, "CWB::History::AddHistory", "Stage not allowed");
229 
230  if (!StageAlreadyPresent(Stage)) {
231  TempStage = new HistoryStage(TypeNames, Stage, NULL, Time);
232  TempStage->SetSortOrder(SortOrder);
233  if (AscendingOrder) TempStage->SetAscendingSortOrder();
234  else TempStage->SetDescendantSortOrder();
235  StageList.AddLast(TempStage);
236  //StageList.AddLast(new HistoryStage(TypeNames, Stage, NULL, Time));
237  }
238 
239  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
240  tmpStage->AddHistory(Type, History, NULL, HistoryModify);
241 }
242 
243 void
244 CWB::History::AddHistory(char* Stage, char* Type, char* History, int Date, int Time) {
245  HistoryStage* TempStage;
246 
247  if (!StageAllowed(Stage)) HistoryException(kBreak, "CWB::History::AddHistory", "Stage not allowed");
248 
249  if (!StageAlreadyPresent(Stage)) {
250  TempStage = new HistoryStage(TypeNames, Stage, NULL, Date, Time);
251  TempStage->SetSortOrder(SortOrder);
252  if (AscendingOrder) TempStage->SetAscendingSortOrder();
253  else TempStage->SetDescendantSortOrder();
254  StageList.AddLast(TempStage);
255  //StageList.AddLast(new HistoryStage(TypeNames, Stage, NULL, Date, Time));
256  }
257 
258  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
259  tmpStage->AddHistory(Type, History, NULL, HistoryModify);
260 }
261 
262 void
264  this->FilePrefix.SetString(FilePrefix);
265 }
266 
267 char*
269  return strdup(FilePrefix.GetString().Data());
270 }
271 
272 char*
273 CWB::History::GetHistory(char* StageName, char* Type) {
274  int i;
275  char* StrApp;
276 
277  if (!NameAllowed(StageName)) HistoryException(kBreak, "CWB::History::GetHistory", "Illegal Stage Name");
278  if (!TypeAllowed(Type)) HistoryException(kBreak, "CWB::History::GetHistory", "Illegal Type Name");
279 
280  for (i = 0; i < StageList.GetSize(); i++) {
281  StrApp = static_cast<HistoryStage*>(StageList.At(i))->GetName();
282  if (strcmp(StrApp, StageName) == 0) {
283  delete StrApp;
284  return static_cast<HistoryStage*>(StageList.At(i))->GetHistory(Type);
285  }
286  delete StrApp;
287  }
288  return NULL;
289 }
290 
291 TDatime*
292 CWB::History::GetHistoryDatime(char* StageName, char* Type) {
293  HistoryException(kBreak, "CWB::History::GetHistoryDatime", "Not implemented !!!");
294  return NULL;
295 }
296 
297 int
299  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
300  return tmpStage ? tmpStage->GetLogSize() : 0;
301 }
302 
303 char*
304 CWB::History::GetLog(char* Stage, int index) {
305  HistoryStage* tmpStage = const_cast<HistoryStage*>(GetStage(Stage));
306  return tmpStage->GetLogEntry(index);
307 }
308 
309 void
310 CWB::History::Browse(TBrowser *b) {
311  Print();
312 }
313 
314 void
316  /*
317  REMOVED 03/05/2007
318  int i, j, ret;
319  int MaxDate, MaxTime, MaxIndex;
320  char tmpStr[256];
321  char* StrApp1, *StrApp2;
322  TDatime* TimePtr;
323 
324  bool *printDone;
325  */
326 
327  int ret;
328  char tmpStr[256];
329 
330  TRandom3 random;
331  random.SetSeed(0);
332 
333  char cfg_tmp_name[256];
334  sprintf(cfg_tmp_name,"/dev/shm/%f.history.cfg",fabs(random.Uniform()));
335  WriteToFile(cfg_tmp_name);
336 
337  if (getenv("IGEC_HISTORY_VIEWER") != NULL) {
338  sprintf(tmpStr, "%s %s", getenv("IGEC_HISTORY_VIEWER"), cfg_tmp_name);
339  ret = system(tmpStr);
340  if (ret != 0) {
341  sprintf(tmpStr, "vim %s", cfg_tmp_name);
342  system(tmpStr);
343  }
344  }
345  else {
346  sprintf(tmpStr, "vim %s", cfg_tmp_name);
347  system(tmpStr);
348  }
349 
350  sprintf(tmpStr, "rm -f %s", cfg_tmp_name);
351  system(tmpStr);
352 }
353 
354 void
356  /*
357  REMOVED 03/05/2007
358  int i, j, ret;
359  int MaxDate, MaxTime, MaxIndex;
360  char tmpStr[256];
361  char* StrApp1, *StrApp2;
362  TDatime* TimePtr;
363  bool *printDone;
364  */
365 
366  int ret;
367  char tmpStr[256];
368 
369 
370  TRandom3 random;
371  random.SetSeed(0);
372 
373  char cfg_tmp_name[256];
374  sprintf(cfg_tmp_name,"/dev/shm/%f.history.cfg",fabs(random.Uniform()));
375  WriteToFile(cfg_tmp_name, true);
376 
377  if (getenv("IGEC_HISTORY_VIEWER") != NULL) {
378  sprintf(tmpStr, "%s %s", getenv("IGEC_HISTORY_VIEWER"), cfg_tmp_name);
379  ret = system(tmpStr);
380  if (ret != 0) {
381  sprintf(tmpStr, "vim %s", cfg_tmp_name);
382  system(tmpStr);
383  }
384  }
385  else {
386  sprintf(tmpStr, "vim %s", cfg_tmp_name);
387  system(tmpStr);
388  }
389 
390  sprintf(tmpStr, "rm -f %s", cfg_tmp_name);
391  system(tmpStr);
392 }
393 
394 void
396  TDatime now;
397  TString file_name;
398 
399  if (FileName != NULL) file_name = TString(FileName);
400  else file_name = TString(FilePrefix.GetString().Data())+TString(now.AsString())+TString(".cfg");
401 
402  cout << "Dump To File " << file_name.Data() << endl;
403 
404  WriteToFile(const_cast<char*>(file_name.Data()));
405 }
406 
407 void
409  char fname[256];
410  TFile* RootFile;
411 
412  if (FileName != NULL) strcpy(fname, FileName);
413  else {
414  TDatime now;
415  TString file_name = TString(FilePrefix.GetString().Data())+TString(now.AsString())+TString(".root");
416  strcpy(fname, file_name.Data());
417  }
418  cout << "Dump To File " << fname << endl;
419 
420  RootFile = new TFile(fname, "RECREATE");
421  this->Write();
422  RootFile->Close();
423  delete RootFile;
424 }
425 
426 TList*
428  int i;
429  TList *TmpList;
430 
431  TmpList = new TList;
432  for(i = 0; i < StageNames.GetEntries(); i++) {
433  TmpList->AddLast(new TObjString(StageNames.At(i)->GetName()));
434  }
435 
436  return TmpList;
437 }
438 
439 TList*
441  int i;
442  TList *TmpList;
443 
444  TmpList = new TList;
445  for(i = 0; i < TypeNames.GetEntries(); i++) {
446  TmpList->AddLast(new TObjString(TypeNames.At(i)->GetName()));
447  }
448 
449  return TmpList;
450 }
451 
452 bool
454  this->HistoryModify = Modify;
455  return this->HistoryModify;
456 }
457 
458 bool
460  return HistoryModify;
461 }
462 
463 char*
464 CWB::History::AddStage(char* StageName) {
465  if (!HistoryModify)
466  HistoryException(kBreak, "CWB::History::AddStage", "History Modify not allowed");
467 
468  if (NameAllowed(StageName))
469  HistoryException(kBreak, "CWB::History::AddStage", "Stage %s already present", StageName);
470 
471  StageNames.AddLast(new TObjString(StageName));
472 
473  return StageName;
474 }
475 
476 char*
477 CWB::History::RemoveStage(char* StageName) {
478  int i;
479  HistoryStage* tmpStage;
480  char* StrApp;
481  TObjString* TempString;
482 
483  if (!HistoryModify)
484  HistoryException(kBreak, "CWB::History::RemoveStage", "History Modify not allowed");
485 
486  if (!NameAllowed(StageName))
487  HistoryException(kBreak, "CWB::History::RemoveStage", "Stage %s not present", StageName);
488 
489  for (i = 0; i < StageNames.GetSize(); i++) {
490  TempString = static_cast<TObjString*>(StageNames.At(i));
491  if (strcmp(TempString->GetName(), StageName) == 0) StageNames.Remove(TempString);
492  }
493 
494  for (i = 0; i < StageList.GetSize(); i++) {
495  tmpStage = static_cast<HistoryStage*>(StageList.At(i));
496  StrApp = tmpStage->GetName();
497  if (!NameAllowed(StrApp)) StageList.Remove(tmpStage);
498  delete StrApp;
499  }
500 
501  return StageName;
502 }
503 
504 char*
505 CWB::History::AddType(char* TypeName) {
506  if (!HistoryModify)
507  HistoryException(kBreak, "Hsitory::AddType", "History modify not allowed");
508 
509  if (TypeAllowed(TypeName))
510  HistoryException(kBreak, "Hsitory::AddType" , "Type %s already present", TypeName);
511 
512  TypeNames.AddLast(new TObjString(TypeName));
513 
514  for(int i = 0; i < StageList.GetSize(); i++) {
515  static_cast<HistoryStage*>(StageList.At(i))->AddType(TypeName);
516  }
517 
518  return TypeName;
519 }
520 
521 char*
522 CWB::History::RemoveType(char* TypeName) {
523  TObjString* TempString;
524  int i;
525 
526  if (!HistoryModify)
527  HistoryException(kBreak, "Hsitory::RemoveType", "History modify not allowed");
528 
529  if (!TypeAllowed(TypeName))
530  HistoryException(kBreak, "Hsitory::RemoveType" , "Type %s not present", TypeName);
531 
532  for (i = 0; i < TypeNames.GetSize(); i++) {
533  TempString = static_cast<TObjString*>(TypeNames.At(i));
534  if (strcmp(TempString->GetName(), TypeName) == 0) TypeNames.Remove(TempString);
535  }
536 
537  for(i = 0; i < StageList.GetSize(); i++) {
538  static_cast<HistoryStage*>(StageList.At(i))->RemoveType(TypeName);
539  }
540 
541  return TypeName;
542 }
543 
544 char*
545 CWB::History::SetStageComment(char* Stage, char* Comment) {
546  if (!StageAllowed(Stage))
547  HistoryException(kBreak, "CWB::History::SetStageComment", "Stage %s not allowed", Stage);
548 
549  if (!StageAlreadyPresent(Stage))
550  HistoryException(kBreak, "CWB::History::SetStageComment", "Stage %s not present yet", Stage);
551 
552  return const_cast<HistoryStage*>(GetStage(Stage))->SetComment(Comment);
553 }
554 
555 char*
556 CWB::History::SetTypeComment(char* Stage, char* Type, char* Comment) {
557  if (!StageAllowed(Stage))
558  HistoryException(kBreak, "CWB::History::SetTypeComment", "Stage %s not allowed", Stage);
559 
560  if (!StageAlreadyPresent(Stage))
561  HistoryException(kBreak, "CWB::History::SetTypeComment", "Stage %s not present yet", Stage);
562 
563  return const_cast<HistoryStage*>(GetStage(Stage))->SetTypeComment(Type, Comment);
564 }
565 
566 char*
568  if (!StageAllowed(Stage))
569  HistoryException(kBreak, "CWB::History::GetStageComment", "Stage %s not allowed", Stage);
570 
571  if (!StageAlreadyPresent(Stage))
572  HistoryException(kBreak, "CWB::History::GetStageComment", "Stage %s not present", Stage);
573 
574  return const_cast<HistoryStage*>(GetStage(Stage))->GetComment();
575 }
576 
577 char*
578 CWB::History::GetTypeComment(char* Stage, char* Type) {
579  if (!StageAllowed(Stage))
580  HistoryException(kBreak, "CWB::History::GetTypeComment", "Stage %s not allowed", Stage);
581 
582  if (!StageAlreadyPresent(Stage))
583  HistoryException(kBreak, "CWB::History::GetTypeComment", "Stage %s not present", Stage);
584 
585  return const_cast<HistoryStage*>(GetStage(Stage))->GetTypeComment(Type);
586 }
587 
590  int i;
591 
592  this->SortOrder = SortOrder;
593  for (i = 0; i < StageList.GetSize(); i++) {
594  static_cast<HistoryStage*>(StageList.At(i))->SetSortOrder(SortOrder);
595  }
596  return this->SortOrder;
597 }
598 
601  return this->SortOrder;
602 }
603 
604 bool
606  if (SortOrder == InsertionOrder) return true;
607  else return false;
608 }
609 
610 bool
612  if (SortOrder == ElementDate) return true;
613  else return false;
614 }
615 
616 bool
618  if (SortOrder == Alphabetical) return true;
619  else return false;
620 }
621 
622 bool
624  int i;
625 
626  AscendingOrder = true;
627  for (i = 0; i < StageList.GetSize(); i++) {
628  static_cast<HistoryStage*>(StageList.At(i))->SetAscendingSortOrder();
629  }
630  return AscendingOrder;
631 }
632 
633 bool
635  int i;
636 
637  AscendingOrder = false;
638  for (i = 0; i < StageList.GetSize(); i++) {
639  static_cast<HistoryStage*>(StageList.At(i))->SetDescendantSortOrder();
640  }
641  return AscendingOrder;
642 }
643 
644 bool
646  return AscendingOrder;
647 }
648 
649 bool
651  return !AscendingOrder;
652 }
653 
654 void
656  int i;
657 
659  for (i = 0; i < StageList.GetSize(); i++) {
660  static_cast<HistoryStage*>(StageList.At(i))->Sort();
661  }
662 }
663 
664 TTimeStamp
666  TTimeStamp CreationTT(CreationDate_Sec, CreationDate_NSec);
667 
668  return CreationTT;
669 }
670 
671 TTimeStamp
673  if (!StageAllowed(Stage))
674  HistoryException(kBreak, "CWB::History::GetCreationDate", "Stage %s not allowed", Stage);
675 
676  if (!StageAlreadyPresent(Stage))
677  HistoryException(kBreak, "CWB::History::GetCreationDate", "Stage %s not present yet", Stage);
678 
679  return const_cast<HistoryStage*>(GetStage(Stage))->GetCreationTimeStamp();
680 }
681 
682 void
684  HistoryModify = false;
687 }
688 
689 void
691 }
692 
693 const CWB::HistoryStage*
695  int i;
696  char* StrApp;
697 
698  for (i = 0; i < StageList.GetSize(); i++) {
699  HistoryStage* tmpStage = static_cast<HistoryStage*>(StageList.At(i));
700  StrApp = tmpStage->GetName();
701  if (strcmp(StrApp, Name) == 0) {
702  delete StrApp;
703  return tmpStage;
704  }
705  delete StrApp;
706  }
707  return NULL;
708 }
709 
710 bool
711 CWB::History::DuplicateNames(char** NameList, int NameNumber) {
712  int i, j;
713 
714  for (i = 0; i < NameNumber; i++) {
715  for (j = i + 1; j < NameNumber; j++) {
716  if (strcmp(NameList[i], NameList[j]) == 0) return true;
717  }
718  }
719  return false;
720 }
721 
722 void
723 CWB::History::WriteToFile(char* FileName, bool SummaryOnly) {
724  char *StrApp1, *StrApp2, tmpStr[256];
725  int i, j, length;
726  TDatime* TimePtr;
727 
728  ofstream OutFile(FileName, ios::out);
729 
730  if (OutFile.fail()) HistoryException(kBreak, "CWB::History::WriteToFile", "Error opening output file");
731 
732  Sort();
733 
734  for (i = 0; i < StageList.GetSize(); i++) {
735  TDatime tmpTime(static_cast<HistoryStage*>(StageList.At(i))->GetDate(),
736  static_cast<HistoryStage*>(StageList.At(i))->GetTime());
737 
738  StrApp1 = static_cast<HistoryStage*>(StageList.At(i))->GetName();
739  memset(tmpStr, '*', HEADER_WIDTH);
740  tmpStr[HEADER_WIDTH] = 0;
741  length = strlen(StrApp1);
742  tmpStr[(HEADER_WIDTH - length) / 2 - 1] = ' ';
743  for (j = 0; j < length; j++) tmpStr[(HEADER_WIDTH - length) / 2 + j] = StrApp1[j];
744  tmpStr[(HEADER_WIDTH + length) / 2] = ' ';
745  /*
746  sprintf(tmpStr, "Stage Name: %s - Date: %i/%i/%i - Time: %i:%i:%i\n", StrApp1, tmpTime.GetDay(), tmpTime.GetMonth(),
747  tmpTime.GetYear(), tmpTime.GetHour(), tmpTime.GetMinute(), tmpTime.GetSecond());
748  */
749  OutFile << tmpStr << endl;
750  delete StrApp1;
751  StrApp1 = static_cast<HistoryStage*>(StageList.At(i))->GetComment();
752  //if (StrApp1 != NULL) {
753  if (strlen(StrApp1) > 0) {
754  OutFile << StrApp1 << endl;
755  delete StrApp1;
756  }
757  else {
758  sprintf(tmpStr, "Date: %i/%i/%i - Time: %i:%i:%i", tmpTime.GetDay(), tmpTime.GetMonth(),
759  tmpTime.GetYear(), tmpTime.GetHour(), tmpTime.GetMinute(), tmpTime.GetSecond());
760  OutFile << tmpStr << endl;
761  }
762  memset(tmpStr, '*', HEADER_WIDTH);
763  tmpStr[HEADER_WIDTH + 1] = 0;
764  OutFile << tmpStr << endl;
765 
766  if (!SummaryOnly) {
767  if (static_cast<HistoryStage*>(StageList.At(i))->GetHistorySize() > 0) {
768  sprintf(tmpStr, "Stage's History:");
769  OutFile << tmpStr << endl;
770 
771  for (j = 0; j < static_cast<HistoryStage*>(StageList.At(i))->GetHistorySize(); j++) {
772  StrApp2 = static_cast<HistoryStage*>(StageList.At(i))->GetHistoryEntryType(j);
773  OutFile << StrApp2 << ": " << endl;
774  delete StrApp2;
775  StrApp2 = static_cast<HistoryStage*>(StageList.At(i))->GetHistoryEntry(j);
776  OutFile << StrApp2 << endl;
777  delete StrApp2;
778  }
779  }
780 
781  if (static_cast<HistoryStage*>(StageList.At(i))->GetLogSize() > 0) {
782  sprintf(tmpStr, "Stage's Logs:");
783  OutFile << tmpStr << endl;
784 
785  static_cast<HistoryStage*>(StageList.At(i))->SortLogs();
786  for (j = 0; j < static_cast<HistoryStage*>(StageList.At(i))->GetLogSize(); j++) {
787  TimePtr = static_cast<HistoryStage*>(StageList.At(i))->GetLogEntryDatime(j);
788  OutFile << TimePtr->GetDay() << "/" << TimePtr->GetMonth() << "/" << TimePtr->GetYear() << " - ";
789  OutFile << TimePtr->GetHour() << ":" << TimePtr->GetMinute() << ":" << TimePtr->GetSecond() << " ";
790  delete TimePtr;
791  StrApp2 = static_cast<HistoryStage*>(StageList.At(i))->GetLogEntry(j);
792  OutFile << StrApp2 << endl;
793  delete StrApp2;
794  }
795  }
796  }
797  }
798  OutFile << endl << endl;
799  OutFile.close();
800 }
801 
802 int
804  char* StrApp;
805  int Position = -1;
806 
807  for (int i = 0; i < StageList.GetSize(); i++) {
808  StrApp = static_cast<HistoryStage*>(StageList.At(i))->GetName();
809  if (strcmp(StrApp, Name) == 0) {
810  Position = i;
811  }
812  }
813  return Position;
814 }
815 
816 void CWB::History::Streamer(TBuffer &R__b)
817 {
818  // Stream an object of class History.
819  TDatime CreationDatime;
820  TTimeStamp CreationTT;
821 
822  UInt_t R__s, R__c;
823  if (R__b.IsReading()) {
824  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
825  TObject::Streamer(R__b);
826  StageNames.Streamer(R__b);
827  TypeNames.Streamer(R__b);
828  StageList.Streamer(R__b);
829  FilePrefix.Streamer(R__b);
830  if (R__v > 1) {
831  R__b >> HistoryModify;
832  R__b >> (Int_t&)SortOrder;
833  R__b >> AscendingOrder;
834  if (R__v == 1) {
835  CreationDatime.Streamer(R__b);
836  CreationTT.Set(CreationDatime.GetYear(), CreationDatime.GetMonth(), CreationDatime.GetDay(), CreationDatime.GetHour(), CreationDatime.GetMinute(), CreationDatime.GetSecond(), 0, true, 0);
837  CreationDate_Sec = CreationTT.GetSec();
838  CreationDate_NSec = CreationTT.GetNanoSec();
839  }
840  else {
841  R__b >> CreationDate_Sec;
842  R__b >> CreationDate_NSec;
843  R__b.CheckByteCount(R__s, R__c, CWB::History::IsA());
844  }
845  }
846  else {
847  HistoryModify = false;
850  CreationDate_Sec = CreationTT.GetSec();
851  CreationDate_NSec = CreationTT.GetNanoSec();
852  }
853  } else {
854  R__c = R__b.WriteVersion(CWB::History::IsA(), kTRUE);
855  TObject::Streamer(R__b);
856  StageNames.Streamer(R__b);
857  TypeNames.Streamer(R__b);
858  StageList.Streamer(R__b);
859  FilePrefix.Streamer(R__b);
860  R__b << HistoryModify;
861  R__b << (Int_t)SortOrder;
862  R__b << AscendingOrder;
863  R__b << CreationDate_Sec;
864  R__b << CreationDate_NSec;
865  R__b.SetByteCount(R__c, kTRUE);
866  }
867 }
868 
869 void
870 CWB::History::HistoryException(int type, const char *location, const char *msgfmt, ...) {
871  cout << location << " " << msgfmt << endl;
872  exit(1);
873 }
874 
bool IsSortOrderAlphabetical()
Definition: History.cc:617
bool IsSortOrderInsertion()
Definition: History.cc:605
void DumpToROOTFile(char *FileName=NULL)
Definition: History.cc:408
char * RemoveStage(char *StageName)
Definition: History.cc:477
bool SetDescendantSortOrder()
#define DEFAULT_SORT_ORDER
bool IsSortOrderDate()
Definition: History.cc:611
bool HistoryModify
Definition: History.hh:145
bool DuplicateNames(char **NameList, int NameNumber)
Definition: History.cc:711
bool GetDescendantSortOrder()
Definition: History.cc:650
long CreationDate_Sec
Definition: History.hh:149
SortOrderType
bool SetDescendantSortOrder()
Definition: History.cc:634
TString("c")
bool TypeAllowed(char *Name)
Definition: History.cc:127
TDatime * GetHistoryDatime(char *StageName, char *Type)
Definition: History.cc:292
void HistoryException(int type, const char *location, const char *msgfmt,...)
Definition: History.cc:870
ofstream out
Definition: cwb_merge.C:214
SortOrderType SetSortOrder(SortOrderType SortOrder)
bool GetHistoryModify()
Definition: History.cc:459
SortOrderType SortOrder
Definition: History.hh:146
void Destroy()
Definition: History.cc:690
long CreationDate_NSec
Definition: History.hh:150
char * RemoveType(char *TypeName)
Definition: History.cc:522
int j
Definition: cwb_net.C:28
i drho i
void SetStageNames(char **StageNames, int StageNumber)
Definition: History.cc:135
#define HEADER_WIDTH
Definition: History.hh:49
tlive_fix Write()
char * GetStageComment(char *Stage)
Definition: History.cc:567
void Print()
Definition: History.cc:315
virtual void Browse(TBrowser *b)
Definition: History.cc:310
char * GetFilePrefix()
Definition: History.cc:268
char * GetLog(char *Stage, int index)
Definition: History.cc:304
int GetLogSize(char *Stage)
Definition: History.cc:298
void AddLog(char *LogMsg, TDatime *Time=NULL)
char fname[1024]
TList * GetStageNames()
Definition: History.cc:427
char * SetStageComment(char *Stage, char *Comment=NULL)
Definition: History.cc:545
bool StageAlreadyPresent(char *Name)
Definition: History.cc:107
bool GetAscendingSortOrder()
Definition: History.cc:645
TList * GetTypeNames()
Definition: History.cc:440
TList StageNames
Definition: History.hh:139
bool SetHistoryModify(bool Replace=true)
Definition: History.cc:453
bool SetAscendingSortOrder()
bool AscendingOrder
Definition: History.hh:147
char * SetTypeComment(char *Stage, char *Type, char *Comment=NULL)
Definition: History.cc:556
TObjString FilePrefix
Definition: History.hh:143
wavearray< int > index
double fabs(const Complex &x)
Definition: numpy.cc:55
int GetStagePosition(char *Name)
Definition: History.cc:803
bool StageAllowed(char *Name)
Definition: History.cc:99
void AddHistory(char *Type, char *History, char *Comment=NULL, bool Replace=false)
void AddLog(char *Stage, char *Log, TDatime *Time=NULL)
Definition: History.cc:187
bool NameAllowed(char *Name)
Definition: History.cc:122
strcpy(RunLabel, RUN_LABEL)
bool SetAscendingSortOrder()
Definition: History.cc:623
#define DEFAULT_ASCENDING
History(char **StageNames=NULL, int StageNumber=0, char **TypeNames=NULL, int TypeNumber=0, char *FilePrefix=NULL, bool HistoryModify=false)
Definition: History.cc:43
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
void SetTypeNames(char **TypeNames, int TypeNumber)
Definition: History.cc:159
char * AddType(char *TypeName)
Definition: History.cc:505
void DumpToTextFile(char *FileName=NULL)
Definition: History.cc:395
char * GetLogEntry(int index)
SortOrderType GetSortOrder()
Definition: History.cc:600
SortOrderType SetSortOrder(SortOrderType SortOrder)
Definition: History.cc:589
char * GetTypeComment(char *Stage, char *Type)
Definition: History.cc:578
void SetFilePrefix(char *FilePrefix)
Definition: History.cc:263
char * GetHistory(char *StageName, char *Type)
Definition: History.cc:273
const CWB::HistoryStage * GetStage(char *Name)
Definition: History.cc:694
void PrintSummary()
Definition: History.cc:355
void WriteToFile(char *FileName, bool SummaryOnly=false)
Definition: History.cc:723
TTimeStamp GetCreationTimeStamp()
Definition: History.cc:665
TList TypeNames
Definition: History.hh:140
double length
Definition: TestBandPass.C:18
Type
Definition: FrDisplay.cc:123
void Init()
Definition: History.cc:683
void AddHistory(char *Stage, char *Type, char *History, TDatime *Time=NULL)
Definition: History.cc:225
void Sort()
Definition: History.cc:655
char * AddStage(char *StageName)
Definition: History.cc:464
exit(0)
TList StageList
Definition: History.hh:142