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  if (!m_modeStr.value().empty())
68  {
72  else if (m_modeStr.value() == Job::optXaodAccessMode_branch)
74  else if (m_modeStr.value() == Job::optXaodAccessMode_athena)
76  else
77  {
78  ANA_MSG_ERROR ("unknown XAOD access mode: " << m_modeStr.value());
79  return StatusCode::FAILURE;
80  }
81  m_event.reset (new xAOD::TEvent (mode));
82  } else
83  {
84  m_event.reset (new xAOD::TEvent);
85  }
86  if (!m_summaryReport.value())
88 
89  m_store.reset (new xAOD::TStore);
90 
91  m_evtStore = std::make_unique<asg::SgTEvent> (m_event.get(), m_store.get());
92 
93  if (m_useStats.value())
95 
96  data.m_tevent = m_event.get();
97  data.m_tstore = m_store.get();
98  data.m_evtStore = m_evtStore.get();
99 
100  // Perform a sanity check.
101  if (!data.m_inputFile)
102  {
103  ANA_MSG_ERROR ("File is not available during initialization?!?");
104  return StatusCode::FAILURE;
105  }
106  // Set up the reading from the first input file, which should be
107  // open already. But note that no event is loaded with getEntry(...)
108  // yet, as we don't want to allow users to access the first event
109  // during initialisation. Only the in-file metadata...
110  ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
111 
112  return StatusCode::SUCCESS;
113  }
114 
115 
116 
119  {
120  if (m_useStats.value())
121  {
123  std::unique_ptr<xAOD::ReadStats> stats
125  stats->SetName (Job::optXAODReadStats.c_str());
126  stats->Print ();
127  data.addOutput (std::move (stats));
128  }
129  data.m_evtStore = nullptr;
130  data.m_tevent = nullptr;
131  data.m_tstore = nullptr;
132  m_evtStore.reset ();
133  m_event.reset ();
134  m_store.reset ();
135  return StatusCode::SUCCESS;
136  }
137 
138 
139 
142  {
143  if (m_event == nullptr || m_store == nullptr)
144  {
145  ANA_MSG_ERROR ("module not inititalized");
146  return StatusCode::FAILURE;
147  }
148  ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
149  if ((m_event->getEntries() > 0) && (m_event->getEntry (0) < 0))
150  {
151  ANA_MSG_ERROR ("Failed to load first entry from file");
152  return StatusCode::FAILURE;
153  }
154  m_store->clear ();
155  return StatusCode::SUCCESS;
156  }
157 
158 
159 
162  {
163  if (m_event == nullptr || m_store == nullptr)
164  {
165  ANA_MSG_ERROR ("module not inititalized");
166  return StatusCode::FAILURE;
167  }
168  ANA_CHECK (m_event->readFrom ((TFile *)nullptr));
169  return StatusCode::SUCCESS;
170  }
171 
172 
173 
176  {
177  m_store->clear ();
178  if (m_event->getEntry (data.m_inputTreeEntry) < 0)
179  RCU_THROW_MSG ("failed to read from xAOD");
180  return StatusCode::SUCCESS;
181  }
182  }
183 }
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:175
EL::Detail::TEventModule::m_summaryReport
Gaudi::Property< bool > m_summaryReport
Definition: TEventModule.h:80
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:102
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:118
EL::Job::optXaodAccessMode_class
static const std::string optXaodAccessMode_class
Definition: Job.h:402
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:101
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
PerfStats.h
EL::Detail::TEventModule::postCloseInputFile
virtual StatusCode postCloseInputFile(ModuleData &data) override
actions after CloseInputFile is called on the algorithms
Definition: TEventModule.cxx:161
EL::Detail::TEventModule::m_useStats
Gaudi::Property< bool > m_useStats
description: whether we collect D3PDPerfStats statistics
Definition: TEventModule.h:77
EL::Detail::TEventModule::m_evtStore
std::unique_ptr< asg::SgTEvent > m_evtStore
Definition: TEventModule.h:73
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:71
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
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:141
TEvent.h
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AsgComponentFactories.h:16
Preparation.mode
mode
Definition: Preparation.py:107
EL::Detail::TEventModule::m_store
std::unique_ptr< xAOD::TStore > m_store
Definition: TEventModule.h:72
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::DiTauJetParameters::Detail
Detail
Definition: DiTauDefs.h:38
ThrowMsg.h
EL::Job::optXaodAccessMode_branch
static const std::string optXaodAccessMode_branch
Definition: Job.h:401
TEventModule.h
xAOD::PerfStats::instance
static PerfStats & instance()
Function accessing the singleton instance.
EL::Detail::TEventModule::m_modeStr
Gaudi::Property< std::string > m_modeStr
Definition: TEventModule.h:79
xAOD::TEvent::EAuxMode
EAuxMode
Auxiliary store "mode".
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:99
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:47
EL::Job::optXaodAccessMode_athena
static const std::string optXaodAccessMode_athena
Definition: Job.h:403
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:100
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:85
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:365
EL::Detail::TEventModule::TEventModule
TEventModule(const std::string &name)
effects: standard constructor.
Definition: TEventModule.cxx:41
SgTEvent.h