11#include "nlohmann/json.hpp"
13#include "GeoModelKernel/throwExcept.h"
39 return StatusCode::SUCCESS;
52 <<
" In theory this should not be called, but may happen"
53 <<
" if multiple concurrent events are being processed out of order.");
54 return StatusCode::SUCCESS;
62 "Failed to retrieve the detector manager from the conditions store "
64 return StatusCode::FAILURE;
67 std::unique_ptr<NswDcsDbData> wrCdo{std::make_unique<NswDcsDbData>(
m_idHelperSvc.get(), detMgr.
cptr())};
97 if (wrHdl.
record(std::move(wrCdo)).isFailure()) {
99 <<
" with EventRange " << wrHdl.
getRange()
100 <<
" into Conditions Store");
101 return StatusCode::FAILURE;
105 return StatusCode::SUCCESS;
118 return StatusCode::FAILURE;
121 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
126 unsigned int nChns = 0;
127 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
130 const unsigned int chanNum = itr->first;
131 const std::string& chanName = readCdo->
chanName(chanNum);
132 if(chanName.empty()){
133 ATH_MSG_DEBUG(
"Channel number "<< chanNum <<
"has empty name");
141 ATH_MSG_ERROR(
"Could not identify valid channelId for channel "<<chanNum<<
" with name "<< chanName<<
"!");
142 THROW_EXCEPTION(
"NswDcsDbAlg: Could not identify valid channelId for HV channel");
148 const coral::AttributeList& atr = itr->second;
151 dcs_data.
standbyVolt = *(
static_cast<const float*
>((atr[
"v0Set"]).addressOfData()));
152 dcs_data.
readyVolt = *(
static_cast<const float*
>((atr[
"v1Set"]).addressOfData()));
154 ATH_MSG_DEBUG(
"channel " << chanName <<
" has fsm state " << *(
static_cast<const std::string*
>((atr[
"fsmCurrentState"]).addressOfData()))<<
" has v0 state " << *(
static_cast<const float*
>( (atr[
"v0Set"]).addressOfData()))<<
" has v1 " << *(
static_cast<const float*
>((atr[
"v1Set"]).addressOfData())));
156 writeCdo->
setDataHv(tech, channelId, dcs_data);
161 return StatusCode::SUCCESS;
173 return StatusCode::FAILURE;
176 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
181 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
184 const coral::AttributeList& atr = itr->second;
185 std::string
data = *(
static_cast<const std::string *
>((atr[
"data_array"]).addressOfData()));
188 nlohmann::json jx = nlohmann::json::parse(
data);
189 unsigned int nLB = 0;
192 for (
auto &yy : jx[
"holes"].items()) {
193 nlohmann::json jt = yy.value();
202 ATH_MSG_DEBUG(
"Could not identify valid channelId for channel "<<jt[
"channelId"]<<
" with name "<< jt[
"channelName"]<<
"! Skipping...");
206 int channelDead = jt[
"channelDead"];
207 writeCdo->
setDataTDaq(tech, channelId, jt[
"hole_iovSince"], jt[
"hole_iovUntil"], elink, channelDead );
208 ATH_MSG_VERBOSE(
m_idHelperSvc->toString(channelId)<<
" " << jt[
"channelName"] <<
" " << jt[
"hole_iovSince"]<<
" " <<jt[
"hole_iovUntil"]<<
" " << elink<<
" "<<channelDead );
211 ATH_MSG_VERBOSE(
"Retrieved data for "<<nLB<<
" entries (combinations of lumi block and channel).");
214 return StatusCode::SUCCESS;
224 return StatusCode::FAILURE;
227 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
236 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
239 const unsigned int chanNum = itr->first;
240 const std::string& chanName = readCdo->
chanName(chanNum);
241 if(chanName.empty()){
242 ATH_MSG_DEBUG(
"Channel number "<< chanNum <<
"has empty name");
245 const coral::AttributeList& atr = itr->second;
246 bool online = *(
static_cast<const bool*
>((atr[
"online"]).addressOfData()));
247 ATH_MSG_DEBUG(
"found SCA " << chanName <<
" with status " << atr[
"online"] <<
" " << online);
257 return StatusCode::SUCCESS;
267 std::regex reMMG(
"^([A-Za-z]{1})([0-9]{2})_ML([0-9])P([0-9])_(IP|HO)R([0-9])__HV");
268 std::regex reMMD(
"^([A-Za-z]{1})([0-9]{2})_DRIFT_(IP|HO)R([0-9])__HV");
269 std::regex reSTG(
"^([A-Za-z]{1})([0-9]{2})_ML([0-9])_(IP|HO)R([0-9])__HV");
274 if(std::regex_match(chanName, reMMG)) {
276 tech = DcsTechType::MMG;
278 else if(std::regex_match(chanName, reMMD)) {
280 tech = DcsTechType::MMD;
282 else if(std::regex_match(chanName, reSTG)) {
284 tech = DcsTechType::STG;
287 ATH_MSG_ERROR(
"Could not identify channel with name "<<chanName);
301 std::regex_match(chanName, m,
re);
304 std::vector<std::string>
res;
305 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
308 if(tech==DcsTechType::MMG){
309 int wheel =
res[1]==
"A"? 1 : -1;
310 int sector = std::stoi(
res[2]);
311 const std::string stationName = sector%2==0 ?
"MMS" :
"MML";
312 int stationEta = wheel*std::stoi(
res[6]);
313 int stationPhi = (sector-1)/2+1;
314 int multiLayer =
res[5]==
"IP" ? 1 : 2;
315 int gasGap = std::stoi(
res[3]);
316 int pcb = std::stoi(
res[4]);
319 ATH_MSG_DEBUG(
"Could not extract valid channelId for MMG channel "<<chanName);
320 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer);
328 else if(tech==DcsTechType::MMD){
329 int wheel =
res[1]==
"A"? 1 : -1;
330 int sector = std::stoi(
res[2]);
331 const std::string stationName = sector%2==0 ?
"MMS" :
"MML";
332 int stationEta = wheel*std::stoi(
res[4]);
333 int stationPhi = (sector-1)/2+1;
334 int multiLayer =
res[3]==
"IP" ? 1 : 2;
337 ATH_MSG_DEBUG(
"Could not extract valid elementId for MMGD channel "<<chanName);
338 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer);
344 ATH_MSG_DEBUG(
"Could not extract valid multilayerId for MMG channel "<<chanName);
345 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer);
353 else if(tech==DcsTechType::STG){
354 int wheel =
res[1]==
"A"? 1 : -1;
355 int sector = std::stoi(
res[2]);
356 const std::string stationName = sector%2==0 ?
"STS" :
"STL";
357 int radius = std::stoi(
res[5]);
358 int stationEta = wheel*(radius<=2 ? 1 : radius-1);
359 int stationPhi = (sector-1)/2+1;
360 int multiLayer =
res[4]==
"IP" ? 1 : 2;
361 int gasGap = std::stoi(
res[3]);
364 ATH_MSG_DEBUG(
"Could not extract valid channelId for STG channel "<<chanName);
365 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer);
381 std::regex reMMG(
"^ELink-MM-(A|C)/V([0-9]{1})/L1A/Strip/S([0-9]{1,2})/L([0-9]{1})/R([0-9]{1,2})/E([0-9]{1})");
382 std::regex reSTG(
"^ELink-sTGC-(A|C)/V([0-9]{1})/L1A/(Strip|Pad)/S([0-9]{1,2})/L([0-9]{1})/R([0-9]{1})/E([0-9]{1})");
383 std::regex reSTGTrigProc(
"^ELink-sTGC-A/V0/L1A/TrigProc/");
384 std::regex reSTGPadTrig(
"^ELink-sTGC-A/V0/L1A/PadTrig/");
390 if(std::regex_match(chanName, reMMG)) {
392 tech = DcsTechType::MMG;
394 else if(std::regex_match(chanName, reSTG)) {
396 tech = DcsTechType::STG;
397 }
else if(std::regex_match(chanName, reSTGPadTrig) || std::regex_match(chanName, reSTGTrigProc)){
402 ATH_MSG_DEBUG(
"Could not identify channel with name "<<chanName);
416 std::regex_match(chanName, m,
re);
419 std::vector<std::string>
res;
420 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
423 if(tech==DcsTechType::MMG){
424 int wheel =
res[1]==
"A"? 1 : -1;
425 int sector = std::stoi(
res[3])+1;
426 int stationName = sector%2==0 ? 55 : 56;
432 int stationEta = wheel*(std::stoi(
res[5])<10? 1 : 2);
433 int stationPhi = (sector-1)/2+1;
434 int multiLayer = std::stoi(
res[4])< 4 ? 1 : 2;
435 int gasGap = (std::stoi(
res[4])%4) + 1;
436 int radius = std::stoi(
res[5]);
438 elink = std::stoi(
res[6]);
440 ATH_MSG_DEBUG(
"Could not extract valid channelId for MMG channel "<<chanName);
441 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << elink);
449 else if(tech==DcsTechType::STG){
450 int wheel =
res[1]==
"A"? 1 : -1;
451 int sector = std::stoi(
res[4]) + 1;
452 std::string stationName = sector%2==0 ?
"STS" :
"STL";
461 int radius = std::stoi(
res[6]);
462 int stationEta = wheel*(radius+1);
463 int stationPhi = (sector-1)/2+1;
464 int multiLayer = (std::stoi(
res[5]) < 4 ? 1 : 2);
465 int gasGap = ((std::stoi(
res[5]))%4)+1;
469 ATH_MSG_DEBUG(
"Could not extract valid channelId for STG channel "<<chanName);
470 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << elink);
475 elink = std::stoi(
res[7]);
486 std::regex
re(
"^(A|C)_([0-9]{2})_L([0-9])_B([0-9]{2})");
490 if(!std::regex_match(chanName,
re)) {
499 std::regex_match(chanName, m,
re);
502 std::vector<std::string>
res;
503 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
506 int wheel =
res[1]==
"A"? 1 : -1;
507 int sector = std::stoi(
res[2])+1;
508 int board = std::stoi(
res[4]);
509 int layer = std::stoi(
res[3]);
510 int stationPhi = (sector-1)/2+1;
511 int multiLayer = layer< 5 ? 1 : 2;
512 int gasGap = ((layer-1)%4) + 1;
516 if(tech==DcsTechType::MMG){
517 int stationName = sector%2==0 ? 56 : 55;
519 board -= (layer%2==1 ? 1 : 2);
522 radius = 2*(board/4);
523 }
else if (board%4==3) {
524 radius = 2*(board/4) + 1;
530 int stationEta = wheel*(radius<10? 1 : 2);
533 ATH_MSG_WARNING(
"Could not extract valid channelId for MMG channel "<<chanName);
534 ATH_MSG_WARNING(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << board);
539 }
else if(tech==DcsTechType::STG){
540 int stationName = sector%2==0 ? 58 : 57;
542 uint radius = board/2;
543 int stationEta = wheel*(radius+1);
549 else if((layer&1)==1){
555 }
else if(layer%1==0){
564 ATH_MSG_WARNING(
"Could not extract valid channelId for STG channel "<<chanName);
565 ATH_MSG_WARNING(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " << stationEta<<
" "<<stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << board <<
" " << channelType);
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
#define CHECK(...)
Evaluate an expression and check for errors.
char data[hepevt_bytes_allocation_ATLAS]
std::pair< std::vector< unsigned int >, bool > res
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
const std::string & chanName(ChanNum chanNum) const
find name for particular channel
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
bool buildChannelIdForHv(Identifier &channelId, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
Gaudi::Property< bool > m_loadTdaq
bool buildChannelIdForEltx(Identifier &channelId, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
bool buildChannelIdForTDaq(Identifier &channelId, uint &elink, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
readKey_t m_readKey_stg_eltx
StatusCode loadELTXData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
readKey_t m_readKey_mmg_tdaq
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
StatusCode loadHvData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
readKey_t m_readKey_stg_hv
SG::ReadCondHandleKey< CondAttrListCollection > readKey_t
virtual StatusCode execute(const EventContext &) const override
virtual StatusCode initialize() override
SG::WriteCondHandle< NswDcsDbData > writeHandleDcs_t
readKey_t m_readKey_stg_tdaq
Gaudi::Property< bool > m_loadEltx
ServiceHandle< ICondSvc > m_condSvc
readKey_t m_readKey_mmg_hv
NswDcsDbData::DcsTechType DcsTechType
readKey_t m_readKey_mmg_eltx
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode loadTDaqData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
MuonCond::DcsConstants DcsConstants
void setDataHv(const DcsTechType tech, const Identifier &chnlId, DcsConstants constants)
void setDataTDaq(const DcsTechType tech, const Identifier &chnlId, uint64_t timeSince, uint64_t timeUntil, unsigned int elink, bool permanentlyDisabled)
void setDataEltx(const DcsTechType tech, const Identifier &chnlId)
const DataObjID & fullKey() const
const EventIDRange & getRange()
const_pointer_type cptr()
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
DcsFsmState getFsmStateEnum(const std::string &fsmState)
#define THROW_EXCEPTION(MESSAGE)