ATLAS Offline Software
EventSelectorByteStream.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENTSELECTORBYTESTREAM_H
6 #define EVENTSELECTORBYTESTREAM_H
7 
19 #include "GaudiKernel/IEvtSelector.h"
20 #include "GaudiKernel/ServiceHandle.h"
21 #include "GaudiKernel/ToolHandle.h"
22 #include "GaudiKernel/IIoComponent.h"
23 
30 
34 #include <mutex>
35 
36 // Forward declarations.
37 class ISvcLocator;
40 
41 // Class EventSelectorByteStream.
43  public extends<::AthService, IEvtSelector, IEvtSelectorSeek, IEventShare, IIoComponent, ISecondaryEventSelector>
44 {
45 public:
47  EventSelectorByteStream(const std::string& name, ISvcLocator* svcloc);
49  virtual ~EventSelectorByteStream();
50 
52  virtual StatusCode initialize() override;
53  virtual StatusCode start() override;
54  virtual StatusCode stop() override;
55  virtual StatusCode finalize() override;
56 
57  //-------------------------------------------------
58  // IEventSelector
60  virtual StatusCode createContext(Context*& it) const override;
62  virtual StatusCode next(Context& it) const override;
65  virtual StatusCode next(Context& it, int jump) const override;
67  virtual StatusCode previous(Context& it) const override;
70  virtual StatusCode previous(Context& it, int jump) const override;
71 
73  virtual StatusCode last(Context& it) const override;
75  virtual StatusCode rewind(Context& it) const override;
76 
79  virtual StatusCode createAddress(const Context& it,IOpaqueAddress*& iop) const override;
80 
82  virtual StatusCode releaseContext(Context*& it) const override;
83 
87  virtual StatusCode resetCriteria(const std::string& criteria, Context& context) const override;
88 
89  //-------------------------------------------------
90  // IEventSelectorSeek
94  virtual StatusCode seek (Context& /* it */, int evtnum) const override;
95 
98  virtual int curEvent (const Context& it) const override;
99 
102  virtual int size (Context& it) const override;
103 
104  //-------------------------------------------------
105  // IEventShare
107  virtual StatusCode makeServer(int num) override;
108 
110  virtual StatusCode makeClient(int num) override;
111 
114  virtual StatusCode share(int evtnum) override;
115 
118  virtual StatusCode readEvent(int maxevt) override;
119 
120  //-------------------------------------------------
121  // IIoComponent
123  virtual StatusCode io_reinit() override;
124 
125 protected:
126  typedef std::recursive_mutex mutex_t;
127  typedef std::lock_guard<mutex_t> lock_t;
128 
129  //-------------------------------------------------
130  // ISecondaryEventSelector
132  virtual StatusCode nextHandleFileTransition(IEvtSelector::Context& ctxt) const override;
134  virtual StatusCode nextWithSkip(IEvtSelector::Context& ctxt) const override;
136  virtual StatusCode recordAttributeList() const override;
138  virtual StatusCode fillAttributeList(coral::AttributeList *attrList, const std::string &suffix, bool copySource) const override;
139  // Disconnect DB if all events from the source FID were processed and the Selector moved to another file
140  virtual bool disconnectIfFinished(const SG::SourceID &fid) const override;
141 
142 private: // internal member functions
143  StatusCode nextImpl(Context& it, lock_t& lock) const;
144  StatusCode nextImpl(Context& it, int jump, lock_t& lock) const;
145  StatusCode previousImpl(Context& it, lock_t& lock) const;
146  StatusCode previousImpl(Context& it, int jump, lock_t& lock) const;
147  StatusCode nextHandleFileTransitionImpl(IEvtSelector::Context& ctxt,
148  lock_t& lock) const;
149  StatusCode nextWithSkipImpl(IEvtSelector::Context& ctxt,
150  lock_t& lock) const;
152  StatusCode fillAttributeListImpl(coral::AttributeList *attrList, const std::string &suffix, bool copySource,
153  lock_t& lock) const;
154 
156  StatusCode reinit(lock_t& lock);
157  StatusCode openNewRun(lock_t& lock) const;
158  void nextFile(lock_t& lock) const;
160  int findEvent(int evtNum, lock_t& lock) const;
161  StoreGateSvc* eventStore() const;
162 
163 private: // properties
164  // FIXME: A Gaudi EventSelector is not meant to have mutable state.
165  // Any needed state is meant to be kept in the Context object.
166  // So the mutable members here should instead be kept in
167  // EventContextByteStream. However, making that work would
168  // require redesigning other Athena interfaces. So for now,
169  // just add a mutex to protect access to them.
170  mutable mutex_t m_mutex;
171  mutable int m_fileCount ATLAS_THREAD_SAFE = 0;
172  mutable std::vector<int> m_numEvt ATLAS_THREAD_SAFE;
173  mutable std::vector<int> m_firstEvt ATLAS_THREAD_SAFE;
174  mutable std::vector<std::string>::const_iterator m_inputCollectionsIterator ATLAS_THREAD_SAFE;
175  mutable std::vector<long> m_skipEventSequence ATLAS_THREAD_SAFE;
176  mutable long m_NumEvents ATLAS_THREAD_SAFE = 0; // Number of Events read so far.
177  mutable ToolHandle<IAthenaIPCTool> m_eventStreamingTool ATLAS_THREAD_SAFE {this, "SharedMemoryTool", "", ""};
178 
180  Gaudi::Property<bool> m_isSecondary{this, "IsSecondary", false, ""};
181 
182  Gaudi::Property<std::string> m_eventSourceName{this, "ByteStreamInputSvc", "", ""};
183  Gaudi::Property<bool> m_procBadEvent{this, "ProcessBadEvent", false, ""};
184  Gaudi::Property<int> m_maxBadEvts{this, "MaxBadEvents", -1, ""};
185 
188  SmartIF<IByteStreamInputSvc> m_eventSource;
189  Gaudi::Property<std::vector<std::string>> m_inputCollectionsProp{this, "Input", {}, ""};
190  void inputCollectionsHandler(Gaudi::Details::PropertyBase&);
191  ServiceHandle<IIncidentSvc> m_incidentSvc{this, "IncidentSvc", "IncidentSvc", ""};
192 
193  Gaudi::Property<long> m_skipEvents{this, "SkipEvents", 0, ""}; // Number of events to skip at the beginning
194  Gaudi::Property<std::vector<long>> m_skipEventSequenceProp{this, "SkipEventSequence", {}, ""};
195 
198 
200  ToolHandleArray<IAthenaSelectorTool> m_helperTools{this};
201  ToolHandle<IAthenaSelectorTool> m_counterTool{this, "CounterTool", "", ""};
202 
206  Gaudi::Property<bool> m_overrideRunNumber{this, "OverrideRunNumber", false, ""};
207  Gaudi::Property<bool> m_filebased{this, "FileBased", true, ""};
208 
209  Gaudi::CheckedProperty<int> m_runNo{this, "RunNumber", 0, ""};
210  Gaudi::CheckedProperty<int> m_firstEventNo{this, "FirstEvent", 1, ""};
211  Gaudi::CheckedProperty<int> m_eventsPerRun{this, "EventsPerRun", 1000000, ""};
212  Gaudi::CheckedProperty<int> m_firstLBNo{this, "FirstLB", 0, ""};
213  Gaudi::CheckedProperty<int> m_eventsPerLB{this, "EventsPerLB", 1000, ""};
214  Gaudi::CheckedProperty<int> m_initTimeStamp{this, "InitialTimeStamp", 0, ""};
215  Gaudi::Property<int> m_timeStampInterval{this, "TimeStampInterval", 0, ""};
216 };
217 
218 #endif
EventSelectorByteStream::m_firstFileFired
bool m_firstFileFired
Definition: EventSelectorByteStream.h:196
EventSelectorByteStream::curEvent
virtual int curEvent(const Context &it) const override
Return the current event number.
Definition: EventSelectorByteStream.cxx:943
EventSelectorByteStream::findEvent
int findEvent(int evtNum, lock_t &lock) const
Search for event with number evtNum.
Definition: EventSelectorByteStream.cxx:905
EventSelectorByteStream::m_filebased
Gaudi::Property< bool > m_filebased
Definition: EventSelectorByteStream.h:207
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
EventSelectorByteStream::m_skipEvents
Gaudi::Property< long > m_skipEvents
Definition: EventSelectorByteStream.h:193
EventSelectorByteStream::ATLAS_THREAD_SAFE
std::vector< int > m_firstEvt ATLAS_THREAD_SAFE
Definition: EventSelectorByteStream.h:173
EventSelectorByteStream::makeClient
virtual StatusCode makeClient(int num) override
Make this a client.
Definition: EventSelectorByteStream.cxx:964
EventSelectorByteStream::fillAttributeList
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.
Definition: EventSelectorByteStream.cxx:808
IEventShare.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
EventSelectorByteStream::nextWithSkipImpl
StatusCode nextWithSkipImpl(IEvtSelector::Context &ctxt, lock_t &lock) const
Definition: EventSelectorByteStream.cxx:578
EventSelectorByteStream::eventStore
StoreGateSvc * eventStore() const
Definition: EventSelectorByteStream.cxx:78
IAthenaSelectorTool.h
This file contains the class definition for the IAthenaSelectorTool class.
EventSelectorByteStream::openNewRun
StatusCode openNewRun(lock_t &lock) const
Definition: EventSelectorByteStream.cxx:288
EventSelectorByteStream::fillAttributeListImpl
StatusCode fillAttributeListImpl(coral::AttributeList *attrList, const std::string &suffix, bool copySource, lock_t &lock) const
Definition: EventSelectorByteStream.cxx:813
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
EventSelectorByteStream::m_runNo
Gaudi::CheckedProperty< int > m_runNo
Definition: EventSelectorByteStream.h:209
EventSelectorByteStream::~EventSelectorByteStream
virtual ~EventSelectorByteStream()
Standard Destructor.
Definition: EventSelectorByteStream.cxx:72
EventSelectorByteStream::nextHandleFileTransitionImpl
StatusCode nextHandleFileTransitionImpl(IEvtSelector::Context &ctxt, lock_t &lock) const
Definition: EventSelectorByteStream.cxx:522
EventSelectorByteStream::m_firstLBNo
Gaudi::CheckedProperty< int > m_firstLBNo
Definition: EventSelectorByteStream.h:212
EventSelectorByteStream::rewind
virtual StatusCode rewind(Context &it) const override
Definition: EventSelectorByteStream.cxx:706
EventSelectorByteStream::m_beginIter
EventContextByteStream * m_beginIter
Definition: EventSelectorByteStream.h:186
EventSelectorByteStream::EventSelectorByteStream
EventSelectorByteStream(const std::string &name, ISvcLocator *svcloc)
Standard Constructor.
Definition: EventSelectorByteStream.cxx:41
EventSelectorByteStream::nextHandleFileTransition
virtual StatusCode nextHandleFileTransition(IEvtSelector::Context &ctxt) const override
Handle file transition at the next iteration.
Definition: EventSelectorByteStream.cxx:517
EventSelectorByteStream::readEvent
virtual StatusCode readEvent(int maxevt) override
Read the next maxevt events.
Definition: EventSelectorByteStream.cxx:991
EventSelectorByteStream::createContext
virtual StatusCode createContext(Context *&it) const override
create context
Definition: EventSelectorByteStream.cxx:338
EventSelectorByteStream::m_mutex
mutex_t m_mutex
Definition: EventSelectorByteStream.h:170
EventSelectorByteStream::createAddress
virtual StatusCode createAddress(const Context &it, IOpaqueAddress *&iop) const override
Definition: EventSelectorByteStream.cxx:1038
EventSelectorByteStream::m_endIter
EventContextByteStream * m_endIter
Definition: EventSelectorByteStream.h:187
EventSelectorByteStream::size
virtual int size(Context &it) const override
Always returns -1.
Definition: EventSelectorByteStream.cxx:950
EventSelectorByteStream::m_helperTools
ToolHandleArray< IAthenaSelectorTool > m_helperTools
HelperTools, vector of names of AlgTools that are executed by the EventSelector.
Definition: EventSelectorByteStream.h:200
IROBDataProviderSvc
Interface class for managing ROB for both online and offline.
Definition: IROBDataProviderSvc.h:23
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
EventSelectorByteStream::m_initTimeStamp
Gaudi::CheckedProperty< int > m_initTimeStamp
Definition: EventSelectorByteStream.h:214
EventSelectorByteStream::reinit
StatusCode reinit(lock_t &lock)
Reinitialize the service when a fork() occurred/was-issued.
Definition: EventSelectorByteStream.cxx:172
EventSelectorByteStream::m_overrideRunNumber
Gaudi::Property< bool > m_overrideRunNumber
The following are included for compatibility with McEventSelector and are not really used.
Definition: EventSelectorByteStream.h:206
EventSelectorByteStream::nextFile
void nextFile(lock_t &lock) const
Definition: EventSelectorByteStream.cxx:281
EventSelectorByteStream::nextImpl
StatusCode nextImpl(Context &it, lock_t &lock) const
Definition: EventSelectorByteStream.cxx:347
EventSelectorByteStream::m_counterTool
ToolHandle< IAthenaSelectorTool > m_counterTool
Definition: EventSelectorByteStream.h:201
EventSelectorByteStream::m_eventsPerRun
Gaudi::CheckedProperty< int > m_eventsPerRun
Definition: EventSelectorByteStream.h:211
RawEvent.h
EventSelectorByteStream::m_procBadEvent
Gaudi::Property< bool > m_procBadEvent
process bad events, which fail check_tree().
Definition: EventSelectorByteStream.h:183
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EventSelectorByteStream::inputCollectionsHandler
void inputCollectionsHandler(Gaudi::Details::PropertyBase &)
Definition: EventSelectorByteStream.cxx:63
EventSelectorByteStream
concrete implementation of IEvtSelector for ByteStream
Definition: EventSelectorByteStream.h:44
EventSelectorByteStream::mutex_t
std::recursive_mutex mutex_t
Definition: EventSelectorByteStream.h:126
EventSelectorByteStream::m_maxBadEvts
Gaudi::Property< int > m_maxBadEvts
number of bad events allowed before quitting.
Definition: EventSelectorByteStream.h:184
EventSelectorByteStream::ATLAS_THREAD_SAFE
int m_fileCount ATLAS_THREAD_SAFE
number of files to process.
Definition: EventSelectorByteStream.h:171
EventSelectorByteStream::last
virtual StatusCode last(Context &it) const override
Definition: EventSelectorByteStream.cxx:698
EventSelectorByteStream::ATLAS_THREAD_SAFE
std::vector< std::string >::const_iterator m_inputCollectionsIterator ATLAS_THREAD_SAFE
Definition: EventSelectorByteStream.h:174
EventSelectorByteStream::m_firstEventNo
Gaudi::CheckedProperty< int > m_firstEventNo
Definition: EventSelectorByteStream.h:210
EventSelectorByteStream::m_isSecondary
Gaudi::Property< bool > m_isSecondary
IsSecondary, know if this is an instance of secondary event selector.
Definition: EventSelectorByteStream.h:180
EventSelectorByteStream::m_timeStampInterval
Gaudi::Property< int > m_timeStampInterval
Definition: EventSelectorByteStream.h:215
EventSelectorByteStream::ATLAS_THREAD_SAFE
std::vector< long > m_skipEventSequence ATLAS_THREAD_SAFE
Definition: EventSelectorByteStream.h:175
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
EventSelectorByteStream::stop
virtual StatusCode stop() override
Definition: EventSelectorByteStream.cxx:234
EventSelectorByteStream::m_incidentSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
Definition: EventSelectorByteStream.h:191
EventSelectorByteStream::m_eventSourceName
Gaudi::Property< std::string > m_eventSourceName
Definition: EventSelectorByteStream.h:182
EventSelectorByteStream::m_inputCollectionsProp
Gaudi::Property< std::vector< std::string > > m_inputCollectionsProp
Definition: EventSelectorByteStream.h:189
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IByteStreamInputSvc.h
This file contains the interface for the ByteStreamInputSvc classes.
EventSelectorByteStream::m_beginFileFired
bool m_beginFileFired
Definition: EventSelectorByteStream.h:197
EventSelectorByteStream::recordAttributeListImpl
StatusCode recordAttributeListImpl(lock_t &lock) const
Definition: EventSelectorByteStream.cxx:778
EventSelectorByteStream::previous
virtual StatusCode previous(Context &it) const override
Definition: EventSelectorByteStream.cxx:616
EventSelectorByteStream::seek
virtual StatusCode seek(Context &, int evtnum) const override
Seek to a given event number.
Definition: EventSelectorByteStream.cxx:717
EventSelectorByteStream::finalize
virtual StatusCode finalize() override
Definition: EventSelectorByteStream.cxx:249
EventSelectorByteStream::m_eventSource
SmartIF< IByteStreamInputSvc > m_eventSource
Definition: EventSelectorByteStream.h:188
EventSelectorByteStream::share
virtual StatusCode share(int evtnum) override
Request to share a given event number.
Definition: EventSelectorByteStream.cxx:974
EventSelectorByteStream::start
virtual StatusCode start() override
Definition: EventSelectorByteStream.cxx:222
SG::SourceID
std::string SourceID
Definition: AthenaKernel/AthenaKernel/SourceID.h:25
EventSelectorByteStream::makeServer
virtual StatusCode makeServer(int num) override
Make this a server.
Definition: EventSelectorByteStream.cxx:955
EventSelectorByteStream::releaseContext
virtual StatusCode releaseContext(Context *&it) const override
Definition: EventSelectorByteStream.cxx:1052
EventSelectorByteStream::disconnectIfFinished
virtual bool disconnectIfFinished(const SG::SourceID &fid) const override
Definition: EventSelectorByteStream.cxx:1099
EventContextByteStream
This class provides the Context for EventSelectorByteStream.
Definition: EventContextByteStream.h:21
AthService.h
EventSelectorByteStream::nextWithSkip
virtual StatusCode nextWithSkip(IEvtSelector::Context &ctxt) const override
Go to next event and skip if necessary.
Definition: EventSelectorByteStream.cxx:573
EventSelectorByteStream::recordAttributeList
virtual StatusCode recordAttributeList() const override
Record AttributeList in StoreGate.
Definition: EventSelectorByteStream.cxx:773
EventSelectorByteStream::m_eventsPerLB
Gaudi::CheckedProperty< int > m_eventsPerLB
Definition: EventSelectorByteStream.h:213
EventSelectorByteStream::m_skipEventSequenceProp
Gaudi::Property< std::vector< long > > m_skipEventSequenceProp
Definition: EventSelectorByteStream.h:194
IEvtSelectorSeek.h
Extension to IEvtSelector to allow for seeking.
EventSelectorByteStream::ATLAS_THREAD_SAFE
std::vector< int > m_numEvt ATLAS_THREAD_SAFE
Definition: EventSelectorByteStream.h:172
checker_macros.h
Define macros for attributes used to control the static checker.
EventSelectorByteStream::lock_t
std::lock_guard< mutex_t > lock_t
Definition: EventSelectorByteStream.h:127
EventSelectorByteStream::previousImpl
StatusCode previousImpl(Context &it, lock_t &lock) const
Definition: EventSelectorByteStream.cxx:621
IAthenaIPCTool.h
EventSelectorByteStream::initialize
virtual StatusCode initialize() override
Implementation of Service base class methods.
Definition: EventSelectorByteStream.cxx:84
EventSelectorByteStream::next
virtual StatusCode next(Context &it) const override
Definition: EventSelectorByteStream.cxx:343
EventSelectorByteStream::resetCriteria
virtual StatusCode resetCriteria(const std::string &criteria, Context &context) const override
Set a selection criteria.
Definition: EventSelectorByteStream.cxx:712
ServiceHandle< IIncidentSvc >
ISecondaryEventSelector.h
Abstract interface for secondary event selectors.
EventSelectorByteStream::io_reinit
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
Definition: EventSelectorByteStream.cxx:1057