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