ATLAS Offline Software
TEventModule.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
12 #include <EventLoop/TEventModule.h>
13 
14 #include <memory>
15 #include <AsgTools/SgTEvent.h>
16 #include <xAODRootAccess/TEvent.h>
18 #include <xAODRootAccess/TStore.h>
19 // #include <xAODRootAccess/D3PDPerfStats.h>
20 #include <EventLoop/Job.h>
21 #include <EventLoop/StatusCode.h>
22 #include <EventLoop/Worker.h>
23 #include <RootCoreUtils/Assert.h>
24 #include <RootCoreUtils/ThrowMsg.h>
28 #include <xAODCore/tools/IOStats.h>
30 #include <TList.h>
31 
32 //
33 // method implementations
34 //
35 
36 namespace EL
37 {
38  namespace Detail
39  {
41  TEventModule (const std::string& name)
42  : Module (name)
43  {}
44 
45 
46 
49  {}
50 
51 
52 
55  {
56  if (m_event != nullptr || m_store != nullptr)
57  {
58  ANA_MSG_ERROR ("module initialized twice");
59  return StatusCode::FAILURE;
60  }
61  if (data.m_tevent != nullptr || data.m_tstore != nullptr)
62  {
63  ANA_MSG_ERROR ("duplicate TEventModule??");
64  return StatusCode::FAILURE;
65  }
66 
67  std::string modeStr = data.m_metaData->castString
69  if (!modeStr.empty())
70  {
72  if (modeStr == Job::optXaodAccessMode_class)
74  else if (modeStr == Job::optXaodAccessMode_branch)
76  else if (modeStr == Job::optXaodAccessMode_athena)
78  else
79  {
80  ANA_MSG_ERROR ("unknown XAOD access mode: " << modeStr);
81  return StatusCode::FAILURE;
82  }
83  m_event.reset (new xAOD::TEvent (mode));
84  } else
85  {
86  m_event.reset (new xAOD::TEvent);
87  }
88  if (data.m_metaData->castDouble (Job::optXAODSummaryReport, 1) == 0)
90 
91  m_store.reset (new xAOD::TStore);
92 
93  m_evtStore = std::make_unique<asg::SgTEvent> (m_event.get(), m_store.get());
94 
95  m_useStats = data.m_metaData->castBool (Job::optXAODPerfStats, false);
96  if (m_useStats)
98 
99  data.m_tevent = m_event.get();
100  data.m_tstore = m_store.get();
101  data.m_evtStore = m_evtStore.get();
102 
103  // Perform a sanity check.
104  if (!data.m_inputFile)
105  {
106  ANA_MSG_ERROR ("File is not available during initialization?!?");
107  return StatusCode::FAILURE;
108  }
109  // Set up the reading from the first input file, which should be
110  // open already. But note that no event is loaded with getEntry(...)
111  // yet, as we don't want to allow users to access the first event
112  // during initialisation. Only the in-file metadata...
113  ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
114 
115  return StatusCode::SUCCESS;
116  }
117 
118 
119 
122  {
123  if (m_useStats)
124  {
126  std::unique_ptr<xAOD::ReadStats> stats
128  stats->SetName (Job::optXAODReadStats.c_str());
129  stats->Print ();
130  data.addOutput (std::move (stats));
131  }
132  data.m_evtStore = nullptr;
133  data.m_tevent = nullptr;
134  data.m_tstore = nullptr;
135  m_evtStore.reset ();
136  m_event.reset ();
137  m_store.reset ();
138  return StatusCode::SUCCESS;
139  }
140 
141 
142 
145  {
146  if (m_event == nullptr || m_store == nullptr)
147  {
148  ANA_MSG_ERROR ("module not inititalized");
149  return StatusCode::FAILURE;
150  }
151  ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
152  if ((m_event->getEntries() > 0) && (m_event->getEntry (0) < 0))
153  {
154  ANA_MSG_ERROR ("Failed to load first entry from file");
155  return StatusCode::FAILURE;
156  }
157  m_store->clear ();
158  return StatusCode::SUCCESS;
159  }
160 
161 
162 
165  {
166  if (m_event == nullptr || m_store == nullptr)
167  {
168  ANA_MSG_ERROR ("module not inititalized");
169  return StatusCode::FAILURE;
170  }
171  ANA_CHECK (m_event->readFrom ((TFile *)nullptr));
172  return StatusCode::SUCCESS;
173  }
174 
175 
176 
179  {
180  m_store->clear ();
181  if (m_event->getEntry (data.m_inputTreeEntry) < 0)
182  RCU_THROW_MSG ("failed to read from xAOD");
183  return StatusCode::SUCCESS;
184  }
185  }
186 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
EL::Detail::TEventModule::onExecute
virtual StatusCode onExecute(ModuleData &data) override
actions just before execute is called on algorithms
Definition: TEventModule.cxx:178
EL::Job::optXaodAccessMode
static const std::string optXaodAccessMode
description: the option to select the access mode for xAODs.
Definition: Job.h:397
xAOD::PerfStats::start
void start(bool clear=true)
Start the statistics collection.
EL::Detail::ModuleData
the data the EventLoop core classes are sharing with the Module implementation
Definition: ModuleData.h:64
EL::Detail::TEventModule::~TEventModule
~TEventModule()
effects: standard destructor.
Definition: TEventModule.cxx:48
EL::Detail::TEventModule::onInitialize
virtual StatusCode onInitialize(ModuleData &data) override
action just before algorithms are initialized
Definition: TEventModule.cxx:54
Job.h
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:101
xAOD::TFileAccessTracer::enableDataSubmission
static void enableDataSubmission(::Bool_t value)
Function for turning data submission on/off.
Definition: TFileAccessTracer.cxx:281
EL::Detail::TEventModule::postFinalize
virtual StatusCode postFinalize(ModuleData &data) override
actions after algorithms have been finalized
Definition: TEventModule.cxx:121
EL::Job::optXaodAccessMode_class
static const std::string optXaodAccessMode_class
Definition: Job.h:399
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
Assert.h
IOStats.h
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
PerfStats.h
EL::Job::optXAODSummaryReport
static const std::string optXAODSummaryReport
the option to turn on/off the xAOD summary reporting at the end of the job
Definition: Job.h:406
EL::Detail::TEventModule::postCloseInputFile
virtual StatusCode postCloseInputFile(ModuleData &data) override
actions after CloseInputFile is called on the algorithms
Definition: TEventModule.cxx:164
EL::Detail::TEventModule::m_evtStore
std::unique_ptr< asg::SgTEvent > m_evtStore
Definition: TEventModule.h:72
MetaObject.h
TFileAccessTracer.h
ReadStats.h
EL::Detail::TEventModule::m_event
std::unique_ptr< xAOD::TEvent > m_event
description: the event structure used
Definition: TEventModule.h:70
EL::Detail::Module
the base class for EventLoop instrumentation module
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/Module.h:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::Job::optXAODPerfStats
static const std::string optXAODPerfStats
description: the name of the option for turning on XAODPerfStats.
Definition: Job.h:353
MessageCheck.h
macros for messaging and checking status codes
EL::Detail::TEventModule::onNewInputFile
virtual StatusCode onNewInputFile(ModuleData &data) override
actions after opening a new input file
Definition: TEventModule.cxx:144
TEvent.h
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
Preparation.mode
mode
Definition: Preparation.py:94
EL::Detail::TEventModule::m_store
std::unique_ptr< xAOD::TStore > m_store
Definition: TEventModule.h:71
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::DiTauJetParameters::Detail
Detail
Definition: DiTauDefs.h:38
ThrowMsg.h
EL::Job::optXaodAccessMode_branch
static const std::string optXaodAccessMode_branch
Definition: Job.h:398
TEventModule.h
xAOD::PerfStats::instance
static PerfStats & instance()
Function accessing the singleton instance.
xAOD::TEvent::EAuxMode
EAuxMode
Auxiliary store "mode".
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
EL::Job::optXaodAccessMode_athena
static const std::string optXaodAccessMode_athena
Definition: Job.h:400
Worker.h
StatusCode.h
xAOD::PerfStats::stop
void stop()
Stop the statistics collection.
xAOD::TEvent::kBranchAccess
@ kBranchAccess
Access auxiliary data branch-by-branch.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:99
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
xAOD::ReadStats
Class describing the access statistics of a collection of branches.
Definition: ReadStats.h:123
TStore.h
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
EL::Job::optXAODReadStats
static const std::string optXAODReadStats
description: the name of the XAODPerfStats object produced as I gather it, as well as the name of the...
Definition: Job.h:362
EL::Detail::TEventModule::TEventModule
TEventModule(const std::string &name)
effects: standard constructor.
Definition: TEventModule.cxx:41
EL::Detail::TEventModule::m_useStats
bool m_useStats
description: whether we collect D3PDPerfStats statistics
Definition: TEventModule.h:76
SgTEvent.h