ATLAS Offline Software
RpcPrepDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 
14 // Gaudi
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/StatusCode.h"
18 #include "GaudiKernel/Service.h"
19 #include "GaudiKernel/MsgStream.h"
20 
21 // Athena
23 #include "StoreGate/StoreGateSvc.h"
26 #include "AthAllocators/DataPool.h"
27 
28 
30  // Do not initialize again:
31  m_isInitialized=true;
32 
33  // get DetectorStore service
34  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
35  CHECK( detStore.isValid() );
36 
37  // Get the helper from the detector store
38  CHECK( detStore->retrieve(m_RpcId) );
39 
40  CHECK( m_eventCnvTool.retrieve() );
41 
42  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
43  return StatusCode::SUCCESS;
44 }
46  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
47  if (!cnv_tool) return nullptr;
48  return dynamic_cast<const MuonGM::RpcReadoutElement*>(cnv_tool->getDetectorElement(id));
49 }
51 {
52 
53  // The transient model has a container holding collections and the
54  // collections hold channels.
55  //
56  // The persistent model flattens this so that the persistent
57  // container has two vectors:
58  // 1) all collections, and
59  // 2) all RDO
60  //
61  // The persistent collections, then only maintain indexes into the
62  // container's vector of all channels.
63  //
64  // So here we loop over all collection and add their channels
65  // to the container's vector, saving the indexes in the
66  // collection.
67 
70 
71  RpcPrepDataCnv_p1 chanCnv;
72  TRANS::const_iterator it_Coll = transCont->begin();
73  TRANS::const_iterator it_CollEnd = transCont->end();
74  unsigned int collIndex = 0;
75  unsigned int chanBegin = 0;
76  unsigned int chanEnd = 0;
77  int numColl = transCont->numberOfCollections();
78 
79  persCont->m_collections.resize(numColl);
80  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
81 
82  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
83  // Add in new collection
84  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
85  const Muon::RpcPrepDataCollection& collection = (**it_Coll);
86  chanBegin = chanEnd;
87  chanEnd += collection.size();
88  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
89  pcollection.m_id = collection.identify().get_identifier32().get_compact();
90  pcollection.m_hashId = (unsigned int) collection.identifyHash();
91  pcollection.m_begin = chanBegin;
92  pcollection.m_end = chanEnd;
93  // Add in channels
94  persCont->m_PRD.resize(chanEnd);
95  for (unsigned int i = 0; i < collection.size(); ++i) {
96  const Muon::RpcPrepData* chan = collection[i];
97  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
98  }
99  }
100  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing RpcPrepDataContainer ***" << endmsg;
101 }
102 
104 {
105 
106  // The transient model has a container holding collections and the
107  // collections hold channels.
108  //
109  // The persistent model flattens this so that the persistent
110  // container has two vectors:
111  // 1) all collections, and
112  // 2) all channels
113  //
114  // The persistent collections, then only maintain indexes into the
115  // container's vector of all channels.
116  //
117  // So here we loop over all collection and extract their channels
118  // from the vector.
119 
120 
121  Muon::RpcPrepDataCollection* coll = nullptr;
122 
123  RpcPrepDataCnv_p1 chanCnv;
125 
126  log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
127  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
128  // Create trans collection - is NOT owner of RpcPrepData (SG::VIEW_ELEMENTS)
129  // IDet collection don't have the Ownership policy c'tor
130  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
131  Identifier collID(Identifier(pcoll.m_id));
132  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
133  coll = new Muon::RpcPrepDataCollection(collIDHash);
134  coll->setIdentifier(Identifier(pcoll.m_id));
135  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
136  coll->resize(nchans);
137  // Fill with channels
138  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
139  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
140  Muon::RpcPrepData* chan = dynamic_cast<Muon::RpcPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
141  if (!chan) {
142  log << MSG::ERROR << "RpcPrepDataContainerCnv_p1::persToTrans: Cannot get RpcPrepData!" << endmsg;
143  continue;
144  }
145  const MuonGM::RpcReadoutElement * de = getReadOutElement(chan->identify());
146  chan->m_detEl = de;
147  (*coll)[ichan] = chan;
148 
149  // check to handle cases explained in bug#56227
150  if (de->nGasGapPerLay() == 1 && de->NphiStripPanels() == 2){
151  // okay, so this was originally on a large surface and needs correcting.
152  const Amg::Vector3D& globalposHIT = de->stripPos( chan->identify() );
153 
154  double tolerance = 3.0;
155  const Trk::PlaneSurface& surf = de->surface( chan->identify() );
156  std::optional<Amg::Vector2D> pos = surf.Trk::Surface::globalToLocal(globalposHIT,tolerance);
157  if (!pos){
158  log << MSG::WARNING << "RpcPrepDataContainerCnv_p1::persToTrans - globalToLocal failed!"<<endmsg;
159  chan->m_localPos = Amg::Vector2D(0,0);
160  }
161  else chan->m_localPos = *pos;
162  }
163  }
164 
165  // register the rdo collection in IDC with hash - faster addCollection
166  StatusCode sc = transCont->addCollection(coll, collIDHash);
167  if (sc.isFailure()) {
168  throw std::runtime_error("Failed to add collection to ID Container");
169  }
170  if (log.level() <= MSG::DEBUG) {
171  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
172  collID.get_compact() << ", added to Identifiable container." << endmsg;
173  }
174  }
175 
176  log << MSG::DEBUG << " *** Reading RpcPrepDataContainer" << endmsg;
177 }
178 
179 
180 
181 //================================================================
183 {
184  if(!m_isInitialized) {
185  if (this->initialize(log) != StatusCode::SUCCESS) {
186  log << MSG::FATAL << "Could not initialize RpcPrepDataContainerCnv_p1 " << endmsg;
187  return nullptr;
188  }
189  }
190  std::unique_ptr<Muon::RpcPrepDataContainer> trans(new Muon::RpcPrepDataContainer(m_RpcId->module_hash_max()));
191  persToTrans(persObj, trans.get(), log);
192  return(trans.release());
193 }
194 
195 
Muon::RpcPrepDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p1.cxx:50
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
Muon::MuonPRD_Container_p1::m_collections
std::vector< Muon::MuonPRD_Collection_p1 > m_collections
Definition: MuonPRD_Container_p1.h:19
ITPConverterFor< Trk::PrepRawData >
MuonGM::RpcReadoutElement::NphiStripPanels
int NphiStripPanels() const
returns the number of phi strip panels (1 or 2)
RpcPrepDataCnv_p1
Definition: RpcPrepDataCnv_p1.h:23
Muon::RpcPrepDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcPrepDataContainerCnv_p1.cxx:29
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
Muon::RpcPrepDataContainerCnv_p1::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: RpcPrepDataContainerCnv_p1.h:40
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:300
Muon::MuonPRD_Collection_p1::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonPRD_Collection_p1.h:31
Muon::MuonPRD_Collection_p1::m_hashId
unsigned int m_hashId
Hash Identifier of this collection (write this one as well, so we don't rely on the IdHelper for it)
Definition: MuonPRD_Collection_p1.h:35
MuonGM::RpcReadoutElement::nGasGapPerLay
int nGasGapPerLay() const
returns the number of gasgaps
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Muon::RpcPrepDataCollection
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
Definition: MuonPrepDataCollection.h:107
Muon::MuonPRD_Collection_p1::m_end
unsigned int m_end
End index into master collection.
Definition: MuonPRD_Collection_p1.h:41
initialize
void initialize()
Definition: run_EoverP.cxx:894
RpcPrepDataCnv_p1.h
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier::get_compact
value_type get_compact() const
Get the compact id.
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:55
RpcPrepData_p1.h
RpcPrepDataContainer.h
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
MuonGM::MuonClusterReadoutElement::surface
virtual const Trk::PlaneSurface & surface() const override
access to chamber surface (phi orientation), uses the first gas gap
Definition: MuonClusterReadoutElement.h:123
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
TPObjRef
Definition: TPObjRef.h:20
Muon::RpcPrepDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p1.cxx:103
RpcIdHelper.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonPRD_Container_p1.h
Muon::RpcPrepDataContainerCnv_p1::getReadOutElement
const MuonGM::RpcReadoutElement * getReadOutElement(const Identifier &id) const
Definition: RpcPrepDataContainerCnv_p1.cxx:45
GeoPrimitives.h
RpcPrepDataContainerCnv_p1.h
Muon::MuonPrepDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
lumiFormat.i
int i
Definition: lumiFormat.py:85
Muon::RpcPrepData
Class to represent RPC measurements.
Definition: RpcPrepData.h:35
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::MuonPrepDataCollection::identify
virtual Identifier identify() const override final
Trk::ITrkEventCnvTool
Definition: ITrkEventCnvTool.h:31
Muon::RpcPrepDataContainerCnv_p1::m_RpcId
const RpcIdHelper * m_RpcId
Definition: RpcPrepDataContainerCnv_p1.h:39
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:242
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
DataPool.h
tolerance
Definition: suep_shower.h:17
EventPrimitives.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
MuonGM::RpcReadoutElement::stripPos
Amg::Vector3D stripPos(const Identifier &id) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx:177
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Muon::MuonPRD_Collection_p1::m_begin
unsigned int m_begin
Begin index into master collection.
Definition: MuonPRD_Collection_p1.h:38
Muon::MuonPRD_Collection_p1
Definition: MuonPRD_Collection_p1.h:11
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonDetectorManager.h
Muon::MuonPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: MuonPRD_Container_p1.h:20
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Muon::RpcPrepDataContainerCnv_p1::createTransient
virtual Muon::RpcPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p1.cxx:182
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::ITrkEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
RpcPrepData.h
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Muon::RpcPrepDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: RpcPrepDataContainerCnv_p1.h:41
Identifier
Definition: IdentifierFieldParser.cxx:14