17#include "GaudiKernel/ConcurrencyFlags.h"
23 const std::string& name,
24 ISvcLocator* pSvcLocator)
43 <<
" has been succesfully registered ");
46 (
m_useDCS ?
"conditions" :
"parameters"));
48 ATH_MSG_INFO(
"Initialize: useDCS, useSoleCurrent, useToroCurrent. "
53 return StatusCode::SUCCESS;
68 << writeHandle.
fullKey() <<
" is already valid. "
69 <<
" May happen if multiple concurrent events are being "
70 "processed out of order.");
71 return StatusCode::SUCCESS;
87 if (mapCondObj ==
nullptr) {
88 ATH_MSG_ERROR(
"execute: Could not access conditions map for key: "
90 return StatusCode::FAILURE;
103 auto fieldCondObj = std::make_unique<AtlasFieldCacheCondObj>();
107 fieldCondObj->initialize(
108 cache.m_solScaleFactor, cache.m_torScaleFactor, fieldMap);
112 if (writeHandle.
record(cache.m_condObjOutputRange, std::move(fieldCondObj))
115 "execute: Could not record AtlasFieldCacheCondObj object with "
116 << writeHandle.
key() <<
" with EventRange " << cache.m_condObjOutputRange
117 <<
" into Conditions Store");
118 return StatusCode::FAILURE;
122 "execute: initialized AtlasFieldCacheCondObj and cache with SFs - sol/tor "
123 << cache.m_solScaleFactor <<
"/" << cache.m_torScaleFactor
124 <<
", EventRange " << cache.m_condObjOutputRange);
131 return StatusCode::SUCCESS;
136 const EventContext& ctx,
143 if (attrListColl ==
nullptr) {
144 ATH_MSG_ERROR(
"updateCurrentFromConditions: Failed to retrieve "
145 "CondAttributeListCollection with key "
147 return StatusCode::FAILURE;
152 if (!readHandle.
range(rangeW)) {
154 "updateCurrentFromConditions: Failed to retrieve validity range for "
155 << readHandle.
key());
156 return StatusCode::FAILURE;
158 cache.m_condObjOutputRange = rangeW;
159 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Range of input/output is "
160 << cache.m_condObjOutputRange);
165 bool gotsol{
false };
166 bool gottor{
false };
173 bool hasChanNames{
false };
174 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Attempt 1 at reading currents "
175 "from DCS (using channel name)");
177 itr != attrListColl->
end();
179 const std::string& name = attrListColl->
chanName(itr->first);
180 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Trying to read from DCS: "
181 "[channel name, index, value] "
182 << name <<
" , " << itr->first <<
" , "
183 << itr->second[
"value"].data<
float>());
184 if (name.compare(
"") != 0) {
187 if (name.compare(
"CentralSol_Current") == 0) {
189 solcur = itr->second[
"value"].data<
float>();
191 }
else if (name.compare(
"Toroids_Current") == 0) {
193 torcur = itr->second[
"value"].data<
float>();
198 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Attempt 2 at reading currents "
199 "from DCS (using channel index)");
202 itr != attrListColl->
end();
205 if (itr->first == 1) {
207 solcur = itr->second[
"value"].data<
float>();
209 }
else if (itr->first == 3) {
211 torcur = itr->second[
"value"].data<
float>();
216 if (!gotsol || !gottor) {
218 ATH_MSG_ERROR(
"UpdateCurrentFromConditions: Missing solenoid current in "
221 ATH_MSG_ERROR(
"UpdateCurrentFromConditions: Missing toroid current in "
223 return StatusCode::FAILURE;
226 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Currents read from DCS - solenoid "
227 << solcur <<
" toroid " << torcur);
232 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Solenoid is off");
236 ATH_MSG_INFO(
"UpdateCurrentFromConditions: Toroids are off");
239 cache.m_solenoidCurrent = solcur;
240 cache.m_toroidCurrent = torcur;
242 return StatusCode::SUCCESS;
247 const EventContext& ctx,
256 ATH_MSG_INFO(
"updateCurrentFromParameters: Solenoid is off");
260 ATH_MSG_INFO(
"updateCurrentFromParameters: Toroids are off");
262 cache.m_solenoidCurrent = solcur;
263 cache.m_toroidCurrent = torcur;
267 EventIDBase start, stop;
268 start.set_run_number(ctx.eventID().run_number());
269 start.set_lumi_block(0);
270 stop.set_run_number(ctx.eventID().run_number() + 1);
271 stop.set_lumi_block(0);
272 cache.m_condObjOutputRange = EventIDRange(start, stop);
274 ATH_MSG_INFO(
"updateCurrentFromParameters: Update from job options: Range of "
276 << cache.m_condObjOutputRange);
278 return StatusCode::SUCCESS;
292 bool mapHasToroid = fieldMap && (fieldMap->
toroidCurrent()>0);
298 if (cache.m_solenoidCurrent > 0.0) {
299 if (mapHasSolenoid &&
300 std::abs(cache.m_solenoidCurrent / fieldMap->
solenoidCurrent() - 1.0) >
302 cache.m_solScaleFactor =
306 << cache.m_solScaleFactor
307 <<
". Desired current and map current: "
308 << cache.m_solenoidCurrent <<
","
313 cache.m_solScaleFactor = 0;
315 << cache.m_solScaleFactor
316 <<
". Desired current and map current: "
317 << cache.m_solenoidCurrent <<
","
323 if (cache.m_toroidCurrent > 0.0) {
325 std::abs(cache.m_toroidCurrent / fieldMap->
toroidCurrent() - 1.0) >
328 cache.m_torScaleFactor =
332 << cache.m_torScaleFactor
333 <<
". Desired current and map current: "
334 << cache.m_toroidCurrent <<
","
337 cache.m_torScaleFactor = 0;
339 << cache.m_torScaleFactor
340 <<
". Desired current and map current: "
341 << cache.m_toroidCurrent <<
","
346 if (mapHasToroid && !mapHasSolenoid) {
347 cache.m_solScaleFactor = cache.m_torScaleFactor;
351 if (!mapHasToroid && mapHasSolenoid) {
352 cache.m_torScaleFactor = cache.m_solScaleFactor;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
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