Get the geography table which gives where the MURs (harnesses, for endcap) really are. In fact for the barrel its obvious, so only extract the endcap ones
get the RODMUR which gives where the individual MURs are; this is an intermediate step, so make a temporary data structure.
218 {
219
220 SG::WriteCondHandle<SCT_CablingData> writeHandle{
m_writeKey, ctx};
223 << ". In theory this should not be called, but may happen"
224 << " if multiple concurrent events are being processed out of order.");
225 return StatusCode::SUCCESS;
226 }
227
228
230
231
232 SG::ReadCondHandle<CondAttrListVec> readHandleRod{
m_readKeyRod, ctx};
233 const CondAttrListVec* pRod{*readHandleRod};
234 if (pRod==nullptr) {
236 return StatusCode::FAILURE;
237 }
238
241 using IntMap = std::map<int, int>;
242 IntMap slotMap;
243
244
245 {
246
247 using S = std::set<int>;
249 for (; rodIt != last_rod; ++rodIt) {
250
251 if (isRun2) {
252 slots.insert(int(rodIt->second["slot"].data<unsigned char>()));
253 } else {
254 slots.insert(int(rodIt->second["slot"].data<short>()));
255 }
256 }
258 for (S::const_iterator i{slots.begin()};
i != slots.end();++
i) {
260 }
261 ATH_MSG_INFO(
"Number of SCT rod slots inserted: " << counter);
262 }
263 IntMap crateSlot2RobMap;
264 bool allInsertsSucceeded{true};
266 int nrods{0};
267 std::set<int> tempRobSet;
268 for (; rodIt != last_rod; ++rodIt) {
269 const coral::AttributeList& rodAttributes{rodIt->second};
270 int rob{rodAttributes["ROB"].data<int>()};
271 if (not tempRobSet.insert(rob).second)
ATH_MSG_WARNING(
"Duplicate rob? :" << std::hex << rob << std::dec);
272 int crate{
isRun2 ?
static_cast<int>(rodAttributes[
"crate"].data<
unsigned char>()) : (rodAttributes[
"crate"].
data<
int>())};
273 int crateSlot{
isRun2 ?
static_cast<int>(rodAttributes[
"slot"].data<
unsigned char>()) : static_cast<
int>(rodAttributes[
"slot"].
data<
short>())};
274
275 IntMap::const_iterator pSlot{slotMap.find(crateSlot)};
276 int slot{(pSlot==slotMap.end()) ? -1 : pSlot->second};
277 if (slot==-1)
ATH_MSG_ERROR(
"Failed to find a crate slot in the crate map");
279
280 bool thisInsertSucceeded{crateSlot2RobMap.insert(IntMap::value_type(rodPosition, rob)).second};
281 if (not thisInsertSucceeded) {
282 ATH_MSG_WARNING(
"Insert (rodPosition, rob) " << rodPosition <<
", " << rob <<
" failed.");
283 ATH_MSG_INFO(
"map(rod position) is already " << crateSlot2RobMap[rodPosition]);
285 }
286 allInsertsSucceeded = thisInsertSucceeded and allInsertsSucceeded;
287 ++nrods;
288 }
289 ATH_MSG_INFO(nrods <<
" rods entered, of which " << tempRobSet.size() <<
" are unique.");
290
291 if (not allInsertsSucceeded)
ATH_MSG_WARNING(
"Some Rod-Rob map inserts failed.");
292
297 IntMap geoMurMap;
298 SG::ReadCondHandle<CondAttrListVec> readHandleGeo{
m_readKeyGeo, ctx};
299 const CondAttrListVec* pGeo{*readHandleGeo};
300 if (pGeo==nullptr) {
302 return StatusCode::FAILURE;
303 }
306 for (;geoIt != last_geo;++geoIt) {
307 const coral::AttributeList& geoAttributes{geoIt->second};
308 int mur{
isRun2 ?
static_cast<int>(geoAttributes[
"MUR"].data<
unsigned int>()) : (geoAttributes[
"MUR"].
data<
int>())};
309 int position{
isRun2 ?
static_cast<int>(geoAttributes[
"position"].data<
short>()) : (geoAttributes[
"position"].
data<
int>())};
310 if (mur > 10000) geoMurMap[mur]=position;
311 }
312
317 IntMap murPositionMap;
318 SG::ReadCondHandle<CondAttrListVec> readHandleRodMur{
m_readKeyRodMur, ctx};
319 const CondAttrListVec* pRodMur{*readHandleRodMur};
320 if (pRodMur==nullptr) {
322 return StatusCode::FAILURE;
323 }
326 allInsertsSucceeded = true;
327 std::set<int> tempRobSet2;
328 for (; rodMurIt!=last_rodMur; ++rodMurIt) {
329 const coral::AttributeList& rodMurAttributes{rodMurIt->second};
330 int mur{
isRun2 ?
static_cast<int>(rodMurAttributes[
"MUR"].data<
unsigned int>()) : (rodMurAttributes[
"MUR"].
data<
int>())};
331 int crate{
isRun2 ?
static_cast<int>(rodMurAttributes[
"crate"].data<
unsigned char>()) : (rodMurAttributes[
"crate"].
data<
int>())};
332 int crateSlot{
isRun2 ?
static_cast<int>(rodMurAttributes[
"rod"].data<
unsigned char>()) : (rodMurAttributes[
"rod"].
data<
int>())};
333
334 IntMap::const_iterator pSlot{slotMap.find(crateSlot)};
335 int slot{(pSlot==slotMap.end()) ? -1 : pSlot->second};
336 if (slot==-1)
ATH_MSG_ERROR(
"Failed to find a crate slot in the crate map");
337
338 int order{
isRun2 ?
static_cast<int>(rodMurAttributes[
"position"].data<
unsigned char>()) : (rodMurAttributes[
"position"].
data<
int>())};
340 bool thisInsertSucceeded{murPositionMap.insert(IntMap::value_type(mur, fibreOrder)).second};
341 if (not thisInsertSucceeded)
ATH_MSG_WARNING(
"Insert (mur, fibre) " << mur <<
", " << fibreOrder <<
" failed.");
342 allInsertsSucceeded = thisInsertSucceeded and allInsertsSucceeded;
343 }
344 if (not allInsertsSucceeded)
ATH_MSG_WARNING(
"Some MUR-position map inserts failed.");
345
346
347 SG::ReadCondHandle<CondAttrListVec> readHandleMur{
m_readKeyMur, ctx};
348 const CondAttrListVec* pMur{*readHandleMur};
349 if (pMur==nullptr) {
351 return StatusCode::FAILURE;
352 }
353
354
359
360
361 std::unique_ptr<SCT_CablingData> writeCdo{std::make_unique<SCT_CablingData>()};
362
363
366 int numEntries{0};
367 std::set<int> onlineIdSet, robSet;
368 std::set<Identifier> offlineIdSet;
369 long long lastSerialNumber{0};
370 for (; murIt != last_mur; ++murIt) {
371 const coral::AttributeList& murAttributes{murIt->second};
372 int mur{
isRun2 ?
static_cast<int>(murAttributes[
"MUR"].data<
unsigned int>()) : (murAttributes[
"MUR"].
data<
int>())};
373 bool nullMur{murAttributes["moduleID"].isNull() or murAttributes["module"].isNull()};
374 if (9999 == mur or nullMur) continue;
375 int fibreInMur{ (
isRun2 ?
static_cast<int>(murAttributes[
"module"].data<
unsigned char>()) : (murAttributes[
"module"].data<
int>()) ) - 1};
376 long long sn{murAttributes["moduleID"].data<long long>()};
377 if (lastSerialNumber==sn) {
378 continue;
379 }
380 lastSerialNumber=sn;
381 std::string snString{std::to_string(sn)};
382 IntMap::const_iterator pFibre{murPositionMap.find(mur)};
383 int fibreOffset{-1};
384 if (pFibre==murPositionMap.end()) {
385 ATH_MSG_WARNING("Failed to find an MUR position in the cabling");
386 } else {
387 fibreOffset = pFibre->second;
388 }
389 int encodedCrateSlot{fibreOffset / (fibresPerMur * mursPerRod)};
390 int rob{-1};
391 IntMap::const_iterator pCrate{crateSlot2RobMap.find(encodedCrateSlot)};
392 if (pCrate == crateSlot2RobMap.end()) {
393 ATH_MSG_WARNING("Failed to find a crate slot in the cabling, slot " << encodedCrateSlot);
394 } else {
395 rob=pCrate->second;
396 tempRobSet2.insert(rob);
397 }
398
399
400 int bec{0},
eta{0}, layer{0},
phi{0};
401 std::pair<int, int> etaPhiPair;
402 int harnessPosition{-1};
404 layer = (mur/10000) - 1;
405 bec = (((mur /1000) % 2)==0) ? ENDCAP_A :
ENDCAP_C;
406 int quadrant{(mur/100) % 10};
407
408
409 harnessPosition=geoMurMap[mur];
410 etaPhiPair= convertToAthenaCoords(bec,layer, quadrant, harnessPosition, fibreInMur);
411 eta=etaPhiPair.first;
412 phi=etaPhiPair.second;
413 } else {
415 layer= (mur /1000) - 3;
416 phi= (mur % 100) - 1;
417 eta = (((mur / 100) % 10) *2 -1) * (fibreInMur+1);
418 }
419 int rxLink[2];
420 if (isRun2) {
421 rxLink[0]=murAttributes["rx0Fibre"].data<unsigned char>();rxLink[1]= murAttributes["rx1Fibre"].data<unsigned char>();
422 } else {
423 rxLink[0]=murAttributes["rx0Fibre"].data<int>();rxLink[1]=murAttributes["rx1Fibre"].data<int>();
424 }
425 if (not (validLinkNumber(rxLink[0]) and validLinkNumber(rxLink[1]))) {
426 ATH_MSG_WARNING(
"Invalid link number in database in one of these db entries: rx0Fibre=" << rxLink[0] <<
", rx1Fibre=" << rxLink[1]);
427 continue;
428 }
429
430 bool normalOrdering{true};
432 normalOrdering=(rxLink[0] % 2)==0;
433 } else {
434 normalOrdering=(rxLink[1] % 2)==1;
435 }
436
437 int possibleLinks[2]{0,0};
438 if (normalOrdering) {
439 possibleLinks[0]=(rxLink[0]!=
disabledFibre) ? rxLink[0] : (rxLink[1]-1);
440 possibleLinks[1]=(rxLink[1]!=
disabledFibre) ? rxLink[1] : (rxLink[0]+1);
441 } else {
442 possibleLinks[0]=(rxLink[0]!=
disabledFibre) ? rxLink[0] : (rxLink[1]+1);
443 possibleLinks[1]=(rxLink[1]!=
disabledFibre) ? rxLink[1] : (rxLink[0]-1);
444 }
445 for (
int side{0};
side!=2; ++
side) {
446 if ((-1==
phi) and (-1==
eta)) {
447 ATH_MSG_WARNING(
"Invalid eta, phi..skipping insertion to map for module " << snString <<
" (may be already present in map)");
448 continue;
449 }
451 int link{rxLink[
side]};
453 link = (fibreOffset %
fibresPerRod) + fibreInMur*2 + side;
454 }
456 int otherLink{rxLink[1-
side]};
457 if (otherLink==possibleLinks[0]) link=possibleLinks[1];
458 if (otherLink==possibleLinks[1]) link=possibleLinks[0];
459 }
460 bool flippedModule{isOdd(side)!=isOdd(link)};
461 if (flippedModule) {
462 link = (link==possibleLinks[0]) ? possibleLinks[1] : possibleLinks[0];
463 }
464 int onlineId{(rob & 0xFFFFFF)|(link << 24)};
465
466 if (not onlineIdSet.insert(onlineId).second)
ATH_MSG_WARNING(
"Insert of online Id : " << onlineId <<
" failed.");
467 if (not offlineIdSet.insert(offlineId).second) {
470 ATH_MSG_INFO(
"MUR, position " << mur <<
", " << harnessPosition);
471 }
472 IdentifierHash offlineIdHash{
m_idHelper->wafer_hash(offlineId)};
473 insert(offlineIdHash, onlineId, SCT_SerialNumber(sn), writeCdo.get());
474 numEntries++;
475 }
476 }
477
478 if (writeHandle.
record(std::move(writeCdo)).isFailure()) {
480 <<
" with EventRange " << writeHandle.
getRange()
481 << " into Conditions Store");
482 return StatusCode::FAILURE;
483 }
484 ATH_MSG_INFO(
"recorded new CDO " << writeHandle.
key() <<
" with range " << writeHandle.
getRange() <<
" into Conditions Store");
485
486 const int robLo{*(tempRobSet2.cbegin())};
487 const int robHi{*(tempRobSet2.crbegin())};
488 ATH_MSG_INFO(numEntries <<
" entries were made to the identifier map.");
489 ATH_MSG_INFO(tempRobSet2.size() <<
" unique rob ids were used, spanning 0x" << std::hex << robLo <<
" to 0x" << robHi << std::dec);
490 if (tempRobSet.size() != tempRobSet2.size()) {
492 std::cout << std::hex;
493 std::set_difference(tempRobSet.cbegin(), tempRobSet.cend(),
494 tempRobSet2.cbegin(), tempRobSet2.cend(),
495 std::ostream_iterator<int>(std::cout,", "));
496 std::cout << std::dec << std::endl;
497 }
498 tempRobSet.clear();
500}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
static const int fibresPerRod
static const int mursPerRod
static const std::string rodFolderName2
static const int disabledFibre
static const int defaultLink
static const int fibresPerMur
static const int slotsPerCrate
AttrListVec::const_iterator const_iterator
const_iterator end() const
const_iterator begin() const
SG::ReadCondHandleKey< CondAttrListVec > m_readKeyMur
SG::ReadCondHandleKey< CondAttrListVec > m_readKeyRod
Input conditions folders.
SG::ReadCondHandleKey< CondAttrListVec > m_readKeyRodMur
SG::ReadCondHandleKey< CondAttrListVec > m_readKeyGeo
SG::WriteCondHandleKey< SCT_CablingData > m_writeKey
Output condition data.
const SCT_ID * m_idHelper
bool insert(const IdentifierHash &hash, const SCT_OnlineId &onlineId, const SCT_SerialNumber &sn, SCT_CablingData *data) const
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
::StatusCode StatusCode
StatusCode definition for legacy code.
isRun2(cursor, schemaname)