133{
134
135
136
137
138
139
140
141
142 std::string fullMapFilename;
143 std::string soleMapFilename;
144 std::string toroMapFilename;
145
147
148 ATH_MSG_INFO(
"updateFieldMap: Update map from conditions");
149
150
151 SG::ReadCondHandle<CondAttrListCollection> readHandle{
m_mapsInputKey,
152 ctx };
153 const CondAttrListCollection* attrListColl{ *readHandle };
154 if (attrListColl == nullptr) {
156 "CondAttributeListCollection with key "
157 << readHandle.
key());
158 return StatusCode::FAILURE;
159 }
160
161
162
163
164
165 EventIDRange rangeW;
166 if (!readHandle.
range(rangeW)) {
167 ATH_MSG_FATAL(
"updateFieldMap: Failed to retrieve validity range for "
168 << readHandle.
key());
169 return StatusCode::FAILURE;
170 }
171 cache.m_mapCondObjOutputRange = rangeW;
173 "updateFieldMap: Update map from conditions: Range of input/output is "
174 << cache.m_mapCondObjOutputRange);
175
177 "updateFieldMap: reading magnetic field map filenames from COOL");
178
180 itr != attrListColl->
end();
181 ++itr) {
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>();
187
189 << mapType << " with soleCur=" << soleCur
190 << " toroCur=" << toroCur << " (path " << mapFile << ")");
191
192
193 const std::string mapFile_decoded = mapFile.substr(5);
194 if (mapType == "GlobalMap") {
195 fullMapFilename = mapFile_decoded;
196 cache.m_mapSoleCurrent = soleCur;
197 cache.m_mapToroCurrent = toroCur;
198 } else if (mapType == "SolenoidMap") {
199 soleMapFilename = mapFile_decoded;
200 } else if (mapType == "ToroidMap") {
201 toroMapFilename = mapFile_decoded;
202 }
203
204
205
206 }
207
209
210
211
212
215
216
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);
222 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
223
224 ATH_MSG_INFO(
"updateFieldMap: loadMapOnStart is set, overriding currents "
225 "from job options - solCur "
226 << cache.m_mapSoleCurrent << ", torCur "
227 << cache.m_mapToroCurrent << " and setting IOV range: "
228 << cache.m_mapCondObjOutputRange);
229 } else {
230
231
232
233
234
235
236
237
238
239
240 double soleCurrent;
241 double toroCurrent;
242 EventIDRange rangeDCS;
245
246 bool mustCreateIOVRange = false;
248 cache.m_mapSoleCurrent = 0;
249 mustCreateIOVRange = true;
250 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
251 }
253 cache.m_mapToroCurrent = 0;
254 mustCreateIOVRange = true;
255 ATH_MSG_INFO(
"updateFieldMap: set toroid current to 0 from DCS");
256 }
257 if (mustCreateIOVRange) {
258
259
261
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);
266 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
268 << cache.m_mapCondObjOutputRange);
269 } else {
270 ATH_MSG_INFO(
"updateFieldMap: currents are OK, will use nominal maps");
271 }
272 }
273 }
274
275 else {
276
281 cache.m_mapSoleCurrent = 0;
282 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
285 } else {
287 }
289 cache.m_mapToroCurrent = 0;
290 ATH_MSG_INFO(
"updateFieldMap: requested toroid current in JobOpt "
293 } else {
295 }
296
297
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);
303 cache.m_mapCondObjOutputRange = EventIDRange(
start, stop);
304
306 "updateFieldMap: useMapsFromCOOL == false, using default range "
307 << cache.m_mapCondObjOutputRange);
308 }
309
310
311
312
314
315
316 ServiceHandle<ITagInfoMgr> tagInfoMgr(
"TagInfoMgr",
name());
317 if (tagInfoMgr.retrieve().isSuccess()) {
319 bool resetCurrentsFromTagInfo = false;
320 std::string mapSoleCurrent = tagInfoMgr->findTag("MapSoleCurrent");
321 if (not mapSoleCurrent.empty()) {
322 cache.m_mapSoleCurrent = std::stof(mapSoleCurrent);
323 resetCurrentsFromTagInfo = true;
324 ATH_MSG_INFO(
"updateFieldMap: found MapSoleCurrent in TagInfo, setting "
325 "the solenoid current "
326 << cache.m_mapSoleCurrent);
327 }
328 std::string mapToroCurrent = tagInfoMgr->findTag("MapToroCurrent");
329 if (not mapToroCurrent.empty()) {
330 cache.m_mapToroCurrent = std::stof(mapToroCurrent);
331 resetCurrentsFromTagInfo = true;
332 ATH_MSG_INFO(
"updateFieldMap: found MapToroCurrent in TagInfo, setting "
333 "the toroid current "
334 << cache.m_mapToroCurrent);
335 }
336 if (resetCurrentsFromTagInfo)
337 ATH_MSG_INFO(
"updateFieldMap: reset currents from TagInfo");
338 else
339 ATH_MSG_INFO(
"updateFieldMap: DID NOT reset currents from TagInfo");
340 } else {
342 }
343 }
344
345
346
347
348
349 std::string mapFile;
350 if (cache.solenoidOn() && cache.toroidOn())
351 mapFile = fullMapFilename;
352 else if (cache.solenoidOn())
353 mapFile = soleMapFilename;
354 else if (cache.toroidOn())
355 mapFile = toroMapFilename;
356 else {
357
358 return StatusCode::SUCCESS;
359 }
360
362 "updateFieldMap: Set map currents from FieldSvc: solenoid/toroid "
363 << cache.m_mapSoleCurrent << "," << cache.m_mapToroCurrent);
364 ATH_MSG_INFO(
"updateFieldMap: Use map file " << mapFile);
365
366
368 if (resolvedMapFile.empty()) {
370 return StatusCode::FAILURE;
371 }
372
373 if (resolvedMapFile.find(".root") == std::string::npos) {
375 << resolvedMapFile << "' does not end with .root");
376 return StatusCode::FAILURE;
377 }
378 TFile*
rootfile =
new TFile(resolvedMapFile.c_str(),
"OLD");
380 ATH_MSG_ERROR(
"updateFieldMap: failed to open " << resolvedMapFile);
381 return StatusCode::FAILURE;
382 }
384
386 "updateFieldMap: unable to cd() into the ROOT field map TFile");
389 return StatusCode::FAILURE;
390 }
391
393 if (
tree ==
nullptr) {
394
396 "updateFieldMap: TTree 'BFieldMap' does not exist in ROOT field map");
399 return StatusCode::FAILURE;
400 }
401
402
403 cache.m_fieldMap = std::make_unique<MagField::AtlasFieldMap>();
404
405
406 if (!cache.m_fieldMap->initializeMap(
407 rootfile, cache.m_mapSoleCurrent, cache.m_mapToroCurrent)) {
408
410 "updateFieldMap: unable to initialize the map for AtlasFieldMap for file "
411 << resolvedMapFile);
414 return StatusCode::FAILURE;
415 }
416
419
420 ATH_MSG_INFO(
"updateFieldMap: Initialized the field map from "
421 << resolvedMapFile);
422
423 return StatusCode::SUCCESS;
424}
StatusCode start() override final
Gaudi::Property< std::string > m_toroMapFilename
Gaudi::Property< double > m_mapToroCurrent
StatusCode checkCurrentFromConditions(const EventContext &ctx, double &soleCurrent, double &toroCurrent, EventIDRange &rangeDCS) const
Gaudi::Property< std::string > m_soleMapFilename
Gaudi::Property< std::string > m_fullMapFilename
map file names - if not read from cool
Gaudi::Property< double > m_mapSoleCurrent
nominal current for the maps
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
static std::vector< std::string > rootfile