ATLAS Offline Software
SCT_RDO_ContainerCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "SCT_RDO_ContainerCnv.h"
6 
8 
9 #include <memory>
10 
11 #include <iostream>
12 
13 
14 //================================================================
15 namespace {
16 #ifdef SCT_DEBUG
17  std::string shortPrint(const SCT_RDO_Container* main_input_SCT, unsigned maxprint=25) {
18  std::ostringstream os;
19  if (main_input_SCT) {
20  for (unsigned i=0; i<maxprint; i++) {
21  const auto* p = main_input_SCT->indexFindPtr(i);
22  if (p != nullptr) {
23  os<<" "<< p->size();
24  }
25  else {
26  os<<" *";
27  }
28  }
29  }
30  else {
31  os<<" [SCT_RDO_Container==nullptr]";
32  }
33  return os.str();
34  }
35 #endif
36 }
37 
39  : SCT_RDO_ContainerCnvBase(svcloc, "SCT_RDO_ContainerCnv"),
40  m_converter_p0()
41 {}
42 
43 //================================================================
46 
47  ATH_MSG_DEBUG("SCT_RDO_ContainerCnv::initialize()");
48 
49  // Get the sct helper from the detector store
50  const SCT_ID* idhelper(nullptr);
51  ATH_CHECK( detStore()->retrieve(idhelper, "SCT_ID") );
52 
53  m_converter_p0.initialize(idhelper);
54  m_converter_TP1.initialize(idhelper);
59  m_converter_PERS.initialize(idhelper);
60 
61  return StatusCode::SUCCESS;
62 }
63 
64 //================================================================
66 
67 #ifdef SCT_DEBUG
68  ATH_MSG_DEBUG("createPersistent(): main converter. TRANS = "<<shortPrint(transCont));
69 #endif
70  // converter_num is a switch to determine which persistent type to use
71  // 1: if concrete type private data is equivalent to InDetRawData_p1
72  // 3: for cosmic/TB
73  //
74  unsigned int converter_num(1);
75  SCT_RDO_Container::const_iterator it_Coll = transCont->begin();
76  SCT_RDO_Container::const_iterator it_CollEnd = transCont->end();
77  // check one element of the container. The container can't be empty for this...
78  if (it_Coll != it_CollEnd) {
79  while (it_Coll != it_CollEnd && (*it_Coll)->size() == 0) ++it_Coll;
80  if (it_Coll != it_CollEnd) {
81  const SCT_RDORawData* test((**it_Coll)[0]);
82  if (dynamic_cast<const SCT1_RawData*>(test) != nullptr) {
83  //ATH_MSG_DEBUG("Found container with SCT1_RawData concrete type objects");
84  converter_num=1;
85  } else if (dynamic_cast<const SCT3_RawData*>(test) != nullptr) {
86  //ATH_MSG_DEBUG("Found container with SCT3_RawData concrete type objects");
87  converter_num=3;
88  } else {
89  ATH_MSG_FATAL("Converter not implemented for this concrete type ");
90  throw "Converter not implemented";
91  }
92  } else {
93  ATH_MSG_WARNING("Container has only empty collections. Using TP1 converter");
94  }
95  } else {
96  ATH_MSG_WARNING("Empty container. Using TP1 converter");
97  }
98  // Switch facility depending on the concrete data type of the contained objects
99  // Should do by getting the type_info of one of the contained objects
100  SCT_RDO_Container_PERS* persObj(nullptr);
101  if (converter_num == 1 || converter_num == 3) {
102  m_converter_PERS.setType(converter_num);
103  persObj = m_converter_PERS.createPersistent( transCont, msg() );
104  } else {
105  ATH_MSG_FATAL("This shouldn't happen!! ");
106  }
107 #ifdef SCT_DEBUG
108  ATH_MSG_DEBUG("Success");
109 #endif
110  return persObj;
111 }
112 
113 //================================================================
115 
116  static const pool::Guid p0_guid("B82A1D11-3F86-4F07-B380-B61BA2DAF3A9"); // with SCT1_RawData
117  static const pool::Guid TP1_guid("DA76970C-E019-43D2-B2F9-25660DCECD9D"); // for t/p separated version with InDetRawDataContainer_p1
118  static const pool::Guid SCT_TP1_guid("8E13963E-13E5-4D10-AA8B-73F00AFF8FA8"); // for t/p separated version with SCT_RawDataContainer_p1
119  static const pool::Guid SCT_TP2_guid("D1258125-2CBA-476E-8578-E09D54F477E1"); // for t/p separated version with SCT_RawDataContainer_p2
120  static const pool::Guid SCT_TP3_guid("5FBC8D4D-7B4D-433A-8487-0EA0C870CBDB"); // for t/p separated version with SCT_RawDataContainer_p3
121  static const pool::Guid SCT_TP4_guid("6C7540BE-E85C-4777-BC1C-A9FF11460F54"); // for t/p separated version with SCT_RawDataContainer_p4
122 
123 #ifdef SCT_DEBUG
124  ATH_MSG_DEBUG("createTransient(): main converter");
125 #endif
126  if ( compareClassGuid(SCT_TP4_guid) ) {
127 #ifdef SCT_DEBUG
128  ATH_MSG_DEBUG("createTransient(): New TP version - TP4 branch");
129 #endif
130 
131  std::unique_ptr< SCT_RawDataContainer_p4 > col_vect( poolReadObject< SCT_RawDataContainer_p4 >() );
133 #ifdef SCT_DEBUG
134  ATH_MSG_DEBUG("createTransient(), TP4 branch: returns TRANS = "<<shortPrint(res));
135 #endif
136  return res;
137 
138  }
139  else if ( compareClassGuid(SCT_TP3_guid) ) {
140 #ifdef SCT_DEBUG
141  ATH_MSG_DEBUG("createTransient(): New TP version - TP3 branch");
142 #endif
143 
144  std::unique_ptr< SCT_RawDataContainer_p3 > col_vect( poolReadObject< SCT_RawDataContainer_p3 >() );
146 #ifdef SCT_DEBUG
147  ATH_MSG_DEBUG("createTransient(), TP3 branch: returns TRANS = "<<shortPrint(res));
148 #endif
149  return res;
150 
151  }
152  else if ( compareClassGuid(SCT_TP2_guid) ) {
153 #ifdef SCT_DEBUG
154  ATH_MSG_DEBUG("createTransient(): New TP version - TP2 branch");
155 #endif
156 
157  std::unique_ptr< SCT_RawDataContainer_p2 > col_vect( poolReadObject< SCT_RawDataContainer_p2 >() );
159 #ifdef SCT_DEBUG
160  ATH_MSG_DEBUG("createTransient(), TP2 branch: returns TRANS = "<<shortPrint(res));
161 #endif
162  return res;
163 
164  }
165  else if ( compareClassGuid(SCT_TP1_guid) ) {
166 #ifdef SCT_DEBUG
167  ATH_MSG_DEBUG("createTransient(): New TP version - TP1 branch");
168 #endif
169  std::unique_ptr< SCT_RawDataContainer_p1 > col_vect( poolReadObject< SCT_RawDataContainer_p1 >() );
171 #ifdef SCT_DEBUG
172  ATH_MSG_DEBUG("createTransient(), TP1 branch: returns TRANS = "<<shortPrint(res));
173 #endif
174  return res;
175 
176 
177  }
178  else if ( compareClassGuid(TP1_guid) ) {
179  ATH_MSG_DEBUG("createTransient(): New TP version - TP1 branch");
180 
181  std::unique_ptr< InDetRawDataContainer_p1 > col_vect( poolReadObject< InDetRawDataContainer_p1 >() );
182  SCT_RDO_Container* res = m_converter_TP1.createTransient( col_vect.get(), msg() );
183 #ifdef SCT_DEBUG
184  ATH_MSG_DEBUG("createTransient(), TP1 branch: returns TRANS = "<<shortPrint(res));
185 #endif
186  return res;
187 
188 
189  }
190  else if ( compareClassGuid(p0_guid) ) {
191 #ifdef SCT_DEBUG
192  ATH_MSG_DEBUG("createTransient(): Old input file - p0 branch");
193 #endif
194  std::unique_ptr< SCT_RDO_Container_p0 > col_vect( poolReadObject< SCT_RDO_Container_p0 >() );
195  SCT_RDO_Container* res = m_converter_p0.createTransient( col_vect.get(), msg() );
196 #ifdef SCT_DEBUG
197  ATH_MSG_DEBUG("createTransient(), p0 branch: returns TRANS = "<<shortPrint(res));
198 #endif
199  return res;
200  }
201 
202  throw std::runtime_error("Unsupported persistent version of SCT_RDO_Container");
203 }
204 
205 //================================================================
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SCT_RDO_ContainerCnv::m_converter_SCT_TP1
SCT_RawDataContainerCnv_p1 m_converter_SCT_TP1
Definition: SCT_RDO_ContainerCnv.h:33
SCT_RDO_ContainerCnv::m_converter_SCT_TP2
SCT_RawDataContainerCnv_p2 m_converter_SCT_TP2
Definition: SCT_RDO_ContainerCnv.h:34
SCT1_RawDataContainerCnv_p1::createTransient
virtual SCT_RDO_Container * createTransient(const InDetRawDataContainer_p1 *persObj, MsgStream &log)
Definition: SCT1_RawDataContainerCnv_p1.cxx:122
SCT_RDO_ContainerCnv.h
SCT_RDO_ContainerCnv::SCT_RDO_ContainerCnv
SCT_RDO_ContainerCnv(ISvcLocator *svcloc)
Definition: SCT_RDO_ContainerCnv.cxx:38
SCT_RDORawData
Definition: SCT_RDORawData.h:24
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
TPAbstractPolyCnvBase::createPersistent
virtual PERS * createPersistent(const TRANS *transObj, MsgStream &log)
Create persistent representation of a transient object.
SCT_RawDataContainerCnv_p2::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p2 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p2.cxx:196
pool::Guid
::Guid Guid
Definition: T_AthenaPoolCustCnv.h:19
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SCT_RawDataContainerCnv_p4::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p4 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p4.cxx:190
T_AthenaPoolCustomCnv
Compatibility for old converter classes that don't get passed the key.
Definition: T_AthenaPoolCustomCnv.h:132
lumiFormat.i
int i
Definition: lumiFormat.py:85
SCT3_RawData
Definition: SCT3_RawData.h:24
SCT_RawDataContainerCnv_p1::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT_RawDataContainerCnv_p1.h:42
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
SCT_RDO_ContainerCnv::m_converter_PERS
SCT_RDO_ContainerCnv_PERS m_converter_PERS
Definition: SCT_RDO_ContainerCnv.h:37
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
SCT_RawDataContainerCnv_p3::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p3 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p3.cxx:194
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
SCT_RDO_ContainerCnv::m_converter_SCT_TP3
SCT_RawDataContainerCnv_p3 m_converter_SCT_TP3
Definition: SCT_RDO_ContainerCnv.h:35
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:79
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
AthenaPoolConverter::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Handle to DetectorStore.
Definition: AthenaPoolConverter.h:69
SCT_RDO_ContainerCnv::m_converter_p0
SCT_RDO_ContainerCnv_p0 m_converter_p0
Definition: SCT_RDO_ContainerCnv.h:31
SCT_RDO_ContainerCnv::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: SCT_RDO_ContainerCnv.cxx:44
SCT_RawDataContainerCnv_p1::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p1 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p1.cxx:147
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
SCT_RDO_ContainerCnv::m_converter_SCT_TP4
SCT_RawDataContainerCnv_p4 m_converter_SCT_TP4
Definition: SCT_RDO_ContainerCnv.h:36
SCT_RDO_ContainerCnv::createPersistent
virtual SCT_RDO_Container_PERS * createPersistent(SCT_RDO_Container *transCont) override
Definition: SCT_RDO_ContainerCnv.cxx:65
SCT_RawDataContainer_p4
Persistent represenation of an SCT_RawDataContainer.
Definition: SCT_RawDataContainer_p4.h:24
SCT_RDO_ContainerCnv::m_converter_TP1
SCT1_RawDataContainerCnv_p1 m_converter_TP1
Definition: SCT_RDO_ContainerCnv.h:32
SCT_RawDataContainerCnv_p4::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT_RawDataContainerCnv_p4.h:43
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:289
SCT1_RawDataContainerCnv_p1::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT1_RawDataContainerCnv_p1.h:42
SCT_RDO_ContainerCnv_p0::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RDO_Container_p0 *persObj, MsgStream &log)
Definition: SCT_RDO_ContainerCnv_p0.cxx:14
SCT_RDO_ContainerCnv_p0::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT_RDO_ContainerCnv_p0.h:33
SCT_RawDataContainerCnv_p4::setType
void setType(int type)
Definition: SCT_RawDataContainerCnv_p4.h:44
SCT_ID
Definition: SCT_ID.h:68
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SCT1_RawData
Definition: SCT1_RawData.h:27
T_AthenaPoolCustCnv::compareClassGuid
virtual bool compareClassGuid(const Guid &clid) const
Compare POOL class GUID with the one of the object being read.
T_AthenaPoolCustCnv::initialize
virtual StatusCode initialize()
Gaudi Service Interface method implementations:
SCT_RawDataContainerCnv_p2::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT_RawDataContainerCnv_p2.h:43
SCT_RawDataContainerCnv_p3::initialize
void initialize(const SCT_ID *idhelper)
Definition: SCT_RawDataContainerCnv_p3.h:44
SCT_RDO_ContainerCnv::createTransient
virtual SCT_RDO_Container * createTransient() override
Definition: SCT_RDO_ContainerCnv.cxx:114