HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoDetReader.cxx
Go to the documentation of this file.
1 //
2 // File HarpoDetReader.cxx
3 //
9 #include "HarpoDetReader.h"
10 #include "HarpoDet.h"
11 #include "HarpoDebug.h"
12 #include <TSystem.h>
13 
14 #include <climits>
15 #include <cstdio>
16 #include <arpa/inet.h>
17 //#include <cstdlib>
18 //#include <cstring>
19 #include <iostream>
20 
21 ClassImp(HarpoDetReader)
22 
23 
29 {
30  if(gHarpoDebug>0) Info("HarpoDetReader","Creating");
31 
32  fRunNo = 0;
33  fDet = -1;
34 
35  fInFile = (TString *) NULL;
36  //fIn = (FILE *) NULL;
37  fNevts = 0;
38 
39  // fNewFile = (TFile *) NULL;
40  // fNewNb = 0;
41 
42  fEvent = (HarpoDetEvent *) NULL;
43  fRunHeader = (HarpoDetHeader *) NULL;
44 
45  fMaxEvents = LONG_MAX;
46  fPrevTimeStamp = 0;
47  isEventSaved = false;
48 
49 }
50 
52 
57  // Config Function
58  fRunNo = cfg->GetRunNo();
59  fInFile = cfg->GetInFile(0);
60  //fIn = (FILE *) NULL;
61  fNevts = 0;
62  fMaxEvents = cfg->GetMaxEvents();
63 
64  // fNewNb = 0;
65 
66  fEvent = (HarpoDetEvent *) NULL;
67  fRunHeader = (HarpoDetHeader *) NULL;
68 
69  fPrevTimeStamp = 0;
70  isEventSaved = false;
71 }
72 
74 {
75  //std::fclose(fIn);
76  delete fRunHeader;
77 }
78 
79 void HarpoDetReader::SetDetFile(TString *name)
80 {
81  fInFile = name;
82 }
83 
84 // void HarpoDetReader::SetRootFile(TString *name)
85 // {
86 // fNewFileName = name;
87 // fNewFile = new TFile(name->Data(),"RECREATE","HARPO Det Events");
88 // }
89 
91 {
92  if(gHarpoDebug>1) Info("GetEvent","%p",(void *)fEvent);
93  return fEvent;
94 }
95 
97 {
98  if(gHarpoDebug>1) Info("GetDetHeader"," ");
99  return fRunHeader;
100 }
101 
103 
106 // Bool_t HarpoDetReader::Init()
107 // {
108  // const char * fn = fInFile->Data();
109  // std::cout << " Init " << fn << std::endl;
110  // if ( fInFile->BeginsWith("/" )) { // full path
111  // if ( gSystem->AccessPathName(fn,kReadPermission) ) {
112  // perror("Det File access");
113  // return false;
114  // }
115  // } else {
116  // if ( gSystem->AccessPathName(fn,kReadPermission) ) { // file not exist
117  // // TODO
118  // // TString *DataDir = gHDetCfg->GetDataDir();
119  // // Not a best way but i can't use config hire
120  // TString DataDir(gSystem->Getenv("HARPO_DATA_DIR"));
121 
122  // if ( ! DataDir.EndsWith("/") ) DataDir.Append("/");
123  // fInFile->Prepend(DataDir);
124  // fn = fInFile->Data();
125  // if ( gSystem->AccessPathName(fn,kReadPermission) ) {
126  // perror("Det File access");
127  // return false;
128  // }
129  // }
130  // }
131 
132  // std::cout << " Guessed " << fn << std::endl;
133 
134  // fIn = std::fopen(fn,"r");
135  // if ( fIn != NULL ) {
136  // fRunHeader = new HarpoDetHeader(fIn);
137  // fRunHeader->check();
138  // return fRunHeader->check();
139  // } else {
140  // perror("Det File open");
141  // return false;
142  // }
143 // return false;
144 // }
145 
146 
147 Bool_t HarpoDetReader::Find(Long_t eventNo)
148 {
149  Long_t cnt=0;
150  Long_t maxevents = fMaxEvents;
151  Bool_t found = false;
152  HarpoDetEvent *evt;
153  if(gHarpoDebug>0) Info("Find","%ld",eventNo);
154 
155  while (NextEvent()) {
156  evt = GetEvent(); // Read Event
157  if(gHarpoDebug>1) Info("Find val","%ld in evt %d",
158  eventNo,(evt->GetHeader())->eventNumb);
159  if ((evt->GetHeader())->eventNumb == eventNo) {
160  found = true;
161  break;
162  }
163  SkipEvent();
164  if (++cnt >= maxevents) break;
165  }
166  return found;
167 }
168 
170 {
171  if(gHarpoDebug>1) {
172  HarpoDet dt(fDet);
173  Info("SkipEvent","%s, evt %ld",dt.GetName(), fNevts);
174  }
175  //isEventSaved = false;
176  HarpoDetEvent *evt = GetEvent(); // We need read event data
177  if ( evt != NULL ) delete evt ; // We will not process this event,
178  // return NULL on read arror
179 }
180 
182 {
183  fSaveEvent = fEvent;
184  fEvent = NULL;
185  isEventSaved = true;
186  if(gHarpoDebug>1) {
187  HarpoDet dt(fDet);
188  Info("PushBack","%s (%ld), evt %ld",dt.GetName(), fDet, fNevts);
189  }
190 }
A class hold HARPO run iformation.
virtual ~HarpoDetReader()
Long64_t GetRunNo()
Set Run Number.
Definition: HarpoConfig.h:127
A virtual class store event data for un detector.
Definition: HarpoDetEvent.h:32
const char * GetName() const
Definition: HarpoDet.h:33
TString * GetInFile(Int_t idet)
Get Input file name for detector.
Definition: HarpoConfig.h:96
HarpoDetHeader * GetDetHeader()
Base class for all Harpo Detectors.
Definition: HarpoDet.h:27
virtual void PushBack()
Skeeping not "intersting" event.
ULong_t fPrevTimeStamp
A virtual base class for all HARPO detectors readers.
virtual HarpoDetEvent * GetEvent()
HarpoDetEvent * fSaveEvent
HarpoDetHeader * fRunHeader
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
TString * fInFile
virtual Bool_t NextEvent()=0
virtual const EventHeader_t * GetHeader() const
Definition: HarpoDetEvent.h:38
void SetDetFile(TString *name)
Bool_t Find(Long_t eventNo)
Init method : Open in/out files and check run header signature.
HarpoDetEvent * fEvent
virtual void SkipEvent()
Read next event from raw file.
A class which keeps track of the entire configuration of the analysis.
Definition: HarpoConfig.h:50
Long64_t GetMaxEvents()
Get Max Event for prosess.
Definition: HarpoConfig.h:118