ATLAS Offline Software
AthFilterAlgorithm.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // AthFilterAlgorithm.cxx
8 // Implementation file for class AthFilterAlgorithm
9 // Author: S.Binet<binet@cern.ch>
11 
12 // AthenaBaseComps includes
15 #include "StoreGate/ReadHandle.h"
16 
17 // STL includes
18 
19 // Framework includes
20 #include "Gaudi/Property.h"
21 
22 
24 // Public methods:
26 
27 // Constructors
30  ISvcLocator* pSvcLocator ) :
31  ::AthAlgorithm( name, pSvcLocator ),
32  m_cutID ( 0 ),
33  m_cutFlowSvc("CutFlowSvc/CutFlowSvc", name)
34 {
35  //
36  // Property declaration
37  //
38  //declareProperty( "Property", m_nProperty );
39 
40  declareProperty("CutFlowSvc", m_cutFlowSvc,
41  "handle to the ICutFlowSvc instance this filtering algorithm"
42  " will use for building the flow of cuts.");
43 
44  declareProperty("FilterDescription", m_filterDescr = "N/A",
45  "describe to the cutflowsvc what this filter does.")
46  ->declareUpdateHandler(&AthFilterAlgorithm::doNotResetSelfDescription, this);
48 }
49 
50 // Destructor
53 {}
54 
56 // Non-const methods:
58 
66 {
67  // ---- stolen from GaudiKernel/Algorithm::sysInitialize -------
68  // Bypass the initialization if the algorithm
69  // has already been initialized.
70  if ( Gaudi::StateMachine::INITIALIZED <= FSMState() ) return StatusCode::SUCCESS;
71 
72  // Set the Algorithm's properties
73  bindPropertiesTo( serviceLocator()->getOptsSvc() );
74 
75  // Bypass the initialization if the algorithm is disabled.
76  // Need to do this after bindPropertiesTo.
77  if ( !isEnabled( ) ) return StatusCode::SUCCESS;
78 
79  // ---- stolen from GaudiKernel/Algorithm::sysInitialize ------- END ---
80 
81  // register ourselves with the cutFlowSvc
82  if ( cutFlowSvc().retrieve().isSuccess()) {
83  m_cutID = cutFlowSvc()->registerFilter(this->name(), m_filterDescr, false);
84  if (0 == m_cutID) {
85  ATH_MSG_INFO("problem registering myself with cutflow-svc");
86  } else {
87  ATH_MSG_VERBOSE("registered with cutflow-svc");
88  }
89  }
90 
92 
93  // re-direct to base class...
95 }
96 
98 void
100 {
101  AthAlgorithm::setFilterPassed(state);
102 
103  if (state) {
104  const EventContext& ctx = Gaudi::Hive::currentContext();
106  // Only try to access the mcEventWeight if we are running on Monte Carlo, duhhh!
107  if ( evtInfo->eventType(xAOD::EventInfo::IS_SIMULATION) ) {
108  m_cutFlowSvc->addEvent(m_cutID, evtInfo->mcEventWeights());
109  } else {
110  m_cutFlowSvc->addEvent(m_cutID, 1.0);
111  }
112  }
113 }
114 
117 void
119 {
120  if( cutFlowSvc()==0 ){
122  }
123  else if( m_resetSelfDescription and cutID() ){
124  cutFlowSvc()->setFilterDescription(cutID(),descr);
125  }
126  else{
127  ATH_MSG_INFO("problem setting filter description with cutflow-svc");
128  }
129 
130  return;
131 }
132 
135 {
136  return m_eventInfoKey;
137 }
138 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AthFilterAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
Definition: AthFilterAlgorithm.cxx:99
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthFilterAlgorithm::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: AthFilterAlgorithm.h:97
xAOD::EventInfo_v1::mcEventWeights
const std::vector< float > & mcEventWeights() const
The weights of all the MC events used in the simulation.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthFilterAlgorithm::~AthFilterAlgorithm
virtual ~AthFilterAlgorithm()
Destructor:
Definition: AthFilterAlgorithm.cxx:52
AthFilterAlgorithm::cutID
CutIdentifier cutID()
return the CutIdentifier corresponding to the top-level cut of this filter algorithm
Definition: AthFilterAlgorithm.h:116
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< xAOD::EventInfo >
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
AthFilterAlgorithm::m_filterDescr
std::string m_filterDescr
filter description: describes what this filter does.
Definition: AthFilterAlgorithm.h:90
AthFilterAlgorithm::sysInitialize
virtual StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: AthFilterAlgorithm.cxx:65
AthFilterAlgorithm::m_cutFlowSvc
ICutFlowSvc_t m_cutFlowSvc
handle to the service holding tables of cut-flows for filtering algs.
Definition: AthFilterAlgorithm.h:86
AthAlgorithm::sysInitialize
virtual StatusCode sysInitialize() override
Override sysInitialize.
Definition: AthAlgorithm.cxx:66
AthFilterAlgorithm::AthFilterAlgorithm
AthFilterAlgorithm()
Default constructor:
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthFilterAlgorithm::doNotResetSelfDescription
void doNotResetSelfDescription(Gaudi::Details::PropertyBase &)
Definition: AthFilterAlgorithm.h:124
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.TransformConfig.descr
descr
print "%s.properties()" % self.__name__
Definition: TransformConfig.py:360
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
AthFilterAlgorithm::m_resetSelfDescription
bool m_resetSelfDescription
Definition: AthFilterAlgorithm.h:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AthFilterAlgorithm::eventInfoKey
const SG::ReadHandleKey< xAOD::EventInfo > & eventInfoKey() const
EventInfo key for use in derived classes.
Definition: AthFilterAlgorithm.cxx:134
EventInfo.h
AthFilterAlgorithm::m_cutID
CutIdentifier m_cutID
The CutIdentifier for this filter algorithm.
Definition: AthFilterAlgorithm.h:82
AthFilterAlgorithm::cutFlowSvc
ServiceHandle< ICutFlowSvc > & cutFlowSvc()
return a handle to an ICutFlowSvc instance
Definition: AthFilterAlgorithm.h:108
AthFilterAlgorithm::setFilterDescription
void setFilterDescription(const std::string &descr)
helper method to ease the setting of this filter's description in derived classes Note that this meth...
Definition: AthFilterAlgorithm.cxx:118
ReadHandle.h
Handle class for reading from StoreGate.
AthFilterAlgorithm.h
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.