17#include "GaudiKernel/ConcurrencyFlags.h"
27 const std::string& name,
28 ISvcLocator* pSvcLocator)
47 <<
" has been succesfully registered ");
50 (
m_useDCS ?
"conditions" :
"parameters"));
52 ATH_MSG_INFO(
"Initialize: useDCS, useSoleCurrent, useToroCurrent. "
57 return StatusCode::SUCCESS;
72 << writeHandle.
fullKey() <<
" is already valid. "
73 <<
" May happen if multiple concurrent events are being "
74 "processed out of order.");
75 return StatusCode::SUCCESS;
91 if (mapCondObj ==
nullptr) {
92 ATH_MSG_ERROR(
"execute: Could not access conditions map for key: "
94 return StatusCode::FAILURE;
107 auto fieldCondObj = std::make_unique<AtlasFieldCacheCondObj>();
111 fieldCondObj->initialize(
112 cache.m_solScaleFactor, cache.m_torScaleFactor, fieldMap);
116 if (writeHandle.
record(cache.m_condObjOutputRange, std::move(fieldCondObj))
119 "execute: Could not record AtlasFieldCacheCondObj object with "
120 << writeHandle.
key() <<
" with EventRange " << cache.m_condObjOutputRange
121 <<
" into Conditions Store");
122 return StatusCode::FAILURE;
126 "execute: initialized AtlasFieldCacheCondObj and cache with SFs - sol/tor "
127 << cache.m_solScaleFactor <<
"/" << cache.m_torScaleFactor
128 <<
", EventRange " << cache.m_condObjOutputRange);
135 return StatusCode::SUCCESS;
140 const EventContext& ctx,
147 if (attrListColl ==
nullptr) {
148 ATH_MSG_ERROR(
"updateCurrentFromConditions: Failed to retrieve "
149 "CondAttributeListCollection with key "
151 return StatusCode::FAILURE;
156 if (!readHandle.
range(rangeW)) {
158 "updateCurrentFromConditions: Failed to retrieve validity range for "
159 << readHandle.
key());
160 return StatusCode::FAILURE;
162 cache.m_condObjOutputRange = rangeW;
163 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Range of input/output is "
164 << cache.m_condObjOutputRange);
169 bool gotsol{
false };
170 bool gottor{
false };
177 bool hasChanNames{
false };
178 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Attempt 1 at reading currents "
179 "from DCS (using channel name)");
181 itr != attrListColl->
end();
183 const std::string& name = attrListColl->
chanName(itr->first);
184 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Trying to read from DCS: "
185 "[channel name, index, value] "
186 << name <<
" , " << itr->first <<
" , "
187 << itr->second[
"value"].data<
float>());
188 if (name.compare(
"") != 0) {
191 if (name.compare(
"CentralSol_Current") == 0) {
193 solcur = itr->second[
"value"].data<
float>();
195 }
else if (name.compare(
"Toroids_Current") == 0) {
197 torcur = itr->second[
"value"].data<
float>();
202 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Attempt 2 at reading currents "
203 "from DCS (using channel index)");
206 itr != attrListColl->
end();
209 if (itr->first == 1) {
211 solcur = itr->second[
"value"].data<
float>();
213 }
else if (itr->first == 3) {
215 torcur = itr->second[
"value"].data<
float>();
220 if (!gotsol || !gottor) {
222 ATH_MSG_ERROR(
"UpdateCurrentFromConditions: Missing solenoid current in "
225 ATH_MSG_ERROR(
"UpdateCurrentFromConditions: Missing toroid current in "
227 return StatusCode::FAILURE;
230 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Currents read from DCS - solenoid "
231 << solcur <<
" toroid " << torcur);
236 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Solenoid is off");
240 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Toroids are off");
243 cache.m_solenoidCurrent = solcur;
244 cache.m_toroidCurrent = torcur;
246 return StatusCode::SUCCESS;
251 const EventContext& ctx,
260 ATH_MSG_INFO(
"updateCurrentFromParameters: Solenoid is off");
264 ATH_MSG_INFO(
"updateCurrentFromParameters: Toroids are off");
266 cache.m_solenoidCurrent = solcur;
267 cache.m_toroidCurrent = torcur;
271 EventIDBase start, stop;
272 start.set_run_number(ctx.eventID().run_number());
273 start.set_lumi_block(0);
274 stop.set_run_number(ctx.eventID().run_number() + 1);
275 stop.set_lumi_block(0);
276 cache.m_condObjOutputRange = EventIDRange(start, stop);
278 ATH_MSG_INFO(
"updateCurrentFromParameters: Update from job options: Range of "
280 << cache.m_condObjOutputRange);
282 return StatusCode::SUCCESS;
296 bool mapHasToroid = fieldMap && (fieldMap->
toroidCurrent()>0);
302 if (cache.m_solenoidCurrent > 0.0) {
303 if (mapHasSolenoid &&
304 std::abs(cache.m_solenoidCurrent / fieldMap->
solenoidCurrent() - 1.0) >
306 cache.m_solScaleFactor =
310 << cache.m_solScaleFactor
311 <<
". Desired current and map current: "
312 << cache.m_solenoidCurrent <<
","
317 cache.m_solScaleFactor = 0;
319 << cache.m_solScaleFactor
320 <<
". Desired current and map current: "
321 << cache.m_solenoidCurrent <<
","
327 if (cache.m_toroidCurrent > 0.0) {
329 std::abs(cache.m_toroidCurrent / fieldMap->
toroidCurrent() - 1.0) >
332 cache.m_torScaleFactor =
336 << cache.m_torScaleFactor
337 <<
". Desired current and map current: "
338 << cache.m_toroidCurrent <<
","
341 cache.m_torScaleFactor = 0;
343 << cache.m_torScaleFactor
344 <<
". Desired current and map current: "
345 << cache.m_toroidCurrent <<
","
350 if (mapHasToroid && !mapHasSolenoid) {
351 cache.m_solScaleFactor = cache.m_torScaleFactor;
355 if (!mapHasToroid && mapHasSolenoid) {
356 cache.m_torScaleFactor = cache.m_solScaleFactor;
#define ATH_CHECK
Evaluate an expression and check for errors.
Base class for conditions algorithms.
const MagField::AtlasFieldMap * fieldMap() const
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
virtual ~AtlasFieldCacheCondAlg()
void scaleField(Cache &cache, const MagField::AtlasFieldMap *fieldMap) const
Gaudi::Property< double > m_useSoleCurrent
Gaudi::Property< double > m_useToroCurrent
SG::WriteCondHandleKey< AtlasFieldCacheCondObj > m_condObjOutputKey
Gaudi::Property< double > m_soleMinCurrent
StatusCode updateCurrentFromConditions(const EventContext &ctx, Cache &cache) const
StatusCode updateCurrentFromParameters(const EventContext &ctx, Cache &cache) const
SG::ReadCondHandleKey< CondAttrListCollection > m_currInputKey
Gaudi::Property< double > m_toroMinCurrent
Gaudi::Property< bool > m_useDCS
StatusCode initialize() override final
AtlasFieldCacheCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_lockMapCurrents
SG::ReadCondHandleKey< AtlasFieldMapCondObj > m_mapCondObjInputKey
StatusCode execute(const EventContext &ctx) const override final
int solenoidZoneId() const
float toroidCurrent() const
float solenoidCurrent() const
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const