10#include "CoralBase/Blob.h"
18#include "GeoModelKernel/throwExcept.h"
58 return StatusCode::SUCCESS;
72 return StatusCode::SUCCESS;
84 <<
" In theory this should not be called, but may happen"
85 <<
" if multiple concurrent events are being processed out of order.");
86 return StatusCode::SUCCESS;
89 std::unique_ptr<NswCalibDbTimeChargeData> wrCdo{std::make_unique<NswCalibDbTimeChargeData>(
m_idHelperSvc.get())};
120 if (wrHdl.
record(std::move(wrCdo)).isFailure()) {
122 <<
" with EventRange " << wrHdl.
getRange()
123 <<
" into Conditions Store");
124 return StatusCode::FAILURE;
128 return StatusCode::SUCCESS;
143 <<
" In theory this should not be called, but may happen"
144 <<
" if multiple concurrent events are being processed out of order.");
145 return StatusCode::SUCCESS;
148 std::unique_ptr<NswCalibDbThresholdData> wrCdo{std::make_unique<NswCalibDbThresholdData>(
m_idHelperSvc.get())};
164 if (wrHdl.
record(std::move(wrCdo)).isFailure()) {
166 <<
" with EventRange " << wrHdl.
getRange()
167 <<
" into Conditions Store");
168 return StatusCode::FAILURE;
172 return StatusCode::SUCCESS;
182 <<
" In theory this should not be called, but may happen"
183 <<
" if multiple concurrent events are being processed out of order.");
184 return StatusCode::SUCCESS;
187 std::unique_ptr<NswT0Data> wrCdo{std::make_unique<NswT0Data>(
m_idHelperSvc.get())};
195 return StatusCode::FAILURE;
197 std::unique_ptr<TTree>
tree{(TTree*)
file->Get(
"tree_ch")};
199 ATH_MSG_FATAL(
"Failed to load tree containing the NswT0Data.");
200 return StatusCode::FAILURE;
206 std::unique_ptr<TTree>
tree;
211 ATH_MSG_ERROR(
"Neither a database folder nor a file have been provided to read the MM T0 constants");
212 return StatusCode::FAILURE;
222 return StatusCode::FAILURE;
224 std::unique_ptr<TTree>
tree{(TTree*)
file->Get(
"tree_ch")};
226 ATH_MSG_FATAL(
"Failed to load tree containing the NswT0Data.");
227 return StatusCode::FAILURE;
233 std::unique_ptr<TTree>
tree;
238 ATH_MSG_ERROR(
"Neither a database folder nor a file have been provided to read the sTGC T0 constants");
239 return StatusCode::FAILURE;
247 return StatusCode::SUCCESS;
256 return StatusCode::FAILURE;
259 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
264 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
267 const coral::AttributeList& atr = itr->second;
268 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
270 return StatusCode::FAILURE;
272 coral::Blob blob = atr[
"data"].data<coral::Blob>();
275 return StatusCode::FAILURE;
278 return StatusCode::SUCCESS;
282 int sector{0}, layer{0}, channel{0}, channelType{0}, stationEta{0};
284 tree->SetBranchAddress(
"sector" , §or );
285 tree->SetBranchAddress(
"layer" , &layer );
286 tree->SetBranchAddress(
"channel", &channel );
287 tree->SetBranchAddress(
"mean" , &time );
288 tree->SetBranchAddress(
"stationEta" , &stationEta);
289 tree->SetBranchAddress(
"channel_type", &channelType);
290 if (
msgLvl(MSG::VERBOSE)) {
294 ATH_MSG_DEBUG(
"NSW t0 calibration tree has "<<
tree->GetEntries() <<
" entries for tech " << (tech==T0Tech::MM ?
"MM" :
"sTGC"));
296 for(
uint i_channel=0; i_channel<
tree->GetEntries(); i_channel++){
297 tree->GetEntry(i_channel);
299 int stationPhi = ((std::abs(sector)-1)/2)+1;
300 uint multilayer = (layer<4 ? 1:2);
301 uint gasGap = layer - (multilayer-1)*4 + 1;
305 if(tech==T0Tech::MM){
306 std::string stationName = (sector%2==1 ?
"MML" :
"MMS");
308 id =
m_idHelperSvc->mmIdHelper().channelID(stationName, stationEta, stationPhi,multilayer,gasGap, channel
316 ATH_MSG_ERROR(
"MM sector "<< sector <<
" layer " << layer<<
" channel "<< channel <<
" mean "<< time <<
" stationEta " << stationEta <<
" stationPhi " << stationPhi <<
" stationName "<< stationName <<
" multilayer " << multilayer <<
" gas gap "<< gasGap <<
" channel " << channel);
318 return StatusCode::FAILURE;
321 std::string stationName = (sector%2==1 ?
"STL" :
"STS");
323 id =
m_idHelperSvc->stgcIdHelper().channelID(stationName, stationEta, stationPhi, multilayer, gasGap, channelType, channel
331 ATH_MSG_DEBUG(
"STG sector "<< sector <<
" layer " << layer<<
" channel "<< channel <<
" mean "<< time <<
" stationEta " << stationEta <<
" stationPhi " << stationPhi <<
" stationName "<< stationName <<
" multilayer " << multilayer <<
" gas gap "<< gasGap <<
" channel " << channel <<
" channel type" << channelType);
332 return StatusCode::FAILURE;
338 return StatusCode::SUCCESS;
352 return StatusCode::FAILURE;
355 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
360 unsigned int nObjs = 0;
361 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
364 const coral::AttributeList& atr = itr->second;
365 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
367 return StatusCode::FAILURE;
369 coral::Blob blob = atr[
"data"].data<coral::Blob>();
370 std::unique_ptr<TTree>
tree;
373 return StatusCode::FAILURE;
377 unsigned int elinkId{0}, vmm{0}, channel{0};
379 tree->SetBranchAddress(
"vmm" , &vmm );
380 tree->SetBranchAddress(
"channel" , &channel );
381 tree->SetBranchAddress(
"elinkId" , &elinkId );
385 unsigned int nChns = 0;
386 for(
unsigned int iEvt=0; iEvt<
tree->GetEntries(); ++iEvt){
387 tree->GetEntry(iEvt);
390 ATH_MSG_DEBUG(
"Could not find valid channelId for elink "<<elinkId<<
" This is either caused by calibration data of a channel that is known to be not connected to the detector or might point to some issues in the identifier used for the calibration constants");
393 if(channelId.get_compact()==0){
406 return StatusCode::SUCCESS;
420 return StatusCode::FAILURE;
423 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readHandle.
fullKey() <<
" readCdo->size()= " << readCdo->
size());
428 unsigned int nObjs = 0;
429 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
432 const coral::AttributeList& atr = itr->second;
433 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
435 return StatusCode::FAILURE;
437 coral::Blob blob = atr[
"data"].data<coral::Blob>();
438 std::unique_ptr<TTree>
tree;
441 return StatusCode::FAILURE;
444 unsigned int elinkId{0}, vmm{0}, channel{0};
445 float slope{0}, intercept{0};
448 tree->SetBranchAddress(
"vmm" , &vmm );
449 tree->SetBranchAddress(
"channel" , &channel );
450 tree->SetBranchAddress(
"elinkId" , &elinkId );
451 tree->SetBranchAddress(
"slope" , &slope );
453 tree->SetBranchAddress(
"intercept" , &intercept );
458 unsigned int nChns = 0;
459 for(
unsigned int iEvt=0; iEvt<
tree->GetEntries(); ++iEvt){
460 tree->GetEntry(iEvt);
463 ATH_MSG_DEBUG(
"Could not find valid channelId for elink "<<elinkId<<
" This is either caused by calibration data of a channel that is known to be not connected to the detector or might point to some issues in the identifier used for the calibration constants");
468 calib_data.
slope = slope;
473 if(!channelId.get_compact()){
487 return StatusCode::SUCCESS;
502 std::unique_ptr<Muon::nsw::NSWResourceId> resId = std::make_unique<Muon::nsw::NSWResourceId>((uint32_t) elinkId);
505 std::string stationName;
506 if(resId->detId() == eformat::MUON_MMEGA_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_MMEGA_ENDCAP_C_SIDE) {
507 stationName = resId->is_large_station () ?
"MML" :
"MMS";
508 }
else if(resId->detId() == eformat::MUON_STGC_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_STGC_ENDCAP_C_SIDE) {
509 stationName = resId->is_large_station () ?
"STL" :
"STS";
511 ATH_MSG_ERROR(
"NSWResource Id "<< elinkId <<
" does not yield detID that is either sTGC or MMG");
512 THROW_EXCEPTION(
"NSWCalibDbAlg buildChannelId called with detID that is neither sTGC or MMG");
515 int8_t stationEta = resId->station_eta ();
516 uint8_t stationPhi = resId->station_phi ();
517 uint8_t multiLayer = resId->multi_layer ();
518 uint8_t gasGap = resId->gas_gap ();
520 uint8_t channelType = helper.channel_type ();
521 uint16_t channelNumber = helper.channel_number();
524 <<
" Station eta=" <<
static_cast <int> (stationEta)
525 <<
" Station phi=" <<
static_cast <unsigned int> (stationPhi)
526 <<
" Multilayer=" <<
static_cast <unsigned int> (multiLayer)
527 <<
" Gas gap=" <<
static_cast <unsigned int> (gasGap)
528 <<
" Channel type=" <<
static_cast <unsigned int> (channelType)
529 <<
" Channel Number=" << channelNumber );
533 if(resId->detId() == eformat::MUON_MMEGA_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_MMEGA_ENDCAP_C_SIDE){
535 Identifier chnlId =
m_idHelperSvc->mmIdHelper().channelID(stationName,
static_cast<int>(stationEta),
static_cast<int>(stationPhi),
static_cast<int>(multiLayer),
static_cast<int>(gasGap),
static_cast<int>(channelNumber),
isValid);
537 ATH_MSG_DEBUG(
"Could not extract valid channelId for MM elink "<<elinkId);
543 else if(resId->detId() == eformat::MUON_STGC_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_STGC_ENDCAP_C_SIDE){
545 Identifier chnlId =
m_idHelperSvc->stgcIdHelper().channelID(stationName,
static_cast<int>(stationEta),
static_cast<int>(stationPhi),
static_cast<int>(multiLayer),
static_cast<int>(gasGap),
static_cast<int>(channelType),
static_cast<int>(channelNumber),
isValid);
547 ATH_MSG_DEBUG(
"Could not extract valid channelId for STGC elink "<<elinkId);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(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...
static const Attributes_t empty
bool msgLvl(const MSG::Level lvl) const
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.
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
writeKeyTdoPdo_t m_writeKey_tdopdo
readKey_t m_readKey_mm_sidea_pdo
StatusCode loadT0ToTree(const EventContext &ctx, const readKey_t &readKey, writeHandleT0_t &writeHandle, std::unique_ptr< TTree > &tree) const
SG::ReadCondHandleKey< CondAttrListCollection > readKey_t
NswCalibDbThresholdData::ThrsldTechType ThresholdTech
Gaudi::Property< bool > m_processThresholds
readKey_t m_readKey_stgc_sidec_tdo
readKey_t m_readKey_mm_sidec_tdo
Gaudi::Property< std::string > m_mmT0FilePath
virtual StatusCode initialize() override
StatusCode loadThresholdData(const EventContext &, const readKey_t &, const ThresholdTech, writeHandleThr_t &, NswCalibDbThresholdData *) const
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
ServiceHandle< ICondSvc > m_condSvc
readKey_t m_readKey_mm_sidea_thr
readKey_t m_readKey_stgc_sidec_pdo
readKey_t m_readKey_stgc_sidec_thr
readKey_t m_readKey_stgc_sidea_tdo
Gaudi::Property< std::string > m_stgcT0FilePath
readKey_t m_readKey_mm_sidea_tdo
readKey_t m_readKey_mm_sidec_pdo
StatusCode loadT0Data(const std::unique_ptr< TTree > &tree, NswT0Data *writeCdo, const T0Tech tech) const
Gaudi::Property< bool > m_loadsTgcT0Data
readKey_t m_readKey_mm_sidec_thr
readKey_t m_readKey_stgc_sidea_thr
bool buildChannelId(Identifier &channelId, unsigned int elinkId, unsigned int vmm, unsigned int channel) const
readKey_t m_readKey_stgc_t0
NswCalibDbTimeChargeData::CalibDataType TimeChargeType
Gaudi::Property< bool > m_loadMmT0Data
SG::WriteCondHandle< NswCalibDbTimeChargeData > writeHandleTdoPdo_t
StatusCode processThrData(const EventContext &ctx) const
virtual StatusCode execute(const EventContext &) const override
MuonCond::CalibTechType TimeChargeTech
StatusCode processTdoPdoData(const EventContext &ctx) const
StatusCode loadTimeChargeData(const EventContext &ctx, const readKey_t &readKey, const TimeChargeTech, const TimeChargeType type, writeHandleTdoPdo_t &writeHandle, NswCalibDbTimeChargeData *writeCdo) const
StatusCode processNSWT0Data(const EventContext &ctx) const
readKey_t m_readKey_stgc_sidea_pdo
writeKeyMmT0_t m_writeKey_nswT0
SG::WriteCondHandle< NswCalibDbThresholdData > writeHandleThr_t
readKey_t m_readKey_mm_t0
Gaudi::Property< bool > m_isData
writeKeyThr_t m_writeKey_thr
SG::WriteCondHandle< NswT0Data > writeHandleT0_t
MuonCond::CalibTechType T0Tech
void setData(const Identifier &, const float)
void setZero(ThrsldTechType, const float)
void setZero(CalibDataType type, MuonCond::CalibTechType tech, CalibConstants constants)
void setData(CalibDataType type, const Identifier &chnlId, CalibConstants constants)
void setData(const Identifier &channelId, const float channelT0)
const DataObjID & fullKey() const
const EventIDRange & getRange()
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
bool readBlobAsTTree(const coral::Blob &blob, std::unique_ptr< TTree > &tree, const std::string_view name="tree")
Interprets the coral::Blob as a TTree instance.
Helper struct to cache all calibration constants in a common place of the memory.
#define THROW_EXCEPTION(MESSAGE)