20 #include "GaudiKernel/ConcurrencyFlags.h"
34 ISvcLocator* pSvcLocator)
44 ATH_CHECK(m_mapsInputKey.initialize(m_useMapsFromCOOL));
47 ATH_CHECK(m_currInputKey.initialize(!m_loadMapOnStart && m_useMapsFromCOOL));
50 ATH_CHECK(m_mapCondObjOutputKey.initialize());
52 ATH_MSG_DEBUG(
"Initialize: Key " << m_mapCondObjOutputKey.fullKey()
53 <<
" has been succesfully registered ");
55 ATH_MSG_INFO(
"Initialize: Will update the field map from " <<
56 (m_useMapsFromCOOL ?
"conditions" :
"jobOpt file name") );
60 TClass::GetClass(
"TLeafI");
61 TClass::GetClass(
"TLeafD");
62 TClass::GetClass(
"TLeafO");
63 TClass::GetClass(
"TLeafS");
65 return StatusCode::SUCCESS;
74 if (m_loadMapOnStart) {
75 return (
execute(Gaudi::Hive::currentContext()));
78 return StatusCode::SUCCESS;
90 m_mapCondObjOutputKey, ctx
92 if (mapWriteHandle.isValid()) {
93 ATH_MSG_DEBUG(
"execute: CondHandle " << mapWriteHandle.fullKey()
94 <<
" is still valid. ");
95 return StatusCode::SUCCESS;
103 if (cache.m_fieldMap) {
105 << cache.m_fieldMap->solenoidZoneId());
112 auto fieldMapCondObj = std::make_unique<AtlasFieldMapCondObj>();
114 if (cache.m_fieldMap)
115 fieldMapCondObj->setFieldMap(std::move(cache.m_fieldMap));
117 .record(cache.m_mapCondObjOutputRange, std::move(fieldMapCondObj))
119 ATH_MSG_ERROR(
"execute: Could not record AtlasFieldMapCondObj object with "
120 << mapWriteHandle.key() <<
" with EventRange "
121 << cache.m_mapCondObjOutputRange <<
" into Conditions Store");
122 return StatusCode::FAILURE;
124 ATH_MSG_INFO(
"execute: recorded AtlasFieldMapCondObj with EventRange "
125 << cache.m_mapCondObjOutputRange);
127 return StatusCode::SUCCESS;
142 std::string fullMapFilename;
143 std::string soleMapFilename;
144 std::string toroMapFilename;
146 if (m_useMapsFromCOOL) {
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();
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;
208 if (m_loadMapOnStart) {
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;
244 checkCurrentFromConditions(ctx, soleCurrent, toroCurrent, rangeDCS));
246 bool mustCreateIOVRange =
false;
247 if (soleCurrent < m_soleMinCurrent) {
249 mustCreateIOVRange =
true;
250 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
252 if (toroCurrent < m_toroMinCurrent) {
254 mustCreateIOVRange =
true;
255 ATH_MSG_INFO(
"updateFieldMap: set toroid current to 0 from DCS");
257 if (mustCreateIOVRange) {
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");
277 fullMapFilename = m_fullMapFilename;
278 soleMapFilename = m_soleMapFilename;
279 toroMapFilename = m_toroMapFilename;
280 if (m_mapSoleCurrent < m_soleMinCurrent) {
282 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
283 << m_mapSoleCurrent <<
" is below allowed minimum "
284 << m_soleMinCurrent <<
" setting to 0");
288 if (m_mapToroCurrent < m_toroMinCurrent) {
290 ATH_MSG_INFO(
"updateFieldMap: requested toroid current in JobOpt "
291 << m_mapToroCurrent <<
" is below allowed minimum "
292 << m_toroMinCurrent <<
" setting to 0");
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 "
313 if (m_useMapsFromCOOL) {
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 "
440 << m_currInputKey.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);
522 if (solcur < m_soleMinCurrent) {
524 ATH_MSG_INFO(
"checkCurrentFromConditions: Solenoid is off");
526 if (torcur < m_toroMinCurrent) {
528 ATH_MSG_INFO(
"checkCurrentFromConditions: Toroids are off");
531 soleCurrent = solcur;
532 toroCurrent = torcur;
534 return StatusCode::SUCCESS;