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< StoreGateSvcm_evtStore
ServiceHandle< ICutFlowSvcm_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 163 of file DecisionSvc.cxx.

164{
165 // Add alg to list of streams
166 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
167 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
168 // Fill map of stream to alg
169 return fillMap(m_stream_accept,name,stream);
170}
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 173 of file DecisionSvc.cxx.

175{
176 // Add alg to list of streams
177 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
178 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
179 // Fill map of stream to alg
180 return fillMap(m_stream_require,name,stream);
181}
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 : " << stream << " already been registered!");
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: "<< stream << " with no Algs");
113 m_stream_accept.insert(std::make_pair(stream, tmpvec));
114 status = StatusCode::SUCCESS;
115 }
116 }
117 return status;
118}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(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 184 of file DecisionSvc.cxx.

186{
187 // Add alg to list of streams
188 auto it = std::find(m_streamNames.begin(), m_streamNames.end(),stream);
189 if (it != m_streamNames.end()) m_streamNames.push_back(stream);
190 // Fill map of stream to alg
191 return fillMap(m_stream_veto,name,stream);
192}
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 : " << name
138 << " of stream " << stream
139 << " has already been registered!");
140 return StatusCode::FAILURE;
141 }
142 }
143
144
145 // So, if the stream exist but the alg has not been registered
146 // update its content std::vector with a alg
147 if(algexist == false){
148 std::vector<std::string> &tmpvec = it->second;
149 tmpvec.push_back(name);
150 }
151
152 //if the stream doesn't exist yet, then insert it
153 } else {
154 std::vector<std::string> tmpvec;
155 tmpvec.push_back(name);
156 streamsModeMap[stream] = std::move(tmpvec);
157 }
158
159 return StatusCode::SUCCESS;
160}
#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 202 of file DecisionSvc.cxx.

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

◆ getRequireAlgs()

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

Return list of RequireAlg names.

Definition at line 211 of file DecisionSvc.cxx.

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

◆ getStreams()

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

Return list of Streams.

Definition at line 195 of file DecisionSvc.cxx.

196{
197 return m_streamNames;
198}

◆ getVetoAlgs()

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

Return list of VetoAlg names.

Definition at line 220 of file DecisionSvc.cxx.

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

◆ 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 235 of file DecisionSvc.cxx.

236{
237 EventContext ec;
238 ec.setValid(false);
239 ec.setSlot(0);
240 return isEventAccepted(stream,ec);
241}
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 244 of file DecisionSvc.cxx.

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