HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hrunanalizer.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Manuel Sanchez
2 //*-- Modified : 13/19/1999 by Ilse Koenig
3 
4 //_HADES_CLASS_DESCRIPTION
5 ///////////////////////////////////////////////////////////////////////////////
6 //
7 // HRunAnalizer
8 //
9 // Reconstructor to analyze the event header and to retrieve the information
10 // stored in the Oracle database table hades_oper.runs:
11 // hld file name
12 // run id
13 // run start (date and time of first event)
14 // run stop (date and time of last event, must not be a stop event)
15 // total number of events in the file
16 // number of calibration events
17 // The information is written to an Ascii file (default name: "run_info.txt").
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20 
21 #include "hrunanalizer.h"
22 #include "hevent.h"
23 #include "heventheader.h"
24 #include "hades.h"
25 #include "hruntimedb.h"
26 #include <unistd.h>
27 
29 
30 HRunAnalizer::HRunAnalizer(Text_t *name,Text_t *title,Text_t *fileName)
31  : HReconstructor(name,title) {
32  // constructor
33  // default name of output file: run_info.txt
34  Char_t defaultFileName[]="run_info.txt";
35  fEventHeader=0;
36  fFirstRun=kTRUE;
37  fTotEvents=0;
38  fCalEvents=0;
39  if (!fileName) fileName=defaultFileName;
40  if (access(fileName,F_OK)==0) { //If file exists
41  fOut=fopen(fileName,"a");
42  } else {
43  fOut=fopen(fileName,"w");
44  writeHeader();
45  }
46 }
47 /*
48 // old code ... mase copy constructor private
49  HRunAnalizer::HRunAnalizer(HRunAnalizer &analizer) {
50  // copy constructor (not implemented!)
51  Error("HRunAnalizer","Copy constructor not defined");
52 }
53 */
55  // destructor
56  fclose(fOut);
57 }
58 
59 Int_t HRunAnalizer::execute(void) {
60  // reads the start event -> run id, run start
61  // extracts the date and time of the last event, the total number of
62  // events and the number of calibration events in the file
63  UInt_t fId=fEventHeader->getId();
64  if (fId==65538) { // start event
66  fFirstEvent=kFALSE;
67  } else {
70  if (fId!=65539) fTotEvents++; //no increment for stop event
71  if (fId==4) fCalEvents++;
72  }
73  return 0;
74 }
75 
76 Bool_t HRunAnalizer::init(void) {
78  fFirstRun=kTRUE;
79  fTotEvents=0;
80  fCalEvents=0;
81  return kTRUE;
82 }
83 
84 Bool_t HRunAnalizer::reinit(void) {
85  if (fFirstRun)
86  fFirstRun=kFALSE;
87  else
88  writeInfo(); // Write info of previous file.
89  fTotEvents=0;
90  fCalEvents=0;
91  fFirstEvent=kTRUE;
92  return kTRUE;
93 }
94 
95 Bool_t HRunAnalizer::finalize(void) {
96  if (!fFirstRun) writeInfo();
97  return kTRUE;
98 }
99 
105 }
106 
108  fprintf(fOut,"########################################################\n");
109  // fprintf(fOut,"#Run Id\t\tRun Start Time\tNr Events\tFile name\n");
110  fprintf(fOut,"#Run Id File name Total nr of events Nr of cal events\n");
111  fprintf(fOut,"# Run Start Run Stop Time\n");
112  fprintf(fOut,"########################################################\n");
113 }
114 
116  UInt_t db=fRunStartDate;
117  UInt_t tb=fRunStartTime;
118  UInt_t de=fRunStopDate;
119  UInt_t te=fRunStopTime;
120  fprintf(fOut,"%u %s %i %i\n",fRunId,fFileName.Data(),fTotEvents,fCalEvents);
121  fprintf(fOut," %02i-%02i-%4i::%02i:%02i:%02i %02i-%02i-%4i::%02i:%02i:%02i\n",
122  (db & 0xFF),1+( (db>>8) & 0xFF),1900+((db>>16) & 0xFF),
123  ((tb>>16) & 0xFF),( (tb>>8) & 0xFF),( tb & 0xFF),
124  (de & 0xFF),1+( (de>>8) & 0xFF),1900+((de>>16) & 0xFF),
125  ((te>>16) & 0xFF),( (te>>8) & 0xFF),( te & 0xFF));
126 }
127 
UInt_t fRunStopTime
Definition: hrunanalizer.h:18
UInt_t getId(void)
Definition: heventheader.h:134
HEventHeader * fEventHeader
Definition: hrunanalizer.h:11
void writeInfo(void)
Bool_t fFirstEvent
Definition: hrunanalizer.h:16
void extractStartInfo(void)
Int_t fCalEvents
Definition: hrunanalizer.h:13
HRuntimeDb * getRuntimeDb(void)
Definition: hades.h:111
HEvent *& getCurrentEvent(void)
Definition: hades.cc:422
Bool_t fFirstRun
Definition: hrunanalizer.h:14
UInt_t getDate(void)
Definition: heventheader.h:125
virtual HEventHeader * getHeader(void) const
Definition: hevent.h:36
ClassImp(HRunAnalizer) HRunAnalizer
Definition: hrunanalizer.cc:28
Text_t const * getCurrentFileName()
Definition: hruntimedb.h:53
UInt_t fRunStartDate
Definition: hrunanalizer.h:17
~HRunAnalizer(void)
Definition: hrunanalizer.cc:54
Int_t fTotEvents
Definition: hrunanalizer.h:12
TString fileName("be1834507002801.hld")
UInt_t fRunStopDate
Definition: hrunanalizer.h:18
UInt_t fRunId
Definition: hrunanalizer.h:19
Hades * gHades
Definition: hades.cc:1213
Bool_t reinit(void)
Definition: hrunanalizer.cc:84
TString fFileName
Definition: hrunanalizer.h:20
Int_t execute(void)
Definition: hrunanalizer.cc:59
UInt_t getEventRunNumber(void)
Definition: heventheader.h:131
Bool_t init(void)
Definition: hrunanalizer.cc:76
Bool_t finalize(void)
Definition: hrunanalizer.cc:95
void writeHeader(void)
UInt_t getTime(void)
Definition: heventheader.h:137
UInt_t fRunStartTime
Definition: hrunanalizer.h:17