ATLAS Offline Software
Loading...
Searching...
No Matches
SumOfWeightsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ReweightUtils includes
6#include "SumOfWeightsAlg.h"
8
9#include "TString.h"
10#include <string>
11
12using std::string;
13
14//**********************************************************************
15
16SumOfWeightsAlg::SumOfWeightsAlg(const std::string& name, ISvcLocator* pSvcLocator ) :
17 ::AthFilterAlgorithm( name, pSvcLocator ), m_eventsProcessed(0), m_cutIDs() {
18 declareProperty( "WeightTools", m_weightTools);
19}
20
21//**********************************************************************
22
24
25//**********************************************************************
26
27StatusCode SumOfWeightsAlg::initialize ATLAS_NOT_THREAD_SAFE () {
28 // ^ due to registerTopFilter
29 StatusCode sc;
30 ATH_MSG_DEBUG("Initializing " << name() << "...");
31 ATH_MSG_DEBUG("Retrieving tools...");
32 sc = m_weightTools.retrieve();
33 if ( ! sc.isSuccess() ) {
34 ATH_MSG_ERROR("Tool retrieval failed.");
35 return sc;
36 }
37 ATH_MSG_DEBUG("Tool retrieval completed.");
38 unsigned int ntool = m_weightTools.size();
39 ATH_MSG_DEBUG(" Tool count: " << ntool);
40 for (size_t itool = 0; itool < ntool; ++itool ) {
41 ATH_MSG_DEBUG(" " << m_weightTools[itool]->name());
42 if(msgLvl(MSG::DEBUG)) m_weightTools[itool]->print();
43 // Get the tool's message property:
44 const WeightToolBase* tool = dynamic_cast< const WeightToolBase* >( m_weightTools[ itool ].operator->() );
45 if( ! tool ) {
46 ATH_MSG_ERROR( "The received tool is not an WeightToolBase?!?" );
47 return StatusCode::FAILURE;
48 }
49 //strip the 'ToolSvc.' off the weight name
50 std::string toolName = m_weightTools[itool]->name();
51 if(toolName.starts_with ("ToolSvc.")) toolName.replace(0,8,"");
52 CutIdentifier cID = cutFlowSvc()->registerTopFilter( toolName,
53 toolName, // description (can be improved FIXME)
55 "AllStreams",
56 true);
57 m_cutIDs.push_back(cID);
58 }
59
60 return StatusCode::SUCCESS;
61}
62
63//**********************************************************************
64
66 ATH_MSG_DEBUG ("Executing " << name() << ", will loop over WeightTools...");
67 setFilterPassed(true);
68
69 for (std::size_t i = 0; i < m_cutIDs.size(); ++i) {
70 float weight = m_weightTools[i]->getWeight();
71 ATH_MSG_DEBUG(" got weight = " << weight << " for " << m_weightTools[i]->name());
72 const CutIdentifier cutID = m_cutIDs[i];
73 cutFlowSvc()->addEvent(cutID, weight);
74 }
75
77 return StatusCode::SUCCESS;
78}
79
80
81//**********************************************************************
83 ATH_MSG_INFO ("Finalizing " << name() << "...");
84 return StatusCode::SUCCESS;
85}
86
87
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
uint32_t CutIdentifier
InstanceIdentifier is a unique identifer used for every AthFilterAlgorithm instance.
Definition ICutFlowSvc.h:26
static Double_t sc
StatusCode SumOfWeightsAlg::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< ICutFlowSvc > & cutFlowSvc()
return a handle to an ICutFlowSvc instance
CutIdentifier cutID()
return the CutIdentifier corresponding to the top-level cut of this filter algorithm
virtual void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
AthFilterAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ToolHandleArray< IWeightTool > m_weightTools
Athena configured tools.
std::vector< CutIdentifier > m_cutIDs
cut IDs
SumOfWeightsAlg()
Default constructor:
~SumOfWeightsAlg()
Destructor:
unsigned long m_eventsProcessed
number of events processed
StatusCode finalize()
StatusCode execute()