NAIA  1.1.1
TSNaiaChain.cpp
Go to the documentation of this file.
1 
9 #include "Chain/TSNaiaChain.h"
11 
12 using namespace NAIA;
14 
15 TSNAIAChain::TSNAIAChain() : TChain("NAIAChain"), ev(nullptr), rti(nullptr), finfo(nullptr), mcfinfo(nullptr) {
16  rti_chain.SetName("RTI");
17  file_chain.SetName("FileInfo");
18 }
19 
21  if (ev)
22  delete ev;
23  if (rti)
24  delete rti;
25  if (finfo)
26  delete finfo;
27  if (mcfinfo)
28  delete mcfinfo;
29 }
30 
31 Int_t TSNAIAChain::Add(const char *name, Long64_t nentries) {
32  static constexpr std::string_view routineName{"TSNAIAChain::Add"};
33  auto logger = getLogger(routineName);
34 
35  Long64_t ntrees[3] = {0, 0, 0};
36 
37  ntrees[0] += TChain::Add(name, nentries);
38 
39  if (ntrees[0] > 0)
40  GetEntry(0);
41 
42  if (ev == nullptr) {
43  ev = new Event;
44  if (IsMC())
45  ev->SetMC(true);
46  ev->SetAllBranchAddress(this);
47  }
48 
49  ntrees[1] += rti_chain.Add(name, nentries);
50  if (ntrees[1] > 0) {
51  if (rti == nullptr && !IsMC()) {
52  rti = new RTIInfo;
53  rti_chain.SetBranchAddress("RTIInfo", &rti);
54  }
55  if (ntrees[1] != ntrees[0]) {
56  logger->warn("I found {} NAIAChain trees but only {} RTIInfo trees", ntrees[0], ntrees[1]);
57  }
58  rti_chain.BuildIndex("UTCTime");
59  AddFriend(&rti_chain);
60  }
61 
62  ntrees[2] += file_chain.Add(name, nentries);
63  if (finfo == nullptr) {
64  finfo = new FileInfo;
65  file_chain.SetBranchAddress("FileInfo", &finfo);
66  if (IsMC()) {
67  mcfinfo = new MCFileInfo;
68  file_chain.SetBranchAddress("MCFileInfo", &mcfinfo);
69  }
70  }
71  if (ntrees[2] != ntrees[0]) {
72  logger->warn("I found {} NAIAChain trees but only {} FileInfo trees", ntrees[0], ntrees[2]);
73  }
74 
75  GetEntry(0);
76 
77  return ntrees[0];
78 }
79 
80 bool TSNAIAChain::IsMC() { return GetBranch(MCTruthBase::BranchName.c_str()); }
81 
83  if (IsMC())
84  throw(std::runtime_error("UpdateEventRTIInfo called on a MC chain"));
85 
86  if (rti && rti->UTCTime == UT) {
87  return rti;
88  } else {
89  int ret = rti_chain.GetEntryWithIndex(UT);
90  return (ret > 0) ? rti : nullptr;
91  }
92 }
93 
94 Int_t TSNAIAChain::GetEntry(Long64_t entry, Int_t getall) {
95  int ret = TChain::GetEntry(entry, getall);
96  // if (ret > 0 && !IsMC() && ev) UpdateEventRTIInfo(ev->header.UTCTime);
97  return ret;
98 }
99 
100 Int_t TSNAIAChain::GetNextEntry(bool reset) {
101  Long64_t current = GetReadEntry();
102  if (reset)
103  current = -1;
104  return GetEntry(++current);
105 }
106 
108  Long64_t Entry_num = GetEntryNumberWithIndex(run, event);
109  if (Entry_num < 0)
110  return nullptr;
111 
112  int ret = GetEntry(Entry_num);
113 
114  if (ret > 0)
115  return ev;
116  else
117  return nullptr;
118 }
NAIA::TSNAIAChain::TSNAIAChain
TSNAIAChain()
standard constructor
Definition: TSNaiaChain.cpp:15
NAIA::MCFileInfo
Container class for additional MC File information.
Definition: FileInfo.h:54
NAIA::Event::SetMC
void SetMC(bool isMC)
Set wether this is a MC event or not.
Definition: Event.h:86
NAIA::TSNAIAChain::rti
RTIInfo * rti
pointer to the current RTI info in memory
Definition: TSNaiaChain.h:49
NAIA::TSNAIAChain::GetEventWithRunEvent
Event * GetEventWithRunEvent(int run, int event)
load the requested entry in the chain and the corresponding (in time) RTIInfo
Definition: TSNaiaChain.cpp:107
NAIA::TSNAIAChain
TS NAIA Chain true TChain.
Definition: TSNaiaChain.h:38
NAIA::Event
Event object.
Definition: Event.h:20
NAIA::TSNAIAChain::finfo
FileInfo * finfo
pointer to the current FileInfo in memory
Definition: TSNaiaChain.h:51
NAIA::TSNAIAChain::rti_chain
TChain rti_chain
pointer to the chain of the RTI objects
Definition: TSNaiaChain.h:41
NAIA::FileInfo
Container class for processed File information.
Definition: FileInfo.h:23
NAIA::TSNAIAChain::UpdateEventRTIInfo
RTIInfo * UpdateEventRTIInfo(unsigned int UT)
load the RTIInfo object closer to chosen time
Definition: TSNaiaChain.cpp:82
NAIA
Definition: Event.h:13
NAIA::TSNAIAChain::mcfinfo
MCFileInfo * mcfinfo
pointer to the current MCFileInfo in memory
Definition: TSNaiaChain.h:53
NAIA::getLogger
auto getLogger(std::string_view fnName)
Create a new logger with a given function name.
Definition: Logging.h:20
NAIA::TSNAIAChain::Add
Int_t Add(const char *name, Long64_t nentries=kBigNumber) override
Add files to the chain (standard TChain syntax)
Definition: TSNaiaChain.cpp:31
NAIA::TSNAIAChain::~TSNAIAChain
~TSNAIAChain() override
standard destructor
Definition: TSNaiaChain.cpp:20
ClassImp
ClassImp(TSNAIAChain)
NAIA::RTIInfo
Container class for RTI info.
Definition: RTIInfo.h:33
NAIA::RTIInfo::UTCTime
unsigned int UTCTime
JMDC unix time (seconds since 1 Jan 1970)
Definition: RTIInfo.h:104
NAIA::Event::SetAllBranchAddress
void SetAllBranchAddress(TTree *tree)
Forwards this tree to all containers so that each one can create its own branch address for reading o...
Definition: Event.cpp:39
NAIA::TSNAIAChain::IsMC
bool IsMC()
checks if the current files are MC or data
Definition: TSNaiaChain.cpp:80
NAIA::MCTruthBase::BranchName
static const std::string BranchName
Definition: MCTruth.h:172
Logging.h
NAIA::TSNAIAChain::GetNextEntry
Int_t GetNextEntry(bool reset=false)
Loads the next event in the chain.
Definition: TSNaiaChain.cpp:100
TSNaiaChain.h
TSNaiaAChain class description.
NAIA::TSNAIAChain::GetEntry
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
load the requested entry in the chain and the corresponding (in time) RTIInfo
Definition: TSNaiaChain.cpp:94
NAIA::TSNAIAChain::ev
Event * ev
pointer to the current event in memory
Definition: TSNaiaChain.h:47
NAIA::TSNAIAChain::file_chain
TChain file_chain
pointer to the chain of th FileInfo objects
Definition: TSNaiaChain.h:43