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.
221 if (writeHandle.isValid()) {
222 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid."
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) {
263 IntMap crateSlot2RobMap;
264 bool allInsertsSucceeded{
true};
267 std::set<int> tempRobSet;
268 for (; rodIt != last_rod; ++rodIt) {
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");
278 int rodPosition{(crate * slotsPerCrate) +slot};
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]);
284 ATH_MSG_INFO(
"crate, slot, slots per crate: " << crate <<
", " << slot <<
", " << slotsPerCrate);
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) {
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) {
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>())};
339 int fibreOrder{((((crate * slotsPerCrate) + slot ) * mursPerRod) +
order) * fibresPerMur};
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;
355 writeHandle.addDependency(readHandleRod);
356 writeHandle.addDependency(readHandleRodMur);
357 writeHandle.addDependency(readHandleMur);
358 writeHandle.addDependency(readHandleGeo);
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) {
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) {
382 IntMap::const_iterator pFibre{murPositionMap.find(mur)};
384 if (pFibre==murPositionMap.end()) {
387 fibreOffset = pFibre->second;
389 int encodedCrateSlot{fibreOffset / (fibresPerMur * mursPerRod)};
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);
401 std::pair<int, int> etaPhiPair;
402 int harnessPosition{-1};
404 layer = (mur/10000) - 1;
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};
431 if (rxLink[0] != disabledFibre) {
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);
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]};
452 if (defaultLink==link) {
453 link = (fibreOffset % fibresPerRod) + fibreInMur*2 +
side;
455 if (disabledFibre==link) {
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()) {
479 ATH_MSG_FATAL(
"Could not record SCT_CablingData " << writeHandle.key()
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);