ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13//this package
14#include "SCT_CablingTool.h"
15
16//Athena
18#include "Identifier/Identifier.h"
20
21//Gaudi includes
22#include "GaudiKernel/StatusCode.h"
23
24//constants in file scope
25static const std::string coracool("CORACOOL");
26static const std::string coolVectorPayload("COOLVECTOR");
27static const std::string defaultSource(coracool);
28static const std::string file("SCT_Sept08Cabling_svc.dat");
29//invalid identifiers to return in case of error
33
34//Utility functions at file scope
35namespace {
36 //make a number even
37 IdentifierHash even(const IdentifierHash& hash) {
38 return (hash>>1) << 1;
39 }
40}
41
42// Constructor
43SCT_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//
50StatusCode
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"));
56 ATH_CHECK(m_data.initialize());
57 return StatusCode::SUCCESS;
58}
59
60//
61unsigned int
62SCT_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
72unsigned int
74 const EventContext& ctx{Gaudi::Hive::currentContext()};
75 return size(ctx);
76}
77
78//
79bool
80SCT_CablingTool::empty(const EventContext& ctx) const {
81 return (size(ctx)==0);
82}
83
84bool
86 const EventContext& ctx{Gaudi::Hive::currentContext()};
87 return empty(ctx);
88}
89
90//
92SCT_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
115SCT_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//
122SCT_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//
140SCT_CablingTool::getOnlineIdFromOfflineId(const Identifier& offlineId, const EventContext& ctx) const {
141 if (not offlineId.is_valid()) return invalidId;
142 IdentifierHash hash(m_idHelper->wafer_hash(offlineId));
143 return getOnlineIdFromHash(hash, ctx);
144}
145
148 const EventContext& ctx{Gaudi::Hive::currentContext()};
149 return getOnlineIdFromOfflineId(offlineId, ctx);
150}
151
152//
153std::uint32_t
154SCT_CablingTool::getRobIdFromHash(const IdentifierHash& hash, const EventContext& ctx) const {
155 return getOnlineIdFromHash(hash, ctx).rod();
156}
157
158std::uint32_t
160 const EventContext& ctx{Gaudi::Hive::currentContext()};
161 return getRobIdFromHash(hash, ctx);
162}
163
164//
165std::uint32_t
166SCT_CablingTool::getRobIdFromOfflineId(const Identifier& offlineId, const EventContext& ctx) const {
167 return getOnlineIdFromOfflineId(offlineId, ctx).rod();
168}
169
170std::uint32_t
172 const EventContext& ctx{Gaudi::Hive::currentContext()};
173 return getRobIdFromOfflineId(offlineId, ctx);
174}
175
176//
178SCT_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
197SCT_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
217void
218SCT_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
228void
229SCT_CablingTool::getAllRods(std::vector<std::uint32_t>& usersVector) const {
230 const EventContext& ctx{Gaudi::Hive::currentContext()};
231 getAllRods(usersVector, ctx);
232}
233
234void
235SCT_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
246void
247SCT_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
252const SCT_CablingData*
253SCT_CablingTool::getData(const EventContext& ctx) const {
255 return condData.retrieve();
256}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const ITkStripOnlineId invalidId
static const std::string coolVectorPayload("COOLVECTOR")
static const std::string coracool("CORACOOL")
static const std::string defaultSource(coracool)
static const std::string coolVectorPayload("COOLVECTOR")
static const SCT_SerialNumber invalidSn
static const IdentifierHash invalidHash
static const std::string coracool("CORACOOL")
static const std::string defaultSource(coracool)
Header file for SCT cabling service.
This is an Identifier helper class for the SCT subdetector.
This is a "hash" representation of an Identifier.
bool is_valid() const
Check if id is in a valid state.
A class to hold the data necessary for SCT_CablingTool.
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)
SG::ReadCondHandleKey< SCT_CablingData > m_data
virtual SCT_OnlineId getOnlineIdFromOfflineId(const Identifier &offlineId, const EventContext &ctx) const override
return the online Id, given an offlineId
virtual bool empty() const override
virtual SCT_SerialNumber getSerialNumberFromHash(const IdentifierHash &hash, const EventContext &ctx) const override
get module serial number from hash, needed during filling of data structure
virtual unsigned int size() const override
SCT_CablingTool(const std::string &type, const std::string &name, const IInterface *parent)
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...
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)
virtual SCT_OnlineId getOnlineIdFromHash(const IdentifierHash &hash, const EventContext &ctx) const override
return the online Id, given a hash (used by simulation encoders)
const SCT_ID * m_idHelper
helper for offlineId/hash conversions
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)
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
virtual StatusCode initialize() override
const SCT_CablingData * getData(const EventContext &ctx) const
virtual void getAllRods(std::vector< std::uint32_t > &usersVector, const EventContext &ctx) const override
fill a users vector with all the RodIds
StringProperty m_cablingDataSource
the name of the data source
SCT_OnlineId is a class to hold an online id number and provide check on validity,...
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...
std::uint32_t rod() const
Return the rod/rob Id.
SCT_SerialNumber is a class to hold a serial number and provide check on validity,...
bool isWellFormed() const
Cursory check on whether the serial number is well formed N.B.
const_pointer_type retrieve()
TFile * file