ATLAS Offline Software
Loading...
Searching...
No Matches
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
13
14#include <memory>
15#include <AsgTools/SgTEvent.h>
19// #include <xAODRootAccess/D3PDPerfStats.h>
20#include <EventLoop/Job.h>
22#include <EventLoop/Worker.h>
30#include <TList.h>
31
32//
33// method implementations
34//
35
36namespace EL
37{
38 namespace Detail
39 {
40 TEventModule ::
41 TEventModule (const std::string& name)
42 : Module (name)
43 {}
44
45
46
47 TEventModule ::
48 ~TEventModule ()
49 {}
50
51
52
53 StatusCode TEventModule ::
54 onInitialize (ModuleData& data)
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 m_event->setOtherMetaDataTreeNamePattern( m_otherMetaDataTreeNamePattern );
83 } else
84 {
85 m_event.reset (new xAOD::TEvent);
86 m_event->setOtherMetaDataTreeNamePattern( m_otherMetaDataTreeNamePattern );
87 }
88 if (!m_summaryReport.value())
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 if (m_useStats.value())
97
98 data.m_tevent = m_event.get();
99 data.m_tstore = m_store.get();
100 data.m_evtStore = m_evtStore.get();
101
102 // Perform a sanity check.
103 if (!data.m_inputFile)
104 {
105 ANA_MSG_ERROR ("File is not available during initialization?!?");
106 return StatusCode::FAILURE;
107 }
108 // Set up the reading from the first input file, which should be
109 // open already. But note that no event is loaded with getEntry(...)
110 // yet, as we don't want to allow users to access the first event
111 // during initialisation. Only the in-file metadata...
112 ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
113
114 return StatusCode::SUCCESS;
115 }
116
117
118
119 StatusCode TEventModule ::
120 postFinalize (ModuleData& data)
121 {
122 if (m_useStats.value())
123 {
125 std::unique_ptr<xAOD::ReadStats> stats
127 stats->SetName (Job::optXAODReadStats.c_str());
128 stats->Print ();
129 data.addOutput (std::move (stats));
130 }
131 data.m_evtStore = nullptr;
132 data.m_tevent = nullptr;
133 data.m_tstore = nullptr;
134 m_evtStore.reset ();
135 m_event.reset ();
136 m_store.reset ();
137 return StatusCode::SUCCESS;
138 }
139
140
141
142 StatusCode TEventModule ::
143 onNewInputFile (ModuleData& data)
144 {
145 if (m_event == nullptr || m_store == nullptr)
146 {
147 ANA_MSG_ERROR ("module not inititalized");
148 return StatusCode::FAILURE;
149 }
150 ANA_CHECK (m_event->readFrom (data.m_inputFile.get()));
151 if ((m_event->getEntries() > 0) && (m_event->getEntry (0) < 0))
152 {
153 ANA_MSG_ERROR ("Failed to load first entry from file");
154 return StatusCode::FAILURE;
155 }
156 m_store->clear ();
157 return StatusCode::SUCCESS;
158 }
159
160
161
162 StatusCode TEventModule ::
163 postCloseInputFile (ModuleData& /*data*/)
164 {
165 if (m_event == nullptr || m_store == nullptr)
166 {
167 ANA_MSG_ERROR ("module not inititalized");
168 return StatusCode::FAILURE;
169 }
170 ANA_CHECK (m_event->readFrom ((TFile *)nullptr));
171 return StatusCode::SUCCESS;
172 }
173
174
175
176 StatusCode TEventModule ::
177 onExecute (ModuleData& data)
178 {
179 m_store->clear ();
180 if (m_event->getEntry (data.m_inputTreeEntry) < 0)
181 RCU_THROW_MSG ("failed to read from xAOD");
182 return StatusCode::SUCCESS;
183 }
184 }
185}
macros for messaging and checking status codes
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
the base class for EventLoop instrumentation module
Gaudi::Property< bool > m_summaryReport
Gaudi::Property< std::string > m_modeStr
std::unique_ptr< asg::SgTEvent > m_evtStore
std::unique_ptr< xAOD::TStore > m_store
Gaudi::Property< std::string > m_otherMetaDataTreeNamePattern
std::unique_ptr< xAOD::TEvent > m_event
description: the event structure used
Gaudi::Property< bool > m_useStats
description: whether we collect D3PDPerfStats statistics
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
static const std::string optXaodAccessMode_athena
Definition Job.h:403
static const std::string optXaodAccessMode_branch
Definition Job.h:401
static const std::string optXaodAccessMode_class
Definition Job.h:402
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void stop()
Stop the statistics collection.
void start(bool clear=true)
Start the statistics collection.
static PerfStats & instance()
Function accessing the singleton instance.
Class describing the access statistics of a collection of branches.
Definition ReadStats.h:123
Tool for accessing xAOD files outside of Athena.
@ kAthenaAccess
Access containers/objects like Athena does.
@ kClassAccess
Access auxiliary data using the aux containers.
@ kBranchAccess
Access auxiliary data branch-by-branch.
static void enableDataSubmission(::Bool_t value)
Function for turning data submission on/off.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
the data the EventLoop core classes are sharing with the Module implementation
Definition ModuleData.h:64