ATLAS Offline Software
AthTPCnvSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // AthTPCnvSvc.cxx
8 // Implementation file for class AthTPCnvSvc
9 // Author: S.Binet<binet@cern.ch>
11 
12 #include "AthTPCnvSvc.h"
13 #include "GaudiKernel/Converter.h"
14 
15 
16 namespace {
17 
19 {
20  switch (type)
21  {
23  return "_ARA";
25  return "_TRIG";
26  default:
27  break;
28  }
29  return "";
30 }
31 
32 } // anonymous namespace
33 
34 
35 // Constructors
37 AthTPCnvSvc::AthTPCnvSvc( const std::string& name,
38  ISvcLocator* pSvcLocator ) :
39  base_class ( name, pSvcLocator ),
40  m_clidSvc("ClassIDSvc/ClassIDSvc", name)
41 {
42 }
43 
44 // Destructor
47 {
48 }
49 
50 
55 ITPCnvBase*
56 AthTPCnvSvc::load_tpcnv(const std::string& cls)
57 {
58  ITPCnvBase* cnv = ITPCnvBase::Factory::create (cls).release();
59  if (cnv == nullptr) {
60  ATH_MSG_INFO("could not load class [" << cls
61  << "] via Reflex::PluginService");
62  }
63  else {
64  std::scoped_lock lock (m_mutex);
65  m_cnvs.emplace_back (cnv);
66  }
67  return cnv;
68 }
69 
73 ITPCnvBase*
74 AthTPCnvSvc::t2p_cnv(const std::string& transClassName,
75  Athena::TPCnvType::Value type /*= Athena::TPCnvType::Athena*/)
76 
77 {
78  ITPCnvBase* cnv = ITPCnvBase::Factory::create (prefix(type) + "_TRANS_" + transClassName).release();
79  if (cnv == nullptr && type != Athena::TPCnvType::Athena)
80  return t2p_cnv (transClassName);
81  if (cnv == nullptr) {
82  ATH_MSG_WARNING("Could not load converter for transient class ["
83  << transClassName << "]");
84  }
85  else {
86  std::scoped_lock lock (m_mutex);
87  m_cnvs.emplace_back (cnv);
88  }
89  return cnv;
90 }
91 
95 ITPCnvBase*
96 AthTPCnvSvc::t2p_cnv(const CLID& transClid,
97  Athena::TPCnvType::Value type /*= Athena::TPCnvType::Athena*/)
98 {
99  std::string trans_type;
100  if (!m_clidSvc->getTypeNameOfID(transClid, trans_type).isSuccess()) {
101  ATH_MSG_INFO("could not get a type-name for clid [" << transClid << "]");
102  return nullptr;
103  }
104 
105  ITPCnvBase* cnv = ITPCnvBase::Factory::create (prefix(type) + "_TRANS_" + trans_type).release();
106  if (cnv == nullptr) {
107  // try a typeinfo-name before bailing out...
108  if (!m_clidSvc->getTypeInfoNameOfID(transClid, trans_type).isSuccess()) {
109  ATH_MSG_INFO("could not get a typeinfo-name for clid ["
110  << transClid << "]");
111  return nullptr;
112  }
113  cnv = ITPCnvBase::Factory::create (prefix(type) + "_TRANS_" + trans_type).release();
114  }
115  if (cnv == nullptr && type != Athena::TPCnvType::Athena)
116  return t2p_cnv (transClid);
117  if (cnv == nullptr) {
118  ATH_MSG_WARNING("could not load converter for transient CLID ["
119  << transClid << "] (" << trans_type << ")");
120  }
121  else {
122  std::scoped_lock lock (m_mutex);
123  m_cnvs.emplace_back (cnv);
124  }
125  return cnv;
126 }
127 
131 ITPCnvBase*
132 AthTPCnvSvc::p2t_cnv(const std::string& persClassName,
133  Athena::TPCnvType::Value type /*= Athena::TPCnvType::Athena*/)
134 {
135  ITPCnvBase* cnv = ITPCnvBase::Factory::create (prefix(type) + "_PERS_" + persClassName).release();
136  if (cnv == nullptr && type != Athena::TPCnvType::Athena)
137  return p2t_cnv (persClassName);
138  if (cnv == nullptr) {
139  ATH_MSG_WARNING("Could not load converter for persistent class ["
140  << persClassName << "]");
141  }
142  else {
143  std::scoped_lock lock (m_mutex);
144  m_cnvs.emplace_back (cnv);
145  }
146  return cnv;
147 }
148 
149 
153 std::unique_ptr<ITPCnvBase>
154 AthTPCnvSvc::t2p_cnv_unique(const std::string& transClassName) const
155 {
156  return ITPCnvBase::Factory::create ("_TRANS_" + transClassName);
157 }
158 
159 
164 std::unique_ptr<ITPCnvBase>
165 AthTPCnvSvc::t2p_cnv_unique(const CLID transClid) const
166 {
167  std::string trans_type;
168  if (!m_clidSvc->getTypeNameOfID(transClid, trans_type).isSuccess()) {
169  return nullptr;
170  }
171 
172  std::unique_ptr<ITPCnvBase> cnv = ITPCnvBase::Factory::create (/*prefix(type) +*/ "_TRANS_" + trans_type);
173  if (cnv == nullptr) {
174  // try a typeinfo-name before bailing out...
175  if (!m_clidSvc->getTypeInfoNameOfID(transClid, trans_type).isSuccess()) {
176  return nullptr;
177  }
178  cnv = ITPCnvBase::Factory::create (/*prefix(type) +*/ "_TRANS_" + trans_type);
179  }
180  /*
181  ** FIXME: support other types.
182  if (cnv == nullptr && type != Athena::TPCnvType::Athena)
183  return t2p_cnv (transClid);
184  */
185  return cnv;
186 }
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthTPCnvSvc.h
Athena::TPCnvType::Value
Value
Definition: TPCnvFactory.h:122
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
Athena::TPCnvType::Trigger
@ Trigger
Definition: TPCnvFactory.h:125
AthTPCnvSvc::AthTPCnvSvc
AthTPCnvSvc()
Default constructor:
Athena::TPCnvType::Athena
@ Athena
Definition: TPCnvFactory.h:123
Athena::TPCnvType::ARA
@ ARA
Definition: TPCnvFactory.h:124
AthTPCnvSvc::t2p_cnv_unique
virtual std::unique_ptr< ITPCnvBase > t2p_cnv_unique(const std::string &transClassName) const override
return the T/P converter for a transient class (NULL if failure) Ownership is returned to the caller.
Definition: AthTPCnvSvc.cxx:154
AthTPCnvSvc::m_mutex
std::mutex m_mutex
Definition: AthTPCnvSvc.h:114
AthTPCnvSvc::t2p_cnv
virtual ITPCnvBase * t2p_cnv(const std::string &transClassName, Athena::TPCnvType::Value type=Athena::TPCnvType::Athena) override
return the T/P converter for a transient class (NULL if failure) ITPCnvSvc owns the ITPCnvBase pointe...
Definition: AthTPCnvSvc.cxx:74
AthTPCnvSvc::m_clidSvc
ServiceHandle< IClassIDSvc > m_clidSvc
handle to a IClassIDSvc to handle loading of types by CLID
Definition: AthTPCnvSvc.h:106
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
AthTPCnvSvc::~AthTPCnvSvc
virtual ~AthTPCnvSvc() override
Destructor:
Definition: AthTPCnvSvc.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ITPCnvBase
Definition: ITPCnvBase.h:24
AthTPCnvSvc::load_tpcnv
virtual ITPCnvBase * load_tpcnv(const std::string &cls) override
load the T/P converter class named cls return NULL on failure.
Definition: AthTPCnvSvc.cxx:56
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthTPCnvSvc::m_cnvs
TpCnvs_t m_cnvs
a registry of ITPCnvBase* instances
Definition: AthTPCnvSvc.h:111
AthTPCnvSvc::p2t_cnv
virtual ITPCnvBase * p2t_cnv(const std::string &persClassName, Athena::TPCnvType::Value type=Athena::TPCnvType::Athena) override
return the T/P converter for a persistent class (NULL if failure) ITPCnvSvc owns the ITPCnvBase point...
Definition: AthTPCnvSvc.cxx:132