20#include "GaudiKernel/ConcurrencyFlags.h"
34 ISvcLocator* pSvcLocator)
53 <<
" has been succesfully registered ");
55 ATH_MSG_INFO(
"Initialize: Will update the field map from " <<
60 TClass::GetClass(
"TLeafI");
61 TClass::GetClass(
"TLeafD");
62 TClass::GetClass(
"TLeafO");
63 TClass::GetClass(
"TLeafS");
65 return StatusCode::SUCCESS;
75 return (
execute(Gaudi::Hive::currentContext()));
78 return StatusCode::SUCCESS;
94 <<
" is still valid. ");
95 return StatusCode::SUCCESS;
112 auto fieldMapCondObj = std::make_unique<AtlasFieldMapCondObj>();
115 fieldMapCondObj->setFieldMap(std::move(cache.
m_fieldMap));
119 ATH_MSG_ERROR(
"execute: Could not record AtlasFieldMapCondObj object with "
120 << mapWriteHandle.
key() <<
" with EventRange "
122 return StatusCode::FAILURE;
124 ATH_MSG_INFO(
"execute: recorded AtlasFieldMapCondObj with EventRange "
127 return StatusCode::SUCCESS;
142 std::string fullMapFilename;
143 std::string soleMapFilename;
144 std::string toroMapFilename;
148 ATH_MSG_INFO(
"updateFieldMap: Update map from conditions");
154 if (attrListColl ==
nullptr) {
156 "CondAttributeListCollection with key "
157 << readHandle.
key());
158 return StatusCode::FAILURE;
166 if (!readHandle.
range(rangeW)) {
167 ATH_MSG_FATAL(
"updateFieldMap: Failed to retrieve validity range for "
168 << readHandle.
key());
169 return StatusCode::FAILURE;
173 "updateFieldMap: Update map from conditions: Range of input/output is "
177 "updateFieldMap: reading magnetic field map filenames from COOL");
180 itr != attrListColl->
end();
182 const coral::AttributeList& attr = itr->second;
183 const std::string& mapType = attr[
"FieldType"].data<std::string>();
184 const std::string& mapFile = attr[
"MapFileName"].data<std::string>();
185 const float soleCur = attr[
"SolenoidCurrent"].data<
float>();
186 const float toroCur = attr[
"ToroidCurrent"].data<
float>();
189 << mapType <<
" with soleCur=" << soleCur
190 <<
" toroCur=" << toroCur <<
" (path " << mapFile <<
")");
193 const std::string mapFile_decoded = mapFile.substr(5);
194 if (mapType ==
"GlobalMap") {
195 fullMapFilename = mapFile_decoded;
198 }
else if (mapType ==
"SolenoidMap") {
199 soleMapFilename = mapFile_decoded;
200 }
else if (mapType ==
"ToroidMap") {
201 toroMapFilename = mapFile_decoded;
217 EventIDBase
start, stop;
218 start.set_run_number(ctx.eventID().run_number());
219 start.set_lumi_block(0);
220 stop.set_run_number(ctx.eventID().run_number() + 1);
221 stop.set_lumi_block(0);
224 ATH_MSG_INFO(
"updateFieldMap: loadMapOnStart is set, overriding currents "
225 "from job options - solCur "
242 EventIDRange rangeDCS;
246 bool mustCreateIOVRange =
false;
249 mustCreateIOVRange =
true;
250 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
254 mustCreateIOVRange =
true;
255 ATH_MSG_INFO(
"updateFieldMap: set toroid current to 0 from DCS");
257 if (mustCreateIOVRange) {
260 EventIDBase
start, stop;
262 start.set_run_number(ctx.eventID().run_number());
263 start.set_lumi_block(0);
264 stop.set_run_number(ctx.eventID().run_number() + 1);
265 stop.set_lumi_block(0);
270 ATH_MSG_INFO(
"updateFieldMap: currents are OK, will use nominal maps");
282 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
290 ATH_MSG_INFO(
"updateFieldMap: requested toroid current in JobOpt "
298 EventIDBase
start, stop;
299 start.set_run_number(ctx.eventID().run_number());
300 start.set_lumi_block(0);
301 stop.set_run_number(ctx.eventID().run_number() + 1);
302 stop.set_lumi_block(0);
306 "updateFieldMap: useMapsFromCOOL == false, using default range "
317 if (tagInfoMgr.retrieve().isSuccess()) {
319 bool resetCurrentsFromTagInfo =
false;
320 std::string mapSoleCurrent = tagInfoMgr->findTag(
"MapSoleCurrent");
321 if (not mapSoleCurrent.empty()) {
323 resetCurrentsFromTagInfo =
true;
324 ATH_MSG_INFO(
"updateFieldMap: found MapSoleCurrent in TagInfo, setting "
325 "the solenoid current "
328 std::string mapToroCurrent = tagInfoMgr->findTag(
"MapToroCurrent");
329 if (not mapToroCurrent.empty()) {
331 resetCurrentsFromTagInfo =
true;
332 ATH_MSG_INFO(
"updateFieldMap: found MapToroCurrent in TagInfo, setting "
333 "the toroid current "
336 if (resetCurrentsFromTagInfo)
337 ATH_MSG_INFO(
"updateFieldMap: reset currents from TagInfo");
339 ATH_MSG_INFO(
"updateFieldMap: DID NOT reset currents from TagInfo");
351 mapFile = fullMapFilename;
353 mapFile = soleMapFilename;
355 mapFile = toroMapFilename;
358 return StatusCode::SUCCESS;
362 "updateFieldMap: Set map currents from FieldSvc: solenoid/toroid "
364 ATH_MSG_INFO(
"updateFieldMap: Use map file " << mapFile);
368 if (resolvedMapFile.empty()) {
370 return StatusCode::FAILURE;
373 if (resolvedMapFile.find(
".root") == std::string::npos) {
375 << resolvedMapFile <<
"' does not end with .root");
376 return StatusCode::FAILURE;
378 TFile*
rootfile =
new TFile(resolvedMapFile.c_str(),
"OLD");
380 ATH_MSG_ERROR(
"updateFieldMap: failed to open " << resolvedMapFile);
381 return StatusCode::FAILURE;
386 "updateFieldMap: unable to cd() into the ROOT field map TFile");
389 return StatusCode::FAILURE;
393 if (
tree ==
nullptr) {
396 "updateFieldMap: TTree 'BFieldMap' does not exist in ROOT field map");
399 return StatusCode::FAILURE;
403 cache.
m_fieldMap = std::make_unique<MagField::AtlasFieldMap>();
410 "updateFieldMap: unable to initialize the map for AtlasFieldMap for file "
414 return StatusCode::FAILURE;
420 ATH_MSG_INFO(
"updateFieldMap: Initialized the field map from "
423 return StatusCode::SUCCESS;
428 const EventContext& ctx,
431 EventIDRange& rangeDCS)
const
437 if (attrListColl ==
nullptr) {
438 ATH_MSG_ERROR(
"checkCurrentFromConditions: Failed to retrieve "
439 "CondAttributeListCollection with key "
441 return StatusCode::FAILURE;
445 if (!readHandle.
range(rangeDCS)) {
447 "checkCurrentFromConditions: Failed to retrieve validity range for "
448 << readHandle.
key());
449 return StatusCode::FAILURE;
451 ATH_MSG_INFO(
"checkCurrentFromConditions: Range of input currents is "
457 bool gotsol{
false };
458 bool gottor{
false };
465 bool hasChanNames{
false };
466 ATH_MSG_INFO(
"checkCurrentFromConditions: Attempt 1 at reading currents from "
467 "DCS (using channel name)");
469 itr != attrListColl->
end();
471 const std::string& name = attrListColl->
chanName(itr->first);
472 ATH_MSG_INFO(
"checkCurrentFromConditions: Trying to read from DCS: "
473 "[channel name, index, value] "
474 << name <<
" , " << itr->first <<
" , "
475 << itr->second[
"value"].data<
float>());
476 if (name.compare(
"") != 0) {
479 if (name.compare(
"CentralSol_Current") == 0) {
481 solcur = itr->second[
"value"].data<
float>();
483 }
else if (name.compare(
"Toroids_Current") == 0) {
485 torcur = itr->second[
"value"].data<
float>();
490 ATH_MSG_INFO(
"checkCurrentFromConditions: Attempt 2 at reading currents "
491 "from DCS (using channel index)");
494 itr != attrListColl->
end();
497 if (itr->first == 1) {
499 solcur = itr->second[
"value"].data<
float>();
501 }
else if (itr->first == 3) {
503 torcur = itr->second[
"value"].data<
float>();
508 if (!gotsol || !gottor) {
510 ATH_MSG_ERROR(
"checkCurrentFromConditions: Missing solenoid current in "
513 ATH_MSG_ERROR(
"checkCurrentFromConditions: Missing toroid current in DCS "
515 return StatusCode::FAILURE;
518 ATH_MSG_INFO(
"checkCurrentFromConditions: Currents read from DCS - solenoid "
519 << solcur <<
" toroid " << torcur);
524 ATH_MSG_INFO(
"checkCurrentFromConditions: Solenoid is off");
528 ATH_MSG_INFO(
"checkCurrentFromConditions: Toroids are off");
531 soleCurrent = solcur;
532 toroCurrent = torcur;
534 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
Base class for conditions algorithms.
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
ChanAttrListMap::const_iterator const_iterator
StatusCode start() override final
Gaudi::Property< std::string > m_toroMapFilename
Gaudi::Property< double > m_mapToroCurrent
AtlasFieldMapCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode checkCurrentFromConditions(const EventContext &ctx, double &soleCurrent, double &toroCurrent, EventIDRange &rangeDCS) const
StatusCode initialize() override final
StatusCode updateFieldMap(const EventContext &ctx, Cache &cache) const
Gaudi::Property< bool > m_loadMapOnStart
virtual ~AtlasFieldMapCondAlg()
Gaudi::Property< std::string > m_soleMapFilename
Gaudi::Property< std::string > m_fullMapFilename
map file names - if not read from cool
SG::ReadCondHandleKey< CondAttrListCollection > m_mapsInputKey
Gaudi::Property< double > m_soleMinCurrent
SG::WriteCondHandleKey< AtlasFieldMapCondObj > m_mapCondObjOutputKey
Gaudi::Property< double > m_toroMinCurrent
Gaudi::Property< bool > m_useMapsFromCOOL
Gaudi::Property< double > m_mapSoleCurrent
nominal current for the maps
SG::ReadCondHandleKey< CondAttrListCollection > m_currInputKey
StatusCode execute(const EventContext &ctx) const override final
int solenoidZoneId() const
bool initializeMap(TFile *rootfile, float solenoidCurrent, float toroidCurrent)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
const DataObjID & fullKey() const
static std::vector< std::string > rootfile
std::unique_ptr< MagField::AtlasFieldMap > m_fieldMap
EventIDRange m_mapCondObjOutputRange