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 EventIDRange rangeW;
163 if (!readHandle.
range(rangeW)) {
164 ATH_MSG_FATAL(
"updateFieldMap: Failed to retrieve validity range for "
165 << readHandle.
key());
166 return StatusCode::FAILURE;
167 }
168 cache.m_mapCondObjOutputRange = rangeW;
170 "updateFieldMap: Update map from conditions: Range of input/output is "
171 << cache.m_mapCondObjOutputRange);
172
174 "updateFieldMap: reading magnetic field map filenames from COOL");
175
177 itr != attrListColl->
end();
178 ++itr) {
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>();
184
186 << mapType << " with soleCur=" << soleCur
187 << " toroCur=" << toroCur << " (path " << mapFile << ")");
188
189
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;
199 }
200
201
202
203 }
204
206
207
208
209
212
213
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);
220
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);
226 } else {
227
228
229
230
231
232
233
234
235
236
237 double soleCurrent;
238 double toroCurrent;
239 EventIDRange rangeDCS;
242
243 bool mustCreateIOVRange = false;
245 cache.m_mapSoleCurrent = 0;
246 mustCreateIOVRange = true;
247 ATH_MSG_INFO(
"updateFieldMap: set solenoid current to 0 from DCS");
248 }
250 cache.m_mapToroCurrent = 0;
251 mustCreateIOVRange = true;
252 ATH_MSG_INFO(
"updateFieldMap: set toroid current to 0 from DCS");
253 }
254 if (mustCreateIOVRange) {
255
256
258
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);
266 } else {
267 ATH_MSG_INFO(
"updateFieldMap: currents are OK, will use nominal maps");
268 }
269 }
270 }
271
272 else {
273
278 cache.m_mapSoleCurrent = 0;
279 ATH_MSG_INFO(
"updateFieldMap: requested solenoid current in JobOpt "
282 } else {
284 }
286 cache.m_mapToroCurrent = 0;
287 ATH_MSG_INFO(
"updateFieldMap: requested toroid current in JobOpt "
290 } else {
292 }
293
294
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);
301
303 "updateFieldMap: useMapsFromCOOL == false, using default range "
304 << cache.m_mapCondObjOutputRange);
305 }
306
307
308
309
311
312
313 ServiceHandle<ITagInfoMgr> tagInfoMgr(
"TagInfoMgr",
name());
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);
324 }
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);
332 }
333 if (resetCurrentsFromTagInfo)
334 ATH_MSG_INFO(
"updateFieldMap: reset currents from TagInfo");
335 else
336 ATH_MSG_INFO(
"updateFieldMap: DID NOT reset currents from TagInfo");
337 } else {
339 }
340 }
341
342
343
344
345
346 std::string mapFile;
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;
353 else {
354
355 return StatusCode::SUCCESS;
356 }
357
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);
362
363
365 if (resolvedMapFile.empty()) {
367 return StatusCode::FAILURE;
368 }
369
370 if (resolvedMapFile.find(".root") == std::string::npos) {
372 << resolvedMapFile << "' does not end with .root");
373 return StatusCode::FAILURE;
374 }
375 TFile*
rootfile =
new TFile(resolvedMapFile.c_str(),
"OLD");
377 ATH_MSG_ERROR(
"updateFieldMap: failed to open " << resolvedMapFile);
378 return StatusCode::FAILURE;
379 }
381
383 "updateFieldMap: unable to cd() into the ROOT field map TFile");
386 return StatusCode::FAILURE;
387 }
388
390 if (
tree ==
nullptr) {
391
393 "updateFieldMap: TTree 'BFieldMap' does not exist in ROOT field map");
396 return StatusCode::FAILURE;
397 }
398
399
400 cache.m_fieldMap = std::make_unique<MagField::AtlasFieldMap>();
401
402
403 if (!cache.m_fieldMap->initializeMap(
404 rootfile, cache.m_mapSoleCurrent, cache.m_mapToroCurrent)) {
405
407 "updateFieldMap: unable to initialize the map for AtlasFieldMap for file "
408 << resolvedMapFile);
411 return StatusCode::FAILURE;
412 }
413
416
417 ATH_MSG_INFO(
"updateFieldMap: Initialized the field map from "
418 << resolvedMapFile);
419
420 return StatusCode::SUCCESS;
421}
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