ATLAS Offline Software
TruthParticleContainerCnv.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // TruthParticleContainerCnv.cxx
8 // Implementation file for class TruthParticleContainerCnv
9 // Author: S.Binet<binet@cern.ch>
11 
12 // STL includes
13 
14 // Framework includes
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/IToolSvc.h"
17 #include "GaudiKernel/IAlgTool.h"
18 #include "StoreGate/StoreGateSvc.h"
19 
20 // McParticleKernel includes
22 
23 // McParticleEventTPCnv includes
26 
27 // McParticleEventAthenaPool includes
29 
32  TruthParticleContainer_PERS>(svcLocator),
33  m_storeGate( 0 ),
34  m_cnvTool ( 0 )
35 {
36  if ( 0 == svcLocator ) {
37  throw std::runtime_error("NULL pointer to ISvcLocator !!");
38  }
39 
40  IToolSvc* toolSvc = 0;
41  if ( svcLocator->service("ToolSvc",toolSvc).isFailure() || 0 == toolSvc ) {
42  throw std::runtime_error("Could not fetch ToolSvc !!");
43  }
44 
45  IAlgTool * algTool = 0;
46  if ( toolSvc->retrieveTool( "TruthParticleCnvTool", algTool ).isFailure() ) {
47  throw std::runtime_error("Could not fetch TruthParticleCnvTool !!");
48  } else {
49  m_cnvTool = dynamic_cast<ITruthParticleCnvTool*>(algTool);
50  if ( 0 == m_cnvTool ) {
51  throw std::runtime_error("Could not dyn-cast to ITruthParticleCnvTool !!");
52  }
53  }
54 
55  if ( svcLocator->service("StoreGateSvc",m_storeGate).isFailure() ||
56  0 == m_storeGate ) {
57  throw std::runtime_error("Could not fetch StoreGateSvc !!");
58  }
59 }
60 
61 
64 {
65  MsgStream log( msgSvc(), "TruthParticleContainerCnv" );
66 
69 
70  log << MSG::DEBUG << "::createPersistent [Success]" << endmsg;
71  return pers;
72 }
73 
75 {
76  MsgStream msg( msgSvc(), "TruthParticleContainerCnv" );
77 
78  TruthParticleContainer *trans = 0;
79 
80  static const pool::Guid p5_guid("2D25E3D9-950B-49E0-A51F-2B6EC93D1A23");
81  static const pool::Guid p6_guid("97AC2CEE-7E8A-4E2E-B6B5-FD8545D77FC4");
82 
83  if ( compareClassGuid(p6_guid) ) {
84 
85  std::unique_ptr<TruthParticleContainer_p6> pers( poolReadObject<TruthParticleContainer_p6>() );
87  trans = cnv.createTransient( pers.get(), msg );
88 
89  } else if ( compareClassGuid(p5_guid) ) {
90 
91  std::unique_ptr<TruthParticleContainer_p5> pers( poolReadObject<TruthParticleContainer_p5>() );
93  trans = cnv.createTransient( pers.get(), msg );
94 
95  } else {
96  throw std::runtime_error("Unsupported persistent version of TruthParticleContainer");
97  }
98 
99  return trans;
100 }
ITruthParticleCnvTool.h
TruthParticleContainerCnv::createTransient
virtual TruthParticleContainer * createTransient()
Build the transient representation from a persistent one.
Definition: TruthParticleContainerCnv.cxx:74
TPPolyCnvBase::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
TruthParticleContainerCnv::m_cnvTool
ITruthParticleCnvTool * m_cnvTool
Pointer to the McEventCollection -> TruthParticleContainer converter tool.
Definition: TruthParticleContainerCnv.h:75
TruthParticleContainerCnv.h
TruthParticleContainer_p6
Definition: TruthParticleContainer_p6.h:27
TruthParticleContainer
Definition: PhysicsAnalysis/TruthParticleID/McParticleEvent/McParticleEvent/TruthParticleContainer.h:42
TPAbstractPolyCnvBase::createPersistent
virtual PERS * createPersistent(const TRANS *transObj, MsgStream &log)
Create persistent representation of a transient object.
pool::Guid
::Guid Guid
Definition: T_AthenaPoolCustCnv.h:19
TruthParticleContainerCnv_p5
Definition: TruthParticleContainerCnv_p5.h:41
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
T_AthenaPoolCustomCnv
Compatibility for old converter classes that don't get passed the key.
Definition: T_AthenaPoolCustomCnv.h:132
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
TruthParticleContainerCnv_p6
Definition: TruthParticleContainerCnv_p6.h:41
TruthParticleContainerCnv::createPersistent
virtual TruthParticleContainer_PERS * createPersistent(TruthParticleContainer *transCont)
Build the persistent representation from the transient one.
Definition: TruthParticleContainerCnv.cxx:63
TruthParticleContainerCnv::m_storeGate
StoreGateSvc * m_storeGate
Pointer to the StoreGateSvc.
Definition: TruthParticleContainerCnv.h:70
TruthParticleContainerCnv_p6.h
ITruthParticleCnvTool
Definition: ITruthParticleCnvTool.h:41
TruthParticleContainerCnv_p5.h
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
T_AthenaPoolCustCnv< TruthParticleContainer, TruthParticleContainer_PERS >::compareClassGuid
virtual bool compareClassGuid(const Guid &clid) const
Compare POOL class GUID with the one of the object being read.
StoreGateSvc.h
TruthParticleContainerCnv::TruthParticleContainerCnv
TruthParticleContainerCnv(ISvcLocator *svcloc)
Create the converter from the service locator.
Definition: TruthParticleContainerCnv.cxx:30