ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMaker::ElementLinkResetAlg Class Reference

Algorithm reseting ElementLink objects to their default state. More...

#include <ElementLinkResetAlg.h>

Inheritance diagram for xAODMaker::ElementLinkResetAlg:
Collaboration diagram for xAODMaker::ElementLinkResetAlg:

Classes

class  AuxIDType
 Helper class for caching auxiliary ID types. More...

Public Member Functions

 ElementLinkResetAlg (const std::string &name, ISvcLocator *svcLoc)
 Regular Algorithm constructor.
virtual StatusCode initialize ()
 Function initialising the algorithm.
virtual StatusCode execute ()
 Function executing the algorithm.
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
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

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.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

StatusCode reset (const SG::IConstAuxStore &store, const std::string &key)
 Function reseting all the ElementLinks in one specific container.
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

std::vector< std::string > m_keys
 StoreGate keys of the auxiliary objects to be processed.
std::vector< AuxIDTypem_typeCache
 Cached types of the auxiliary IDs.
DataObjIDColl m_extendedExtraObjects
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

Algorithm reseting ElementLink objects to their default state.

   This algorithm can be used to make sure that during/after an
   AODFix-like configuration EDM objects are not left with cached
   pointers to no longer existing objects.

   The algorithm can make sure that every ElementLink in some
   selected container(s), or all containers that are in StoreGate,
   are cleared of all cached information.
Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 39 of file ElementLinkResetAlg.h.

Member Typedef Documentation

◆ StoreGateSvc_t

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

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ ElementLinkResetAlg()

xAODMaker::ElementLinkResetAlg::ElementLinkResetAlg ( const std::string & name,
ISvcLocator * svcLoc )

Regular Algorithm constructor.

Definition at line 23 of file ElementLinkResetAlg.cxx.

25 : AthAlgorithm( name, svcLoc ) {
26
27 declareProperty( "SGKeys", m_keys );
28 }
AthAlgorithm()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::vector< std::string > m_keys
StoreGate keys of the auxiliary objects to be processed.

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::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 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::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< Algorithm > >::detStore ( ) const
inlineinherited

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

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

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

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

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode xAODMaker::ElementLinkResetAlg::execute ( )
virtual

Function executing the algorithm.

Definition at line 40 of file ElementLinkResetAlg.cxx.

40 {
41
42 // Collect all the container(s):
43 std::vector< std::pair< const SG::IConstAuxStore*, std::string > > stores;
44 if( !m_keys.empty() ) {
45 for( const std::string& key : m_keys ) {
46 const SG::IConstAuxStore* store = nullptr;
47 ATH_CHECK( evtStore()->retrieve( store, key ) );
48 stores.emplace_back( store, key );
49 }
50 } else {
51 SG::ConstIterator< SG::IConstAuxStore > itr, end;
52 ATH_CHECK( evtStore()->retrieve( itr, end ) );
53 for( ; itr != end; ++itr ) {
54 const SG::IConstAuxStore* store = nullptr;
55 ATH_CHECK( evtStore()->retrieve( store, itr.key() ) );
56 stores.emplace_back( store, itr.key() );
57 }
58 }
59 ATH_MSG_DEBUG( "Number of IConstAuxStore objects retrieved: "
60 << stores.size() );
61
62 // Reset the ElementLinks in all of them:
63 for( const auto& storeKey : stores ) {
64 ATH_MSG_VERBOSE( "Reseting element links in store: "
65 << storeKey.second );
66 ATH_CHECK( reset( *( storeKey.first ), storeKey.second ) );
67 }
68
69 // Return gracefully:
70 return StatusCode::SUCCESS;
71 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
const std::string & key() const
Get the key string with which the current object was stored.
StatusCode reset(const SG::IConstAuxStore &store, const std::string &key)
Function reseting all the ElementLinks in one specific container.
TestStore store
Definition TestStore.cxx:23
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::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

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}
DataObjIDColl m_extendedExtraObjects

◆ initialize()

StatusCode xAODMaker::ElementLinkResetAlg::initialize ( )
virtual

Function initialising the algorithm.

Definition at line 30 of file ElementLinkResetAlg.cxx.

30 {
31
32 // Tell the user what's happening:
33 ATH_MSG_INFO( "Initialising" );
34 ATH_MSG_DEBUG( "SGKeys = " << m_keys );
35
36 // Return gracefully:
37 return StatusCode::SUCCESS;
38 }
#define ATH_MSG_INFO(x)

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::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.

◆ msg()

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

Definition at line 24 of file AthCommonMsg.h.

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

◆ msgLvl()

bool AthCommonMsg< Algorithm >::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< Algorithm > >::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.

◆ 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< Algorithm > >::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< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ reset()

StatusCode xAODMaker::ElementLinkResetAlg::reset ( const SG::IConstAuxStore & store,
const std::string & key )
private

Function reseting all the ElementLinks in one specific container.

Definition at line 73 of file ElementLinkResetAlg.cxx.

74 {
75
76 // If the container is empty, return right away:
77 if( ! store.size() ) {
78 return StatusCode::SUCCESS;
79 }
80
81 // Get all the IDs stored in this object:
82 const SG::auxid_set_t& auxids = store.getAuxIDs();
83
84 // The auxiliary type registry:
85 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
86
87 // Loop over them:
88 for( SG::auxid_t auxid : auxids ) {
89
90 // Check/cache its type:
91 if( m_typeCache.size() <= auxid ) {
92 m_typeCache.resize( auxid + 1 );
93 }
94 if( ! m_typeCache[ auxid ].isSet ) {
95 const std::string tname =
96 SG::normalizedTypeinfoName( *( reg.getType( auxid ) ) );
97 static const std::string pat1 = "ElementLink<";
98 static const std::string pat2 = "std::vector<ElementLink<";
99 if( tname.substr( 0, pat1.size() ) == pat1 ) {
100 m_typeCache[ auxid ].isEL = true;
101 } else if( tname.substr( 0, pat2.size() ) == pat2 ) {
102 m_typeCache[ auxid ].isELVec = true;
103 }
104 m_typeCache[ auxid ].isSet = true;
105 ATH_MSG_VERBOSE( "Type for \"" << tname << "\": isEL = "
106 << m_typeCache[ auxid ].isEL << ", isELVec = "
107 << m_typeCache[ auxid ].isELVec );
108 }
109
110 // If it's not an EL type, then don't bother:
111 if( ! ( m_typeCache[ auxid ].isEL || m_typeCache[ auxid ].isELVec ) ) {
112 continue;
113 }
114
115 // Get a pointer to the vector variable. We need to cast away
116 // its constness in this ugly way, we can't afford to only ask for
117 // non-const pointers from the store. Since the ElementLink to be
118 // reset may very well be a const variable that was accessed already,
119 // and now needs its cache wiped.
120 void* ptr = const_cast< void* >( store.getData( auxid ) );
121
122 // If the pointer is null, then something dodgy happened with this
123 // (dynamic) variable.
124 if( ! ptr ) {
125 // Check if this is a static variable. If it is, it's not an error
126 // to get a null pointer for it. Since such a case can only happen
127 // when a new static variable was introduced into the EDM, and we're
128 // reading an old input file that doesn't have this variable in it
129 // yet. Which is an okay scenario.
130 const SG::IAuxStoreIO* storeIO =
131 dynamic_cast< const SG::IAuxStoreIO* >( &store );
132 if( ( ! storeIO ) || ( storeIO->getDynamicAuxIDs().find( auxid ) !=
133 storeIO->getDynamicAuxIDs().end() ) ) {
134 REPORT_MESSAGE( MSG::ERROR )
135 << "Invalid pointer received for variable: " << key
136 << reg.getName( auxid );
137 } else {
138 ATH_MSG_DEBUG( "Static variable " << key << reg.getName( auxid )
139 << " is empty" );
140 }
141 continue;
142 }
143
144 // Get the variable's element size:
145 const size_t eltSize = reg.getEltSize( auxid );
146
147 // Loop over its elements:
148 const size_t sz_i = store.size();
149 for( size_t i = 0; i < sz_i; ++i ) {
150
151 // Raw pointer to the object:
152 void* eltPtr = reinterpret_cast< char* >( ptr ) + i * eltSize;
153
154 // Do different things based on the variable type:
155 if( m_typeCache[ auxid ].isEL ) {
156 // Cast to an ElementLinkBase object:
157 ElementLinkBase* elb =
158 reinterpret_cast< ElementLinkBase* >( eltPtr );
159 // Reset the link only if it has its persistent variable(s) set:
160 if( elb->persKey() ) {
161 elb->toTransient();
162 }
163 } else if( m_typeCache[ auxid ].isELVec ) {
164 // For a vector of links we heavily rely on knowing how GCC/Clang
165 // lays out the memory for vectors.
166 std::vector< ElementLinkBase >& v =
167 *( reinterpret_cast< std::vector< ElementLinkBase >* >( eltPtr ) );
168 const size_t sz_j = v.size();
169 for( size_t j = 0; j < sz_j; ++j ) {
170 // Access the link:
171 ElementLinkBase& elb = v[ j ];
172 // Reset the link only if it has its persistent variable(s)
173 // set:
174 if( elb.persKey() ) {
175 elb.toTransient();
176 }
177 }
178 } else {
179 ATH_MSG_FATAL( "There is a logic error in the code" );
180 return StatusCode::FAILURE;
181 }
182 }
183 }
184
185 // Return gracefully:
186 return StatusCode::SUCCESS;
187 }
#define ATH_MSG_FATAL(x)
#define REPORT_MESSAGE(LVL)
Report a message.
const_iterator end() const
Return an end iterator.
const_iterator find(bit_t bit) const
If bit bit is set, return an iterator pointing to it.
sgkey_t persKey() const
Return the SG key that we reference, as a hash.
bool toTransient(IProxyDict *sg=0)
Finish initialization after link has been read.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
virtual const SG::auxid_set_t & getDynamicAuxIDs() const =0
Get the list of all dynamically created variables.
std::vector< AuxIDType > m_typeCache
Cached types of the auxiliary IDs.
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, and PyAthena::Alg.

Definition at line 66 of file AthAlgorithm.cxx.

66 {
68
69 if (sc.isFailure()) {
70 return sc;
71 }
72 ServiceHandle<ICondSvc> cs("CondSvc",name());
73 for (auto h : outputHandles()) {
74 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75 // do this inside the loop so we don't create the CondSvc until needed
76 if ( cs.retrieve().isFailure() ) {
77 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78 return StatusCode::SUCCESS;
79 }
80 if (cs->regHandle(this,*h).isFailure()) {
81 sc = StatusCode::FAILURE;
82 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83 << " with CondSvc");
84 }
85 }
86 }
87 return sc;
88}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
virtual StatusCode sysInitialize() override
Override sysInitialize.
AthCommonDataStore(const std::string &name, T... args)
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::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< Algorithm > >::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_detStore

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

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

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

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_keys

std::vector< std::string > xAODMaker::ElementLinkResetAlg::m_keys
private

StoreGate keys of the auxiliary objects to be processed.

Definition at line 56 of file ElementLinkResetAlg.h.

◆ m_typeCache

std::vector< AuxIDType > xAODMaker::ElementLinkResetAlg::m_typeCache
private

Cached types of the auxiliary IDs.

Definition at line 68 of file ElementLinkResetAlg.h.

◆ m_varHandleArraysDeclared

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

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

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

Definition at line 398 of file AthCommonDataStore.h.


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