ATLAS Offline Software
Loading...
Searching...
No Matches
DecisionSvc Class Reference

This implementes the methods for IDecisionSvc. More...

#include <DecisionSvc.h>

Inheritance diagram for DecisionSvc:
Collaboration diagram for DecisionSvc:

Public Member Functions

 DecisionSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor.
virtual ~DecisionSvc ()
 Destructor.
virtual StatusCode initialize () override
 Gaudi Service Implementation.
virtual StatusCode start ATLAS_NOT_THREAD_SAFE () override
virtual StatusCode finalize () override
virtual StatusCode addStream (const std::string &stream) override
 Add a stream.
virtual StatusCode addAcceptAlg (const std::string &name, const std::string &stream) override
 Add an algorithm to the list of AcceptAlgs of a stream.
virtual StatusCode addRequireAlg (const std::string &name, const std::string &stream) override
 Add an algorithm to the list of RequireAlgs of a stream.
virtual StatusCode addVetoAlg (const std::string &name, const std::string &stream) override
 Add an algorithm to the list of VetoAlgs of a stream.
virtual const std::vector< std::string > getAcceptAlgs (const std::string &stream) const override
 Return list of AcceptAlg names.
virtual const std::vector< std::string > getRequireAlgs (const std::string &stream) const override
 Return list of RequireAlg names.
virtual const std::vector< std::string > getVetoAlgs (const std::string &stream) const override
 Return list of VetoAlg names.
virtual const std::vector< std::string > getStreams () const override
 Return list of Streams.
virtual bool isEventAccepted (const std::string &stream) const override
 Test whether this event should be output.
virtual bool isEventAccepted (const std::string &stream, const EventContext &) const override

Private Member Functions

StatusCode interpretAlgMap ()
StatusCode DeclareToCutFlowSvc ATLAS_NOT_THREAD_SAFE ()
StatusCode fillMap (std::map< std::string, std::vector< std::string > > &streamsModeMap, const std::string &name, const std::string &stream)

Private Attributes

std::map< std::string, std::vector< std::string > > m_stream_accept
 Maps of streams – algorithm names' vectors.
std::map< std::string, std::vector< std::string > > m_stream_require
std::map< std::string, std::vector< std::string > > m_stream_veto
std::vector< std::string > m_streamNames
Gaudi::Property< bool > m_calcStats {this, "CalcStats", false}
bool m_frozen {false}
ServiceHandle< StoreGateSvc > m_evtStore
ServiceHandle< ICutFlowSvc > m_cutflowSvc
ServiceHandle< IAlgExecStateSvc > m_algstateSvc

Detailed Description

This implementes the methods for IDecisionSvc.

Author
S.Binetbinet.nosp@m.@cer.nosp@m.n.ch
B.Radicsradba.nosp@m.l@ce.nosp@m.rn.ch

Definition at line 30 of file DecisionSvc.h.

Constructor & Destructor Documentation

◆ DecisionSvc()

DecisionSvc::DecisionSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Constructor.

Definition at line 12 of file DecisionSvc.cxx.

13 :
14 base_class(name, pSvcLocator),
15 m_evtStore("StoreGateSvc",name),
16#ifdef SIMULATIONBASE
17 m_cutflowSvc("",name),
18#else
19 m_cutflowSvc("CutFlowSvc/CutFlowSvc",name),
20#endif
21 m_algstateSvc("AlgExecStateSvc",name)
22{
23}
ServiceHandle< StoreGateSvc > m_evtStore
Definition DecisionSvc.h:97
ServiceHandle< ICutFlowSvc > m_cutflowSvc
Definition DecisionSvc.h:98
ServiceHandle< IAlgExecStateSvc > m_algstateSvc
Definition DecisionSvc.h:99

◆ ~DecisionSvc()

DecisionSvc::~DecisionSvc ( )
virtual

Destructor.

Definition at line 25 of file DecisionSvc.cxx.

26{
27}

Member Function Documentation

◆ addAcceptAlg()

StatusCode DecisionSvc::addAcceptAlg ( const std::string & name,
const std::string & stream )
overridevirtual

Add an algorithm to the list of AcceptAlgs of a stream.

Definition at line 162 of file DecisionSvc.cxx.

163{
164 // Add alg to list of streams
165 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
166 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
167 // Fill map of stream to alg
168 return fillMap(m_stream_accept,name,stream);
169}
std::map< std::string, std::vector< std::string > > m_stream_accept
Maps of streams – algorithm names' vectors.
Definition DecisionSvc.h:89
std::vector< std::string > m_streamNames
Definition DecisionSvc.h:93
StatusCode fillMap(std::map< std::string, std::vector< std::string > > &streamsModeMap, const std::string &name, const std::string &stream)

◆ addRequireAlg()

StatusCode DecisionSvc::addRequireAlg ( const std::string & name,
const std::string & stream )
overridevirtual

Add an algorithm to the list of RequireAlgs of a stream.

Definition at line 172 of file DecisionSvc.cxx.

174{
175 // Add alg to list of streams
176 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
177 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
178 // Fill map of stream to alg
179 return fillMap(m_stream_require,name,stream);
180}
std::map< std::string, std::vector< std::string > > m_stream_require
Definition DecisionSvc.h:90

◆ addStream()

StatusCode DecisionSvc::addStream ( const std::string & stream)
overridevirtual

Add a stream.

Definition at line 98 of file DecisionSvc.cxx.

99{
100 StatusCode status = StatusCode::SUCCESS;
101 if(m_frozen != true){
102 // check if this stream already exist
103 auto it = m_stream_accept.find(stream);
104 if(it != m_stream_accept.end()){
105 // ok, it exists, then do nothing
106 ATH_MSG_WARNING("Stream name : {} already been registered!", stream);
107 status = StatusCode::FAILURE;
108 }else{
109 //if the stream doesn't exist yet, then insert it to the accept list with an empty vector of Algs
110 std::vector<std::string> tmpvec;
111 tmpvec.clear();
112 ATH_MSG_INFO("Inserting stream: {} with no Algs", stream);
113 m_stream_accept.insert(std::make_pair(stream, tmpvec));
114 status = StatusCode::SUCCESS;
115 }
116 }
117 return status;
118}
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
::StatusCode StatusCode
StatusCode definition for legacy code.
status
Definition merge.py:16

◆ addVetoAlg()

StatusCode DecisionSvc::addVetoAlg ( const std::string & name,
const std::string & stream )
overridevirtual

Add an algorithm to the list of VetoAlgs of a stream.

Definition at line 183 of file DecisionSvc.cxx.

185{
186 // Add alg to list of streams
187 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
188 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
189 // Fill map of stream to alg
190 return fillMap(m_stream_veto,name,stream);
191}
std::map< std::string, std::vector< std::string > > m_stream_veto
Definition DecisionSvc.h:91

◆ ATLAS_NOT_THREAD_SAFE() [1/2]

StatusCode DeclareToCutFlowSvc DecisionSvc::ATLAS_NOT_THREAD_SAFE ( )
private

◆ ATLAS_NOT_THREAD_SAFE() [2/2]

virtual StatusCode start DecisionSvc::ATLAS_NOT_THREAD_SAFE ( )
overridevirtual

◆ fillMap()

StatusCode DecisionSvc::fillMap ( std::map< std::string, std::vector< std::string > > & streamsModeMap,
const std::string & name,
const std::string & stream )
private

Definition at line 121 of file DecisionSvc.cxx.

123{
124 // check if this stream already exist
125 std::map<std::string, std::vector<std::string> >::iterator it = streamsModeMap.find(stream);
126 if(it != streamsModeMap.end()){
127 // ok, it exists, then check if the algname was already been inserted
128
129
130 bool algexist = false;
131 // Check if alg already registered for this stream
132 for(auto vit = (it->second).begin();
133 vit != (it->second).end(); ++vit) {
134 if((*vit) == name){
135 algexist = true;
136 // it seems the alg was already inserted, warn the user
137 ATH_MSG_ERROR("Alg name : {} of stream {} has already been registered!",
138 name, stream);
139 return StatusCode::FAILURE;
140 }
141 }
142
143
144 // So, if the stream exist but the alg has not been registered
145 // update its content std::vector with a alg
146 if(algexist == false){
147 std::vector<std::string> &tmpvec = it->second;
148 tmpvec.push_back(name);
149 }
150
151 //if the stream doesn't exist yet, then insert it
152 } else {
153 std::vector<std::string> tmpvec;
154 tmpvec.push_back(name);
155 streamsModeMap[stream] = std::move(tmpvec);
156 }
157
158 return StatusCode::SUCCESS;
159}
#define ATH_MSG_ERROR(x,...)

◆ finalize()

StatusCode DecisionSvc::finalize ( )
overridevirtual

Definition at line 57 of file DecisionSvc.cxx.

58{
59 ATH_MSG_INFO ("Finalized successfully.");
60 return StatusCode::SUCCESS;
61}

◆ getAcceptAlgs()

const std::vector< std::string > DecisionSvc::getAcceptAlgs ( const std::string & stream) const
overridevirtual

Return list of AcceptAlg names.

Definition at line 201 of file DecisionSvc.cxx.

202{
203 auto iter = m_stream_accept.find(stream);
204 if (iter != m_stream_accept.end()) return iter->second;
205 return std::vector<std::string>();
206}

◆ getRequireAlgs()

const std::vector< std::string > DecisionSvc::getRequireAlgs ( const std::string & stream) const
overridevirtual

Return list of RequireAlg names.

Definition at line 210 of file DecisionSvc.cxx.

211{
212 auto iter = m_stream_require.find(stream);
213 if (iter != m_stream_require.end()) return iter->second;
214 return std::vector<std::string>();
215}

◆ getStreams()

const std::vector< std::string > DecisionSvc::getStreams ( ) const
overridevirtual

Return list of Streams.

Definition at line 194 of file DecisionSvc.cxx.

195{
196 return m_streamNames;
197}

◆ getVetoAlgs()

const std::vector< std::string > DecisionSvc::getVetoAlgs ( const std::string & stream) const
overridevirtual

Return list of VetoAlg names.

Definition at line 219 of file DecisionSvc.cxx.

220{
221 auto iter = m_stream_veto.find(stream);
222 if (iter != m_stream_veto.end()) return iter->second;
223 return std::vector<std::string>();
224}

◆ initialize()

StatusCode DecisionSvc::initialize ( )
overridevirtual

Gaudi Service Implementation.

Definition at line 30 of file DecisionSvc.cxx.

31{
32 // Decode the accept, required and veto Algorithms.
33 // The logic is the following:
34 // a. The event is accepted if all lists are empty.
35 // b. The event is provisionally accepted if any Algorithm in the
36 // accept list
37 // has been executed and has indicated that its filter is passed. This
38 // provisional acceptance can be overridden by the other lists.
39 // c. The event is rejected unless all Algorithms in the required list have
40 // been executed and have indicated that their filter passed.
41 // d. The event is rejected if any Algorithm in the veto list has been
42 // executed and has indicated that its filter has passed.
43
44 // Set to be listener for BeginRun
45 // Declares top filters to ICutFlowSvc if (and only if) needed (David Cote, Sep 2010)
46
47 // Get handle to exec state service for retrieving decisions
48 ATH_CHECK( m_algstateSvc.retrieve() );
49
50 ATH_CHECK(m_evtStore.retrieve());
51
52 return StatusCode::SUCCESS;
53}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ interpretAlgMap()

StatusCode DecisionSvc::interpretAlgMap ( )
private

Definition at line 64 of file DecisionSvc.cxx.

65{
66 StatusCode status = StatusCode::SUCCESS;
67
68 // Fill up m_streamNames vector
69 std::set<std::string> uniStreams;
70 m_streamNames.clear();
71 // first take list of streams from accept streams
72 for(auto iter = m_stream_accept.begin();
73 iter != m_stream_accept.end(); ++iter){
74 uniStreams.insert(iter->first);
75 }
76 // then require
77 for(auto iter = m_stream_require.begin();
78 iter != m_stream_require.end(); ++iter){
79 uniStreams.insert(iter->first);
80 }
81 // then veto
82 for(auto iter = m_stream_veto.begin();
83 iter != m_stream_veto.end(); ++iter){
84 uniStreams.insert(iter->first);
85 }
86 std::copy(uniStreams.begin(),uniStreams.end(),std::back_inserter(m_streamNames));
87
88 return status;
89}

◆ isEventAccepted() [1/2]

bool DecisionSvc::isEventAccepted ( const std::string & stream) const
overridevirtual

Test whether this event should be output.

Definition at line 234 of file DecisionSvc.cxx.

235{
236 EventContext ec;
237 ec.setValid(false);
238 ec.setSlot(0);
239 return isEventAccepted(stream,ec);
240}
virtual bool isEventAccepted(const std::string &stream) const override
Test whether this event should be output.

◆ isEventAccepted() [2/2]

bool DecisionSvc::isEventAccepted ( const std::string & stream,
const EventContext & ectx ) const
overridevirtual

Definition at line 243 of file DecisionSvc.cxx.

245{
246
247 ATH_MSG_DEBUG("In DecisionSvc::isEventAccepted( {} )", stream);
248
249 // By construction a stream is accepted
250 bool result = true;
251
252 bool found_accept = false;
253 bool found_require = false;
254 bool found_veto = false;
255
256 //Loop over all streams of accept type and find the one of interest
257 auto itAlgs = m_stream_accept.find(stream);
258 if(itAlgs != m_stream_accept.end()){
259 found_accept = true;
260 // get a handle of the streams' algos vector
261 const auto &vecAlgs = itAlgs->second;
262 // Loop over all Algorithms in the list to see
263 // whether any have been executed and have their filter
264 // passed flag set. Any match causes the event to be
265 // provisionally accepted.
266 if ( ! vecAlgs.empty( ) ) {
267 result = false;
268 for (auto it = vecAlgs.begin(); it != vecAlgs.end(); it++) {
269 bool isE,fp;
270 isE = (m_algstateSvc->algExecState(*it,ectx).state() == AlgExecState::State::Done);
271 fp = m_algstateSvc->algExecState(*it,ectx).filterPassed();
272 if (isE && fp) {
273 result = true;
274 break;
275 }
276 }
277 }
278 }
279
280 //Loop over all streams of require type and find the one of interest
281 itAlgs = m_stream_require.find(stream);
282 if(itAlgs != m_stream_require.end()){
283 found_require = true;
284 // get a handle of the streams' algos vector
285 const auto &vecAlgs = itAlgs->second;
286 // Loop over all Algorithms in the list to see
287 // whether any have been executed and have their filter
288 // passed flag set. Any match causes the event to be
289 // provisionally accepted.
290 if ( ! vecAlgs.empty( ) ) {
291 for (auto it = vecAlgs.begin(); it != vecAlgs.end(); it++) {
292 bool isE,fp;
293 isE = (m_algstateSvc->algExecState(*it,ectx).state() == AlgExecState::State::Done);
294 fp = m_algstateSvc->algExecState(*it,ectx).filterPassed();
295 if (!isE || !fp) {
296 result = false;
297 break;
298 }
299 }
300 }
301 }
302
303 //Loop over all streams of veto type and find the one of interest
304 itAlgs = m_stream_veto.find(stream);
305 if(itAlgs != m_stream_veto.end()){
306 found_veto = true;
307 // get a handle of the streams' algos vector
308 const auto &vecAlgs = itAlgs->second;
309 // Loop over all Algorithms in the list to see
310 // whether any have been executed and have their filter
311 // passed flag set. Any match causes the event to be
312 // provisionally accepted.
313 if ( ! vecAlgs.empty( ) ) {
314 for (auto it = vecAlgs.begin(); it != vecAlgs.end(); it++) {
315 bool isE,fp;
316 isE = (m_algstateSvc->algExecState(*it,ectx).state() == AlgExecState::State::Done);
317 fp = m_algstateSvc->algExecState(*it,ectx).filterPassed();
318 if ( isE && fp ) {
319 result = false;
320 break;
321 }
322 }
323 }
324 }
325
326 if(found_accept == false && found_require == false && found_veto == false){
327 ATH_MSG_DEBUG("Stream: {} not found registered in DecisionSvc -- accepting event by default ", stream);
328 }
329
330 return result;
331}
#define ATH_MSG_DEBUG(x,...)

Member Data Documentation

◆ m_algstateSvc

ServiceHandle<IAlgExecStateSvc> DecisionSvc::m_algstateSvc
private

Definition at line 99 of file DecisionSvc.h.

◆ m_calcStats

Gaudi::Property<bool> DecisionSvc::m_calcStats {this, "CalcStats", false}
private

Definition at line 95 of file DecisionSvc.h.

95{this, "CalcStats", false};

◆ m_cutflowSvc

ServiceHandle<ICutFlowSvc> DecisionSvc::m_cutflowSvc
private

Definition at line 98 of file DecisionSvc.h.

◆ m_evtStore

ServiceHandle<StoreGateSvc> DecisionSvc::m_evtStore
private

Definition at line 97 of file DecisionSvc.h.

◆ m_frozen

bool DecisionSvc::m_frozen {false}
private

Definition at line 96 of file DecisionSvc.h.

96{false};

◆ m_stream_accept

std::map<std::string, std::vector<std::string> > DecisionSvc::m_stream_accept
private

Maps of streams – algorithm names' vectors.

Definition at line 89 of file DecisionSvc.h.

◆ m_stream_require

std::map<std::string, std::vector<std::string> > DecisionSvc::m_stream_require
private

Definition at line 90 of file DecisionSvc.h.

◆ m_stream_veto

std::map<std::string, std::vector<std::string> > DecisionSvc::m_stream_veto
private

Definition at line 91 of file DecisionSvc.h.

◆ m_streamNames

std::vector<std::string> DecisionSvc::m_streamNames
private

Definition at line 93 of file DecisionSvc.h.


The documentation for this class was generated from the following files: