HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseWriter.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseWriter.cxx
3 //
11 #include "HarpoAnalyseWriter.h"
12 #include "HarpoConfig.h"
13 #include "HarpoDetSet.h"
14 //#include "HarpoDetSet.h"
15 #include "HarpoEvent.h"
16 #include "HarpoDccEvent.h"
17 #include "HarpoFeminosEvent.h"
18 #include "Pmm2Event.h"
19 #include "HarpoSimEvent.h"
20 #include "HarpoRecoEvent.h"
21 
22 #include "TFile.h"
23 #include "TROOT.h"
24 
25 #include <cstdlib>
26 #include <cstring>
27 #include <cassert>
28 #include <iostream>
29 
30 ClassImp(HarpoAnalyseWriter)
31 
32 const int bufsize = 16000;
33 const int splitlevel = 2;
34 const int compress = 6; //default ???
35 
37  {
38  rootFile = NULL;
39  fNewFile = NULL;
40  fNewTree = NULL;
41  fRawBranch = NULL;
42  fNewNb = 0;
43  fDoAna = true;
44 
45  fEvtHdr = NULL ; // event header
46 
47  ULong_t ndet;
48  for (ndet = 0; ndet < gkNDetectors; ndet++)
49  fDetEvt[ndet] = NULL;
50  }
51 
53  {
54  // if (! fDoAna ) return;
55  ULong_t ndet; // number of detectors
57  HarpoDetEvent *devt;
58 
59  assert(hdr != NULL);
60  hdr->print();
61 
62  for (ndet = 0; ndet < gkNDetectors; ndet++) {
63  if (gHDetSet->isExist(ndet)) {
64  std::cout << "Print Det " << ndet << std::endl;
65  devt = fEvt->GetDetEvent(ndet);
66  devt->print();
67  std::cout << "** Class ["<< devt->ClassName() << "]" << std::endl;
68  }
69  }
70  }
71 
72 // Set pointer to new event for analyse, anlyse event , and delete
74 {
75  // if ( fDoAna && (event->GetHeader()->GetEvAnaStatus() < hAnaEventWrt) )
76  if ( (event->GetHeader()->GetEvAnaStatus() < hAnaEventWrt) )
77  return;
78 
79  Set(event);
80  process();
81 }
82 
84 {
85 
86  if(gHarpoDebug>1)
87  std::cout << "HarpoRunHeader = " << fRunHeader << std::endl;
88  //HarpoDetEvent *devt;
89  nEvents++;
90  if(gHarpoDebug>1){
91  Info("process()","Processing Event %ld",nEvents);
92  fEvt->print();
93  }
94 
95  // if (! fDoAna ) return;
96  // ULong_t ndet;
97 
98  if(nEvents%100 == 0)
99  Info("process()"," Processing Event %ld",nEvents);
100 
101  fEvtHdr = fEvt->GetHeader();
102  (void) fEvt->GetDccMap(0); // create map
103  (void) fEvt->GetDccMap(1); //
104  for (UInt_t ndet = 0; ndet < gkNDetectors; ndet++){
105  if (gHDetSet->isExist(ndet)){
106  if(gHarpoDebug>1)
107  Info("process()"," Get DetEvent %d",ndet);
108  fDetEvt[ndet] = fEvt->GetDetEvent(ndet);
109  if(!fDoAna && ndet == SIMDET)
110  ((HarpoSimEvent*)fDetEvt[ndet])->DeleteIonisationTracks();
111  // fDetEvt[1] = fEvt->GetDetEvent(1);
112  }
113  }
114  // Info("process","HasRecoEvent: %d",fEvt->HasRecoEvent());
115 
116  if(fEvt->HasRecoEvent())
118  fNewNb =+ fNewTree->Fill();
119  if(gHarpoDebug>0) Info("process","fNewNb = %d",fNewNb);
120  if(gHarpoDebug>1)
121  fRecoEvent->Summary();
122  if(gHarpoDebug>0)
123  Info("process()"," Tree Filled ");
124 
125 
126 
127 
128  if(gHConfig->GetSplit() != 0 && nEvents%gHConfig->GetSplit()==0){
129  Info("process","Splitting (evt %li)",nEvents);
130  Save();
131  // InitFile(Form("%s_%d.root",rootFile->Data(),fNfiles));
132  InitFile(Form("%s_%d.root",rootFile->Data(),fNfiles));
133  fNfiles++;
134  }
135 
136 
137  //gROOT->ls();
138 }
139 
140 
141 
143  {
145 
146  if(!fDoAna){
147  Info("HarpoAnalyseWriter","Do Not Save ionisation data");
148  // Info("HarpoAnalyseWriter","Do Not run analysis");
149  //return;
150  }
151 
153  if ( rootFile == NULL ) {
154  std::cout << gHConfig->GetProgramName() << " " <<
155  "No Root Output File name gived, use default" << std::endl;
156  rootFile = new TString("hraw");
157  }
158 
159  fNfiles = 0;
160  if(rootFile->EndsWith(".root")){
161  Ssiz_t pos = rootFile->Last('.');
162  rootFile->Remove(pos,5);
163  }
164  if(gHConfig->GetSplit()>0)
165  InitFile(Form("%s_0.root",rootFile->Data()));
166  else
167  InitFile(Form("%s.root",rootFile->Data()));
168  fNfiles++;
169  }
170 
171 void HarpoAnalyseWriter::InitFile(const char* fileName)
172 {
173 
174  // if (! fDoAna ) return;
176  // Dummy Event
178  fEvt = new HarpoEvent();
179  fEvtHdr = new HarpoEventHeader();
182 
183  fNewFile = new TFile(fileName,"RECREATE",
184  "Harpo ROOT file");
185  fNewFile->SetCompressionLevel(compress);
186  fNewTree = new TTree("HarpoTree","Harpo ROOT Tree");
187  fNewTree->SetAutoSave(); // autosave when 1 Gbyte written
188  fNewTree->SetAutoFlush(); // autosave when 1 Gbyte written
189  //TTree::SetBranchStyle(branchStyle);
190 
191  // fRawBranch = fNewTree->Branch("BRawEvent","HarpoEvent",
192  // &fEvt, bufsize,splitlevel);
193  fRawBranch = fNewTree->Branch("BRawEventHeader","HarpoEventHeader",
194  &fEvtHdr, 32000,99);
195  fRecoEvent = new HarpoRecoEvent();
196  fNewTree->Branch("RecoEvent","HarpoRecoEvent",
197  &fRecoEvent, 32000,99);
198  gHDetSet->print();
199  Long64_t trdr;
200  for (UInt_t ndet = 0; ndet < gkNDetectors; ndet++){
201  if (gHDetSet->isExist(ndet)){
202  trdr = gHConfig->GetDetRdrType(static_cast<HarpoDetType>(ndet)); // Det Reader instance type
203  HarpoDet dt(ndet);
204  if(gHarpoDebug>0) Info("Init()","Add Branch %d (%s)",ndet,dt.GetName());
205  switch(ndet){
206  case XDCC:
207  if (trdr == 0 ) {
208  std::cout << "Branch for T2K XDCC" << std::endl;
209  fDetEvt[ndet] = new HarpoDccEvent();
210  fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoDccEvent",
211  &fDetEvt[ndet], 16000,99);
212  }
213  else if (trdr == 1) {
214  std::cout << "Branch for MINOS XDCC" << std::endl;
215  fDetEvt[ndet] = new HarpoFeminosEvent();
216  fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoFeminosEvent",
217  &fDetEvt[ndet], 16000,99);
218  }
219  else {
220  std::cout << "UNKNOWN XDCC" << std::endl;
221  }
222  break;
223  case YDCC:
224  if (trdr == 0 ) {
225  std::cout << "Branch for T2K YDCC" << std::endl;
226  fDetEvt[ndet] = new HarpoDccEvent();
227  fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoDccEvent",
228  &fDetEvt[ndet], 16000,99);
229  }
230  else if (trdr == 1) {
231  std::cout << "Branch for MINOS YDCC" << std::endl;
232  fDetEvt[ndet] = new HarpoFeminosEvent();
233  fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoFeminosEvent",
234  &fDetEvt[ndet], 16000,99);
235  }
236  else {
237  std::cout << "UNKNOWN YDCC" << std::endl;
238  }
239  break;
240  case PMM2:
241  fDetEvt[ndet] = new Pmm2Event();
242  fRawBranch = fNewTree->Branch(dt.GetName(),"Pmm2Event",
243  &fDetEvt[ndet], 16000,99);
244  break;
245  // case TEMP_PRESSION,:
246  // fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoDccEvent",
247  // &fDetEvt[ndet], 16000,99);
248  // break;
249  case SIMDET:
250  fDetEvt[ndet] = new HarpoSimEvent();
251  fRawBranch = fNewTree->Branch(dt.GetName(),"HarpoSimEvent",
252  &fDetEvt[ndet], 16000,99);
253  break;
254  }
255  }
256 
257  }
258  }
259 
260 void HarpoAnalyseWriter::Save(char * /* mode */)
261 {
262  // if(!fDoAna) return;
263 
264  Info("Save","%s",fNewFile->GetName());
265 
266  fRunHeader->print();
267  fNewFile->cd();
268 
269  for (UInt_t ndet = 0; ndet < gkNDetectors; ndet++){
270  if (gHDetSet->isExist(ndet)){
271  HarpoDetHeader* hdr = fRunHeader->GetHeader(ndet);
272  std::cout << "Save Header " << ndet << " " << hdr << std::endl;
273  if(hdr) hdr->Write(Form("fDetHeader%d",ndet));
274  }
275  }
276  std::cout << "fRunHeader " << fRunHeader << std::endl;
277  fRunHeader->Write("fRunHeader");
278 
279 
280  fNewFile->Write();
281  fNewFile->Close();
282  printf("fNewFile %s closed %d bytes written\n", fNewFile->GetName(),fNewNb );
283 }
284 
A class hold HARPO run iformation.
void Save(char *mode=NULL)
virtual void print()
Definition: HarpoDetSet.cxx:43
Dcc Plane Y.
Definition: HarpoDet.h:20
const int bufsize
Bool_t isWriterEnabled()
Check if Writer Enabled.
Definition: HarpoConfig.h:168
TString * GetProgramName()
Get Program Name.
Definition: HarpoConfig.h:105
void print()
Definition: HarpoEvent.cxx:123
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
HarpoDetHeader * GetHeader(UInt_t ndet=XDCC)
A virtual class store event data for un detector.
Definition: HarpoDetEvent.h:32
Int_t GetEvAnaStatus()
Get Event Analise status.
TString * GetOutFile()
Get Output root file name.
Definition: HarpoConfig.h:98
const char * GetName() const
Definition: HarpoDet.h:33
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
Dcc Plane X.
Definition: HarpoDet.h:19
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
const int splitlevel
void InitFile(const char *name)
FullEvent Header not scecific to the detectors The class is ....
Base class for all Harpo Detectors.
Definition: HarpoDet.h:27
A class store HARPO row DCC event data and header. End provide access metods to the row data...
Definition: HarpoSimEvent.h:24
virtual void print()
A class store HARPO row FEMINOS event data and header. End provide access metods to the row data...
HarpoDetEvent * fDetEvt[gkNDetectors]
HarpoDetEvent * GetDetEvent(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:93
Bool_t fDoAna
Redefine empty default.
void ProcessEvent(HarpoEvent *event)
Data from Keller temperuture and pressure sensors.
Definition: HarpoDet.h:22
void Set(HarpoEvent *event)
HarpoEventHeader * fEvtHdr
void SetHeader(HarpoEventHeader *data)
Definition: HarpoEvent.cxx:75
void print() const
HarpoRecoEvent * fRecoEvent
stop event analysis, without writig
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
Long64_t GetDetRdrType(HarpoDetType nDet)
Return type of reader impementation for given Harpo Detector.
Unknown Detector.
Definition: HarpoDet.h:18
A class which write harpo events to ROOT Tree.
A class store HARPO raw PMM2 event buffer and header. End provide access metods to the row data...
Definition: Pmm2Event.h:19
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
A class store HARPO row event data and header. Provide access metods to the row event data...
Definition: HarpoEvent.h:29
HarpoRunHeader * fRunHeader
Definition: HarpoAnalyse.h:76
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoConfig * gHConfig
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
Bool_t HasRecoEvent()
Definition: HarpoEvent.h:50
Long64_t GetSplit()
Definition: HarpoConfig.h:93
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
const int compress
void print()
Mast be implemented, This method which do all job.
A class store HARPO EVENT : header and row data. Its provide also the methods for access to this data...
Definition: HarpoDccEvent.h:22