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 <EventLoop/Job.h>
21#include <EventLoop/Worker.h>
28#include <TList.h>
29
30//
31// method implementations
32//
33
34namespace EL
35{
36 namespace Detail
37 {
38 EventModule::EventModule (const std::string& name)
39 : Module (name)
40 {}
41
44
45
47
48 if (m_event != nullptr || m_store != nullptr) {
49 ANA_MSG_ERROR ("module initialized twice");
50 return StatusCode::FAILURE;
51 }
52 if (data.m_event != nullptr || data.m_tstore != nullptr) {
53 ANA_MSG_ERROR ("duplicate EventModule??");
54 return StatusCode::FAILURE;
55 }
56
57 // Perform a sanity check.
58 if (!data.m_inputFile) {
59 ANA_MSG_ERROR ("File is not available during initialization?!?");
60 return StatusCode::FAILURE;
61 }
62
63 // Set up the reading from the first input file. This is the generic
64 // interface for both TTree and RNTuple reading. But note that no event is loaded with getEntry(...)
65 // yet, as we don't want to allow users to access the first event
66 // during initialisation. Only the in-file metadata...
67 m_event = xAOD::Event::createAndReadFrom(*data.m_inputFile.get());
68 if (!m_event) {
69 ATH_MSG_ERROR( "cannot read from file: " << data.m_inputFile->GetName());
70 return StatusCode::FAILURE;
71 }
72 // Set event in module data
73 data.m_event = m_event.get();
74 ATH_MSG_DEBUG( "EventModule::onFirstInputFile: opened " << data.m_inputFile->GetName());
75 if (!m_summaryReport.value())
77
78 m_store.reset (new xAOD::TStore);
79
80 m_evtStore = std::make_unique<asg::SgEvent> (m_event.get(), m_store.get());
81
82 if (m_useStats.value())
84
85 data.m_tstore = m_store.get();
86 data.m_evtStore = m_evtStore.get();
87 return StatusCode::SUCCESS;
88 }
89
90
92
93 if (m_event == nullptr || m_store == nullptr) {
94 ANA_MSG_ERROR ("module not inititalized");
95 return StatusCode::FAILURE;
96 }
97 ANA_CHECK (m_event->readFrom (*data.m_inputFile.get()));
98 m_store->clear ();
99 return StatusCode::SUCCESS;
100 }
101
103 {
104 if (m_event == nullptr || m_store == nullptr) {
105 ANA_MSG_ERROR ("module not inititalized");
106 return StatusCode::FAILURE;
107 }
108 // readFrom has already been done in onFirstInputFile or onNextInputFile
109 // Here we only need to make sure getEntry(0) is called
110 if ((m_event->getEntries() > 0) && (m_event->getEntry (0) < 0)) {
111 ANA_MSG_ERROR ("Failed to load first entry from file");
112 return StatusCode::FAILURE;
113 }
114 m_store->clear ();
115 return StatusCode::SUCCESS;
116 }
117
119
120 if (m_event == nullptr || m_store == nullptr) {
121 ANA_MSG_ERROR ("module not inititalized");
122 return StatusCode::FAILURE;
123 }
124 // Nothing to do post close input file
125 return StatusCode::SUCCESS;
126 }
127
128
130 // move to next event
131 m_store->clear ();
132 if (m_event->getEntry (data.m_inputEntry) < 0)
133 {
134 ANA_MSG_ERROR ("failed to read from xAOD");
135 return StatusCode::FAILURE;
136 }
137 return StatusCode::SUCCESS;
138 }
139
140
142
143 // Only stop the stats if we actually started them, which happens in
144 // onFirstInputFile once m_event is created. With an empty file list
145 // start() is never called, so stop() must be skipped too.
146 if (m_useStats.value() && m_event != nullptr) {
148 std::unique_ptr<xAOD::ReadStats> stats
150 stats->SetName (Job::optXAODReadStats.c_str());
151 stats->Print ();
152 data.addOutput (std::move (stats));
153 }
154 data.m_evtStore = nullptr;
155 data.m_event = nullptr;
156 data.m_tstore = nullptr;
157 m_evtStore.reset ();
158 m_event.reset ();
159 m_store.reset ();
160 return StatusCode::SUCCESS;
161 }
162
163 }
164
165}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(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:64