Belle II Software development
InputController.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/core/InputController.h>
9#include <framework/logging/Logger.h>
10
11#include <TChain.h>
12#include <TFile.h>
13
14using namespace Belle2;
15
17std::pair<long, long> InputController::s_nextEntry = { -1, -1};
21std::pair<long, long> InputController::s_currentEntry = { 0, 0};
22std::pair<long, long> InputController::s_skippedEntries = { 0, 0};
23std::pair<const TChain*, const TChain*> InputController::s_chain = { nullptr, nullptr};
26
28{
29 if (s_doEventMerging) {
30 B2FATAL("Event merging is already enabled, can not merge twice in the same job, aborting");
31 };
32 s_doEventMerging = true;
33 s_steerRootInputModule = steerRootInputModule;
34}
35
36
37void InputController::setChain(const TChain* chain, bool independentPath)
38{
39 if (!independentPath) {
40 s_chain.first = chain;
41 } else {
42 s_chain.second = chain;
43 }
44}
45
46void InputController::eventLoaded(long entry, bool independentPath)
47{
48 if (!independentPath) s_nextEntry.first = -1;
49 else s_nextEntry.second = -1;
51 s_nextRun = -1;
52 s_nextEvent = -1;
53 if (!independentPath) s_currentEntry.first = entry;
54 else s_currentEntry.second = entry;
55}
56
58{
59 s_canControlInput = false;
60 s_nextEntry = { -1, -1};
62 s_nextRun = -1;
63 s_nextEvent = -1;
64 s_currentEntry = { 0, 0};
65 //s_chain is not touched, so numEntries() still works
66}
67
68std::string InputController::getCurrentFileName(bool independentPath)
69{
70 const TChain* chain = !independentPath ? s_chain.first : s_chain.second;
71 if (!chain)
72 return "";
73
74 const TFile* f = chain->GetFile();
75 if (!f)
76 return "";
77
78 return f->GetName();
79}
80
81long InputController::numEntries(bool independentPath)
82{
83 if (!independentPath) {
84 if (s_chain.first)
85 return s_chain.first->GetEntries();
86 } else {
87 if (s_chain.second)
88 return s_chain.second->GetEntries();
89 }
90
91 return 0;
92}
93
95{
96 if (!s_doEventMerging) {
97 return numEntries();
98 } else {
99 return numEntries(true) * numEntries(false);
100 }
101}
static std::string getCurrentFileName(bool independentPath=false)
Return name of current file in loaded chain (or empty string if none loaded).
static std::pair< long, long > s_currentEntry
current entry in file.
static void eventLoaded(long entry, bool independentPath=false)
Indicate that an event (in the given entry) was loaded and reset all members related to the next entr...
static long numEntries(bool independentPath=false)
Returns total number of entries in the event tree.
static void resetForChildProcess()
Reset InputController (e.g.
static long s_nextExperiment
Experiment number to load next.
static long getNumEntriesToProcess()
Necessary to make sure the ProgressModule shows reasonable output.
static std::pair< long, long > s_skippedEntries
entries skipped by RootInputModule (if any) Storing two values (second one if independent path is exe...
static void enableEventMerging(Module *steerRootInputModule)
Set that we are merging events from two paths.
static long s_nextEvent
Event (not entry!) to load next.
static long s_nextRun
Run number to load next.
static std::pair< const TChain *, const TChain * > s_chain
Opened TChain (event durability).
static void setChain(const TChain *chain, bool independentPath=false)
Set the loaded TChain (event durability).
static Module * s_steerRootInputModule
Explicit pointer to steerRootInput.
static bool s_doEventMerging
Are we merging events from two paths?
static std::pair< long, long > s_nextEntry
entry to be loaded the next time event() is called in an input module.
static bool s_canControlInput
Is there an input module to be controlled?
Base class for Modules.
Definition: Module.h:72
Abstract base class for different kinds of events.