ATLAS Offline Software
SCT_CablingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 //this package
14 #include "SCT_CablingTool.h"
15 
16 //Athena
17 #include "InDetIdentifier/SCT_ID.h"
18 #include "Identifier/Identifier.h"
20 
21 //Gaudi includes
22 #include "GaudiKernel/StatusCode.h"
23 
24 //constants in file scope
25 static const std::string coracool("CORACOOL");
26 static const std::string coolVectorPayload("COOLVECTOR");
27 static const std::string defaultSource(coracool);
28 static const std::string file("SCT_Sept08Cabling_svc.dat");
29 //invalid identifiers to return in case of error
30 static const SCT_OnlineId invalidId;
31 static const IdentifierHash invalidHash;
32 static const SCT_SerialNumber invalidSn;
33 
34 //Utility functions at file scope
35 namespace {
36  //make a number even
37  IdentifierHash even(const IdentifierHash& hash) {
38  return (hash>>1) << 1;
39  }
40 }
41 
42 // Constructor
43 SCT_CablingTool::SCT_CablingTool(const std::string& type, const std::string& name, const IInterface* parent) :
44  base_class(type, name, parent)
45 {
46  declareProperty("DataSource", m_cablingDataSource=defaultSource);
47 }
48 
49 //
52  ATH_MSG_DEBUG("Initialize SCT cabling");
53  const std::string cablingDataSource = m_cablingDataSource.value();
54  m_usingDatabase=(cablingDataSource == coracool) or (cablingDataSource == coolVectorPayload) or (cablingDataSource == file);
55  ATH_CHECK(detStore()->retrieve(m_idHelper, "SCT_ID"));
57  return StatusCode::SUCCESS;
58 }
59 
60 //
61 unsigned int
62 SCT_CablingTool::size(const EventContext& ctx) const {
63  const SCT_CablingData* data{getData(ctx)};
64  if (data==nullptr) {
65  ATH_MSG_FATAL("Filling the cabling FAILED");
66  return 0;
67  }
68 
69  return data->getHashEntries();
70 }
71 
72 unsigned int
74  const EventContext& ctx{Gaudi::Hive::currentContext()};
75  return size(ctx);
76 }
77 
78 //
79 bool
80 SCT_CablingTool::empty(const EventContext& ctx) const {
81  return (size(ctx)==0);
82 }
83 
84 bool
86  const EventContext& ctx{Gaudi::Hive::currentContext()};
87  return empty(ctx);
88 }
89 
90 //
92 SCT_CablingTool::getHashFromOnlineId(const SCT_OnlineId& onlineId, const EventContext& ctx, const bool withWarnings) const {
93  //is it valid at all?
94  if (not onlineId.is_valid()) {
95  if (withWarnings) ATH_MSG_WARNING("Invalid online id ("<<std::hex<<onlineId<<") "<<std::dec);
96  return invalidHash;
97  }
98  //is it specifically valid for the given datasource?
99  if (not onlineId.is_valid(m_usingDatabase)) {
100  const std::string alternative=m_usingDatabase?"text file cabling":"cabling from database";
101  if (withWarnings) ATH_MSG_WARNING("Invalid online id ("<<std::hex<<onlineId<<") try using the "<<alternative<<std::dec);
102  return invalidHash;
103  }
104 
105  const SCT_CablingData* data{getData(ctx)};
106  if (data==nullptr) {
107  ATH_MSG_FATAL("Filling the cabling FAILED");
108  return invalidHash;
109  }
110 
111  return data->getHashFromOnlineId(onlineId);
112 }
113 
115 SCT_CablingTool::getHashFromOnlineId(const SCT_OnlineId& onlineId, const bool withWarnings) const {
116  const EventContext& ctx{Gaudi::Hive::currentContext()};
117  return getHashFromOnlineId(onlineId, ctx, withWarnings);
118 }
119 
120 //
122 SCT_CablingTool::getOnlineIdFromHash(const IdentifierHash& hash, const EventContext& ctx) const {
123  const SCT_CablingData* data{getData(ctx)};
124  if (data==nullptr) {
125  ATH_MSG_FATAL("Filling the cabling FAILED");
126  return invalidId;
127  }
128 
129  return data->getOnlineIdFromHash(hash);
130 }
131 
134  const EventContext& ctx{Gaudi::Hive::currentContext()};
135  return getOnlineIdFromHash(hash, ctx);
136 }
137 
138 //
140 SCT_CablingTool::getOnlineIdFromOfflineId(const Identifier& offlineId, const EventContext& ctx) const {
141  if (not offlineId.is_valid()) return invalidId;
143  return getOnlineIdFromHash(hash, ctx);
144 }
145 
148  const EventContext& ctx{Gaudi::Hive::currentContext()};
149  return getOnlineIdFromOfflineId(offlineId, ctx);
150 }
151 
152 //
154 SCT_CablingTool::getRobIdFromHash(const IdentifierHash& hash, const EventContext& ctx) const {
155  return getOnlineIdFromHash(hash, ctx).rod();
156 }
157 
160  const EventContext& ctx{Gaudi::Hive::currentContext()};
161  return getRobIdFromHash(hash, ctx);
162 }
163 
164 //
166 SCT_CablingTool::getRobIdFromOfflineId(const Identifier& offlineId, const EventContext& ctx) const {
167  return getOnlineIdFromOfflineId(offlineId, ctx).rod();
168 }
169 
172  const EventContext& ctx{Gaudi::Hive::currentContext()};
173  return getRobIdFromOfflineId(offlineId, ctx);
174 }
175 
176 //
178 SCT_CablingTool::getHashFromSerialNumber(const SCT_SerialNumber& sn, const EventContext& ctx) const {
179  if (not sn.isWellFormed()) return invalidHash;
180 
181  const SCT_CablingData* data{getData(ctx)};
182  if (data==nullptr) {
183  ATH_MSG_FATAL("Filling the cabling FAILED");
184  return invalidHash;
185  }
186 
187  return data->getHashFromSerialNumber(sn);
188 }
189 
192  const EventContext& ctx{Gaudi::Hive::currentContext()};
193  return getHashFromSerialNumber(sn, ctx);
194 }
195 
197 SCT_CablingTool::getSerialNumberFromHash(const IdentifierHash& hash, const EventContext& ctx) const {
198  if (not hash.is_valid()) return invalidSn;
199  //hash must be even
200  IdentifierHash evenHash{even(hash)};
201 
202  const SCT_CablingData* data{getData(ctx)};
203  if (data==nullptr) {
204  ATH_MSG_FATAL("Filling the cabling FAILED");
205  return invalidSn;
206  }
207 
208  return data->getSerialNumberFromHash(evenHash);
209 }
210 
213  const EventContext& ctx{Gaudi::Hive::currentContext()};
214  return getSerialNumberFromHash(hash, ctx);
215 }
216 
217 void
218 SCT_CablingTool::getAllRods(std::vector<std::uint32_t>& usersVector, const EventContext& ctx) const {
219  const SCT_CablingData* data{getData(ctx)};
220  if (data==nullptr) {
221  ATH_MSG_FATAL("Filling the cabling FAILED");
222  return;
223  }
224 
225  data->getRods(usersVector);
226 }
227 
228 void
229 SCT_CablingTool::getAllRods(std::vector<std::uint32_t>& usersVector) const {
230  const EventContext& ctx{Gaudi::Hive::currentContext()};
231  getAllRods(usersVector, ctx);
232 }
233 
234 void
235 SCT_CablingTool::getHashesForRod(std::vector<IdentifierHash>& usersVector, const std::uint32_t rodId, const EventContext& ctx) const {
236  SCT_OnlineId firstPossibleId{rodId, SCT_OnlineId::FIRST_FIBRE};
237  const bool withWarnings{false};
238  for (SCT_OnlineId i{firstPossibleId}; i!=SCT_OnlineId::INVALID_ONLINE_ID; ++i) {
239  IdentifierHash thisHash(getHashFromOnlineId(i, ctx, withWarnings));
240  if (thisHash != invalidHash) {
241  usersVector.push_back(thisHash);
242  }
243  }
244 }
245 
246 void
247 SCT_CablingTool::getHashesForRod(std::vector<IdentifierHash>& usersVector, const std::uint32_t rodId) const {
248  const EventContext& ctx{Gaudi::Hive::currentContext()};
249  getHashesForRod(usersVector, rodId, ctx);
250 }
251 
252 const SCT_CablingData*
253 SCT_CablingTool::getData(const EventContext& ctx) const {
255  return condData.retrieve();
256 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_CablingTool::m_usingDatabase
bool m_usingDatabase
Definition: SCT_CablingTool.h:100
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SCT_CablingTool::size
virtual unsigned int size() const override
Definition: SCT_CablingTool.cxx:73
SCT_CablingTool::getRobIdFromOfflineId
virtual std::uint32_t getRobIdFromOfflineId(const Identifier &offlineId, const EventContext &ctx) const override
return the rob/rod Id, given an offlineId (used by simulation encoders)
Definition: SCT_CablingTool.cxx:166
SCT_CablingTool::getOnlineIdFromHash
virtual SCT_OnlineId getOnlineIdFromHash(const IdentifierHash &hash, const EventContext &ctx) const override
return the online Id, given a hash (used by simulation encoders)
Definition: SCT_CablingTool.cxx:122
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_CablingTool::getHashesForRod
virtual void getHashesForRod(std::vector< IdentifierHash > &usersVector, const std::uint32_t rodId, const EventContext &ctx) const override
fill a user's vector with all the hash ids which belong to a given rod
Definition: SCT_CablingTool.cxx:235
SCT_CablingTool.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SCT_OnlineId::INVALID_ONLINE_ID
@ INVALID_ONLINE_ID
Definition: SCT_OnlineId.h:57
SCT_CablingTool::getRobIdFromHash
virtual std::uint32_t getRobIdFromHash(const IdentifierHash &hash, const EventContext &ctx) const override
return the rob/rod Id, given a hash (used by simulation encoders)
Definition: SCT_CablingTool.cxx:154
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SCT_OnlineId::FIRST_FIBRE
@ FIRST_FIBRE
Definition: SCT_OnlineId.h:57
SCT_OnlineId
Definition: SCT_OnlineId.h:22
SCT_CablingTool::getData
const SCT_CablingData * getData(const EventContext &ctx) const
Definition: SCT_CablingTool.cxx:253
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
ReadCondHandle.h
SCT_CablingTool::getOnlineIdFromOfflineId
virtual SCT_OnlineId getOnlineIdFromOfflineId(const Identifier &offlineId, const EventContext &ctx) const override
return the online Id, given an offlineId
Definition: SCT_CablingTool.cxx:140
SCT_CablingTool::SCT_CablingTool
SCT_CablingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SCT_CablingTool.cxx:43
SCT_OnlineId::is_valid
bool is_valid(const bool usingDbCabling) const
Check whether the onlineId is valid, with flag to switch between validity from the database or text f...
Definition: SCT_OnlineId.cxx:76
SCT_CablingTool::getHashFromSerialNumber
virtual IdentifierHash getHashFromSerialNumber(const SCT_SerialNumber &sn, const EventContext &ctx) const override
get hash from a module serial number, needed in the conditions service because configurations are sto...
Definition: SCT_CablingTool.cxx:178
lumiFormat.i
int i
Definition: lumiFormat.py:85
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_CablingTool::m_idHelper
const SCT_ID * m_idHelper
helper for offlineId/hash conversions
Definition: SCT_CablingTool.h:99
SCT_CablingTool::initialize
virtual StatusCode initialize() override
Definition: SCT_CablingTool.cxx:51
file
TFile * file
Definition: tile_monitor.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_CablingTool::getSerialNumberFromHash
virtual SCT_SerialNumber getSerialNumberFromHash(const IdentifierHash &hash, const EventContext &ctx) const override
get module serial number from hash, needed during filling of data structure
Definition: SCT_CablingTool.cxx:197
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SCT_SerialNumber
Definition: SCT_SerialNumber.h:22
SCT_CablingData
Definition: SCT_CablingData.h:35
SCT_CablingTool::getHashFromOnlineId
virtual IdentifierHash getHashFromOnlineId(const SCT_OnlineId &onlineId, const EventContext &ctx, const bool withWarnings=true) const override
return offline hash, given the online Id (used by decoders)
Definition: SCT_CablingTool.cxx:92
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SCT_SerialNumber::isWellFormed
bool isWellFormed() const
Cursory check on whether the serial number is well formed N.B.
Definition: SCT_SerialNumber.cxx:81
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_CablingTool::m_cablingDataSource
StringProperty m_cablingDataSource
the name of the data source
Definition: SCT_CablingTool.h:98
SCT_CablingTool::getAllRods
virtual void getAllRods(std::vector< std::uint32_t > &usersVector, const EventContext &ctx) const override
fill a users vector with all the RodIds
Definition: SCT_CablingTool.cxx:218
SCT_CablingTool::m_data
SG::ReadCondHandleKey< SCT_CablingData > m_data
Definition: SCT_CablingTool.h:97
SCT_CablingTool::empty
virtual bool empty() const override
Definition: SCT_CablingTool.cxx:85
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
SCT_OnlineId::rod
std::uint32_t rod() const
Return the rod/rob Id.
Definition: SCT_OnlineId.cxx:59
Identifier
Definition: IdentifierFieldParser.cxx:14