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;
117 return StatusCode::FAILURE;
120 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readKey.fullKey() <<
" readCdo->size()= " << readCdo->size());
125 unsigned int nChns = 0;
126 for(itr = readCdo->begin(); itr != readCdo->end(); ++itr) {
129 const unsigned int chanNum = itr->first;
130 const std::string& chanName = readCdo->chanName(chanNum);
131 if(chanName.empty()){
132 ATH_MSG_DEBUG(
"Channel number "<< chanNum <<
"has empty name");
140 ATH_MSG_ERROR(
"Could not identify valid channelId for channel "<<chanNum<<
" with name "<< chanName<<
"!");
141 THROW_EXCEPTION(
"NswDcsDbAlg: Could not identify valid channelId for HV channel");
147 const coral::AttributeList& atr = itr->second;
150 dcs_data.
standbyVolt = *(
static_cast<const float*
>((atr[
"v0Set"]).addressOfData()));
151 dcs_data.
readyVolt = *(
static_cast<const float*
>((atr[
"v1Set"]).addressOfData()));
153 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())));
155 writeCdo->
setDataHv(tech, channelId, dcs_data);
160 return StatusCode::SUCCESS;
171 return StatusCode::FAILURE;
174 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readKey.fullKey() <<
" readCdo->size()= " << readCdo->size());
179 for(itr = readCdo->begin(); itr != readCdo->end(); ++itr) {
182 const coral::AttributeList& atr = itr->second;
183 std::string
data = *(
static_cast<const std::string *
>((atr[
"data_array"]).addressOfData()));
186 nlohmann::json jx = nlohmann::json::parse(
data);
187 unsigned int nLB = 0;
190 for (
auto &yy : jx[
"holes"].items()) {
191 nlohmann::json jt = yy.value();
200 ATH_MSG_DEBUG(
"Could not identify valid channelId for channel "<<jt[
"channelId"]<<
" with name "<< jt[
"channelName"]<<
"! Skipping...");
204 int channelDead = jt[
"channelDead"];
205 writeCdo->
setDataTDaq(tech, channelId, jt[
"hole_iovSince"], jt[
"hole_iovUntil"], elink, channelDead );
206 ATH_MSG_VERBOSE(
m_idHelperSvc->toString(channelId)<<
" " << jt[
"channelName"] <<
" " << jt[
"hole_iovSince"]<<
" " <<jt[
"hole_iovUntil"]<<
" " << elink<<
" "<<channelDead );
209 ATH_MSG_VERBOSE(
"Retrieved data for "<<nLB<<
" entries (combinations of lumi block and channel).");
212 return StatusCode::SUCCESS;
221 return StatusCode::FAILURE;
224 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readKey.fullKey() <<
" readCdo->size()= " << readCdo->size());
233 for(itr = readCdo->begin(); itr != readCdo->end(); ++itr) {
236 const unsigned int chanNum = itr->first;
237 const std::string& chanName = readCdo->chanName(chanNum);
238 if(chanName.empty()){
239 ATH_MSG_DEBUG(
"Channel number "<< chanNum <<
"has empty name");
242 const coral::AttributeList& atr = itr->second;
243 bool online = *(
static_cast<const bool*
>((atr[
"online"]).addressOfData()));
244 ATH_MSG_DEBUG(
"found SCA " << chanName <<
" with status " << atr[
"online"] <<
" " << online);
254 return StatusCode::SUCCESS;
264 std::regex reMMG(
"^([A-Za-z]{1})([0-9]{2})_ML([0-9])P([0-9])_(IP|HO)R([0-9])__HV");
265 std::regex reMMD(
"^([A-Za-z]{1})([0-9]{2})_DRIFT_(IP|HO)R([0-9])__HV");
266 std::regex reSTG(
"^([A-Za-z]{1})([0-9]{2})_ML([0-9])_(IP|HO)R([0-9])__HV");
271 if(std::regex_match(chanName, reMMG)) {
273 tech = DcsTechType::MMG;
275 else if(std::regex_match(chanName, reMMD)) {
277 tech = DcsTechType::MMD;
279 else if(std::regex_match(chanName, reSTG)) {
281 tech = DcsTechType::STG;
284 ATH_MSG_ERROR(
"Could not identify channel with name "<<chanName);
298 std::regex_match(chanName, m,
re);
301 std::vector<std::string>
res;
302 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
305 if(tech==DcsTechType::MMG){
306 int wheel =
res[1]==
"A"? 1 : -1;
307 int sector = std::stoi(
res[2]);
308 const std::string stationName = sector%2==0 ?
"MMS" :
"MML";
311 int multiLayer =
res[5]==
"IP" ? 1 : 2;
312 int gasGap = std::stoi(
res[3]);
313 int pcb = std::stoi(
res[4]);
316 ATH_MSG_DEBUG(
"Could not extract valid channelId for MMG channel "<<chanName);
325 else if(tech==DcsTechType::MMD){
326 int wheel =
res[1]==
"A"? 1 : -1;
327 int sector = std::stoi(
res[2]);
328 const std::string stationName = sector%2==0 ?
"MMS" :
"MML";
331 int multiLayer =
res[3]==
"IP" ? 1 : 2;
334 ATH_MSG_DEBUG(
"Could not extract valid elementId for MMGD channel "<<chanName);
341 ATH_MSG_DEBUG(
"Could not extract valid multilayerId for MMG channel "<<chanName);
350 else if(tech==DcsTechType::STG){
351 int wheel =
res[1]==
"A"? 1 : -1;
352 int sector = std::stoi(
res[2]);
353 const std::string stationName = sector%2==0 ?
"STS" :
"STL";
354 int radius = std::stoi(
res[5]);
355 int stationEta = wheel*(radius<=2 ? 1 : radius-1);
357 int multiLayer =
res[4]==
"IP" ? 1 : 2;
358 int gasGap = std::stoi(
res[3]);
361 ATH_MSG_DEBUG(
"Could not extract valid channelId for STG channel "<<chanName);
378 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})");
379 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})");
380 std::regex reSTGTrigProc(
"^ELink-sTGC-A/V0/L1A/TrigProc/");
381 std::regex reSTGPadTrig(
"^ELink-sTGC-A/V0/L1A/PadTrig/");
387 if(std::regex_match(chanName, reMMG)) {
389 tech = DcsTechType::MMG;
391 else if(std::regex_match(chanName, reSTG)) {
393 tech = DcsTechType::STG;
394 }
else if(std::regex_match(chanName, reSTGPadTrig) || std::regex_match(chanName, reSTGTrigProc)){
399 ATH_MSG_DEBUG(
"Could not identify channel with name "<<chanName);
413 std::regex_match(chanName, m,
re);
416 std::vector<std::string>
res;
417 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
420 if(tech==DcsTechType::MMG){
421 int wheel =
res[1]==
"A"? 1 : -1;
422 int sector = std::stoi(
res[3])+1;
423 int stationName = sector%2==0 ? 55 : 56;
431 int multiLayer = std::stoi(
res[4])< 4 ? 1 : 2;
432 int gasGap = (std::stoi(
res[4])%4) + 1;
433 int radius = std::stoi(
res[5]);
435 elink = std::stoi(
res[6]);
437 ATH_MSG_DEBUG(
"Could not extract valid channelId for MMG channel "<<chanName);
438 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " <<
stationEta<<
" "<<
stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << elink);
446 else if(tech==DcsTechType::STG){
447 int wheel =
res[1]==
"A"? 1 : -1;
448 int sector = std::stoi(
res[4]) + 1;
449 std::string stationName = sector%2==0 ?
"STS" :
"STL";
458 int radius = std::stoi(
res[6]);
461 int multiLayer = (std::stoi(
res[5]) < 4 ? 1 : 2);
462 int gasGap = ((std::stoi(
res[5]))%4)+1;
466 ATH_MSG_DEBUG(
"Could not extract valid channelId for STG channel "<<chanName);
467 ATH_MSG_DEBUG(
"Fields: "<< wheel <<
" "<<sector<<
" " << stationName<<
" " <<
stationEta<<
" "<<
stationPhi<<
" "<<multiLayer<<
" " << gasGap<<
" " << radius<<
" " << elink);
472 elink = std::stoi(
res[7]);
483 std::regex
re(
"^(A|C)_([0-9]{2})_L([0-9])_B([0-9]{2})");
487 if(!std::regex_match(chanName,
re)) {
496 std::regex_match(chanName, m,
re);
499 std::vector<std::string>
res;
500 for(
unsigned int i=0; i<m.size(); ++i)
res.push_back(m[i].str());
503 int wheel =
res[1]==
"A"? 1 : -1;
504 int sector = std::stoi(
res[2])+1;
505 int board = std::stoi(
res[4]);
506 int layer = std::stoi(
res[3]);
508 int multiLayer = layer< 5 ? 1 : 2;
509 int gasGap = ((layer-1)%4) + 1;
513 if(tech==DcsTechType::MMG){
514 int stationName = sector%2==0 ? 56 : 55;
516 board -= (layer%2==1 ? 1 : 2);
519 radius = 2*(board/4);
520 }
else if (board%4==3) {
521 radius = 2*(board/4) + 1;
530 ATH_MSG_WARNING(
"Could not extract valid channelId for MMG channel "<<chanName);
536 }
else if(tech==DcsTechType::STG){
537 int stationName = sector%2==0 ? 58 : 57;
539 uint radius = board/2;
546 else if((layer&1)==1){
552 }
else if(layer%1==0){
561 ATH_MSG_WARNING(
"Could not extract valid channelId for STG channel "<<chanName);
562 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
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
readKey_t m_readKey_stg_eltx
NswDcsDbData::DcsTechType DcsTechType
virtual StatusCode initialize() override
readKey_t m_readKey_mmg_eltx
readKey_t m_readKey_stg_hv
Gaudi::Property< bool > m_loadEltx
StatusCode loadHvData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
bool buildChannelIdForEltx(Identifier &channelId, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
virtual StatusCode execute(const EventContext &) const override
SG::ReadCondHandleKey< CondAttrListCollection > readKey_t
readKey_t m_readKey_mmg_tdaq
bool buildChannelIdForHv(Identifier &channelId, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
StatusCode loadELTXData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
SG::WriteCondHandle< NswDcsDbData > writeHandleDcs_t
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode loadTDaqData(const EventContext &ctx, const readKey_t &readKey, const DcsTechType tech, writeHandleDcs_t &writeHandle, NswDcsDbData *writeCdo) const
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
readKey_t m_readKey_mmg_hv
readKey_t m_readKey_stg_tdaq
bool buildChannelIdForTDaq(Identifier &channelId, uint &elink, const DcsTechType tech0, const std::string &chanName, bool &isOK) const
Gaudi::Property< bool > m_loadTdaq
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 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
::StatusCode StatusCode
StatusCode definition for legacy code.
DcsFsmState getFsmStateEnum(const std::string &fsmState)
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
#define THROW_EXCEPTION(MESSAGE)