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;
168 cache.m_mapCondObjOutputRange = rangeW;
170 "updateFieldMap: Update map from conditions: Range of input/output is "
171 << cache.m_mapCondObjOutputRange);
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;
193 cache.m_mapSoleCurrent = soleCur;
194 cache.m_mapToroCurrent = toroCur;
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);
219 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
221 ATH_MSG_INFO(
"updateFieldMap: loadMapOnStart is set, overriding currents "
222 "from job options - solCur "
223 << cache.m_mapSoleCurrent <<
", torCur "
224 << cache.m_mapToroCurrent <<
" and setting IOV range: "
225 << cache.m_mapCondObjOutputRange);
239 EventIDRange rangeDCS;
243 bool mustCreateIOVRange =
false;
245 cache.m_mapSoleCurrent = 0;
246 mustCreateIOVRange =
true;
247 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
250 cache.m_mapToroCurrent = 0;
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);
263 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
265 << cache.m_mapCondObjOutputRange);
267 ATH_MSG_INFO(
"updateFieldMap: currents are OK, will use nominal maps");
278 cache.m_mapSoleCurrent = 0;
279 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
286 cache.m_mapToroCurrent = 0;
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);
300 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
303 "updateFieldMap: useMapsFromCOOL == false, using default range "
304 << cache.m_mapCondObjOutputRange);
314 if (tagInfoMgr.retrieve().isSuccess()) {
316 bool resetCurrentsFromTagInfo =
false;
317 std::string mapSoleCurrent = tagInfoMgr->findTag(
"MapSoleCurrent");
318 if (not mapSoleCurrent.empty()) {
319 cache.m_mapSoleCurrent = std::stof(mapSoleCurrent);
320 resetCurrentsFromTagInfo =
true;
321 ATH_MSG_INFO(
"updateFieldMap: found MapSoleCurrent in TagInfo, setting "
322 "the solenoid current "
323 << cache.m_mapSoleCurrent);
325 std::string mapToroCurrent = tagInfoMgr->findTag(
"MapToroCurrent");
326 if (not mapToroCurrent.empty()) {
327 cache.m_mapToroCurrent = std::stof(mapToroCurrent);
328 resetCurrentsFromTagInfo =
true;
329 ATH_MSG_INFO(
"updateFieldMap: found MapToroCurrent in TagInfo, setting "
330 "the toroid current "
331 << cache.m_mapToroCurrent);
333 if (resetCurrentsFromTagInfo)
334 ATH_MSG_INFO(
"updateFieldMap: reset currents from TagInfo");
336 ATH_MSG_INFO(
"updateFieldMap: DID NOT reset currents from TagInfo");
347 if (cache.solenoidOn() && cache.toroidOn())
348 mapFile = fullMapFilename;
349 else if (cache.solenoidOn())
350 mapFile = soleMapFilename;
351 else if (cache.toroidOn())
352 mapFile = toroMapFilename;
355 return StatusCode::SUCCESS;
359 "updateFieldMap: Set map currents from FieldSvc: solenoid/toroid "
360 << cache.m_mapSoleCurrent <<
"," << cache.m_mapToroCurrent);
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>();
403 if (!cache.m_fieldMap->initializeMap(
404 rootfile, cache.m_mapSoleCurrent, cache.m_mapToroCurrent)) {
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;