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;
236 return StatusCode::FAILURE;
241 using IntMap = std::map<int, int>;
247 using S = std::set<int>;
249 for (; rodIt != last_rod; ++rodIt) {
252 slots.insert(
int(rodIt->second[
"slot"].data<
unsigned char>()));
254 slots.insert(
int(rodIt->second[
"slot"].data<
short>()));
258 for (S::const_iterator i{slots.begin()};i != slots.end();++i) {
259 slotMap[*i]=counter++;
261 ATH_MSG_INFO(
"Number of SCT rod slots inserted: " << counter);
263 IntMap crateSlot2RobMap;
264 bool allInsertsSucceeded{
true};
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>())};
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");
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]);
286 allInsertsSucceeded = thisInsertSucceeded and allInsertsSucceeded;
289 ATH_MSG_INFO(nrods <<
" rods entered, of which " << tempRobSet.size() <<
" are unique.");
291 if (not allInsertsSucceeded)
ATH_MSG_WARNING(
"Some Rod-Rob map inserts failed.");
302 return StatusCode::FAILURE;
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;
317 IntMap murPositionMap;
320 if (pRodMur==
nullptr) {
322 return StatusCode::FAILURE;
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>())};
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");
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;
344 if (not allInsertsSucceeded)
ATH_MSG_WARNING(
"Some MUR-position map inserts failed.");
351 return StatusCode::FAILURE;
361 std::unique_ptr<SCT_CablingData> writeCdo{std::make_unique<SCT_CablingData>()};
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) {
381 std::string snString{std::to_string(sn)};
382 IntMap::const_iterator pFibre{murPositionMap.find(mur)};
384 if (pFibre==murPositionMap.end()) {
387 fibreOffset = pFibre->second;
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);
396 tempRobSet2.insert(rob);
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};
409 harnessPosition=geoMurMap[mur];
410 etaPhiPair= convertToAthenaCoords(bec,layer, quadrant, harnessPosition, fibreInMur);
411 eta=etaPhiPair.first;
412 phi=etaPhiPair.second;
415 layer= (mur /1000) - 3;
416 phi= (mur % 100) - 1;
417 eta = (((mur / 100) % 10) *2 -1) * (fibreInMur+1);
421 rxLink[0]=murAttributes[
"rx0Fibre"].data<
unsigned char>();rxLink[1]= murAttributes[
"rx1Fibre"].data<
unsigned char>();
423 rxLink[0]=murAttributes[
"rx0Fibre"].data<
int>();rxLink[1]=murAttributes[
"rx1Fibre"].data<
int>();
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]);
430 bool normalOrdering{
true};
432 normalOrdering=(rxLink[0] % 2)==0;
434 normalOrdering=(rxLink[1] % 2)==1;
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);
442 possibleLinks[0]=(rxLink[0]!=
disabledFibre) ? rxLink[0] : (rxLink[1]+1);
443 possibleLinks[1]=(rxLink[1]!=
disabledFibre) ? rxLink[1] : (rxLink[0]-1);
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)");
451 int link{rxLink[side]};
453 link = (fibreOffset %
fibresPerRod) + fibreInMur*2 + side;
456 int otherLink{rxLink[1-side]};
457 if (otherLink==possibleLinks[0]) link=possibleLinks[1];
458 if (otherLink==possibleLinks[1]) link=possibleLinks[0];
460 bool flippedModule{isOdd(side)!=isOdd(link)};
462 link = (link==possibleLinks[0]) ? possibleLinks[1] : possibleLinks[0];
464 int onlineId{(rob & 0xFFFFFF)|(link << 24)};
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);
478 if (writeHandle.
record(std::move(writeCdo)).isFailure()) {
480 <<
" with EventRange " << writeHandle.
getRange()
481 <<
" into Conditions Store");
482 return StatusCode::FAILURE;
484 ATH_MSG_INFO(
"recorded new CDO " << writeHandle.
key() <<
" with range " << writeHandle.
getRange() <<
" into Conditions Store");
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;
499 return (numEntries==0) ? (StatusCode::FAILURE) : (StatusCode::SUCCESS);