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;
52 throw(std::runtime_error(
"GetEventRTIInfo called on a MC chain"));
63 static unsigned int lastRun = 0;
74 static unsigned int lastRun = 0;
77 throw(std::runtime_error(
"GetEventMCFileInfo called on a non-MC chain"));
88 static const std::string &fnName =
"SingleTreeChain::GetRTITree";
95 logger->error(
"Not supported in Write mode");
98 throw std::runtime_error(
"SingleTreeChain::GetRTITree - Unrecognized access mode");
103 static const std::string &fnName =
"SingleTreeChain::GetFileInfoTree";
110 logger->error(
"Not supported in Write mode");
113 throw std::runtime_error(
"SingleTreeChain::GetFileInfoTree - Unrecognized access mode");
133 throw std::runtime_error(
"SingleTreeChain::Add - Unrecognized access mode");
144 throw std::runtime_error(
"SingleTreeChain::Fill - Unrecognized access mode");
155 throw std::runtime_error(
"SingleTreeChain::FillRTI - Unrecognized access mode");
166 throw std::runtime_error(
"SingleTreeChain::FillFileInfo - Unrecognized access mode");
177 throw std::runtime_error(
"SingleTreeChain::GetEntries - Unrecognized access mode");
192 throw std::runtime_error(
"SingleTreeChain::Print - Unrecognized access mode");
206 m_rti.
tree->BuildIndex(
"RTIInfo.UTCTime");
209 m_data.
tree->BuildIndex(
"HeaderData.Run",
"HeaderData.EventNo");
212 throw std::runtime_error(
"SingleTreeChain::Write - Unrecognized access mode");
240 throw std::runtime_error(
"SingleTreeChain::SetupBranches - Unrecognized access mode");
244 static const std::unordered_map<std::string, std::function<void(Event &)>>
evDisablers = {
245 {
"EventSummary", [](
Event &event) {
event.evSummary.DisableIO(); }},
246 {
"DAQ", [](
Event &event) {
event.daq.DisableIO(); }},
247 {
"TofBase", [](
Event &event) {
event.tofBase.DisableIO(); }},
248 {
"TofPlus", [](
Event &event) {
event.tofPlus.DisableIO(); }},
249 {
"TofBaseStandalone", [](
Event &event) {
event.tofBaseSt.DisableIO(); }},
250 {
"TofPlusStandalone", [](
Event &event) {
event.tofPlusSt.DisableIO(); }},
251 {
"EcalBase", [](
Event &event) {
event.ecalBase.DisableIO(); }},
252 {
"EcalPlus", [](
Event &event) {
event.ecalPlus.DisableIO(); }},
253 {
"TtrTrackBase", [](
Event &event) {
event.trTrackBase.DisableIO(); }},
254 {
"TtrTrackPlus", [](
Event &event) {
event.trTrackPlus.DisableIO(); }},
255 {
"TrdKBase", [](
Event &event) {
event.trdKBase.DisableIO(); }},
256 {
"TrdKBaseStandalone", [](
Event &event) {
event.trdKBaseSt.DisableIO(); }},
257 {
"RichBase", [](
Event &event) {
event.richBase.DisableIO(); }},
258 {
"RichPlus", [](
Event &event) {
event.richPlus.DisableIO(); }},
259 {
"UnbExtHitBase", [](
Event &event) {
event.extHitBase.DisableIO(); }},
260 {
"MCTruthBase", [](
Event &event) {
event.mcTruthBase.DisableIO(); }},
261 {
"MCTruthPlus", [](
Event &event) {
event.mcTruthPlus.DisableIO(); }},
265 const std::string &exclBranches) {
266 static const std::string &fnName =
"SingleTreeChain::CreateSkimTree";
269 auto outFile = std::make_unique<TFile>(filename.c_str(),
"recreate");
272 if (!exclBranches.empty()) {
273 for (
const std::string &container :
TokenizeString(exclBranches,
';')) {
275 logger->info(
"Disabling container {}", container);
278 logger->error(
"Unknown container {}", container);
284 newChain->m_event.MirrorBranches(newChain->m_data.tree,
m_event);
285 newChain->m_rti.tree->Branch(
"RTIInfo", &
m_rtiInfo);
286 newChain->m_file.tree->Branch(
"FileInfo", &
m_fileInfo);
288 newChain->m_file.tree->Branch(
"MCFileInfo", &
m_fileInfoMC);
290 return {std::move(outFile), std::move(newChain),
this};
294 static const std::string &fnName =
"SingleTreeChain::SetEntryList";
299 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.
bool IsMC()
Check if this file is a MC file.
SingleTreeChain::EventItr end(SingleTreeChain &chain)
Container class for additional MC File information.
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.
const MCFileInfo & GetEventMCFileInfo()
Get the MCFileInfo object associated with this event.
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.