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

#include <TrigSerTPTool.h>

Inheritance diagram for TrigSerTPTool:
Collaboration diagram for TrigSerTPTool:

Public Member Functions

 TrigSerTPTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard AlgTool constructor.
virtual StatusCode initialize () override
 Function initialising the tool.
void * convertTP (const std::string &transName, void *trans, std::string &persName) const
 Convert a transient object to its persistent self.
void * convertPT (const std::string &persName, void *pers, std::string &transName) const
 Convert a persistent object to its transient self.
const std::string & persClassName (const std::string &transClassName) const
 Get the name of the persistent class belonging to a transient one.
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 sysInitialize () override
 Perform system initialization for an algorithm.
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

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Declare the interface provided by the tool.

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

TClass * getClass (const std::string &clname) const
 Get the ROOT dictionary for a type.
ITPCnvBasegetConverter (const std::string &persistent) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

CxxUtils::ClassName::Rules m_clNameRules
std::map< std::string, std::string > m_TPmap
ServiceHandle< IDictLoaderSvcm_dictSvc
bool m_useAthDictLoader
ServiceHandle< ITPCnvSvcm_tpcnvsvc
std::mutex m_convertersCacheMutex
std::map< std::string, ITPCnvBase * > m_convertesCache ATLAS_THREAD_SAFE
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

Author
Jiri Masik Jiri..nosp@m.Masi.nosp@m.k@cer.nosp@m.n.ch based on the code of AthenaROOTAccess by Scott Snyder

Definition at line 27 of file TrigSerTPTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

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

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ TrigSerTPTool()

TrigSerTPTool::TrigSerTPTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Standard AlgTool constructor.

Definition at line 19 of file TrigSerTPTool.cxx.

21 :
22 AthAlgTool( type, name, parent ),
23 m_dictSvc( "AthDictLoaderSvc", name ),
24 m_useAthDictLoader( true ),
25 m_tpcnvsvc( "AthTPCnvSvc", name ) {
26
27 declareInterface< TrigSerTPTool >( this );
28
29 declareProperty( "TPMap", m_TPmap, "map of T->P classes" );
30 declareProperty( "useAthDictLoader", m_useAthDictLoader,
31 "use AthDictLoaderSvc instead of plain ROOT" );
32}
AthAlgTool()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool m_useAthDictLoader
ServiceHandle< ITPCnvSvc > m_tpcnvsvc
ServiceHandle< IDictLoaderSvc > m_dictSvc
std::map< std::string, std::string > m_TPmap

Member Function Documentation

◆ convertPT()

void * TrigSerTPTool::convertPT ( const std::string & persName,
void * pers,
std::string & transName ) const

Convert a persistent object to its transient self.

Definition at line 142 of file TrigSerTPTool.cxx.

144{
145 // First look for a trigger specific converter:
146 ITPCnvBase* cnvtr =
147 m_tpcnvsvc->p2t_cnv( persName, Athena::TPCnvType::Trigger );
148 if( ! cnvtr ) {
149 // If there is no such thing, try a generic one:
150 cnvtr = m_tpcnvsvc->p2t_cnv( persName );
151 }
152 if( ! cnvtr ) {
153 REPORT_MESSAGE( MSG::ERROR )
154 << "T/P Converter for persistent class "
155 << persName << " could not be retrieved";
156 return 0;
157 }
158
159 // Get the name of the transient class:
160 transName = m_clNameRules.apply( System::typeinfoName( cnvtr->transientTInfo() ) );
161
162 // Create the transient object:
163 TClass *transCl = getClass( transName );
164 void *trans( 0 );
165 if( transCl ){
166 trans = transCl->New();
167 ATH_MSG_DEBUG( "trans " << trans );
168 }
169
170 // Do the conversion:
171 ATH_MSG_DEBUG( "invoking PT for " << transName );
172 try {
173 cnvtr->persToTransWithKeyUntyped( pers, trans, "", msg() );
174 ATH_MSG_DEBUG( " succeeded at " << trans );
175 }
176 catch (const std::runtime_error& e){
177 REPORT_MESSAGE( MSG::ERROR ) << "An exception occurred: " << e.what();
178 //it should destruct trans here (is it in a good state?)
179 trans = 0;
180 }
181
182 // Return the converted object:
183 return trans;
184}
#define ATH_MSG_DEBUG(x)
#define REPORT_MESSAGE(LVL)
Report a message.
MsgStream & msg() const
virtual const std::type_info & transientTInfo() const =0
return C++ type id of the transient class this converter is for
virtual void persToTransWithKeyUntyped(const void *pers, void *trans, const std::string &, MsgStream &msg)
Convert persistent object representation to transient.
Definition ITPCnvBase.h:53
CxxUtils::ClassName::Rules m_clNameRules
TClass * getClass(const std::string &clname) const
Get the ROOT dictionary for a type.

◆ convertTP()

void * TrigSerTPTool::convertTP ( const std::string & transName,
void * trans,
std::string & persName ) const

Convert a transient object to its persistent self.

Definition at line 77 of file TrigSerTPTool.cxx.

79{
80 ATH_MSG_DEBUG( "TrigSerTPTool::convertTP" );
81
82 //pers and persName set only after successful conversion
83 persName = "";
84 void *pers( 0 );
85
86 // Start by trying to find the correct persistent class from the TP map
87 // Otherwise, use the internal logic of the TPCnvSvc
88 const auto tpItr = m_TPmap.find( clname );
89 if( tpItr == m_TPmap.end() ) {
90 REPORT_MESSAGE( MSG::ERROR )
91 << "Transient class " << clname
92 << " is not in the T/P Converter map";
93 return 0;
94 }
95 persName = tpItr->second;
96
97 ITPCnvBase* cnvtr = getConverter( persName );
98 if( ! cnvtr ) {
99 ATH_MSG_ERROR( "T/P Converter for transient class " << tpItr->first
100 << " persistent class " << persName << " could not be retrieved");
101 return nullptr;
102 }
103
104 // Create a persistent object:
105 const std::string persname =
106 m_clNameRules.apply( System::typeinfoName( cnvtr->persistentTInfo() ) );
107 TClass *persObjCl = getClass( persname );
108 void *persptr( 0 );
109 if( persObjCl ) {
110 persptr = persObjCl->New();
111 ATH_MSG_DEBUG( "created object of " << persptr << " at " << persptr );
112 } else {
113 REPORT_MESSAGE( MSG::ERROR )
114 << "Couldn't find dictionary for type " << persname;
115 return 0;
116 }
117
118 // Do the conversion:
119 ATH_MSG_DEBUG( "invoking TP for " << clname << " at " << ptr );
120 try {
121 cnvtr->transToPersUntyped( ptr, persptr, msg() );
122 persName = std::move(persname);
123 pers = persptr;
124 ATH_MSG_DEBUG( "succeeded at " << persptr );
125 }
126 catch( const std::runtime_error& e ){
127
128 //delete persObjCl->New();
129 const std::string issue = e.what();
130 if( issue.find( "is deprecated" ) != std::string::npos ) {
131 ATH_MSG_INFO( "An exception " << e.what() );
132 } else {
133 pers = 0;
134 REPORT_MESSAGE( MSG::ERROR ) << "An exception occurred: " << e.what();
135 }
136 }
137
138 // Return the converted object:
139 return pers;
140}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &msg)=0
Convert transient object representation to persistent.
virtual const std::type_info & persistentTInfo() const =0
return C++ type id of the persistent class this converter is for
ITPCnvBase * getConverter(const std::string &persistent) const

◆ 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 }

◆ 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.

◆ 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

◆ getClass()

TClass * TrigSerTPTool::getClass ( const std::string & clname) const
private

Get the ROOT dictionary for a type.

Definition at line 203 of file TrigSerTPTool.cxx.

203 {
204
205 TClass *cl( 0 );
207 m_dictSvc->load_type( cname );
208 }
209 cl = TClass::GetClass( cname.c_str() );
210 return cl;
211}
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ getConverter()

ITPCnvBase * TrigSerTPTool::getConverter ( const std::string & persistent) const
private

Definition at line 60 of file TrigSerTPTool.cxx.

61{
62 std::lock_guard<std::mutex> lock(m_convertersCacheMutex);
63 ITPCnvBase* cnvtr = m_convertesCache[persistent];
64 if ( ATH_LIKELY( cnvtr ) )
65 return cnvtr;
66
67 // no converter, we need to find it, first the trigger specific one
68 cnvtr = m_tpcnvsvc->p2t_cnv( persistent, Athena::TPCnvType::Trigger );
69 if( ! cnvtr ) {
70 // If there is no such thing, try a generic one:
71 cnvtr = m_tpcnvsvc->p2t_cnv( persistent );
72 }
73 m_convertesCache[persistent] = cnvtr;
74 return cnvtr;
75}
#define ATH_LIKELY(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::mutex m_convertersCacheMutex

◆ initialize()

StatusCode TrigSerTPTool::initialize ( )
overridevirtual

Function initialising the tool.

Definition at line 34 of file TrigSerTPTool.cxx.

34 {
35
36 // Greet the user:
37 ATH_MSG_INFO( "Initializing" );
38
39 // Retrieve the used services:
40 ATH_CHECK( m_dictSvc.retrieve() );
41 ATH_CHECK( m_tpcnvsvc.retrieve() );
42
43 /* When a P<->T conversion is requested, this tool makes a call to TClass::GetClass.
44 * The way it's done here can cause performance issues in some circumstances.
45 * For example, reading data16 RAW files trigger a P->T conversion from
46 * DataVector<xAOD::TauJet_v2> to DataVector<xAOD::TauJet_v3> in RAWtoALL/22.0.62.
47 * The problem is that the converter returns the full class name through
48 * ITPCnvBase::transientTInfo(), which in this case resolves into
49 * DataVector<xAOD::TauJet_v3,DataVector<xAOD::IParticle,DataModel_detail::NoBase> >
50 * Passing this directly to TClass::GetClass causes AutoLoading/HeaderParsing
51 * which notoriously allocates memory and never releases it. Here, we work
52 * around this problem by stripping the base class information from the name
53 * that's passed to TClass::GetClass, in this case simply DataVector<xAOD::TauJet_v3>
54 */
55 m_clNameRules.add("DataVector<$T, $B>", "DataVector<$T>");
56
57 return StatusCode::SUCCESS;
58}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ 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.

◆ interfaceID()

const InterfaceID & TrigSerTPTool::interfaceID ( )
inlinestatic

Declare the interface provided by the tool.

Definition at line 31 of file TrigSerTPTool.h.

31 {
32 static const InterfaceID
33 IID_TrigSerTPTool("TrigSerTPTool", 1, 0);
34 return IID_TrigSerTPTool;
35 }

◆ msg()

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

Definition at line 24 of file AthCommonMsg.h.

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

◆ 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.

◆ persClassName()

const std::string & TrigSerTPTool::persClassName ( const std::string & transClassName) const

Get the name of the persistent class belonging to a transient one.

Definition at line 187 of file TrigSerTPTool.cxx.

187 {
188
189 // Try to extract from the TP map
190 const auto tpItr = m_TPmap.find( transClassName );
191 if( tpItr == m_TPmap.end() ) {
192 REPORT_MESSAGE( MSG::ERROR )
193 << "Transient class " << transClassName
194 << " is not in the T/P Converter map";
195 static const std::string dummy( "" );
196 return dummy;
197 }
198
199 // Return the persistent class name:
200 return tpItr->second;
201}

◆ 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 }

◆ sysInitialize()

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

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ 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

◆ ATLAS_THREAD_SAFE

std::map<std::string, ITPCnvBase*> m_convertesCache TrigSerTPTool::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 64 of file TrigSerTPTool.h.

◆ m_clNameRules

CxxUtils::ClassName::Rules TrigSerTPTool::m_clNameRules
private

Definition at line 57 of file TrigSerTPTool.h.

◆ m_convertersCacheMutex

std::mutex TrigSerTPTool::m_convertersCacheMutex
mutableprivate

Definition at line 63 of file TrigSerTPTool.h.

◆ 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_dictSvc

ServiceHandle< IDictLoaderSvc > TrigSerTPTool::m_dictSvc
private

Definition at line 60 of file TrigSerTPTool.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_tpcnvsvc

ServiceHandle< ITPCnvSvc > TrigSerTPTool::m_tpcnvsvc
private

Definition at line 62 of file TrigSerTPTool.h.

◆ m_TPmap

std::map< std::string, std::string > TrigSerTPTool::m_TPmap
private

Definition at line 59 of file TrigSerTPTool.h.

◆ m_useAthDictLoader

bool TrigSerTPTool::m_useAthDictLoader
private

Definition at line 61 of file TrigSerTPTool.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: