ATLAS Offline Software
TrigEventSelectorByteStream.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Trigger includes
8 
9 // Athena includes
15 #include "StoreGate/StoreGateSvc.h"
18 
19 // =============================================================================
20 // Standard constructor
21 // =============================================================================
22 TrigEventSelectorByteStream::TrigEventSelectorByteStream(const std::string& name, ISvcLocator* svcLoc)
23 : base_class(name, svcLoc),
24  m_eventSource("ByteStreamInputSvc", name),
25  m_evtStore("StoreGateSvc", name) {
26  declareProperty("ByteStreamInputSvc", m_eventSource);
27 }
28 
29 // =============================================================================
30 // Standard destructor
31 // =============================================================================
33 
34 // =============================================================================
35 // Implementation of Service::initialize
36 // =============================================================================
38 {
39  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
40 
41  ATH_CHECK(m_eventSource.retrieve());
42  ATH_CHECK(m_evtStore.retrieve());
43 
44  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
45  return StatusCode::SUCCESS;
46 }
47 
48 // =============================================================================
49 // Implementation of Service::finalize
50 // =============================================================================
52 {
53  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
54  if (m_eventSource.release().isFailure()) {
55  ATH_MSG_WARNING("Cannot release the event source service");
56  }
57  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
58  return StatusCode::SUCCESS;
59 }
60 
61 // =============================================================================
62 // Implementation of IEvtSelector::next(Context&)
63 // There is actually no event selection here, we process all events online
64 // =============================================================================
65 StatusCode TrigEventSelectorByteStream::next(IEvtSelector::Context& /*c*/) const
66 {
67  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
68 
69  // RawEvent is a typedef for FullEventFragment
70  const RawEvent* ptrRawEvent = nullptr;
71 
72  // Try to get the next event from the event source
73  try {
74  ptrRawEvent = m_eventSource->nextEvent();
75  }
76  catch (const hltonl::Exception::NoMoreEvents& e) {
77  ATH_MSG_INFO(e.what());
78  throw; // rethrow NoMoreEvents
79  }
81  ATH_MSG_DEBUG(e.what());
82  throw; // rethrow NoEventsTemporarily
83  }
85  ATH_MSG_ERROR(e.what());
86  throw; // rethrow EventSourceCorrupted
87  }
89  ATH_MSG_INFO(e.what());
90  throw; // rethrow MissingCTPFragment
91  }
92  catch (const hltonl::Exception::BadCTPFragment& e) {
93  ATH_MSG_INFO(e.what());
94  throw; // rethrow BadCTPFragment
95  }
96  catch (const std::exception& e) {
97  ATH_MSG_ERROR("Failed to get next event from the event source, std::exception caught: " << e.what());
98  return StatusCode::FAILURE;
99  }
100  catch (...) {
101  ATH_MSG_ERROR("Failed to get next event from the event source, unknown exception caught");
102  return StatusCode::FAILURE;
103  }
104 
105  // Check if something was returned
106  if (ptrRawEvent == nullptr) {
107  ATH_MSG_ERROR("Failed to get next event from the event source, nullptr returned");
108  return StatusCode::FAILURE;
109  }
110 
111  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
112  return StatusCode::SUCCESS;
113 }
114 
115 // =============================================================================
116 // Implementation of IEvtSelector::createContext(Context*&)
117 // =============================================================================
119 {
121  return StatusCode::SUCCESS;
122 }
123 
124 // =============================================================================
125 // Implementation of IEvtSelector::releaseContext(Context*&)
126 // =============================================================================
127 StatusCode TrigEventSelectorByteStream::releaseContext(IEvtSelector::Context*& /*c*/) const
128 {
129  // this does nothing
130  return StatusCode::SUCCESS;
131 }
132 
133 // =============================================================================
134 // Implementation of IEvtSelector::createAddress(Context&,IOpaqueAddress*&)
135 // =============================================================================
136 StatusCode TrigEventSelectorByteStream::createAddress(const IEvtSelector::Context& /*c*/, IOpaqueAddress*& iop) const
137 {
138  ATH_MSG_VERBOSE("start of " << __FUNCTION__);
139 
140  // Get the EventContext via event store because the interface doesn't allow passing it explicitly as an argument
141  // and we don't want to use ThreadLocalContext. Don't use ReadHandle here because it calls ThreadLocalContext if
142  // not given a context (which we want to retrieve).
143  const EventContext* eventContext = nullptr;
144  ATH_CHECK(m_evtStore->retrieve(eventContext));
145 
146  // Create and record ByteStreamAddress for xAOD::EventInfo
148  addr->setEventContext(*eventContext);
149  iop = static_cast<IOpaqueAddress*>(addr);
150  ATH_CHECK(m_evtStore->recordAddress("EventInfo",iop));
151  ATH_MSG_DEBUG("Recorded new ByteStreamAddress for xAOD::EventInfo with event context " << *eventContext);
152 
153  // Create and record ByteStreamAddress for xAOD::EventAuxInfo
154  ByteStreamAddress* auxaddr = new ByteStreamAddress(ClassID_traits<xAOD::EventAuxInfo>::ID(), "EventInfoAux.", "");
155  auxaddr->setEventContext(*eventContext);
156  ATH_CHECK(m_evtStore->recordAddress("EventInfoAux.", static_cast<IOpaqueAddress*>(auxaddr)));
157  ATH_MSG_DEBUG("Recorded new ByteStreamAddress for xAOD::EventAuxInfo with event context " << *eventContext);
158 
159  ATH_MSG_VERBOSE("end of " << __FUNCTION__);
160  return StatusCode::SUCCESS;
161 }
162 
163 // =============================================================================
164 // Unimplemented methods of IEvtSelector
165 // =============================================================================
166 #define TRIGEVENTSELECTORBYTESTREAM_UNIMPL \
167  ATH_MSG_FATAL("Misconfiguration - the method " << __FUNCTION__ << " cannot be used online"); \
168  return StatusCode::FAILURE;
169 
170 StatusCode TrigEventSelectorByteStream::next(IEvtSelector::Context& /*c*/, int /*jump*/) const
171 {
173 }
174 
175 StatusCode TrigEventSelectorByteStream::previous(IEvtSelector::Context& /*c*/) const
176 {
178 }
179 
180 StatusCode TrigEventSelectorByteStream::previous(IEvtSelector::Context& /*c*/, int /*jump*/) const
181 {
183 }
184 
185 StatusCode TrigEventSelectorByteStream::last(IEvtSelector::Context& /*refContext*/) const
186 {
188 }
189 
190 StatusCode TrigEventSelectorByteStream::rewind(IEvtSelector::Context& /*c*/) const
191 {
193 }
194 
195 StatusCode TrigEventSelectorByteStream::resetCriteria(const std::string& /*cr*/, IEvtSelector::Context& /*c*/) const
196 {
198 }
199 
200 // =============================================================================
201 // Context implementation
202 // =============================================================================
204 : m_evtSelector(selector) {}
205 
207 : m_evtSelector(other.m_evtSelector) {}
208 
210 
212 {
213  IEvtSelector* id ATLAS_THREAD_SAFE = const_cast<IEvtSelector*>(m_evtSelector);
214  return id;
215 }
TrigEventSelectorByteStream.h
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
hltonl::Exception::MissingCTPFragment
Thrown if the CTP ROBFragment cannot be retrieved for a new event.
Definition: HltExceptions.h:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HltExceptions.h
hltonl::Exception::EventSourceCorrupted
Thrown if event source throws an exception when new event is requested.
Definition: HltExceptions.h:33
TrigEventSelectorByteStream::m_eventSource
ServiceHandle< IByteStreamInputSvc > m_eventSource
Definition: TrigEventSelectorByteStream.h:64
RawEvent
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition: RawEvent.h:37
TrigEventSelectorByteStream::rewind
virtual StatusCode rewind(IEvtSelector::Context &c) const override
Definition: TrigEventSelectorByteStream.cxx:190
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
EventContextClid.h
Assign a CLID to EventContext.
TrigEventSelectorByteStream::last
virtual StatusCode last(IEvtSelector::Context &refContext) const override
Definition: TrigEventSelectorByteStream.cxx:185
hltonl::Exception::BadCTPFragment
Thrown if the CTP ROBFragment for a new event has non-zero status word or other errors.
Definition: HltExceptions.h:49
TrigEventSelectorByteStream::releaseContext
virtual StatusCode releaseContext(IEvtSelector::Context *&c) const override
Definition: TrigEventSelectorByteStream.cxx:127
TrigEventSelectorByteStream::Context::Context
Context(const IEvtSelector *selector)
Constructor from a selector.
Definition: TrigEventSelectorByteStream.cxx:203
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
RawEvent.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
calibdata.exception
exception
Definition: calibdata.py:496
TrigEventSelectorByteStream::createContext
virtual StatusCode createContext(IEvtSelector::Context *&c) const override
Definition: TrigEventSelectorByteStream.cxx:118
TrigEventSelectorByteStream::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Definition: TrigEventSelectorByteStream.h:66
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ByteStreamAddress.h
hltonl::Exception::NoEventsTemporarily
Thrown if the event source cannot provide new events temporarily, e.g. when trigger is on hold.
Definition: HltExceptions.h:25
EventAuxInfo.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IByteStreamInputSvc.h
This file contains the interface for the ByteStreamInputSvc classes.
TrigEventSelectorByteStream::TrigEventSelectorByteStream
TrigEventSelectorByteStream(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
Definition: TrigEventSelectorByteStream.cxx:22
TrigEventSelectorByteStream::~TrigEventSelectorByteStream
virtual ~TrigEventSelectorByteStream()
Standard destructor.
Definition: TrigEventSelectorByteStream.cxx:32
TrigEventSelectorByteStream::next
virtual StatusCode next(IEvtSelector::Context &c) const override
Definition: TrigEventSelectorByteStream.cxx:65
ByteStreamAddress::setEventContext
void setEventContext(const EventContext &eid)
Definition: ByteStreamAddress.h:59
TrigEventSelectorByteStream::Context::~Context
virtual ~Context()
Default destructor.
Definition: TrigEventSelectorByteStream.cxx:209
EventInfo.h
TrigEventSelectorByteStream::initialize
virtual StatusCode initialize() override
Definition: TrigEventSelectorByteStream.cxx:37
TrigEventSelectorByteStream::Context::identifier
virtual void * identifier() const override
Implementation of IEvtSelector::Context::identifier.
Definition: TrigEventSelectorByteStream.cxx:211
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
TrigEventSelectorByteStream::resetCriteria
virtual StatusCode resetCriteria(const std::string &cr, IEvtSelector::Context &c) const override
Definition: TrigEventSelectorByteStream.cxx:195
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigEventSelectorByteStream::Context
Event Selector context for TrigEventSelectorByteStream.
Definition: TrigEventSelectorByteStream.h:26
TrigEventSelectorByteStream::previous
virtual StatusCode previous(IEvtSelector::Context &c) const override
Definition: TrigEventSelectorByteStream.cxx:175
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TrigEventSelectorByteStream::finalize
virtual StatusCode finalize() override
Definition: TrigEventSelectorByteStream.cxx:51
checker_macros.h
Define macros for attributes used to control the static checker.
TrigEventSelectorByteStream::createAddress
virtual StatusCode createAddress(const IEvtSelector::Context &c, IOpaqueAddress *&iop) const override
Definition: TrigEventSelectorByteStream.cxx:136
StoreGateSvc.h
python.compressB64.c
def c
Definition: compressB64.py:93
hltonl::Exception::NoMoreEvents
Thrown if all events are already read from the input and another one is requested.
Definition: HltExceptions.h:17
TRIGEVENTSELECTORBYTESTREAM_UNIMPL
#define TRIGEVENTSELECTORBYTESTREAM_UNIMPL
Definition: TrigEventSelectorByteStream.cxx:166