ATLAS Offline Software
Loading...
Searching...
No Matches
EventSelectorByteStream.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef BYTESTREAMCNVSVC_EVENTSELECTORBYTESTREAM_H
6#define BYTESTREAMCNVSVC_EVENTSELECTORBYTESTREAM_H
7
18
19#include "GaudiKernel/IEvtSelector.h"
20#include "GaudiKernel/ServiceHandle.h"
21#include "GaudiKernel/ToolHandle.h"
22#include "GaudiKernel/IIoComponent.h"
23
31
35#include <mutex>
36#include <optional>
37#include <utility>
38
39// Forward declarations.
40class ISvcLocator;
43
44// Class EventSelectorByteStream.
46 public extends<::AthService, IEvtSelector, IEvtSelectorSeek, IEventShare, IIoComponent, ISecondaryEventSelector>
47{
48public:
50 EventSelectorByteStream(const std::string& name, ISvcLocator* svcloc);
53
55 virtual StatusCode initialize() override;
56 virtual StatusCode start() override;
57 virtual StatusCode stop() override;
58 virtual StatusCode finalize() override;
59
60 //-------------------------------------------------
61 // IEventSelector
63 virtual StatusCode createContext(Context*& it) const override;
65 virtual StatusCode next(Context& it) const override;
68 virtual StatusCode next(Context& it, int jump) const override;
70 virtual StatusCode previous(Context& it) const override;
73 virtual StatusCode previous(Context& it, int jump) const override;
74
76 virtual StatusCode last(Context& it) const override;
78 virtual StatusCode rewind(Context& it) const override;
79
82 virtual StatusCode createAddress(const Context& it,IOpaqueAddress*& iop) const override;
83
85 virtual StatusCode releaseContext(Context*& it) const override;
86
90 virtual StatusCode resetCriteria(const std::string& criteria, Context& context) const override;
91
92 //-------------------------------------------------
93 // IEventSelectorSeek
97 virtual StatusCode seek (Context& /* it */, int evtnum) const override;
98
101 virtual int curEvent (const Context& it) const override;
102
105 virtual int size (Context& it) const override;
106
107 //-------------------------------------------------
108 // IEventShare
110 virtual StatusCode makeServer(int num) override;
111
113 virtual StatusCode makeClient(int num) override;
114
117 virtual StatusCode share(int evtnum) override;
118
121 virtual StatusCode readEvent(int maxevt) override;
122
123 //-------------------------------------------------
124 // IIoComponent
126 virtual StatusCode io_reinit() override;
127
128protected:
129 using mutex_t = std::recursive_mutex;
130 using lock_t = std::lock_guard<mutex_t>;
131
132 //-------------------------------------------------
133 // ISecondaryEventSelector
135 virtual StatusCode nextHandleFileTransition(IEvtSelector::Context& ctxt) const override;
137 virtual StatusCode nextWithSkip(IEvtSelector::Context& ctxt) const override;
139 virtual StatusCode recordAttributeList() const override;
141 virtual StatusCode fillAttributeList(coral::AttributeList *attrList, const std::string &suffix, bool copySource) const override;
142 // Disconnect DB if all events from the source FID were processed and the Selector moved to another file
143 virtual bool disconnectIfFinished(const SG::SourceID &fid) const override;
144
145private: // internal member functions
146 StatusCode nextImpl(Context& it, lock_t& lock) const;
147 StatusCode nextImpl(Context& it, int jump, lock_t& lock) const;
148 StatusCode previousImpl(Context& it, lock_t& lock) const;
149 StatusCode previousImpl(Context& it, int jump, lock_t& lock) const;
150 StatusCode nextHandleFileTransitionImpl(IEvtSelector::Context& ctxt,
151 lock_t& lock) const;
152 StatusCode nextWithSkipImpl(IEvtSelector::Context& ctxt,
153 lock_t& lock) const;
154 StatusCode recordAttributeListImpl(lock_t& lock) const;
155 StatusCode fillAttributeListImpl(coral::AttributeList *attrList, const std::string &suffix, bool copySource,
156 lock_t& lock) const;
157
159 StatusCode reinit(lock_t& lock);
160 StatusCode openNewRun(lock_t& lock) const;
163 long openBlock(const std::string& fileName, lock_t& lock) const;
165 void fileTransition(lock_t& lock) const;
166 void nextFile(lock_t& lock) const;
168 int findEvent(int evtNum, lock_t& lock) const;
169 StoreGateSvc* eventStore() const;
170
171private: // properties
172 // FIXME: A Gaudi EventSelector is not meant to have mutable state.
173 // Any needed state is meant to be kept in the Context object.
174 // So the mutable members here should instead be kept in
175 // EventContextByteStream. However, making that work would
176 // require redesigning other Athena interfaces. So for now,
177 // just add a mutex to protect access to them.
179 mutable int m_fileCount ATLAS_THREAD_SAFE = 0;
180 mutable std::vector<int> m_numEvt ATLAS_THREAD_SAFE;
181 mutable std::vector<int> m_firstEvt ATLAS_THREAD_SAFE;
182 mutable std::vector<std::string>::const_iterator m_inputCollectionsIterator ATLAS_THREAD_SAFE;
183 mutable std::vector<long> m_skipEventSequence ATLAS_THREAD_SAFE;
184 mutable long m_NumEvents ATLAS_THREAD_SAFE = 0; // Number of Events read so far.
185 mutable ToolHandle<IAthenaIPCTool> m_eventStreamingTool ATLAS_THREAD_SAFE {this, "SharedMemoryTool", "", ""};
186
188 Gaudi::Property<bool> m_isSecondary{this, "IsSecondary", false, ""};
189
190 Gaudi::Property<std::string> m_eventSourceName{this, "ByteStreamInputSvc", "", ""};
191 Gaudi::Property<bool> m_procBadEvent{this, "ProcessBadEvent", false, ""};
192 Gaudi::Property<int> m_maxBadEvts{this, "MaxBadEvents", -1, ""};
193
196 SmartIF<IByteStreamInputSvc> m_eventSource;
197 Gaudi::Property<std::vector<std::string>> m_inputCollectionsProp{this, "Input", {}, ""};
198 void inputCollectionsHandler(Gaudi::Details::PropertyBase&);
199 ServiceHandle<IIncidentSvc> m_incidentSvc{this, "IncidentSvc", "IncidentSvc", ""};
200
201 Gaudi::Property<long> m_skipEvents{this, "SkipEvents", 0, ""}; // Number of events to skip at the beginning
202 Gaudi::Property<std::vector<long>> m_skipEventSequenceProp{this, "SkipEventSequence", {}, ""};
203
206 mutable std::optional<InputFileIncidentGuard> m_inputFileGuard ATLAS_THREAD_SAFE;
208 mutable std::optional<std::pair<std::string, std::string>> m_pendingFile ATLAS_THREAD_SAFE;
209
211 ToolHandleArray<IAthenaSelectorTool> m_helperTools{this, "HelperTools", {}, "Helper tools executed by EventSelector"};
212 ToolHandle<IAthenaSelectorTool> m_counterTool{this, "CounterTool", "", ""};
213
217 Gaudi::Property<bool> m_overrideRunNumber{this, "OverrideRunNumber", false, ""};
218 Gaudi::Property<bool> m_filebased{this, "FileBased", true, ""};
219
220 Gaudi::CheckedProperty<uint32_t> m_runNo{this, "RunNumber", 0, ""};
221 Gaudi::CheckedProperty<uint64_t> m_firstEventNo{this, "FirstEvent", 1, ""};
222 Gaudi::CheckedProperty<uint64_t> m_eventsPerRun{this, "EventsPerRun", 1000000, ""};
223 Gaudi::CheckedProperty<uint32_t> m_firstLBNo{this, "FirstLB", 0, ""};
224 Gaudi::CheckedProperty<uint32_t> m_eventsPerLB{this, "EventsPerLB", 1000, ""};
225 Gaudi::CheckedProperty<uint32_t> m_initTimeStamp{this, "InitialTimeStamp", 0, ""};
226 Gaudi::Property<uint32_t> m_timeStampInterval{this, "TimeStampInterval", 0, ""};
227};
228
229#endif // BYTESTREAMCNVSVC_EVENTSELECTORBYTESTREAM_H
This file contains the class definition for the IAthenaSelectorTool class.
This file contains the interface for the ByteStreamInputSvc classes.
Extension to IEvtSelector to allow for seeking.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Abstract interface for secondary event selectors.
RAII guard that guarantees a matching end-incident for every begin-incident.
size_t size() const
Number of registered mappings.
Define macros for attributes used to control the static checker.
This class provides the Context for EventSelectorByteStream.
virtual StatusCode initialize() override
Implementation of Service base class methods.
virtual StatusCode stop() override
Gaudi::Property< bool > m_isSecondary
IsSecondary, know if this is an instance of secondary event selector.
virtual StatusCode previous(Context &it, int jump) const override
void fileTransition(lock_t &lock) const
EndInputFile for the file begun last and BeginInputFile for the file opened since,...
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.
Gaudi::Property< std::string > m_eventSourceName
ToolHandle< IAthenaSelectorTool > m_counterTool
virtual StatusCode share(int evtnum) override
Request to share a given event number.
Gaudi::Property< bool > m_filebased
Gaudi::Property< uint32_t > m_timeStampInterval
virtual StatusCode resetCriteria(const std::string &criteria, Context &context) const override
Set a selection criteria.
std::lock_guard< mutex_t > lock_t
SmartIF< IByteStreamInputSvc > m_eventSource
Gaudi::CheckedProperty< uint32_t > m_firstLBNo
virtual StatusCode readEvent(int maxevt) override
Read the next maxevt events.
EventContextByteStream * m_endIter
int findEvent(int evtNum, lock_t &lock) const
Search for event with number evtNum.
virtual StatusCode releaseContext(Context *&it) const override
virtual StatusCode makeServer(int num) override
Make this a server.
virtual StatusCode next(Context &it, int jump) const override
virtual bool disconnectIfFinished(const SG::SourceID &fid) const override
Gaudi::CheckedProperty< uint64_t > m_eventsPerRun
StatusCode nextImpl(Context &it, int jump, lock_t &lock) const
virtual StatusCode nextWithSkip(IEvtSelector::Context &ctxt) const override
Go to next event and skip if necessary.
ToolHandleArray< IAthenaSelectorTool > m_helperTools
HelperTools, vector of names of AlgTools that are executed by the EventSelector.
virtual StatusCode finalize() override
StatusCode previousImpl(Context &it, lock_t &lock) const
virtual StatusCode last(Context &it) const override
long openBlock(const std::string &fileName, lock_t &lock) const
Open fileName as the current file, without input file incidents (see fileTransition()).
Gaudi::CheckedProperty< uint32_t > m_initTimeStamp
Gaudi::CheckedProperty< uint32_t > m_eventsPerLB
Gaudi::Property< bool > m_overrideRunNumber
The following are included for compatibility with McEventSelector and are not really used.
Gaudi::Property< bool > m_procBadEvent
process bad events, which fail check_tree().
Gaudi::CheckedProperty< uint32_t > m_runNo
virtual StatusCode createContext(Context *&it) const override
create context
virtual StatusCode createAddress(const Context &it, IOpaqueAddress *&iop) const override
virtual StatusCode makeClient(int num) override
Make this a client.
virtual int curEvent(const Context &it) const override
Return the current event number.
ServiceHandle< IIncidentSvc > m_incidentSvc
StatusCode nextImpl(Context &it, lock_t &lock) const
StatusCode fillAttributeListImpl(coral::AttributeList *attrList, const std::string &suffix, bool copySource, lock_t &lock) const
void nextFile(lock_t &lock) const
StatusCode nextHandleFileTransitionImpl(IEvtSelector::Context &ctxt, lock_t &lock) const
virtual StatusCode rewind(Context &it) const override
StatusCode reinit(lock_t &lock)
Reinitialize the service when a fork() occurred/was-issued.
Gaudi::Property< std::vector< std::string > > m_inputCollectionsProp
virtual StatusCode next(Context &it) const override
int m_fileCount ATLAS_THREAD_SAFE
number of files to process.
StatusCode openNewRun(lock_t &lock) const
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
virtual ~EventSelectorByteStream()
Standard Destructor.
Gaudi::Property< std::vector< long > > m_skipEventSequenceProp
StoreGateSvc * eventStore() const
void inputCollectionsHandler(Gaudi::Details::PropertyBase &)
virtual StatusCode start() override
virtual StatusCode recordAttributeList() const override
Record AttributeList in StoreGate.
virtual StatusCode seek(Context &, int evtnum) const override
Seek to a given event number.
StatusCode nextWithSkipImpl(IEvtSelector::Context &ctxt, lock_t &lock) const
StatusCode recordAttributeListImpl(lock_t &lock) const
Gaudi::CheckedProperty< uint64_t > m_firstEventNo
EventContextByteStream * m_beginIter
virtual StatusCode nextHandleFileTransition(IEvtSelector::Context &ctxt) const override
Handle file transition at the next iteration.
StatusCode previousImpl(Context &it, int jump, lock_t &lock) const
Gaudi::Property< long > m_skipEvents
virtual StatusCode previous(Context &it) const override
Gaudi::Property< int > m_maxBadEvts
number of bad events allowed before quitting.
EventSelectorByteStream(const std::string &name, ISvcLocator *svcloc)
Standard Constructor.
Interface class for managing ROB for both online and offline.
The Athena Transient Store API.