FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGetEventTime.cxx
Go to the documentation of this file.
1 #include "FairGetEventTime.h"
2 
3 #include <iostream>
4 
5 // Root includes
6 #include "TBranch.h"
7 #include "TClonesArray.h"
8 #include "TParticlePDG.h"
9 #include "TROOT.h"
10 #include "TString.h"
11 #include "TTree.h"
12 
13 // framework includes
14 #include "FairFileSource.h"
15 #include "FairRootManager.h"
16 #include "FairRun.h"
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "FairTimeStamp.h"
20 
21 #include <fairlogger/Logger.h>
22 
23 // ----- Public method Init --------------------------------------------
25 {
26  if (fRunOnce == true) {
28  FairSource *source = ioman->GetSource();
29  if (source->GetSourceType() == Source_Type::kFILE) {
30  LOG(info) << "Event t0 times:";
31  for (int i = 0; i < source->CheckMaxEventNo(); i++) {
32  source->ReadEvent(i);
33  fEventTime.push_back(((FairFileSource *)source)->GetEventTime());
34  LOG(info) << i << " : " << fEventTime.back();
35  }
36  }
37  fRunOnce = false;
38  LOG(debug) << "-I- FairGetEventTime: Initialization successful #Times: " << fEventTime.size();
39  }
40  return kSUCCESS;
41 }
42 
43 std::pair<int, double> FairGetEventTime::GetEvent(double simTime) const
44 {
45  auto lower = std::lower_bound(fEventTime.begin(), fEventTime.end(), simTime + 0.01);
46  int evtIndex = std::distance(fEventTime.begin(), lower) - 1;
47  double evtTime = -1.0;
48  if (evtIndex > -1) {
49  evtTime = fEventTime.at(evtIndex);
50  LOG(debug) << "FairTimebasedMCSource::RetrieveData " << simTime << " lower " << *lower << " at index "
51  << evtIndex + 1;
52  LOG(debug) << "GetEvent " << evtIndex << " time: " << evtTime << std::endl;
53  }
54  return std::make_pair(evtIndex, evtTime);
55 }
56 
virtual Int_t ReadEvent(UInt_t=0)=0
InitStatus
Definition: FairTask.h:33
virtual Source_Type GetSourceType()=0
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
std::pair< int, double > GetEvent(double simTime) const
FairSource * GetSource()
Singleton which reads in the event times stored in the event headers of each event in the Init() and ...
virtual Int_t CheckMaxEventNo(Int_t=0)
Definition: FairSource.h:50