4 #include "TTreeIndex.h"
7 #include <unordered_map>
12 switch (m_accessMode) {
13 case AccessMode::Read:
14 m_data.chain =
new TChain(
"NAIAChain");
15 m_rti.chain =
new TChain(
"RTI");
16 m_file.chain =
new TChain(
"FileInfo");
18 case AccessMode::Write:
19 m_data.tree =
new TTree(
"NAIAChain",
"AMS-Italy ntuple tree");
20 m_rti.tree =
new TTree(
"RTI",
"RTIInfo tree");
21 m_file.tree =
new TTree(
"FileInfo",
"FileInfo tree");
24 throw std::runtime_error(
"SingleTreeChain::GetEntries - Unrecognized access mode");
29 static int currentTree = -1;
34 spdlog::trace(
"Event {} -> CHANGING TREE", iEv);
49 static unsigned int lastSec = 0;
60 static unsigned int lastRun = 0;
71 static const std::string &fnName =
"SingleTreeChain::GetRTITree";
78 logger->error(
"Not supported in Write mode");
81 throw std::runtime_error(
"SingleTreeChain::GetRTITree - Unrecognized access mode");
87 static const std::string &fnName =
"SingleTreeChain::GetFileInfoTree";
94 logger->error(
"Not supported in Write mode");
97 throw std::runtime_error(
"SingleTreeChain::GetFileInfoTree - Unrecognized access mode");
117 throw std::runtime_error(
"SingleTreeChain::Add - Unrecognized access mode");
128 throw std::runtime_error(
"SingleTreeChain::Fill - Unrecognized access mode");
139 throw std::runtime_error(
"SingleTreeChain::FillRTI - Unrecognized access mode");
150 throw std::runtime_error(
"SingleTreeChain::FillFileInfo - Unrecognized access mode");
161 throw std::runtime_error(
"SingleTreeChain::GetEntries - Unrecognized access mode");
176 throw std::runtime_error(
"SingleTreeChain::Print - Unrecognized access mode");
190 m_rti.
tree->BuildIndex(
"RTIInfo.UTCTime");
193 m_data.
tree->BuildIndex(
"HeaderData.Run",
"HeaderData.EventNo");
196 throw std::runtime_error(
"SingleTreeChain::Write - Unrecognized access mode");
224 throw std::runtime_error(
"SingleTreeChain::SetupBranches - Unrecognized access mode");
228 static const std::unordered_map<std::string, std::function<void(Event &)>>
evDisablers = {
229 {
"EventSummary", [](
Event &event) {
event.evSummary.DisableIO(); }},
230 {
"DAQ", [](
Event &event) {
event.daq.DisableIO(); }},
231 {
"TofBase", [](
Event &event) {
event.tofBase.DisableIO(); }},
232 {
"TofPlus", [](
Event &event) {
event.tofPlus.DisableIO(); }},
233 {
"TofBaseStandalone", [](
Event &event) {
event.tofBaseSt.DisableIO(); }},
234 {
"TofPlusStandalone", [](
Event &event) {
event.tofPlusSt.DisableIO(); }},
235 {
"EcalBase", [](
Event &event) {
event.ecalBase.DisableIO(); }},
236 {
"EcalPlus", [](
Event &event) {
event.ecalPlus.DisableIO(); }},
237 {
"TtrTrackBase", [](
Event &event) {
event.trTrackBase.DisableIO(); }},
238 {
"TtrTrackPlus", [](
Event &event) {
event.trTrackPlus.DisableIO(); }},
239 {
"TrdKBase", [](
Event &event) {
event.trdKBase.DisableIO(); }},
240 {
"TrdKBaseStandalone", [](
Event &event) {
event.trdKBaseSt.DisableIO(); }},
241 {
"RichBase", [](
Event &event) {
event.richBase.DisableIO(); }},
242 {
"RichPlus", [](
Event &event) {
event.richPlus.DisableIO(); }},
243 {
"UnbExtHitBase", [](
Event &event) {
event.extHitBase.DisableIO(); }},
244 {
"MCTruthBase", [](
Event &event) {
event.mcTruthBase.DisableIO(); }},
245 {
"MCTruthPlus", [](
Event &event) {
event.mcTruthPlus.DisableIO(); }},
249 const std::string &exclBranches) {
250 static const std::string &fnName =
"SingleTreeChain::CreateSkimTree";
253 auto outFile = std::make_unique<TFile>(filename.c_str(),
"recreate");
256 if (!exclBranches.empty()) {
257 for (
const std::string &container :
TokenizeString(exclBranches,
';')) {
259 logger->info(
"Disabling container {}", container);
262 logger->error(
"Unknown container {}", container);
268 newChain->m_event.MirrorBranches(newChain->m_data.tree,
m_event);
269 newChain->m_rti.tree->Branch(
"RTIInfo", &
m_rtiInfo);
270 newChain->m_file.tree->Branch(
"FileInfo", &
m_fileInfo);
272 newChain->m_file.tree->Branch(
"MCFileInfo", &
m_fileInfoMC);
274 return {std::move(outFile), std::move(newChain),
this};
278 static const std::string &fnName =
"SingleTreeChain::SetEntryList";
283 logger->error(
"TEntryList not supported in Write mode");
SkimTreeHandle< SingleTreeChain > CreateSkimTree(const std::string &filename, const std::string &exclBranches)
Create a new SkimTree handle object and setup all internal branches.
Event & GetEvent(unsigned long long iEv)
Get the Event object.
Helper class to ease skimming operations.
TChain * GetRTITree()
Get the RTIInfo TTree object.
void SetDirectory(TDirectory *directory)
Set the TDirectory for the trees.
MCFileInfo * m_fileInfoMCPtr
needed for SetBranchAddress
void BranchAll(TTree *tree)
Forwards this tree to all containers so that each one can create its own branch.
int FillRTI()
Fill the RTI data.
const FileInfo & GetEventFileInfo()
Get the FileInfo object associated with this event.
void SetAllBranchAddress(TTree *tree)
Forwards this tree to all containers so that each one can create its own branch address for reading o...
Event & GetEventWithIndex(unsigned int run, unsigned int eventno)
Get the Event object using the underlying index.
TChain * GetFileInfoTree()
Get the FileInfo TTree object.
void SetEntryList(TEntryList *entryList, Option_t *option)
Set an entry list for this tree.
SingleTreeChain(AccessMode mode=AccessMode::Read)
Construct a new Single Tree Chain object.
static const std::unordered_map< std::string, std::function< void(Event &)> > evDisablers
int Write()
Write the trees to disk.
void SetEventNumber(unsigned long long iEv)
Set the Event Number for all containers. The corresponding entry will be loaded upon the first read r...
int Add(const std::string &filePath)
Add a file to the chain.
SingleTreeChain class description.
Container class for processed File information.
const RTIInfo & GetEventRTIInfo()
Get the RTIInfo object associated with this event.
SingleTreeChain::EventItr end(SingleTreeChain &chain)
std::vector< std::string > TokenizeString(const std::string &input, const char separator)
Utility function that splits a string according to the provided separator.
AccessMode
Simple enum to express whether we are in read or write mode.
void SetMC(bool isMC)
Set wether this is a MC event or not.
RTIInfo * m_rtiInfoPtr
needed for SetBranchAddress
int FillFileInfo()
Fill the FileInfo data.
unsigned long int GetEntries()
Get the total number of events.
auto getLogger(const std::string &fnName)
Create a new logger with a given function name.
int Fill()
Fill the event data.
void SetupBranches(bool isMC=false)
Set all branch addresses for reading operations, or create all branches for writing operation...
Container class for RTI info.
void Print()
Print all the chains.