ATLAS Offline Software
Loading...
Searching...
No Matches
DoubleEventSelectorAthenaPool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
13
15
16// Pool
19
21
22
23DoubleEventSelectorAthenaPool::DoubleEventSelectorAthenaPool(const std::string& name, ISvcLocator* pSvcLocator)
24 : EventSelectorAthenaPool(name, pSvcLocator)
25{
26}
27
28
30
31
33{
35
37 if (dynamic_cast<EventSelectorAthenaPool *>(&*(m_secondarySelector)) == nullptr) {
39 }
40
41 return StatusCode::SUCCESS;
42}
43
44
45StatusCode DoubleEventSelectorAthenaPool::next(IEvtSelector::Context& ctxt) const
46{
47 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::next");
48
49 std::lock_guard<CallMutex> lockGuard(m_callLock);
50 if (!eventStore()->clearStore().isSuccess()) {
51 ATH_MSG_WARNING("Cannot clear Store");
52 }
53 for (const auto& tool : m_helperTools) {
54 if (!tool->preNext().isSuccess()) {
55 ATH_MSG_WARNING("Failed to preNext() " << tool->name());
56 }
57 }
58
59 for (;;) {
60 // Move in the primary file (with skipping)
61 if (nextWithSkip(ctxt).isFailure()) {
62 return StatusCode::FAILURE;
63 }
64
65 // Check if we're at the end of secondary file
66 if (m_secondarySelector->nextWithSkip(ctxt).isFailure()) {
67 return StatusCode::FAILURE;
68 }
69
70 // Record the attribute list
71 if (!recordAttributeList().isSuccess()) {
72 ATH_MSG_ERROR("Failed to record AttributeList.");
73 return StatusCode::FAILURE;
74 }
75
76 StatusCode status = StatusCode::SUCCESS;
77 for (const auto& tool : m_helperTools) {
78 StatusCode toolStatus = tool->postNext();
79 if (toolStatus.isRecoverable()) {
80 ATH_MSG_INFO("Request skipping event from: " << tool->name());
81 if (status.isSuccess()) {
82 status = StatusCode::RECOVERABLE;
83 }
84 } else if (toolStatus.isFailure()) {
85 ATH_MSG_WARNING("Failed to postNext() " << tool->name());
86 status = StatusCode::FAILURE;
87 }
88 }
89 if (status.isRecoverable()) {
90 ATH_MSG_INFO("skipping event " << m_evtCount);
91 } else if (status.isFailure()) {
92 ATH_MSG_WARNING("Failed to postNext() HelperTool.");
93 } else {
94 if (!m_counterTool.empty() && !m_counterTool->postNext().isSuccess()) {
95 ATH_MSG_WARNING("Failed to postNext() CounterTool.");
96 }
97 break;
98 }
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104
105StatusCode DoubleEventSelectorAthenaPool::next(IEvtSelector::Context& ctxt, int jump) const
106{
107 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::next(jump)");
108
109 if (jump > 0) {
110 for (int i = 0; i < jump; i++) {
111 if (!next(ctxt).isSuccess()) {
112 return StatusCode::FAILURE;
113 }
114 }
115 return StatusCode::SUCCESS;
116 }
117
118 return StatusCode::FAILURE;
119}
120
121
122StatusCode DoubleEventSelectorAthenaPool::seek(Context& ctxt, int evtNum) const
123{
124 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::seek");
125
127 ATH_CHECK(m_secondarySelector->seek(ctxt, evtNum));
128
129 return StatusCode::SUCCESS;
130}
131
132
134{
135 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::size");
136
137 int sz1 = EventSelectorAthenaPool::size(ctxt);
138 int sz2 = m_secondarySelector->size(ctxt);
139
140 if (sz2 < sz1) {
141 ATH_MSG_WARNING("Fewer secondary input events than primary input events. Expect trouble!");
142 }
143
144 return sz1;
145}
146
147
149{
150 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::recordAttributeList");
151
152 // Get access to AttributeList
153 ATH_MSG_DEBUG("Get AttributeList from the collection");
154 // MN: accessing only attribute list, ignoring token list
155 const coral::AttributeList& attrList = m_headerIterator->currentRow().attributeList();
156 ATH_MSG_DEBUG("AttributeList size " << attrList.size());
157 std::unique_ptr<AthenaAttributeList> athAttrList{};
158
159 // Decide what to do based on the type of secondary file
161 // Create empty attribute list
162 athAttrList = std::make_unique<AthenaAttributeList>();
163 // Always add ByteStream as primary input
164 ATH_CHECK(m_secondarySelector->fillAttributeList(athAttrList.get(), "", false));
165
166 // Then fill the new attribute list from the primary file
167 ATH_MSG_DEBUG("Append primary attribute list properties to the secondary one with a suffix: " << m_secondaryAttrListSuffix.value());
168 ATH_CHECK(fillAttributeList(athAttrList.get(), "_" + m_secondaryAttrListSuffix.value(), true));
169 } else {
170 // Create a new attribute list from the primary input one
171 athAttrList = std::make_unique<AthenaAttributeList>(attrList);
172 // Fill the new attribute list from the primary file
173 ATH_CHECK(fillAttributeList(athAttrList.get(), "", false));
174
175 // Fill the new attribute list from the secondary file
176 ATH_MSG_DEBUG("Append secondary attribute list properties to the primary one with a suffix: " << m_secondaryAttrListSuffix.value());
177 ATH_CHECK(m_secondarySelector->fillAttributeList(athAttrList.get(), "_" + m_secondaryAttrListSuffix.value(), true));
178 }
179
180 // Add info about secondary input
181 athAttrList->extend("hasSecondaryInput", "bool");
182 (*athAttrList)["hasSecondaryInput"].data<bool>() = true;
183
185 ATH_CHECK(wh.record(std::move(athAttrList)));
186
187 return StatusCode::SUCCESS;
188}
189
190
192{
193 ATH_MSG_DEBUG("DoubleEventSelectorAthenaPool::handle");
194
195 if (not Atlas::hasExtendedEventContext(inc.context()) ) {
196 ATH_MSG_WARNING("No extended event context available.");
197 return;
198 }
199
200 SG::SourceID fid1;
201 if (inc.type() == IncidentType::BeginProcessing) {
202 if ( Atlas::hasExtendedEventContext(inc.context()) ) {
203 fid1 = Atlas::getExtendedEventContext(inc.context()).proxy()->sourceID();
204 }
205 *m_sourceID1.get(inc.context()) = fid1;
206 }
207 else {
208 fid1 = *m_sourceID1.get(inc.context());
209 }
210
211 if( fid1.empty() ) {
212 ATH_MSG_WARNING("could not read event source ID from incident event context with key EventSelector");
213 return;
214 }
215
216 ATH_MSG_DEBUG("** MN Incident handler " << inc.type() << " Event source ID=" << fid1 );
217 if( inc.type() == IncidentType::BeginProcessing ) {
218 // increment the events-per-file counter for FID
219 m_activeEventsPerSource[fid1]++;
220 } else if( inc.type() == IncidentType::EndProcessing ) {
221 m_activeEventsPerSource[fid1]--;
222 disconnectIfFinished( fid1 );
223 *m_sourceID1.get(inc.context()) = "";
224 }
225 if( msgLvl(MSG::DEBUG) ) {
226 for( auto& source: m_activeEventsPerSource )
227 msg(MSG::DEBUG) << "SourceID: " << source.first << " active events: " << source.second << endmsg;
228 }
229
230 // Nothing to do if secondary event selector is ByteStream
232 return;
233 }
234
235 // Secondary guid
236 SG::SourceID fid2;
237 if (inc.type() == IncidentType::BeginProcessing) {
238 if ( Atlas::hasExtendedEventContext(inc.context()) ) {
239 fid2 = Atlas::getExtendedEventContext(inc.context()).proxy()->sourceID("SecondaryEventSelector");
240 }
241 *m_sourceID2.get(inc.context()) = fid2;
242 }
243 else {
244 fid2 = *m_sourceID2.get(inc.context());
245 }
246
247 if( fid2.empty() ) {
248 ATH_MSG_WARNING("could not read event source ID from incident event context with key SecondaryEventSelector");
249 return;
250 }
251
252 ATH_MSG_DEBUG("** MN Incident handler " << inc.type() << " Event source ID=" << fid2 );
253 if( inc.type() == IncidentType::BeginProcessing ) {
254 // increment the events-per-file counter for FID
255 m_activeEventsPerSource[fid2]++;
256 } else if( inc.type() == IncidentType::EndProcessing ) {
257 m_activeEventsPerSource[fid2]--;
258 m_secondarySelector->disconnectIfFinished( fid2 );
259 *m_sourceID2.get(inc.context()) = "";
260 }
261 if( msgLvl(MSG::DEBUG) ) {
262 for( auto& source: m_activeEventsPerSource )
263 msg(MSG::DEBUG) << "SourceID: " << source.first << " active events: " << source.second << endmsg;
264 }
265}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
This file contains the class definition for the DoubleEventSelectorAthenaPool class.
An AttributeList represents a logical row of attributes in a metadata table.
SG::SlotSpecificObj< SG::SourceID > m_sourceID2
virtual StatusCode next(IEvtSelector::Context &ctxt) const override
Gaudi::Property< std::string > m_secondaryAttrListSuffix
virtual StatusCode seek(Context &ctxt, int evtNum) const override
Seek to a given event number.
virtual void handle(const Incident &incident) override
Incident service handle listening for BeginProcessing and EndProcessing.
virtual StatusCode recordAttributeList() const override
Record AttributeList in StoreGate.
SG::SlotSpecificObj< SG::SourceID > m_sourceID1
virtual StatusCode initialize() override
Initialize function.
virtual int size(Context &ctxt) const override
Return the size of the collection.
ServiceHandle< ISecondaryEventSelector > m_secondarySelector
EventSelectorAthenaPool(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
virtual StatusCode nextWithSkip(IEvtSelector::Context &ctxt) const override
Go to next event and skip if necessary.
virtual StatusCode initialize() override
Required of all Gaudi Services.
friend class DoubleEventSelectorAthenaPool
make the DoubleEventSelectorAthenaPool a friend so it can access the internal EventSelectorAthenaPool...
StoreGateSvc * eventStore() const
Return pointer to active event SG.
ToolHandle< IAthenaSelectorTool > m_counterTool
virtual StatusCode fillAttributeList(coral::AttributeList *attrList, const std::string &suffix, bool copySource) const override
Fill AttributeList with specific items from the selector and a suffix.
std::string m_attrListKey
AttributeList SG key.
virtual StatusCode seek(Context &ctxt, int evtnum) const override
Seek to a given event number.
virtual bool disconnectIfFinished(const SG::SourceID &fid) const override
Disconnect DB if all events from the source FID were processed and the Selector moved to another file...
virtual int size(Context &ctxt) const override
Return the size of the collection.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
MsgStream & msg
Definition testRead.cxx:32