ATLAS Offline Software
FilteredAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Framework include files
6 #include "GaudiKernel/GaudiException.h"
7 #include "GaudiKernel/IAlgManager.h"
8 #include "GaudiKernel/ISvcLocator.h"
9 #include "GaudiKernel/IProperty.h"
10 #include "GaudiKernel/MsgStream.h"
12 #include <cassert>
13 #include <string>
14 #include <vector>
15 
16 using std::string;
17 using std::vector;
18 
19 // Standard Constructor
21  ISvcLocator* pSvcLocator) :
22  AthAlgorithm(name, pSvcLocator),
23  m_decSvc("DecisionSvc/DecisionSvc",name)
24 {
25  assert( pSvcLocator );
26  declareProperty("AcceptAlgs",
28  "Filters which if any are passed enable output");
29  declareProperty("RequireAlgs",
31  "Filters which must all be passed to enable output");
32  declareProperty("VetoAlgs",
34  "Filters which if any are passed disable output");
35 
36  declareProperty("decSvc", m_decSvc);
37 
38 }
39 
40 // Standard Destructor
42 {}
43 
44 // initialize data writer
47 {
48  ATH_MSG_DEBUG ("In initialize ");
49 
50  // Decode the accept, required and veto Algorithms.
51  // The logic is the following:
52  // a. The event is accepted if all lists are empty.
53  // b. The event is provisionally accepted if any Algorithm in the
54  // accept list
55  // has been executed and has indicated that its filter is passed. This
56  // provisional acceptance can be overridden by the other lists.
57  // c. The event is rejected unless all Algorithms in the required list have
58  // been executed and have indicated that their filter passed.
59  // d. The event is rejected if any Algorithm in the veto list has been
60  // executed and has indicated that its filter has passed.
61 
62  // Use IDecisionSvc, FilteredAlgorithm is a wrapper around DecisionSvc
63  ATH_CHECK(m_decSvc.retrieve());
64  ATH_MSG_DEBUG( "Found IDecisionSvc." );
65 
66  // Register stream, no matter what Properties it has
67  if (!m_decSvc->addStream(this->name()).isSuccess()) {
68  ATH_MSG_ERROR("Couldn't add stream " << this->name());
69  }
70 
71  // Propagate the FilteredAlgorithm's Properties to IDecisionSvc
72  for (std::vector<std::string>::const_iterator
73  it = m_acceptNames.value().begin(),
74  end= m_acceptNames.value().end();
75  it != end;
76  ++it) {
77  ATH_MSG_DEBUG("Trying to add " << (*it) << " of stream "
78  << this->name() << " to AcceptAlg list");
79  if (!m_decSvc->addAcceptAlg((*it), this->name()).isSuccess()) {
80  ATH_MSG_ERROR("Couldn't add acceptAlg");
81  }
82  }
83 
84  for (std::vector<std::string>::const_iterator
85  it = m_requireNames.value().begin(),
86  end= m_requireNames.value().end();
87  it != end;
88  ++it){
89  ATH_MSG_DEBUG("Trying to add " << (*it) << " of stream "
90  << this->name() << " to RequireAlg list");
91  if (!m_decSvc->addRequireAlg((*it), this->name()).isSuccess()) {
92  ATH_MSG_ERROR("Couldn't add requireAlg");
93  }
94  }
95 
96  for (std::vector<std::string>::const_iterator
97  it = m_vetoNames.value().begin(),
98  end= m_vetoNames.value().end();
99  it != end;
100  ++it){
101  ATH_MSG_DEBUG("Trying to add " << (*it) << " of stream "
102  << this->name() << " to VetoAlg list");
103  if (!m_decSvc->addVetoAlg((*it), this->name()).isSuccess()) {
104  ATH_MSG_ERROR("Couldn't add vetoAlg");
105  }
106  }
107 
108  ATH_MSG_DEBUG ("End initialize ");
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 
114 StatusCode
116 {
117 
118  return StatusCode::SUCCESS;
119 }
120 
123 {
124  return StatusCode::SUCCESS;
125 }
126 
127 bool
129 {
130  bool result = true;
131  const EventContext& ctx = this->getContext();
132  if (ctx.valid()) {
133  result = m_decSvc->isEventAccepted(this->name(),ctx);
134  //ATH_MSG_DEBUG("res=" << result << " n=" << this->name() << " sl=" << ctx.slot() << " evt=" << ctx.eventID().event_number());
135  } else {
136  ATH_MSG_DEBUG("Not a threaded app");
137  result = m_decSvc->isEventAccepted(this->name());
138  }
139 
140  return result;
141 }
142 
get_generator_info.result
result
Definition: get_generator_info.py:21
FilteredAlgorithm.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
skel.it
it
Definition: skel.GENtoEVGEN.py:423
FilteredAlgorithm::finalize
virtual StatusCode finalize()
Definition: FilteredAlgorithm.cxx:115
FilteredAlgorithm::m_requireNames
StringArrayProperty m_requireNames
Vector of names of Algorithms that this stream requires.
Definition: FilteredAlgorithm.h:40
FilteredAlgorithm::initialize
virtual StatusCode initialize()
Definition: FilteredAlgorithm.cxx:46
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
FilteredAlgorithm::isEventAccepted
bool isEventAccepted() const
Test whether this event should be output.
Definition: FilteredAlgorithm.cxx:128
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FilteredAlgorithm::m_vetoNames
StringArrayProperty m_vetoNames
Vector of names of Algorithms that this stream is vetoed by.
Definition: FilteredAlgorithm.h:42
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
FilteredAlgorithm::execute
virtual StatusCode execute()
Definition: FilteredAlgorithm.cxx:122
FilteredAlgorithm::m_acceptNames
StringArrayProperty m_acceptNames
Vector of names of Algorithms that this stream accepts.
Definition: FilteredAlgorithm.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FilteredAlgorithm::FilteredAlgorithm
FilteredAlgorithm()
FilteredAlgorithm::~FilteredAlgorithm
virtual ~FilteredAlgorithm()
Standard Destructor.
Definition: FilteredAlgorithm.cxx:41
FilteredAlgorithm::m_decSvc
ServiceHandle< IDecisionSvc > m_decSvc
Definition: FilteredAlgorithm.h:44