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

#include <BookkeeperTool.h>

Inheritance diagram for BookkeeperTool:
Collaboration diagram for BookkeeperTool:

Public Types

Definition of the StoreGate-like object's definition
typedef ServiceHandle< StoreGateSvcMetaStore_t
 Type of the metadata store object in Athena.
typedef const ServiceHandle< StoreGateSvc > & MetaStorePtr_t
 Type of the metadata store pointer in standalone mode.

Public Member Functions

 BookkeeperTool (const std::string &name="BookkeeperTool")
 Declare the correct constructor for Athena.
virtual ~BookkeeperTool ()=default
 Destructor.
virtual StatusCode initialize () override
 Standard reimplemented functions.
virtual StatusCode metaDataStop () override
 Function called when the tool should write out its metadata.
virtual StatusCode beginInputFile () override
 Function called when a new input file is opened.
virtual StatusCode endInputFile () override
 Function called when the currently open input file got completely processed.
virtual StatusCode beginInputFile (const SG::SourceID &source) override
 Function called when a new input file is opened.
virtual StatusCode endInputFile (const SG::SourceID &source) override
 Function called when the currently open input file got completely processed.
virtual StatusCode sysInitialize ()
 Function initialising the tool in the correct way in Athena.
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
 DeclareInterfaceID (IMetaDataTool, 1, 0)
Functions providing access to the input/output metadata
MetaStorePtr_t inputMetaStore () const
 Accessor for the input metadata store.
MetaStorePtr_t outputMetaStore () const
 Accessor for the output metadata store.
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.
Callback functions helping in metadata reading/writing
void setUseIncidents (const bool flag)
virtual void handle (const Incident &inc)
 Function receiving incidents from IncidentSvc/TEvent.
virtual StatusCode beginEvent ()
 Function called when a new events is loaded.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

StatusCode copyInputContainersToOutput (CutBookkeepersLocalCache &target, const SG::SourceID &source="")
 Copy input containers to the output.
StatusCode copyCutflowFromService ()
 Fill Cutflow information from the service.
StatusCode loadXAODMetaData ()
 Initialisation helpers.
StatusCode loadPOOLMetaData ()
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

ServiceHandle< ICutFlowSvcm_cutFlowSvc { this, "CutFlowSvc", "CutFlowSvc/CutFlowSvc", "Pointer to the CutFlowSvc"}
 Pointer to the public CutFlowSvc interface.
CutFlowSvcm_cutFlowSvcPrivate {}
 Direct pointer to the CutFlowSvc for "private" methods access.
Gaudi::Property< std::string > m_inputCollName
 The name of the input CutBookkeeperContainer.
Gaudi::Property< std::string > m_outputCollName
 The name of the output CutBookkeeperContainer.
size_t m_numberOfWeightVariations {}
 Number of event weight variations.
std::unordered_map< SG::SourceID, CutBookkeepersLocalCachem_inputContainers
 Input CutBookkeeperContainers.
CutBookkeepersLocalCache m_completeContainers
 Local CutBookkeeperContainers.
CutBookkeepersLocalCache m_incompleteContainers
MetaStore_t m_inputMetaStore
 Object accessing the input metadata store.
MetaStore_t m_outputMetaStore
 Object accessing the output metadata store.
bool m_beginInputFileCalled
 Flag helping to discover when the tool misses the opening of the first input file.
bool m_useIncidents
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 42 of file BookkeeperTool.h.

Member Typedef Documentation

◆ MetaStore_t

Type of the metadata store object in Athena.

Definition at line 66 of file AsgMetadataTool.h.

◆ MetaStorePtr_t

Type of the metadata store pointer in standalone mode.

Definition at line 68 of file AsgMetadataTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ BookkeeperTool()

BookkeeperTool::BookkeeperTool ( const std::string & name = "BookkeeperTool")

Declare the correct constructor for Athena.

Standard Service Constructor

Definition at line 25 of file BookkeeperTool.cxx.

26 : asg::AsgMetadataTool(name)
27{
28#ifndef XAOD_STANDALONE
29 declareInterface< ::IMetaDataTool >( this );
30#endif // XAOD_STANDALONE
31}

◆ ~BookkeeperTool()

virtual BookkeeperTool::~BookkeeperTool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ beginEvent()

StatusCode asg::AsgMetadataTool::beginEvent ( )
protectedvirtualinherited

◆ beginInputFile() [1/2]

virtual StatusCode BookkeeperTool::beginInputFile ( )
inlineoverridevirtual

Function called when a new input file is opened.

Dummy implementation that can be overridden by the derived tool.

Reimplemented from asg::AsgMetadataTool.

Definition at line 66 of file BookkeeperTool.h.

66{return StatusCode::SUCCESS;}

◆ beginInputFile() [2/2]

StatusCode BookkeeperTool::beginInputFile ( const SG::SourceID & sid)
overridevirtual

Function called when a new input file is opened.

Implements IMetaDataTool.

Definition at line 54 of file BookkeeperTool.cxx.

56{
57 // OPENING NEW INPUT FILE
58 // Things to do:
59 // 1) Load CutBookkeepers from input file
60 // a) if incomplete from input, directly propagate to output
61 // b) if complete from input, wait for EndInputFile to decide what to do in output
62
63 // Get number of event weight variations if needed
65 ATH_MSG_DEBUG("Determining number of weight variations");
66#ifndef GENERATIONBASE
69 if (!status.isSuccess()) {
70 if (status.isRecoverable()) {
72 } else {
73 return StatusCode::FAILURE;
74 }
75 }
76 } else {
78 }
79#else
81#endif
82
84 ATH_MSG_ERROR("Could not determine the number of weight variations");
85 return StatusCode::FAILURE;
86 }
87
88 ATH_MSG_INFO("Using number of event weight variations " << m_numberOfWeightVariations);
89
90#ifndef XAOD_STANDALONE
91 ATH_CHECK(m_cutFlowSvcPrivate->setNumberOfWeightVariations(m_numberOfWeightVariations));
92#endif
93 }
94
95#ifdef XAOD_STANDALONE
96 SG::SourceID source{"file"};
97#endif
98
99 // Prepare local cache
100 ATH_MSG_INFO("Preparing local cache for source '" << source << "' with " << m_numberOfWeightVariations << " variations");
103
104 // Check if a local container is there. IT SHOULD NOT BE
105 auto sit = m_inputContainers.find(source);
106 if (sit != m_inputContainers.end()) {
107 ATH_MSG_ERROR("Undefined behaviour: this file has already been processed");
108 return StatusCode::FAILURE;
109 }
110
111 const xAOD::CutBookkeeperContainer *inputCollection{};
112 // Get the incomplete bookkeeper collections of the input metadata store
113 std::string incompleteCollName = "Incomplete" + m_inputCollName;
114 if (inputMetaStore()->contains<xAOD::CutBookkeeperContainer>(incompleteCollName)) {
115 for (size_t i{}; i < m_numberOfWeightVariations; ++i) {
116 std::string name = incompleteCollName;
117 if (i != 0) {
118 name.append("_weight_");
119 name.append(std::to_string(i));
120 }
122 && inputMetaStore()->retrieve(inputCollection, name).isSuccess()) {
124 }
125 }
126 ATH_MSG_DEBUG("Successfully merged input incomplete bookkeepers with output");
127 } else {
128 ATH_MSG_INFO("No incomplete bookkeepers with name '" << incompleteCollName << "' in this file");
129 }
130
131 // Get the complete bookkeeper collections of the input metadata store
133 // Create the temporary container
134 auto [it, status] = m_inputContainers.emplace(source, CutBookkeepersLocalCache());
136
137 for (size_t i{}; i < m_numberOfWeightVariations; ++i) {
138 std::string name = m_inputCollName;
139 if (i != 0) {
140 name.append("_weight_");
141 name.append(std::to_string(i));
142 }
144 && inputMetaStore()->retrieve(inputCollection, name).isSuccess()) {
145 xAOD::CutFlowHelpers::updateContainer(it->second.at(i), inputCollection);
146 }
147 }
148 ATH_MSG_DEBUG("Successfully copied complete bookkeepers to temp container");
149 } else {
150 ATH_MSG_INFO("No complete bookkeepers with name '" << m_inputCollName.value() << "' in this file");
151 }
152
153 return StatusCode::SUCCESS;
154}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
CutBookkeepersLocalCache m_incompleteContainers
Gaudi::Property< std::string > m_inputCollName
The name of the input CutBookkeeperContainer.
CutFlowSvc * m_cutFlowSvcPrivate
Direct pointer to the CutFlowSvc for "private" methods access.
StatusCode loadPOOLMetaData()
std::unordered_map< SG::SourceID, CutBookkeepersLocalCache > m_inputContainers
Input CutBookkeeperContainers.
size_t m_numberOfWeightVariations
Number of event weight variations.
CutBookkeepersLocalCache m_completeContainers
Local CutBookkeeperContainers.
StatusCode loadXAODMetaData()
Initialisation helpers.
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
::StatusCode StatusCode
StatusCode definition for legacy code.
status
Definition merge.py:16
retrieve(aClass, aKey=None)
Definition PyKernel.py:110
void updateContainer(xAOD::CutBookkeeperContainer *contToUpdate, const xAOD::CutBookkeeperContainer *otherCont)
Helper function to update a container with information from another one.
CutBookkeeperContainer_v1 CutBookkeeperContainer
Define the latest version of the CutBookkeeperContainer class.
static void prepareContainers(CutBookkeepersLocalCache &target, size_t size, bool extend=false)

◆ copyCutflowFromService()

StatusCode BookkeeperTool::copyCutflowFromService ( )
private

Fill Cutflow information from the service.

Definition at line 269 of file BookkeeperTool.cxx.

270{
271#ifndef XAOD_STANDALONE
272 ATH_MSG_DEBUG("Copying cutflow from CutFlowSvc");
273
274 // Get the bookkeeper from the current processing
275 const CutBookkeepersLocalCache &cache = m_cutFlowSvcPrivate->getCutBookkeepers();
276 if (!cache.empty()) {
277 ATH_MSG_DEBUG("Cache size: " << cache.size());
278
279 // sync the size
282
283 for (std::size_t i = 0; i < cache.size(); ++i) {
285 }
286 } else {
287 ATH_MSG_ERROR("No cutflow container in the CutFlowSvc");
288 return StatusCode::FAILURE;
289 }
290#endif
291
292 return StatusCode::SUCCESS;
293}
xAOD::CutBookkeeperContainer * at(std::size_t n) const

◆ copyInputContainersToOutput()

StatusCode BookkeeperTool::copyInputContainersToOutput ( CutBookkeepersLocalCache & target,
const SG::SourceID & source = "" )
private

Copy input containers to the output.

Definition at line 232 of file BookkeeperTool.cxx.

234{
236
237 if (msgLvl(MSG::DEBUG)) {
238 ATH_MSG_DEBUG("Available sources:");
239 for (const auto &[sourceID, list] : m_inputContainers) {
240 ATH_MSG_DEBUG(" " << sourceID);
241 }
242 }
243
244 if (!source.empty()) {
245 auto it = m_inputContainers.find(source);
246 if (it == m_inputContainers.end()) {
247 ATH_MSG_DEBUG("No input containers for this file");
248 return StatusCode::SUCCESS;
249 }
250
251 for (std::size_t i = 0; i < it->second.size(); ++i) {
252 xAOD::CutFlowHelpers::updateContainer(target.at(i), it->second.at(i));
253 }
254 m_inputContainers.erase(it);
255
256 return StatusCode::SUCCESS;
257 }
258
259 for (auto &[s, list] : m_inputContainers) {
260 for (std::size_t i = 0; i < list.size(); ++i) {
262 }
263 }
264 m_inputContainers.clear();
265
266 return StatusCode::SUCCESS;
267}
bool msgLvl(const MSG::Level lvl) const
list(name, path='/')
Definition histSizes.py:38

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ DeclareInterfaceID()

IMetaDataTool::DeclareInterfaceID ( IMetaDataTool ,
1 ,
0  )
inherited

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ endInputFile() [1/2]

virtual StatusCode BookkeeperTool::endInputFile ( )
inlineoverridevirtual

Function called when the currently open input file got completely processed.

Dummy implementation that can be overridden by the derived tool.

Reimplemented from asg::AsgMetadataTool.

Definition at line 67 of file BookkeeperTool.h.

67{return StatusCode::SUCCESS;}

◆ endInputFile() [2/2]

StatusCode BookkeeperTool::endInputFile ( const SG::SourceID & sid)
overridevirtual

Function called when the currently open input file got completely processed.

Implements IMetaDataTool.

Definition at line 159 of file BookkeeperTool.cxx.

161{
162#ifdef XAOD_STANDALONE
163 SG::SourceID source{"file"};
164#endif
165 ATH_MSG_INFO("Copying input containers for source '" << source << "'");
167
168 return StatusCode::SUCCESS;
169}
StatusCode copyInputContainersToOutput(CutBookkeepersLocalCache &target, const SG::SourceID &source="")
Copy input containers to the output.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ handle()

void asg::AsgMetadataTool::handle ( const Incident & inc)
protectedvirtualinherited

Function receiving incidents from IncidentSvc/TEvent.

Reimplemented in Trig::TrigDecisionTool.

Definition at line 135 of file AsgMetadataTool.cxx.

135 {
136
137 // Tell the user what's happening:
138 ATH_MSG_VERBOSE( "Callback received with incident: " << inc.type() );
139
140 // Call the appropriate member function:
141 if( inc.type() == IncidentType::BeginInputFile ) {
143 if( beginInputFile().isFailure() ) {
144 ATH_MSG_FATAL( "Failed to call beginInputFile()" );
145 throw std::runtime_error( "Couldn't call beginInputFile()" );
146 }
147 } else if( inc.type() == IncidentType::EndInputFile ) {
148 if( endInputFile().isFailure() ) {
149 ATH_MSG_FATAL( "Failed to call endInputFile()" );
150 throw std::runtime_error( "Couldn't call endInputFile()" );
151 }
152 } else if( inc.type() == IncidentType::BeginEvent ) {
153 // If the tool didn't catch the begin input file incident for the
154 // first input file of the job, then call the appropriate function
155 // now.
156 if( ! m_beginInputFileCalled ) {
158 if( beginInputFile().isFailure() ) {
159 ATH_MSG_FATAL( "Failed to call beginInputFile()" );
160 throw std::runtime_error( "Couldn't call beginInputFile()" );
161 }
162 }
163 if( beginEvent().isFailure() ) {
164 ATH_MSG_FATAL( "Failed to call beginEvent()" );
165 throw std::runtime_error( "Couldn't call beginEvent()" );
166 }
167
168 #ifdef XAOD_STANDALONE
169 } else if( inc.type() == IncidentType::MetaDataStop ) {
170 if( metaDataStop().isFailure() ) {
171 ATH_MSG_FATAL( "Failed to call metaDataStop()" );
172 throw std::runtime_error( "Couldn't call metaDataStop()" );
173 }
174
175 #endif // XAOD_STANDALONE
176 } else {
177 ATH_MSG_WARNING( "Unknown incident type received in AsgMetaDataTool: " << inc.type() );
178 }
179
180 return;
181 }
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
virtual StatusCode beginEvent()
Function called when a new events is loaded.
bool m_beginInputFileCalled
Flag helping to discover when the tool misses the opening of the first input file.
virtual StatusCode endInputFile()
Function called when the currently open input file got completely processed.
virtual StatusCode metaDataStop()
Function called when the tool should write out its metadata.

◆ initialize()

StatusCode BookkeeperTool::initialize ( void )
overridevirtual

Standard reimplemented functions.

Reimplemented from asg::AsgTool.

Definition at line 34 of file BookkeeperTool.cxx.

35{
36 ATH_MSG_DEBUG("Initializing " << name());
37
38 ATH_MSG_DEBUG("InputCollName = " << m_inputCollName);
39 ATH_MSG_DEBUG("OutputCollName = " << m_outputCollName);
40
41#ifndef XAOD_STANDALONE
42 ATH_CHECK(m_cutFlowSvc.retrieve());
43 // Access "private" CutFlowSvc methods
44 m_cutFlowSvcPrivate = dynamic_cast<CutFlowSvc *>(&*(m_cutFlowSvc));
45#endif
46
47 return StatusCode::SUCCESS;
48}
ServiceHandle< ICutFlowSvc > m_cutFlowSvc
Pointer to the public CutFlowSvc interface.
Gaudi::Property< std::string > m_outputCollName
The name of the output CutBookkeeperContainer.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ inputMetaStore()

AsgMetadataTool::MetaStorePtr_t asg::AsgMetadataTool::inputMetaStore ( ) const
inherited

Accessor for the input metadata store.

Definition at line 93 of file AsgMetadataTool.cxx.

93 {
94
95#ifdef XAOD_STANDALONE
96 return &m_inputMetaStore;
97#else // XAOD_STANDALONE
98 return m_inputMetaStore;
99#endif // XAOD_STANDALONE
100 }
MetaStore_t m_inputMetaStore
Object accessing the input metadata store.

◆ loadPOOLMetaData()

StatusCode BookkeeperTool::loadPOOLMetaData ( )
private

Definition at line 363 of file BookkeeperTool.cxx.

364{
365 // AnalysisBase can only use the xAOD::TruthMetaDataContainer, so skip this
366#ifdef XAOD_STANDALONE
367 return StatusCode::SUCCESS;
368#else
369
370 const IOVMetaDataContainer *container
371 = inputMetaStore()->tryConstRetrieve<IOVMetaDataContainer>("/Generation/Parameters");
372 if (container == nullptr) {
373 // set variations to 1 and exit quietly...
375 return StatusCode::SUCCESS;
376 }
377 // payload is a collection of CondAttrListCollections
378 // only look a the first one, assuming it exists, and within that only look at the first channel;
379 if (!(container->payloadContainer()->size() > 0
380 && container->payloadContainer()->at(0)->size() > 0)) {
381 return StatusCode::FAILURE;
382 }
383
384 // we take the first collection of weights
385 // TODO: improve this
387 const coral::Attribute& attr
388 = container->payloadContainer()->at(0)->attributeList(chanNum)["HepMCWeightNames"];
389
390 ATH_MSG_DEBUG("Attempting to load weight meta data from /Generation/Parameters");
391 std::map<std::string, int> truthWeightMap;
392 ATH_CHECK(Gaudi::Parsers::parse(truthWeightMap, attr.data<std::string>()));
393
394 m_numberOfWeightVariations = truthWeightMap.size();
395
396 return StatusCode::SUCCESS;
397#endif // XAOD_STANDALONE
398}
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
size_type size() const
number of Chan/AttributeList pairs
const IOVPayloadContainer * payloadContainer() const
Access to payload container.
size_type size() const
size of payload vector
CondAttrListCollection * at(unsigned int i) const
Element access.
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)

◆ loadXAODMetaData()

StatusCode BookkeeperTool::loadXAODMetaData ( )
private

Initialisation helpers.

Definition at line 296 of file BookkeeperTool.cxx.

297{
298#ifdef GENERATIONBASE
299 return StatusCode::RECOVERABLE;
300#else
301
302 // Try to load MC channel number from file metadata
303 ATH_MSG_DEBUG("Attempting to retrieve MC channel number...");
304 const xAOD::FileMetaData *fileMetaData{};
306 if (inputMetaStore()->contains<xAOD::FileMetaData>("FileMetaData")) {
307 ATH_CHECK(inputMetaStore()->retrieve(fileMetaData, "FileMetaData"));
308 float fltChannelNumber{-1};
309 if (fileMetaData->value(xAOD::FileMetaData::mcProcID, fltChannelNumber)) {
310 mcChannelNumber = static_cast<uint32_t>(fltChannelNumber);
311 }
312 }
313 if (mcChannelNumber == uint32_t(-1)) {
314 ATH_MSG_WARNING("... MC channel number could not be loaded from FileMetaData");
315#ifdef XAOD_STANDALONE
316 mcChannelNumber = 0;
317#else
318 return StatusCode::RECOVERABLE;
319#endif
320 }
321
322 // Find the correct truth meta data object
323 ATH_MSG_DEBUG("Attempting to load weight meta data from xAOD TruthMetaData for channel " << mcChannelNumber);
324 const xAOD::TruthMetaDataContainer *metaDataContainer{};
325 ATH_CHECK(inputMetaStore()->retrieve(metaDataContainer, "TruthMetaData"));
326
327 // If we only have one metadata item take MC channel from there if needed
328 if (mcChannelNumber == 0 && metaDataContainer->size() == 1) {
329 mcChannelNumber = metaDataContainer->at(0)->mcChannelNumber();
330 ATH_MSG_WARNING("... MC channel number taken from the metadata as " << mcChannelNumber);
331 }
332
333 auto itTruthMetaDataPtr = std::find_if(metaDataContainer->begin(), metaDataContainer->end(),
334 [mcChannelNumber] (const auto& it) { return it->mcChannelNumber() == mcChannelNumber; }
335 );
336
337 // If no such object is found then return
338 if (itTruthMetaDataPtr == metaDataContainer->end()) {
339#ifdef XAOD_STANDALONE
341 ATH_MSG_DEBUG("Could not load weight meta data! Assuming 1 variation.");
342 return StatusCode::SUCCESS;
343#else
344 ATH_MSG_DEBUG("Could not load weight meta data from TruthMetaData!");
345 return StatusCode::RECOVERABLE;
346#endif
347 }
348
349 // Update cached weight data
350 const std::vector<std::string> &truthWeightNames = (*itTruthMetaDataPtr)->weightNames();
351
352 m_numberOfWeightVariations = truthWeightNames.size();
354 ATH_MSG_DEBUG("No variations present, setting to 1.");
356 }
357
358 return StatusCode::SUCCESS;
359#endif
360}
const T * at(size_type n) const
Access an element, as an rvalue.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
@ mcProcID
Same as mc_channel_number [float].
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.
setEventNumber uint32_t

◆ metaDataStop()

StatusCode BookkeeperTool::metaDataStop ( )
overridevirtual

Function called when the tool should write out its metadata.

Dummy implementation that can be overridden by the derived tool.

Reimplemented from asg::AsgMetadataTool.

Definition at line 171 of file BookkeeperTool.cxx.

172{
173 // TERMINATING THE JOB (EndRun)
174 // Things to do:
175 // 1) Create new incomplete CutBookkeepers if relevant
176 // 2) Copy cutflow from the service
177 // 3) Copy containers to output
178
179 // All files that have not been fully processed are incomplete
181
182 // Copy cutflow from the service
184
185 // Write out the containers
186 for (std::size_t i = 0; i < m_completeContainers.size(); ++i) {
187 std::string name = m_outputCollName;
188 if (i != 0) {
189 name.append("_weight_");
190 name.append(std::to_string(i));
191 }
192 std::string incompleteName = "Incomplete" + name;
193
194 // In MP we might already have them written out
197 if (!outputMetaStore()->retrieve(complete, name).isSuccess()) {
198 ATH_MSG_ERROR("Could not get " << name << " CutBookkeepers from output MetaDataStore");
199 return StatusCode::FAILURE;
200 }
202 } else {
203 ATH_CHECK(outputMetaStore()->record(std::move(m_completeContainers.cont[i]), name));
204 ATH_CHECK(outputMetaStore()->record(std::move(m_completeContainers.aux[i]), name + "Aux."));
205 }
206
209 if (!outputMetaStore()->retrieve(incomplete, incompleteName).isSuccess()) {
210 ATH_MSG_ERROR("Could not get " << incompleteName << " CutBookkeepers from output MetaDataStore");
211 return StatusCode::FAILURE;
212 }
214 } else {
215 // Only write non-empty incomplete containers for variations
216 if (i == 0 || !m_incompleteContainers.at(i)->empty()) {
217 ATH_CHECK(outputMetaStore()->record(std::move(m_incompleteContainers.cont[i]), incompleteName));
218 ATH_CHECK(outputMetaStore()->record(std::move(m_incompleteContainers.aux[i]), incompleteName + "Aux."));
219 }
220 }
221 }
222
224 m_completeContainers.clear();
225
226 ATH_MSG_INFO("Successfully copied CutBookkeepers to the output MetaDataStore");
227
228 return StatusCode::SUCCESS;
229}
StatusCode copyCutflowFromService()
Fill Cutflow information from the service.
MetaStorePtr_t outputMetaStore() const
Accessor for the output metadata store.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ outputMetaStore()

AsgMetadataTool::MetaStorePtr_t asg::AsgMetadataTool::outputMetaStore ( ) const
inherited

Accessor for the output metadata store.

Definition at line 102 of file AsgMetadataTool.cxx.

102 {
103
104#ifdef XAOD_STANDALONE
105 return &m_outputMetaStore;
106#else // XAOD_STANDALONE
107 return m_outputMetaStore;
108#endif // XAOD_STANDALONE
109 }
MetaStore_t m_outputMetaStore
Object accessing the output metadata store.

◆ print()

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setUseIncidents()

void asg::AsgMetadataTool::setUseIncidents ( const bool flag)
inlineprotectedinherited

Definition at line 132 of file AsgMetadataTool.h.

133 {
135 }
bool flag
Definition master.py:29

◆ sysInitialize()

StatusCode asg::AsgMetadataTool::sysInitialize ( )
virtualinherited

Function initialising the tool in the correct way in Athena.

This function is used to set up the callbacks from IncidentSvc in Athena at the right time during initialisation, without the user having to do anything special in his/her code.

Reimplemented from AthCommonDataStore< AthCommonMsg< AlgTool > >.

Definition at line 115 of file AsgMetadataTool.cxx.

115 {
116
117#ifndef XAOD_STANDALONE
118 if (m_useIncidents) {
119 // Connect to the IncidentSvc:
120 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
121 ATH_CHECK( incSvc.retrieve() );
122
123 // Set up the right callbacks: don't rethrow exceptions, any failure and we should end
124 incSvc->addListener( this, IncidentType::BeginEvent, 0, false );
125 }
126 // Let the base class do its thing:
127 ATH_CHECK( AlgTool::sysInitialize() );
128
129#endif // not XAOD_STANDALONE
130
131 // Return gracefully:
132 return StatusCode::SUCCESS;
133 }

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_beginInputFileCalled

bool asg::AsgMetadataTool::m_beginInputFileCalled
privateinherited

Flag helping to discover when the tool misses the opening of the first input file.

Definition at line 126 of file AsgMetadataTool.h.

◆ m_completeContainers

CutBookkeepersLocalCache BookkeeperTool::m_completeContainers
private

Local CutBookkeeperContainers.

Definition at line 106 of file BookkeeperTool.h.

◆ m_cutFlowSvc

ServiceHandle<ICutFlowSvc> BookkeeperTool::m_cutFlowSvc { this, "CutFlowSvc", "CutFlowSvc/CutFlowSvc", "Pointer to the CutFlowSvc"}
private

Pointer to the public CutFlowSvc interface.

Definition at line 86 of file BookkeeperTool.h.

86{ this, "CutFlowSvc", "CutFlowSvc/CutFlowSvc", "Pointer to the CutFlowSvc"};

◆ m_cutFlowSvcPrivate

CutFlowSvc* BookkeeperTool::m_cutFlowSvcPrivate {}
private

Direct pointer to the CutFlowSvc for "private" methods access.

Definition at line 88 of file BookkeeperTool.h.

88{};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_incompleteContainers

CutBookkeepersLocalCache BookkeeperTool::m_incompleteContainers
private

Definition at line 107 of file BookkeeperTool.h.

◆ m_inputCollName

Gaudi::Property<std::string> BookkeeperTool::m_inputCollName
private
Initial value:
{this, "InputCollName", "CutBookkeepers",
"The default name of the xAOD::CutBookkeeperContainer for input files"}

The name of the input CutBookkeeperContainer.

Definition at line 92 of file BookkeeperTool.h.

92 {this, "InputCollName", "CutBookkeepers",
93 "The default name of the xAOD::CutBookkeeperContainer for input files"};

◆ m_inputContainers

std::unordered_map<SG::SourceID, CutBookkeepersLocalCache> BookkeeperTool::m_inputContainers
private

Input CutBookkeeperContainers.

Definition at line 103 of file BookkeeperTool.h.

◆ m_inputMetaStore

MetaStore_t asg::AsgMetadataTool::m_inputMetaStore
privateinherited

Object accessing the input metadata store.

Definition at line 119 of file AsgMetadataTool.h.

◆ m_numberOfWeightVariations

size_t BookkeeperTool::m_numberOfWeightVariations {}
private

Number of event weight variations.

Definition at line 100 of file BookkeeperTool.h.

100{};

◆ m_outputCollName

Gaudi::Property<std::string> BookkeeperTool::m_outputCollName
private
Initial value:
{this, "OutputCollName", "CutBookkeepers",
"The default name of the xAOD::CutBookkeeperContainer for output files"}

The name of the output CutBookkeeperContainer.

Definition at line 96 of file BookkeeperTool.h.

96 {this, "OutputCollName", "CutBookkeepers",
97 "The default name of the xAOD::CutBookkeeperContainer for output files"};

◆ m_outputMetaStore

MetaStore_t asg::AsgMetadataTool::m_outputMetaStore
privateinherited

Object accessing the output metadata store.

Definition at line 121 of file AsgMetadataTool.h.

◆ m_useIncidents

bool asg::AsgMetadataTool::m_useIncidents
privateinherited

Definition at line 128 of file AsgMetadataTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


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