10#include "CoralBase/Blob.h"
18#include "GeoModelKernel/throwExcept.h"
58 return StatusCode::SUCCESS;
71 return StatusCode::SUCCESS;
83 <<
" In theory this should not be called, but may happen"
84 <<
" if multiple concurrent events are being processed out of order.");
85 return StatusCode::SUCCESS;
88 auto wrCdo{std::make_unique<NswCalibDbTimeChargeData>(
m_idHelperSvc.get())};
106 return StatusCode::SUCCESS;
116 return StatusCode::SUCCESS;
122 <<
" In theory this should not be called, but may happen"
123 <<
" if multiple concurrent events are being processed out of order.");
124 return StatusCode::SUCCESS;
127 auto wrCdo{std::make_unique<NswCalibDbThresholdData>(
m_idHelperSvc.get())};
140 return StatusCode::SUCCESS;
148 return StatusCode::SUCCESS;
154 <<
" In theory this should not be called, but may happen"
155 <<
" if multiple concurrent events are being processed out of order.");
156 return StatusCode::SUCCESS;
161 auto wrCdo{std::make_unique<NswT0Data>(
m_idHelperSvc.get())};
168 return StatusCode::FAILURE;
170 std::unique_ptr<TTree>
tree{
dynamic_cast<TTree*
>(
file->Get(
"tree_ch"))};
172 ATH_MSG_FATAL(
"Failed to load tree containing the NswT0Data.");
173 return StatusCode::FAILURE;
179 std::unique_ptr<TTree>
tree{};
184 ATH_MSG_ERROR(
"Neither a database folder nor a file have been provided to read the MM T0 constants");
185 return StatusCode::FAILURE;
195 return StatusCode::FAILURE;
197 std::unique_ptr<TTree>
tree{
dynamic_cast<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;
213 ATH_MSG_ERROR(
"Neither a database folder nor a file have been provided to read the sTGC T0 constants");
214 return StatusCode::FAILURE;
223 return StatusCode::SUCCESS;
228 std::unique_ptr<TTree>&
tree)
const{
234 return StatusCode::SUCCESS;
238 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
241 const coral::AttributeList& atr = itr->second;
242 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
244 return StatusCode::FAILURE;
246 coral::Blob blob = atr[
"data"].data<coral::Blob>();
249 return StatusCode::FAILURE;
252 return StatusCode::SUCCESS;
258 int sector{0}, layer{0}, channel{0}, channelType{0},
stationEta{0};
260 tree->SetBranchAddress(
"sector", §or);
261 tree->SetBranchAddress(
"layer", &layer);
262 tree->SetBranchAddress(
"channel", &channel);
263 tree->SetBranchAddress(
"mean", &time);
265 tree->SetBranchAddress(
"channel_type", &channelType);
266 if (
msgLvl(MSG::VERBOSE)) {
270 ATH_MSG_DEBUG(
"NSW t0 calibration tree has "<<
tree->GetEntries() <<
" entries for tech "
271 << (tech==T0Tech::MM ?
"MM" :
"sTGC"));
273 for(Long64_t i_channel=0; i_channel<
tree->GetEntries(); ++i_channel) {
274 tree->GetEntry(i_channel);
277 uint multilayer = (layer<4 ? 1:2);
278 uint gasGap = layer - (multilayer-1)*4 + 1;
282 if(tech==T0Tech::MM){
283 std::string stationName = (sector%2==1 ?
"MML" :
"MMS");
293 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);
295 return StatusCode::FAILURE;
298 std::string stationName = (sector%2==1 ?
"STL" :
"STS");
308 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);
309 return StatusCode::FAILURE;
314 return StatusCode::SUCCESS;
330 return StatusCode::SUCCESS;
335 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
338 const coral::AttributeList& atr = itr->second;
339 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
341 return StatusCode::FAILURE;
343 coral::Blob blob = atr[
"data"].data<coral::Blob>();
344 std::unique_ptr<TTree>
tree;
347 return StatusCode::FAILURE;
351 unsigned elinkId{0}, vmm{0}, channel{0};
353 tree->SetBranchAddress(
"vmm", &vmm);
354 tree->SetBranchAddress(
"channel", &channel);
355 tree->SetBranchAddress(
"elinkId", &elinkId);
360 for(
unsigned iEvt=0; iEvt<
tree->GetEntries(); ++iEvt){
361 tree->GetEntry(iEvt);
364 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");
367 if(channelId.get_compact()==0){
379 return StatusCode::SUCCESS;
382 template <
typename Key_t,
383 typename... KeyArgs_t>
387 KeyArgs_t&... otherKeys)
const {
388 if (!readKey.
empty()) {
391 ATH_MSG_FATAL(
"Failed to load conditions data "<<readKey.fullKey());
392 return StatusCode::FAILURE;
394 ATH_MSG_DEBUG(
"Size of CondAttrListCollection " << readKey.fullKey()
395 <<
" readCdo->size()= " << readHandle->size());
398 if constexpr(
sizeof...(otherKeys) > 0) {
401 return StatusCode::SUCCESS;
414 if (readKey.
empty()) {
416 return StatusCode::SUCCESS;
424 for(itr = readCdo->
begin(); itr != readCdo->
end(); ++itr) {
427 const coral::AttributeList& atr = itr->second;
428 if(atr[
"data"].specification().
type() !=
typeid(coral::Blob)) {
430 return StatusCode::FAILURE;
432 coral::Blob blob = atr[
"data"].data<coral::Blob>();
433 std::unique_ptr<TTree>
tree;
436 return StatusCode::FAILURE;
439 unsigned elinkId{0}, vmm{0}, channel{0};
440 float slope{0.f}, intercept{0.f};
443 tree->SetBranchAddress(
"vmm", &vmm);
444 tree->SetBranchAddress(
"channel", &channel);
445 tree->SetBranchAddress(
"elinkId", &elinkId);
446 tree->SetBranchAddress(
"slope", &slope);
448 tree->SetBranchAddress(
"intercept", &intercept);
454 for(Long64_t iEvt=0; iEvt<
tree->GetEntries(); ++iEvt){
455 tree->GetEntry(iEvt);
458 ATH_MSG_DEBUG(
"Could not find valid channelId for elink "<<elinkId
459 <<
" This is either caused by calibration data of a channel that is known to be not connected "
460 <<
"to the detector or might point to some issues in the identifier used for the calibration constants");
465 calib_data.
slope = slope;
470 if(!channelId.get_compact()){
483 return StatusCode::SUCCESS;
497 auto resId = std::make_unique<Muon::nsw::NSWResourceId>(elinkId);
500 std::string stationName;
501 if(resId->detId() == eformat::MUON_MMEGA_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_MMEGA_ENDCAP_C_SIDE) {
502 stationName = resId->is_large_station () ?
"MML" :
"MMS";
503 }
else if(resId->detId() == eformat::MUON_STGC_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_STGC_ENDCAP_C_SIDE) {
504 stationName = resId->is_large_station () ?
"STL" :
"STS";
506 ATH_MSG_ERROR(
"NSWResource Id "<< elinkId <<
" does not yield detID that is either sTGC or MMG");
507 THROW_EXCEPTION(
"NSWCalibDbAlg buildChannelId called with detID that is neither sTGC or MMG");
512 uint8_t multiLayer = resId->multi_layer ();
513 uint8_t gasGap = resId->gas_gap ();
515 uint8_t channelType = helper.channel_type ();
516 uint16_t channelNumber = helper.channel_number();
519 <<
" Station eta=" <<
static_cast <int> (
stationEta)
520 <<
" Station phi=" <<
static_cast <unsigned> (
stationPhi)
521 <<
" Multilayer=" <<
static_cast <unsigned> (multiLayer)
522 <<
" Gas gap=" <<
static_cast <unsigned> (gasGap)
523 <<
" Channel type=" <<
static_cast <unsigned> (channelType)
524 <<
" Channel Number=" << channelNumber );
528 if(resId->detId() == eformat::MUON_MMEGA_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_MMEGA_ENDCAP_C_SIDE){
532 ATH_MSG_DEBUG(
"Could not extract valid channelId for MM elink "<<elinkId);
538 else if(resId->detId() == eformat::MUON_STGC_ENDCAP_A_SIDE || resId->detId() == eformat::MUON_STGC_ENDCAP_C_SIDE){
540 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);
542 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.
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Gaudi::Property< bool > m_isData
Gaudi::Property< std::string > m_stgcT0FilePath
StatusCode loadT0Data(std::unique_ptr< TTree > &&tree, NswT0Data &writeCdo, const T0Tech tech) const
NswCalibDbThresholdData::ThrsldTechType ThresholdTech
readKey_t m_readKey_mm_sidea_pdo
Gaudi::Property< bool > m_loadsTgcT0Data
readKey_t m_readKey_mm_t0
readKey_t m_readKey_mm_sidec_tdo
StatusCode loadT0ToTree(const EventContext &ctx, const readKey_t &readKey, std::unique_ptr< TTree > &tree) const
StatusCode processNSWT0Data(const EventContext &ctx) const
bool buildChannelId(Identifier &channelId, unsigned elinkId, unsigned vmm, unsigned channel) const
readKey_t m_readKey_mm_sidea_tdo
Gaudi::Property< bool > m_processThresholds
readKey_t m_readKey_mm_sidec_pdo
readKey_t m_readKey_stgc_sidec_thr
Gaudi::Property< bool > m_loadMmT0Data
StatusCode loadThresholdData(const EventContext &ctx, const readKey_t &readKey, const ThresholdTech tech, NswCalibDbThresholdData &writeCdo) const
readKey_t m_readKey_stgc_sidea_pdo
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
NswCalibDbTimeChargeData::CalibDataType TimeChargeType
StatusCode processTdoPdoData(const EventContext &ctx) const
virtual StatusCode initialize() override
MuonCond::CalibTechType TimeChargeTech
readKey_t m_readKey_stgc_t0
MuonCond::CalibTechType T0Tech
readKey_t m_readKey_stgc_sidec_tdo
Gaudi::Property< std::string > m_mmT0FilePath
readKey_t m_readKey_stgc_sidec_pdo
writeKeyMmT0_t m_writeKey_nswT0
virtual StatusCode execute(const EventContext &) const override
SG::ReadCondHandleKey< CondAttrListCollection > readKey_t
readKey_t m_readKey_stgc_sidea_tdo
readKey_t m_readKey_mm_sidec_thr
writeKeyThr_t m_writeKey_thr
readKey_t m_readKey_mm_sidea_thr
SG::WriteCondHandle< NswT0Data > writeHandleT0_t
readKey_t m_readKey_stgc_sidea_thr
StatusCode declareDependency(const EventContext &ctx, SG::WriteCondHandle< Key_t > &writeHandle, const readKey_t &readKey, KeyArgs_t &... otherKeys) const
writeKeyTdoPdo_t m_writeKey_tdopdo
StatusCode processThrData(const EventContext &ctx) const
StatusCode loadTimeChargeData(const EventContext &ctx, const readKey_t &readKey, const TimeChargeTech tech, const TimeChargeType type, NswCalibDbTimeChargeData &writeCdo) const
Conditions data to model a channel dependent energy deposit threshold such that the electronics retur...
void setData(const Identifier &channelId, const float)
void setZero(const ThrsldTechType tech, const float)
void setZero(CalibDataType type, MuonCond::CalibTechType tech, CalibConstants constants)
void setData(CalibDataType type, const Identifier &chnlId, CalibConstants constants)
Conditions data object to calibrate the timeoff set of each individual channel in the NSW.
void setData(const Identifier &channelId, const float channelT0)
Set the t0 calibration constant for a given nsw channel.
bool empty() const
Test if the key is blank.
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.
::StatusCode StatusCode
StatusCode definition for legacy code.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Helper struct to cache all calibration constants in a common place of the memory.
#define THROW_EXCEPTION(MESSAGE)