ATLAS Offline Software
Loading...
Searching...
No Matches
EventModule.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
14#include <memory>
15#include <AsgTools/SgEvent.h>
19// #include <xAODRootAccess/D3PDPerfStats.h>
20#include <EventLoop/Job.h>
22#include <EventLoop/Worker.h>
29#include <TList.h>
30
31//
32// method implementations
33//
34
35namespace EL
36{
37 namespace Detail
38 {
39 EventModule::EventModule (const std::string& name)
40 : Module (name)
41 {}
42
45
46
48
49 if (m_event != nullptr || m_store != nullptr) {
50 ANA_MSG_ERROR ("module initialized twice");
51 return StatusCode::FAILURE;
52 }
53 if (data.m_event != nullptr || data.m_tstore != nullptr) {
54 ANA_MSG_ERROR ("duplicate EventModule??");
55 return StatusCode::FAILURE;
56 }
57
58 // Perform a sanity check.
59 if (!data.m_inputFile) {
60 ANA_MSG_ERROR ("File is not available during initialization?!?");
61 return StatusCode::FAILURE;
62 }
63
64 // Set up the reading from the first input file. This is the generic
65 // interface for both TTree and RNTuple reading. But note that no event is loaded with getEntry(...)
66 // yet, as we don't want to allow users to access the first event
67 // during initialisation. Only the in-file metadata...
68 m_event = xAOD::Event::createAndReadFrom(*data.m_inputFile.get());
69 if (!m_event) {
70 ATH_MSG_ERROR( "cannot read from file: " << *data.m_inputFile->GetName());
71 return StatusCode::FAILURE;
72 }
73 // Set event in module data
74 data.m_event = m_event.get();
75 ATH_MSG_DEBUG( "EventModule::onFirstInputFile: opened " << data.m_inputFile->GetName());
76 if (!m_summaryReport.value())
78
79 m_store.reset (new xAOD::TStore);
80
81 m_evtStore = std::make_unique<asg::SgEvent> (m_event.get(), m_store.get());
82
83 if (m_useStats.value())
85
86 data.m_tstore = m_store.get();
87 data.m_evtStore = m_evtStore.get();
88 return StatusCode::SUCCESS;
89 }
90
91
93
94 if (m_event == nullptr || m_store == nullptr) {
95 ANA_MSG_ERROR ("module not inititalized");
96 return StatusCode::FAILURE;
97 }
98 ANA_CHECK (m_event->readFrom (*data.m_inputFile.get()));
99 m_store->clear ();
100 return StatusCode::SUCCESS;
101 }
102
104 {
105 if (m_event == nullptr || m_store == nullptr) {
106 ANA_MSG_ERROR ("module not inititalized");
107 return StatusCode::FAILURE;
108 }
109 // readFrom has already been done in onFirstInputFile or onNextInputFile
110 // Here we only need to make sure getEntry(0) is called
111 if ((m_event->getEntries() > 0) && (m_event->getEntry (0) < 0)) {
112 ANA_MSG_ERROR ("Failed to load first entry from file");
113 return StatusCode::FAILURE;
114 }
115 m_store->clear ();
116 return StatusCode::SUCCESS;
117 }
118
120
121 if (m_event == nullptr || m_store == nullptr) {
122 ANA_MSG_ERROR ("module not inititalized");
123 return StatusCode::FAILURE;
124 }
125 // Nothing to do post close input file
126 return StatusCode::SUCCESS;
127 }
128
129
131 // move to next event
132 m_store->clear ();
133 if (m_event->getEntry (data.m_inputEntry) < 0)
134 {
135 ANA_MSG_ERROR ("failed to read from xAOD");
136 return StatusCode::FAILURE;
137 }
138 return StatusCode::SUCCESS;
139 }
140
141
143
144 if (m_useStats.value()) {
146 std::unique_ptr<xAOD::ReadStats> stats
148 stats->SetName (Job::optXAODReadStats.c_str());
149 stats->Print ();
150 data.addOutput (std::move (stats));
151 }
152 data.m_evtStore = nullptr;
153 data.m_event = nullptr;
154 data.m_tstore = nullptr;
155 m_evtStore.reset ();
156 m_event.reset ();
157 m_store.reset ();
158 return StatusCode::SUCCESS;
159 }
160
161 }
162
163}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
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
virtual StatusCode onFirstInputFile(ModuleData &data) override
actions after opening a the first input file
Gaudi::Property< bool > m_summaryReport
Definition EventModule.h:76
virtual StatusCode postFinalize(ModuleData &data) override
actions after algorithms have been finalized
EventModule(const std::string &name)
effects: standard constructor.
virtual StatusCode postCloseInputFile(ModuleData &data) override
actions after CloseInputFile is called on the algorithms
std::unique_ptr< asg::SgEvent > m_evtStore
Definition EventModule.h:71
std::unique_ptr< xAOD::Event > m_event
description: the event structure used
Definition EventModule.h:69
virtual StatusCode onNextInputFile(ModuleData &data) override
actions after opening an input file after the first one
std::unique_ptr< xAOD::TStore > m_store
Definition EventModule.h:70
Gaudi::Property< bool > m_useStats
description: whether we collect D3PDPerfStats statistics
Definition EventModule.h:75
virtual StatusCode onExecute(ModuleData &data) override
actions just before execute is called on algorithms
~EventModule()
effects: standard destructor.
virtual StatusCode onNewInputFile(ModuleData &data) override
actions after opening a new input file
the base class for EventLoop instrumentation module
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:361
static std::unique_ptr< Event > createAndReadFrom(TFile &file)
static method to create an Event object and readFrom a file, given by a TFile.
Definition EventIO.cxx:43
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
void enableDataSubmission(bool value)
Function for turning data submission on/off.
static TFileAccessTracer & instance()
Access the singleton instance of this class.
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:65