ATLAS Offline Software
TrigLiveFractionCondAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
3  */
14 #include "CoolKernel/IObject.h"
15 
16 
22 {
26  return StatusCode::SUCCESS;
27 }
28 
29 
35 TrigLiveFractionCondAlg::execute (const EventContext& ctx) const
36 {
37  const EventIDBase::number_type UNDEFNUM = EventIDBase::UNDEFNUM;
38  const EventIDBase::event_number_t UNDEFEVT = EventIDBase::UNDEFEVT;
39  EventIDRange range (EventIDBase (0, UNDEFEVT, UNDEFNUM, 0, 0),
40  EventIDBase (UNDEFNUM-1, UNDEFEVT, UNDEFNUM, 0, 0));
41 
42  unsigned int turnCounter = 0;
43  std::vector<float> liveFractionLo (LuminosityCondData::TOTAL_LHC_BCIDS, 1);
44  std::vector<float> liveFractionHi (LuminosityCondData::TOTAL_LHC_BCIDS, 1);
45  float lumiLiveFractionLo = 1;
46  float lumiLiveFractionHi = 1;
47 
51  ATH_CHECK( deadtimeFolder.range (range) );
52 
53  ATH_CHECK( unpackDeadtime (**deadtimeFolder,
54  turnCounter,
55  liveFractionLo,
56  liveFractionHi) );
57 
59  (m_luminosityInputKey, ctx);
60  EventIDRange range2;
61  ATH_CHECK( luminosityInput.range (range2) );
63 
64  ATH_CHECK( lumiWeight (**luminosityInput,
65  liveFractionLo,
66  liveFractionHi,
67  lumiLiveFractionLo,
68  lumiLiveFractionHi) );
69  }
70 
71  auto livefrac = std::make_unique<TrigLiveFractionCondData>
72  (turnCounter,
73  std::move (liveFractionLo),
74  std::move (liveFractionHi),
75  lumiLiveFractionLo,
76  lumiLiveFractionHi);
77  SG::WriteCondHandle<TrigLiveFractionCondData> trigLiveFractionCondData
79  ATH_CHECK( trigLiveFractionCondData.record (range, std::move (livefrac)) );
80  return StatusCode::SUCCESS;
81 }
82 
83 
95  unsigned int& turnCounter,
96  std::vector<float>& liveFractionLo,
97  std::vector<float>& liveFractionHi) const
98 {
99  if (deadtimeFolder["TurnCounter"].isNull()) {
100  ATH_MSG_WARNING( "TurnCounter is NULL in " << m_deadtimeFolderInputKey.key() << "!" );
101  return StatusCode::SUCCESS;
102  }
103 
104  turnCounter = deadtimeFolder["TurnCounter"].data<uint32_t>();
105  ATH_MSG_DEBUG( "TurnCounter = " << turnCounter );
106 
107  // OK, unpack deadtime counters
108 
109  // Check data availability
110  if (deadtimeFolder["LowPriority"].isNull() || deadtimeFolder["HighPriority"].isNull()) {
111  ATH_MSG_WARNING( " NULL veto counter information in database ... set livefraction to 1 " );
112  return StatusCode::SUCCESS;
113  }
114 
115  ATH_CHECK( unpackVector (deadtimeFolder["LowPriority"].data<coral::Blob>(),
116  turnCounter,
117  liveFractionLo) );
118  ATH_CHECK( unpackVector (deadtimeFolder["HighPriority"].data<coral::Blob>(),
119  turnCounter,
120  liveFractionHi) );
121 
122  if (msgLvl(MSG::DEBUG)) {
123  msg(MSG::DEBUG) << "HighPriority livefraction: ";
124  for (unsigned int i = 0; i < liveFractionHi.size(); i++) {
125  msg(MSG::DEBUG) << liveFractionHi[i] << " ";
126  }
127  msg(MSG::DEBUG) << endmsg;
128  }
129 
130  return StatusCode::SUCCESS;
131 }
132 
133 
143  unsigned int turnCounter,
144  std::vector<float>& livevec) const
145 {
146  if (turnCounter == 0) {
147  return StatusCode::SUCCESS;
148  }
149 
150  // Verify length. Due to a bug, this was sometimes written with 3654 entries
151  // rather than the desired 3564.
152  if ( static_cast<uint32_t>( blob.size() ) < 3*LuminosityCondData::TOTAL_LHC_BCIDS) {
153  ATH_MSG_WARNING( "Deadtime BLOB with " << blob.size() << " < 3 * "
155  return StatusCode::SUCCESS;
156  }
157 
158  assert (livevec.size() == LuminosityCondData::TOTAL_LHC_BCIDS);
159 
160  // Unpack one byte at a time
161  const uint8_t* p = static_cast<const uint8_t*>(blob.startingAddress());
162  for (unsigned int i=0; i < LuminosityCondData::TOTAL_LHC_BCIDS; i++, p+=3)
163  {
164  unsigned int busyCounter = *p | (*(p+1) << 8) | (*(p+2) << 16);
165  livevec[i] = (turnCounter - busyCounter) / static_cast<float>(turnCounter);
166  }
167 
168  return StatusCode::SUCCESS;
169 }
170 
171 
182  const std::vector<float>& liveFractionLo,
183  const std::vector<float>& liveFractionHi,
184  float& lumiLiveFractionLo,
185  float& lumiLiveFractionHi)
186 {
187  double numsumlo = 0.;
188  double numsumhi = 0.;
189  double densum = 0.;
190 
191  // Just use physics bunch group
192  // ??? bcid 0 ignored? Was like that in TrigLivefractionTool.
193  for (unsigned int bcid = 1; bcid < LuminosityCondData::TOTAL_LHC_BCIDS; bcid++)
194  {
195  float bcidlum = lumi.lbLuminosityPerBCIDVector().at(bcid);
196  numsumlo += bcidlum * liveFractionLo.at(bcid);
197  numsumhi += bcidlum * liveFractionHi.at(bcid);
198  densum += bcidlum;
199  }
200 
201  if (densum > 0.) {
202  lumiLiveFractionLo = numsumlo/densum;
203  lumiLiveFractionHi = numsumhi/densum;
204  }
205  else {
206  lumiLiveFractionLo = 1;
207  lumiLiveFractionHi = 1;
208  }
209 
210  return StatusCode::SUCCESS;
211 }
TrigLiveFractionCondAlg::m_luminosityInputKey
SG::ReadCondHandleKey< LuminosityCondData > m_luminosityInputKey
Input luminosity data.
Definition: TrigLiveFractionCondAlg.h:94
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
TrigLiveFractionCondAlg.h
Conditions algorithm for trigger live fraction data.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigLiveFractionCondAlg::unpackDeadtime
StatusCode unpackDeadtime(const AthenaAttributeList &deadtimeFolder, unsigned int &turnCounter, std::vector< float > &liveFractionLo, std::vector< float > &liveFractionHi) const
Unpack information from the deadtime COOL folder.
Definition: TrigLiveFractionCondAlg.cxx:94
TrigLiveFractionCondAlg::m_trigLiveFractionOutputKey
SG::WriteCondHandleKey< TrigLiveFractionCondData > m_trigLiveFractionOutputKey
Output conditions object.
Definition: TrigLiveFractionCondAlg.h:99
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
LuminosityCondData::TOTAL_LHC_BCIDS
static constexpr unsigned int TOTAL_LHC_BCIDS
Definition: LuminosityCondData.h:27
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
TrigLiveFractionCondAlg::m_deadtimeFolderInputKey
SG::ReadCondHandleKey< AthenaAttributeList > m_deadtimeFolderInputKey
Input deadtime folder.
Definition: TrigLiveFractionCondAlg.h:89
TrigLiveFractionCondAlg::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: TrigLiveFractionCondAlg.cxx:21
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
event_number_t
EventIDBase::event_number_t event_number_t
Definition: IEvtIdModifierSvc.h:30
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteCondHandle.h
TrigLiveFractionCondAlg::lumiWeight
static StatusCode lumiWeight(const LuminosityCondData &lumi, const std::vector< float > &liveFractionLo, const std::vector< float > &liveFractionHi, float &lumiLiveFractionLo, float &lumiLiveFractionHi)
Calculate weighted average live fractions.
Definition: TrigLiveFractionCondAlg.cxx:181
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
LuminosityCondData
Definition: LuminosityCondData.h:23
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
TrigLiveFractionCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm execute method.
Definition: TrigLiveFractionCondAlg.cxx:35
lumiFormat.lumi
lumi
Definition: lumiFormat.py:106
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
Definition: GeoPrimitivesHelpers.h:347
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TrigLiveFractionCondAlg::unpackVector
StatusCode unpackVector(const coral::Blob &blob, unsigned int turnCounter, std::vector< float > &livevec) const
Unpack a single deadtime vector.
Definition: TrigLiveFractionCondAlg.cxx:142
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96