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;
163 if (!readHandle.
range(rangeW)) {
164 ATH_MSG_FATAL(
"updateFieldMap: Failed to retrieve validity range for "
165 << readHandle.
key());
166 return StatusCode::FAILURE;
170 "updateFieldMap: Update map from conditions: Range of input/output is "
174 "updateFieldMap: reading magnetic field map filenames from COOL");
177 itr != attrListColl->
end();
179 const coral::AttributeList& attr = itr->second;
180 const std::string& mapType = attr[
"FieldType"].data<std::string>();
181 const std::string& mapFile = attr[
"MapFileName"].data<std::string>();
182 const float soleCur = attr[
"SolenoidCurrent"].data<
float>();
183 const float toroCur = attr[
"ToroidCurrent"].data<
float>();
186 << mapType <<
" with soleCur=" << soleCur
187 <<
" toroCur=" << toroCur <<
" (path " << mapFile <<
")");
190 const std::string mapFile_decoded = mapFile.substr(5);
191 if (mapType ==
"GlobalMap") {
192 fullMapFilename = mapFile_decoded;
195 }
else if (mapType ==
"SolenoidMap") {
196 soleMapFilename = mapFile_decoded;
197 }
else if (mapType ==
"ToroidMap") {
198 toroMapFilename = mapFile_decoded;
214 EventIDBase
start, stop;
215 start.set_run_number(ctx.eventID().run_number());
216 start.set_lumi_block(0);
217 stop.set_run_number(ctx.eventID().run_number() + 1);
218 stop.set_lumi_block(0);
221 ATH_MSG_INFO(
"updateFieldMap: loadMapOnStart is set, overriding currents "
222 "from job options - solCur "
239 EventIDRange rangeDCS;
243 bool mustCreateIOVRange =
false;
246 mustCreateIOVRange =
true;
247 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
251 mustCreateIOVRange =
true;
252 ATH_MSG_INFO(
"updateFieldMap: set toroid current to 0 from DCS");
254 if (mustCreateIOVRange) {
257 EventIDBase
start, stop;
259 start.set_run_number(ctx.eventID().run_number());
260 start.set_lumi_block(0);
261 stop.set_run_number(ctx.eventID().run_number() + 1);
262 stop.set_lumi_block(0);
267 ATH_MSG_INFO(
"updateFieldMap: currents are OK, will use nominal maps");
279 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
287 ATH_MSG_INFO(
"updateFieldMap: requested toroid current in JobOpt "
295 EventIDBase
start, stop;
296 start.set_run_number(ctx.eventID().run_number());
297 start.set_lumi_block(0);
298 stop.set_run_number(ctx.eventID().run_number() + 1);
299 stop.set_lumi_block(0);
303 "updateFieldMap: useMapsFromCOOL == false, using default range "
314 if (tagInfoMgr.retrieve().isSuccess()) {
316 bool resetCurrentsFromTagInfo =
false;
317 std::string mapSoleCurrent = tagInfoMgr->findTag(
"MapSoleCurrent");
318 if (not mapSoleCurrent.empty()) {
320 resetCurrentsFromTagInfo =
true;
321 ATH_MSG_INFO(
"updateFieldMap: found MapSoleCurrent in TagInfo, setting "
322 "the solenoid current "
325 std::string mapToroCurrent = tagInfoMgr->findTag(
"MapToroCurrent");
326 if (not mapToroCurrent.empty()) {
328 resetCurrentsFromTagInfo =
true;
329 ATH_MSG_INFO(
"updateFieldMap: found MapToroCurrent in TagInfo, setting "
330 "the toroid current "
333 if (resetCurrentsFromTagInfo)
334 ATH_MSG_INFO(
"updateFieldMap: reset currents from TagInfo");
336 ATH_MSG_INFO(
"updateFieldMap: DID NOT reset currents from TagInfo");
348 mapFile = fullMapFilename;
350 mapFile = soleMapFilename;
352 mapFile = toroMapFilename;
355 return StatusCode::SUCCESS;
359 "updateFieldMap: Set map currents from FieldSvc: solenoid/toroid "
361 ATH_MSG_INFO(
"updateFieldMap: Use map file " << mapFile);
365 if (resolvedMapFile.empty()) {
367 return StatusCode::FAILURE;
370 if (resolvedMapFile.find(
".root") == std::string::npos) {
372 << resolvedMapFile <<
"' does not end with .root");
373 return StatusCode::FAILURE;
375 TFile*
rootfile =
new TFile(resolvedMapFile.c_str(),
"OLD");
377 ATH_MSG_ERROR(
"updateFieldMap: failed to open " << resolvedMapFile);
378 return StatusCode::FAILURE;
383 "updateFieldMap: unable to cd() into the ROOT field map TFile");
386 return StatusCode::FAILURE;
390 if (
tree ==
nullptr) {
393 "updateFieldMap: TTree 'BFieldMap' does not exist in ROOT field map");
396 return StatusCode::FAILURE;
400 cache.
m_fieldMap = std::make_unique<MagField::AtlasFieldMap>();
407 "updateFieldMap: unable to initialize the map for AtlasFieldMap for file "
411 return StatusCode::FAILURE;
417 ATH_MSG_INFO(
"updateFieldMap: Initialized the field map from "
420 return StatusCode::SUCCESS;
425 const EventContext& ctx,
428 EventIDRange& rangeDCS)
const
434 if (attrListColl ==
nullptr) {
435 ATH_MSG_ERROR(
"checkCurrentFromConditions: Failed to retrieve "
436 "CondAttributeListCollection with key "
438 return StatusCode::FAILURE;
442 if (!readHandle.
range(rangeDCS)) {
444 "checkCurrentFromConditions: Failed to retrieve validity range for "
445 << readHandle.
key());
446 return StatusCode::FAILURE;
448 ATH_MSG_INFO(
"checkCurrentFromConditions: Range of input currents is "
454 bool gotsol{
false };
455 bool gottor{
false };
462 bool hasChanNames{
false };
463 ATH_MSG_INFO(
"checkCurrentFromConditions: Attempt 1 at reading currents from "
464 "DCS (using channel name)");
466 itr != attrListColl->
end();
468 const std::string& name = attrListColl->
chanName(itr->first);
469 ATH_MSG_INFO(
"checkCurrentFromConditions: Trying to read from DCS: "
470 "[channel name, index, value] "
471 << name <<
" , " << itr->first <<
" , "
472 << itr->second[
"value"].data<
float>());
473 if (name.compare(
"") != 0) {
476 if (name.compare(
"CentralSol_Current") == 0) {
478 solcur = itr->second[
"value"].data<
float>();
480 }
else if (name.compare(
"Toroids_Current") == 0) {
482 torcur = itr->second[
"value"].data<
float>();
487 ATH_MSG_INFO(
"checkCurrentFromConditions: Attempt 2 at reading currents "
488 "from DCS (using channel index)");
491 itr != attrListColl->
end();
494 if (itr->first == 1) {
496 solcur = itr->second[
"value"].data<
float>();
498 }
else if (itr->first == 3) {
500 torcur = itr->second[
"value"].data<
float>();
505 if (!gotsol || !gottor) {
507 ATH_MSG_ERROR(
"checkCurrentFromConditions: Missing solenoid current in "
510 ATH_MSG_ERROR(
"checkCurrentFromConditions: Missing toroid current in DCS "
512 return StatusCode::FAILURE;
515 ATH_MSG_INFO(
"checkCurrentFromConditions: Currents read from DCS - solenoid "
516 << solcur <<
" toroid " << torcur);
521 ATH_MSG_INFO(
"checkCurrentFromConditions: Solenoid is off");
525 ATH_MSG_INFO(
"checkCurrentFromConditions: Toroids are off");
528 soleCurrent = solcur;
529 toroCurrent = torcur;
531 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