ATLAS Offline Software
DynVarFixerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Local include(s):
6 #include "DynVarFixerAlg.h"
7 
8 // EDM include(s):
10 #include "StoreGate/ReadHandle.h"
11 
12 // ROOT include(s):
13 #include <TClass.h>
14 #include <TVirtualCollectionProxy.h>
15 #include <TGenCollectionProxy.h>
16 
17 // System include(s).
18 #include <algorithm>
19 #include <cassert>
20 #include <string>
21 
22 namespace xAODMaker {
23 
25 
26  // Greet the user.
27  ATH_MSG_INFO( "Initialising" );
28  ATH_MSG_DEBUG( "Will be fixing dynamic variables in container(s):" );
29  ATH_MSG_DEBUG( " " << m_constKeys );
30 
31  // Initialise the read handle keys.
32  ATH_CHECK( m_constKeys.initialize() );
33  std::vector< std::string > keys( m_constKeys.size() );
34  std::transform( m_constKeys.begin(), m_constKeys.end(), keys.begin(),
36  return key.key(); } );
37  ATH_CHECK( m_ioKeys.assign( keys ) );
38  ATH_CHECK( m_ioKeys.initialize() );
39 
40  // Reset the cache variable.
41  m_dicts.clear();
42 
43  // Return gracefully.
44  return StatusCode::SUCCESS;
45  }
46 
48 
49  // Construct the SG::IConstAuxStore and SG::IAuxStoreIO read handles.
50  auto constHandles = m_constKeys.makeHandles();
51  auto ioHandles = m_ioKeys.makeHandles();
52  assert( constHandles.size() == ioHandles.size() );
53 
54  // Loop over the specified containers:
55  for( std::size_t i = 0; i < constHandles.size(); ++i ) {
56 
57  // Access the appropriate handles.
59  constHandles.at( i );
61  ioHandles.at( i );
62 
63  // If the store is empty, stop here.
64  if( constHandle->size() == 0 ) {
65  continue;
66  }
67 
68  // Remember the store's name and size.
69  const std::string& cname = constHandle.key();
70  const size_t size = constHandle->size();
71  ATH_MSG_VERBOSE( "Size of container \"" << cname << "\": " << size );
72 
73  // Loop over all dynamic variables of the container:
74  for( SG::auxid_t auxid : ioHandle->getDynamicAuxIDs() ) {
75 
76  // Access the registry:
77  static const auto& reg = SG::AuxTypeRegistry::instance();
78 
79  // Tell the user what's happening.
80  ATH_MSG_VERBOSE( "Checking variable \"" << cname
81  << reg.getName( auxid ) << "\"" );
82 
83  // Access the std::vector variable:
84  const void* vecPtr = ioHandle->getIOData( auxid );
85 
86  // Get a dictionary for the variable:
87  ::TClass* cl = getClass( auxid );
88  if( ! cl ) {
89  continue;
90  }
91 
92  // Get the collection proxy for the class:
93  ::TVirtualCollectionProxy* proxy = cl->GetCollectionProxy();
94  if( ! proxy ) {
95  ATH_MSG_FATAL( "Couldn't get collection proxy for variable \""
96  << reg.getName( auxid ) << "\"" );
97  return StatusCode::FAILURE;
98  }
99 
100  // Attach the proxy to the auxiliary variable:
101  ::TVirtualCollectionProxy::TPushPop helper( proxy,
102  ( void* ) vecPtr );
103 
104  // Check if the variable is of the right size. If it is, don't
105  // bother the variable any longer.
106  if( proxy->Size() == size ) {
107  continue;
108  }
109  ATH_MSG_VERBOSE( "Size of variable \"" << cname
110  << reg.getName( auxid ) << "\": "
111  << proxy->Size() );
112 
113  // If it's not, then try to resize it using the TGenCollectionProxy
114  // interface:
115  ::TGenCollectionProxy* genProxy =
116  dynamic_cast< ::TGenCollectionProxy* >( proxy );
117  if( ! genProxy ) {
118  ATH_MSG_WARNING( "Variable \"" << reg.getName( auxid )
119  << "\" doesn't have a TGenCollectionProxy. "
120  << "Variable not fixed!" );
121  continue;
122  }
123 
124  // Resize the variable to the right size:
125  static const ::Bool_t FORCE_DELETE = kFALSE;
126  genProxy->Resize( size, FORCE_DELETE );
127  ATH_MSG_VERBOSE( "Size of variable \"" << cname
128  << reg.getName( auxid ) << "\" after resize: "
129  << proxy->Size() );
130  ATH_MSG_DEBUG( "Fixed variable: \"" << cname << reg.getName( auxid )
131  << "\"" );
132  }
133  }
134 
135  // Return gracefully.
136  return StatusCode::SUCCESS;
137  }
138 
140 
141  // Check if we already checked, and there's no dictionary available for
142  // this type:
143  if( ( m_noDict.size() > auxid ) && m_noDict[ auxid ] ) {
144  return nullptr;
145  }
146 
147  // Check if the cache already has this variable:
148  if( ( m_dicts.size() > auxid ) && m_dicts[ auxid ] ) {
149  return m_dicts[ auxid ];
150  }
151 
152  // Make sure that the cache variables are large enough:
153  if( m_dicts.size() <= auxid ) {
154  m_dicts.resize( auxid + 1, nullptr );
155  }
156  if( m_noDict.size() <= auxid ) {
157  m_noDict.resize( auxid + 1, false );
158  }
159 
160  // If not, then look for a dictionary for this type:
161  static const auto& reg = SG::AuxTypeRegistry::instance();
162  static const ::Bool_t LOAD = kTRUE;
163  static const ::Bool_t SILENT = kTRUE;
164  ::TClass* cl = ::TClass::GetClass( reg.getVecTypeName( auxid ).c_str(),
165  LOAD, SILENT );
166 
167  // Cache the result:
168  if( cl ) {
169  m_dicts[ auxid ] = cl;
170  } else {
171  ATH_MSG_INFO( "No dictionary available for variable \""
172  << reg.getName( auxid ) << "\"" );
173  m_noDict[ auxid ] = true;
174  }
175 
176  // Return what we found:
177  return cl;
178  }
179 
180 } // namespace xAODMaker
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAODMaker::DynVarFixerAlg::m_ioKeys
SG::ReadHandleKeyArray< SG::IAuxStoreIO > m_ioKeys
Containers to access with the SG::IAuxStoreIO interface.
Definition: DynVarFixerAlg.h:71
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
xAODMaker::DynVarFixerAlg::m_dicts
std::vector< ::TClass * > m_dicts
Cache of the dictionaries used.
Definition: DynVarFixerAlg.h:74
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
xAODMaker
Definition: StoreGateSvc.h:72
SG::IConstAuxStore::size
virtual size_t size() const =0
Return the number of elements in the store.
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
xAODMaker::DynVarFixerAlg::execute
StatusCode execute() override
Function executing the algorithm.
Definition: DynVarFixerAlg.cxx:47
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAODMaker::DynVarFixerAlg::initialize
StatusCode initialize() override
Function initialising the algorithm.
Definition: DynVarFixerAlg.cxx:24
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
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
DynVarFixerAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODMaker::DynVarFixerAlg::m_constKeys
SG::ReadHandleKeyArray< SG::IConstAuxStore > m_constKeys
Containers to access with the SG::IConstAuxStore interface.
Definition: DynVarFixerAlg.h:60
SG::IAuxStoreIO::getDynamicAuxIDs
virtual const SG::auxid_set_t & getDynamicAuxIDs() const =0
Get the list of all dynamically created variables.
SG::IAuxStoreIO::getIOData
virtual const void * getIOData(SG::auxid_t auxid) const =0
Return a pointer to the data to be stored for one aux data item.
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
xAODMaker::DynVarFixerAlg::getClass
::TClass * getClass(SG::auxid_t auxid)
Get the dictionary describing an auxiliary vector variable.
Definition: DynVarFixerAlg.cxx:139
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
ReadHandle.h
Handle class for reading from StoreGate.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAODMaker::DynVarFixerAlg::m_noDict
std::vector< bool > m_noDict
Flag showing which variables don't have a dictionary for them.
Definition: DynVarFixerAlg.h:76
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37