EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicRunAna.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicRunAna.cxx
1 //
2 // AYK (ayk@bnl.gov), 2015/07/15
3 //
4 // A trivial (for now) extension of FairRunAna class;
5 //
6 
7 #include <TRandom.h>
8 
9 #include <FairRuntimeDb.h>
10 #include <FairParRootFileIo.h>
11 
12 #include <FairEventHeader.h>
13 #include <FairMCEventHeader.h>
14 #include <FairTrajFilter.h>
15 
16 #include <EicRunAna.h>
17 
19 
20 // ---------------------------------------------------------------------------------------
21 
22 EicRunAna::EicRunAna(): mSeed(_SEED_DEFAULT_), mInitCallHappened(false), mEvStart(0), mEvEnd(0)
23  //, mEvCurrent(-1)
24 {
25  if (mInstance) {
26  Fatal("EicRunAna::EicRunAna()", "Singleton instance already exists.");
27  return;
28  } //if
29 
30  mInstance = this;
31 } // EicRunAna::EicRunAna()
32 
33 // ---------------------------------------------------------------------------------------
34 
35 void EicRunAna::SetInputFile(TString fname)
36 {
37  mInputFileName = fname;
38 
40 } // EicRunAna::SetInputFile()
41 
42 // ---------------------------------------------------------------------------------------
43 
45 {
46  FairRuntimeDb* rtdb = GetRuntimeDb();
47  FairParRootFileIo* parInput1 = new FairParRootFileIo();
48  parInput1->open(mInputFileName);
49 
50  rtdb->setFirstInput(parInput1);
51 
53 
54  mInitCallHappened = true;
55 } // EicRunAna::Init()
56 
57 // ---------------------------------------------------------------------------------------
58 
59 void EicRunAna::Run(Int_t NStart, Int_t NStop)
60 {
61  // This is indeed a clear hack;
62  if (mJanaPluginMode) return;
63 
64  //gRandom->SetSeed(mSeed);
65 
66  // Well, may want to use either {Init(), then Run()} or just {Run()}; avoid
67  // calling Init() twice;
68  //if (!mInitCallHappened) Init();
69 
70  //FairRunAna::Run(NStart, NStop);
71  RunCoreStart(NStart, NStop);
73  RunCoreFinish();
74 
75  // Yes, and get rid of this file as well;
76  //if (!access(_GPHYSI_DAT_, W_OK)) unlink(_GPHYSI_DAT_);
77 
78  // Yes, just exit; change the default behaviour if this ever becomes a problem;
79  // NB: can reach this point in a "standalone" mode only (not as a plugin);
80  // so terminate and exit ROOT session, for user convenience;
81  exit(0);
82 } // EicRunAna::Run()
83 
84 // ---------------------------------------------------------------------------------------
85 
86 void EicRunAna::RunCoreStart(Int_t Ev_start, Int_t Ev_end)
87 {
88  gRandom->SetSeed(mSeed);
89 
90  // Well, may want to use either {Init(), then Run()} or just {Run()}; avoid
91  // calling Init() twice;
92  if (!mInitCallHappened) Init();
93 
95 
96  //if ( fProofAnalysis ) {
97  //RunOnProof(Ev_start,Ev_end);
98  //return;
99  //}
100 
101  //if (fTimeStamps) {
102  //RunTSBuffers();
103  //} else if (fMixedInput) {
104  //RunMixed(Ev_start,Ev_end);
105  //} else {
106  {
107  //UInt_t tmpId =0;
108  // if (fInputFile==0) {
109  //if (!fInFileIsOpen) {
110  //DummyRun(Ev_start,Ev_end);
111  //return;
112  //}
113  if (Ev_end==0) {
114  if (Ev_start==0) {
115  Ev_end=Int_t((fRootManager->GetInChain())->GetEntries());
116  } else {
117  Ev_end = Ev_start;
118  if ( Ev_end > ((fRootManager->GetInChain())->GetEntries()) ) {
119  Ev_end = (Int_t) (fRootManager->GetInChain())->GetEntries();
120  }
121  Ev_start=0;
122  }
123  } else {
124  Int_t fileEnd=(fRootManager->GetInChain())->GetEntries();
125  if (Ev_end > fileEnd) {
126  //cout << "-------------------Warning---------------------------" << endl;
127  //cout << " -W FairRunAna : File has less events than requested!!" << endl;
128  //cout << " File contains : " << fileEnd << " Events" << endl;
129  //cout << " Requested number of events = " << Ev_end << " Events"<< endl;
130  //cout << " The number of events is set to " << fileEnd << " Events"<< endl;
131  //cout << "-----------------------------------------------------" << endl;
132  Ev_end = fileEnd;
133  }
134  }
135 
136  // Assign class instance variables;
137  mEvStart = Ev_start; mEvEnd = Ev_end; mEvCurrent = mEvStart-1;
138 
139  fRunInfo.Reset();
140  }
141 } // EicRunAna::RunCoreStart()
142 
144 {
145  if (++mEvCurrent == mEvEnd) return false;
146 
147  //for (int i=mEvStart; i< mEvEnd; i++) {
149  return true;
150 } // EicRunAna::RunCoreImportNextEvent()
151 
153 {
154  {
155  UInt_t tmpId =0;
156 
161  if (fRootManager->IsEvtHeaderNew()) {
162  tmpId = fMCHeader->GetRunID();
163  } else {
164  tmpId = fEvtHeader->GetRunId();
165  }
166  if ( tmpId != fRunId ) {
167  fRunId = tmpId;
168  if ( !fStatic ) {
169  Reinit( fRunId );
170  fTask->ReInitTask();
171  }
172  }
173  //FairMCEventHeader* header = (FairMCEventHeader*)fRootManager->GetObject("MCEventHeader.");
174  //std::cout << "WriteoutBufferData with time: " << fRootManager->GetEventTime();
176  fTask->ExecuteTask("");
177  fRootManager->Fill();
179  fTask->FinishEvent();
180 
182  if (NULL != FairTrajFilter::Instance()) {
184  }
185  //}
186  }
187 
188  //mEvCurrent++;
189  //return true;
190 } // EicRunAna::RunCoreProcessNextEvent()
191 
193 {
194  {
196  fTask->FinishTask();
197  if (fWriteRunInfo) {
199  }
201  fRootManager->Write();
202  }
203 
204  // Yes, and get rid of this file as well;
205  if (!access(_GPHYSI_DAT_, W_OK)) unlink(_GPHYSI_DAT_);
206 }
207 
208 // ---------------------------------------------------------------------------------------
209