15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/Bootstrap.h"
28 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service(
"DetectorStore")};
29 CHECK( detStore.isValid() );
36 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG <<
"Converter initialized. " <<
endmsg;
37 return StatusCode::SUCCESS;
41 if (!cnv_tool)
return nullptr;
49 if (this->
initialize(log) != StatusCode::SUCCESS) {
50 log << MSG::FATAL <<
"Could not initialize sTgcPrepDataContainerCnv_p3 " <<
endmsg;
72 TRANS::const_iterator it_Coll = transCont->
begin();
73 TRANS::const_iterator it_CollEnd = transCont->
end();
74 unsigned int pcollIndex = 0;
75 unsigned int pcollBegin = 0;
76 unsigned int pcollEnd = 0;
80 if (log.level() <= MSG::DEBUG)
81 log << MSG::DEBUG<<
" Preparing " << persCont->
m_collections.size() <<
"Collections" <<
endmsg;
83 for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
85 if (log.level() <= MSG::DEBUG)
86 log << MSG::DEBUG<<
"New collection"<<
endmsg;
90 pcollBegin = pcollEnd;
91 pcollEnd += collection.
size();
98 persCont->
m_prds.resize(pcollEnd);
101 unsigned int lastPRDIdHash = 0;
102 for (
unsigned int i = 0; i < collection.
size(); ++i) {
103 unsigned int pchanIndex=i+pcollBegin;
112 int multilayer = (
m_sTgcId->multilayer(chan->identify())-1);
113 int gasGap = (
m_sTgcId->gasGap(chan->identify())-1);
114 int channelType = (
m_sTgcId->channelType(chan->identify()));
118 unsigned short diff = ( channel << 5 | channelType << 3 | gasGap << 1 | multilayer) ;
119 log << MSG::DEBUG <<
"Translated id=" << chan->identify().get_compact() <<
" (multilayer=" << multilayer
120 <<
", gasGap << " << gasGap <<
", channel=" << channel <<
") into diff=" <<
diff <<
endmsg;
125 if(log.level() <= MSG::DEBUG){
127 if (temp!=chan->identify() )
128 log << MSG::WARNING <<
"PRD ids differ! Transient:"<<chan->identify()<<
", From persistent:"<<temp<<
" diff = "<<chan->identify().get_compact()-temp.get_compact()<<
endmsg;
130 log << MSG::DEBUG <<
" PRD ids match."<<
endmsg;
131 if (lastPRDIdHash && lastPRDIdHash != chan->collectionHash() ) log << MSG::WARNING <<
"Collection Identifier hashes differ!"<<
endmsg;
132 lastPRDIdHash = chan->collectionHash();
133 log << MSG::DEBUG<<
"Collection hash = "<<lastPRDIdHash<<
endmsg;
135 if (chan->collectionHash()!= collection.
identifyHash() ) log << MSG::WARNING <<
"Collection's idHash does not match PRD collection hash!"<<
endmsg;
137 log << MSG::WARNING <<
"Getting de from identity didn't work!"<<
endmsg;
139 log << MSG::DEBUG<<
"Getting de from identity did work "<<
endmsg;
140 if (chan->detectorElement() !=
getReadOutElement(temp)) log << MSG::WARNING <<
"Getting de from reconstructed identity didn't work!"<<
endmsg;
141 log << MSG::DEBUG<<
"Finished loop"<<
endmsg;
145 if (log.level() <= MSG::DEBUG)
146 log << MSG::DEBUG<<
" *** Writing sTgcPrepDataContainer ***" <<
endmsg;
169 unsigned int pchanIndex(0);
171 if (log.level() <= MSG::DEBUG)
172 log << MSG::DEBUG<<
" Reading " << pCollEnd <<
"Collections" <<
endmsg;
173 for (
unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
179 unsigned int pchanEnd = pchanIndex+pcoll.
m_size;
180 unsigned int chanIndex = 0;
184 for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
190 int channel = (
diff>>5);
191 int channelType = ( 3 & (
diff>>3) );
192 int gasGap = ( 3 & (
diff>>1));
193 int multilayer = ( 1 &
diff );
196 log << MSG::DEBUG <<
"Diff of " <<
diff <<
" translated into multilayer="
197 << multilayer <<
", gasGap=" << gasGap <<
", channelType=" << channelType
202 log << MSG::WARNING <<
"Tgc PRD has invalid Identifier of "<<
m_sTgcId->show_to_string(clusId)<<
" - are you sure you have the correct geometry loaded, and NSW enabled?"<<
endmsg;
207 int result =
m_sTgcId->get_detectorElement_hash(clusId, deIDHash);
208 if (
result&&log.level() <= MSG::WARNING)
209 log << MSG::WARNING<<
" Muon::sTgcPrepDataContainerCnv_p3::persToTrans: problem converting Identifier to DE hash "<<
endmsg;
213 log << MSG::WARNING<<
"Muon::sTgcPrepDataContainerCnv_p3::persToTrans: could not get valid det element for PRD with id="<<clusId<<
". Skipping."<<
endmsg;
217 auto chan = std::make_unique<sTgcPrepData>
223 chan->setHashAndIndex(collIDHash, chanIndex);
229 if (
sc.isFailure()) {
230 throw std::runtime_error(
"Failed to add collection to Identifiable Container");
232 if (log.level() <= MSG::DEBUG) {
233 log << MSG::DEBUG <<
"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash <<
" / " <<
238 if (log.level() <= MSG::DEBUG)
239 log << MSG::DEBUG<<
" *** Reading sTgcPrepDataContainer ***" <<
endmsg;
248 if (this->
initialize(log) != StatusCode::SUCCESS) {
249 log << MSG::FATAL <<
"Could not initialize sTgcPrepDataContainerCnv_p3 " <<
endmsg;
255 return(trans.release());
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
void reserve(size_type n)
value_type push_back(value_type pElem)
size_type size() const noexcept
const_iterator end() const
return const_iterator for end of container
virtual size_t numberOfCollections() const override final
return number of collections
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,...
const_iterator begin() const
return const_iterator for first entry
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
An sTgcReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station c...
Class to hold the persistent representation of MuonPRD_Collection.
unsigned short m_size
Collection size into master collection Note I use a short.
unsigned int m_hashId
Hash Identifier of this collection.
unsigned int m_id
Identifier of this collection.
std::vector< MuonPRD_Collection_p2 > m_collections
std::vector< unsigned short > m_prdDeltaId
The delta identifiers of the PRD i.e.
std::vector< PRD > m_prds
virtual Identifier identify() const override final
virtual void setIdentifier(Identifier id)
virtual IdentifierHash identifyHash() const override final
StatusCode initialize(MsgStream &log)
virtual Muon::sTgcPrepDataContainer * createTransient(const Muon::sTgcPrepDataContainer_p3 *persObj, MsgStream &log)
virtual void transToPers(const Muon::sTgcPrepDataContainer *transCont, Muon::sTgcPrepDataContainer_p3 *persCont, MsgStream &log)
const sTgcIdHelper * m_sTgcId
const MuonGM::sTgcReadoutElement * getReadOutElement(const Identifier &id) const
virtual void persToTrans(const Muon::sTgcPrepDataContainer_p3 *persCont, Muon::sTgcPrepDataContainer *transCont, MsgStream &log)
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Class to represent sTgc measurements.
static Muon::sTgcPrepData createsTgcPrepData(const Muon::sTgcPrepData_p3 *persObj, const Identifier clusId, const MuonGM::sTgcReadoutElement *m_detEl, MsgStream &log)
void transToPers(const Muon::sTgcPrepData *transObj, Muon::sTgcPrepData_p3 *persObj, MsgStream &log)
MuonPRD_Container_p2< sTgcPrepData_p3 > sTgcPrepDataContainer_p3
MuonPrepDataContainerT< sTgcPrepData > sTgcPrepDataContainer
MuonPrepDataCollection< sTgcPrepData > sTgcPrepDataCollection