ATLAS Offline Software
BunchCrossingIntensityCondAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
3  */
4 
6 #include "CoolKernel/IObject.h"
7 #include "CoralBase/Blob.h"
10 #include <charconv>
11 #include <cstdint>
12 #include <bitset>
13 #include "CxxUtils/get_unaligned.h"
15 #include "CoralBase/AttributeListException.h"
16 
17 namespace {
18  // helper to set timestamp based IOV with infinit range
19  EventIDBase infiniteIOVBegin() {
20  return EventIDBase( 0, // run,
21  EventIDBase::UNDEFEVT, // event
22  0, // seconds
23  0, // ns
24  0 // LB
25  );
26  }
27 
28  EventIDBase infiniteIOVEend() {
29  return EventIDBase( std::numeric_limits<int>::max() - 1, // run
30  EventIDBase::UNDEFEVT, // event
31  std::numeric_limits<int>::max() - 1, // seconds
34  );
35  }
36 
37 }
38 
40 
41 
42  if (m_mode == 2) {
43  ATH_CHECK( m_trigConfigSvc.retrieve() );
44  }
45 
49  return StatusCode::SUCCESS;
50 }
51 
52 
53 StatusCode BunchCrossingIntensityCondAlg::execute (const EventContext& ctx) const {
54 
56  if (writeHdl.isValid()) {
57 
58 
59  ATH_MSG_DEBUG("Found valid write handle");
60  return StatusCode::SUCCESS;
61  }
62  // make sure that the output IOV has a valid timestamp, otherwise the conditions
63  // data cannot be added to the "mixed" conditions data container. A mixed container
64  // is needed when the conditions depends on e.g. the LuminosityCondData
65  EventIDRange infinite_range(infiniteIOVBegin(),infiniteIOVEend());
66  writeHdl.addDependency(infinite_range);
67 
68 
69  //Output object & range:
70  auto bccd=std::make_unique<BunchCrossingIntensityCondData>();
71 
72  if (m_mode == 2) { // use trigger bunch groups
73  // To be filled
74  }
75 
76  if (m_mode == 3) { // use luminosity data
77  // To be filled
78  }
79 
80  if (m_mode == 0 || m_mode == 1) { // use FILLPARAMS (data) or /Digitization/Parameters (MC)
81 
83  writeHdl.addDependency(fillParamsHdl);
84  const CondAttrListCollection* attrList_link=*fillParamsHdl;
85  const coral::AttributeList& attrList = attrList_link->attributeList (m_BPTX);
86 
87  if (attrList.size() == 0 || attrList["Valid"].isNull()) {
88  ATH_MSG_DEBUG ("Can't find information for channel " << m_BPTX);
89  return StatusCode::SUCCESS;
90  }
91 
92 
93  const coral::AttributeList& attrList_fBCT = attrList_link->attributeList (m_fBCT);
94 
95  if (attrList_fBCT.size() == 0 || attrList_fBCT["Valid"].isNull()) {
96  ATH_MSG_DEBUG ("Can't find information for channel " << m_fBCT);
97  return StatusCode::SUCCESS;
98  }
99 
100  // const auto& thisevt = ctx.eventID();
101 
102  if (m_mode == 1) {
103  ATH_MSG_INFO("Assuming MC case");
104  ATH_MSG_INFO("Got AttributeList with size " << attrList.size());
105  ATH_MSG_INFO("Got AttributeList fBCT with size " << attrList_fBCT.size());
106 
107  }
108  else { // mode == 0, Data-case
109 
110  float nb1 = attrList["B1BunchAverage"].data<cool::Float>();
111  float nb2 = attrList["B2BunchAverage"].data<cool::Float>();
112  float nb1_fBCT = attrList_fBCT["B1BunchAverage"].data<cool::Float>();
113  float nb2_fBCT = attrList_fBCT["B2BunchAverage"].data<cool::Float>();
114 
115  unsigned long long RunLB = attrList["RunLB"].data<unsigned long long >();
116 
117  int run = RunLB>>32;
118  int lb = RunLB & 0xffffffff;
119  ATH_MSG_DEBUG( "Beam1Intensity: " << nb1 );
120  ATH_MSG_DEBUG( "Beam2Intensity: " << nb2 );
121  ATH_MSG_DEBUG( "Run: " << run );
122  ATH_MSG_DEBUG( "LB: " << lb );
123 
124  const coral::Blob& blob1 = attrList["B1BunchIntensities"].data<coral::Blob>();
125  const coral::Blob& blob2 = attrList["B2BunchIntensities"].data<coral::Blob>();
126  const coral::Blob& blob1_fBCT = attrList_fBCT["B1BunchIntensities"].data<coral::Blob>();
127  const coral::Blob& blob2_fBCT = attrList_fBCT["B2BunchIntensities"].data<coral::Blob>();
128 
129 
130  if (m_isRun1) { //Assume run1 layout as explained at https://twiki.cern.ch/twiki/bin/view/AtlasComputing/CoolOnlineData
131  ATH_MSG_DEBUG("Assuming run 1 database");
132 
133  }
134  else {
135 
136  bccd->SetBeam1IntensityAll(nb1,0);
137  bccd->SetBeam2IntensityAll(nb2,0);
138  bccd->SetBeam1IntensityAll(nb1_fBCT,1);
139  bccd->SetBeam2IntensityAll(nb2_fBCT,1);
140  bccd->SetRunLB(RunLB);
141 
142  //=========== BPTX===================
143  //Blob1
144  // Hardcode the Run2 BLOB decoding (should use CoolLumiUtilities...)
145  const uint8_t* ATH_RESTRICT pchar1 = static_cast<const uint8_t*>(blob1.startingAddress()); // First byte holds storage size and mode
146  ++pchar1; // Points to next char after header
147  unsigned int nbcids = BunchCrossingIntensityCondData::m_MAX_BCID;
148 
149  std::vector<float> instBeam1 (nbcids);
150  for (unsigned int i=0; i<nbcids; i++) {
151  // Can't use assignment directly because source may be misaligned.
152  instBeam1[i] = CxxUtils::get_unaligned_float (pchar1);
153 
154  }
155 
156  // Blob2
157  // Hardcode the Run2 BLOB decoding (should use CoolLumiUtilities...)
158  const uint8_t* ATH_RESTRICT pchar2 = static_cast<const uint8_t*>(blob2.startingAddress()); // First byte holds storage size and mode
159  ++pchar2; // Points to next char after header
160  std::vector<float> instBeam2 (nbcids);
161  for (unsigned int i=0; i<nbcids; i++) {
162  // Can't use assignment directly because source may be misaligned.
163  instBeam2[i] = CxxUtils::get_unaligned_float (pchar2);
164 
165  }
166 
167  bccd->setBeam1IntensityPerBCIDVector(std::move(instBeam1),0);
168  bccd->setBeam2IntensityPerBCIDVector(std::move(instBeam2),0);
169  //
170 
171 
172  //=========== fBCT ===================
173  //Blob1
174  // Hardcode the Run2 BLOB decoding (should use CoolLumiUtilities...)
175  const uint8_t* ATH_RESTRICT pchar1_fBCT = static_cast<const uint8_t*>(blob1_fBCT.startingAddress()); // First byte holds storage size and mode
176  ++pchar1_fBCT; // Points to next char after header
177  unsigned int nbcids_fBCT = BunchCrossingIntensityCondData::m_MAX_BCID;
178 
179  std::vector<float> instBeam1_fBCT (nbcids_fBCT);
180  for (unsigned int i=0; i<nbcids_fBCT; i++) {
181  // Can't use assignment directly because source may be misaligned.
182  instBeam1_fBCT[i] = CxxUtils::get_unaligned_float (pchar1_fBCT);
183 
184  }
185 
186  // Blob2
187  // Hardcode the Run2 BLOB decoding (should use CoolLumiUtilities...)
188  const uint8_t* ATH_RESTRICT pchar2_fBCT = static_cast<const uint8_t*>(blob2_fBCT.startingAddress()); // First byte holds storage size and mode
189  ++pchar2_fBCT; // Points to next char after header
190  std::vector<float> instBeam2_fBCT (nbcids_fBCT);
191  for (unsigned int i=0; i<nbcids_fBCT; i++) {
192  // Can't use assignment directly because source may be misaligned.
193  instBeam2_fBCT[i] = CxxUtils::get_unaligned_float (pchar2_fBCT);
194 
195  }
196 
197  bccd->setBeam1IntensityPerBCIDVector(std::move(instBeam1_fBCT),1);
198  bccd->setBeam2IntensityPerBCIDVector(std::move(instBeam2_fBCT),1);
199 
200 
201  }//end else run2
202  //Filled bcid-bitsets, now extract trains
203  // bccd->m_trains=findTrains(bccd->m_luminous, m_maxBunchSpacing,m_minBunchesPerTrain);
204  }//end else is data
205  }
206 
207  ATH_CHECK( writeHdl.record (std::move (bccd)) );
208  return StatusCode::SUCCESS;
209 }
210 
211 
220 std::vector<float> BunchCrossingIntensityCondAlg::tokenize( const std::string& pattern ) const {
221  ATH_MSG_VERBOSE("Input to tokenize: " << pattern);
222 
223  std::vector< float > result;
224  const char* c= pattern.data();
225  const char* cEnd= c + pattern.size();
226  while(c<cEnd) {
227  //This loop swallows actually any string containing numbers
228  //separated by non-numbers
229  char* end;
230  float f=std::strtof(c,&end);
231  if (c==end) {//Can't convert, try next
232  c++;
233  }
234  else { //got a value
235  result.push_back(f);
236  c=end;
237  }
238  }//end while loop
239  return result;
240 }
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
get_generator_info.result
result
Definition: get_generator_info.py:21
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
BunchCrossingIntensityCondAlg::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: BunchCrossingIntensityCondAlg.cxx:39
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
BunchCrossingIntensityCondAlg::m_fillParamsFolderKey
SG::ReadCondHandleKey< CondAttrListCollection > m_fillParamsFolderKey
Input conditions object.
Definition: BunchCrossingIntensityCondAlg.h:50
BunchCrossingIntensityCondAlg::m_isRun1
Gaudi::Property< bool > m_isRun1
Definition: BunchCrossingIntensityCondAlg.h:72
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
BunchCrossingIntensityCondAlg::m_fBCT
Gaudi::Property< unsigned long > m_fBCT
Definition: BunchCrossingIntensityCondAlg.h:67
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
ReadCondHandle.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ATH_RESTRICT
#define ATH_RESTRICT
Definition: restrict.h:31
CxxUtils::get_unaligned_float
float get_unaligned_float(const uint8_t *ATH_RESTRICT &p)
Read little-endian float value from a possibly unaligned pointer.
Definition: get_unaligned.h:122
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
run
Definition: run.py:1
CondAttrListCollection::attributeList
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
Definition: CondAttrListCollection.h:401
BunchCrossingIntensityCondAlg::m_mode
Gaudi::Property< int > m_mode
Definition: BunchCrossingIntensityCondAlg.h:73
get_unaligned.h
Read little-endian values through possibly unaligned pointers.
BunchCrossingIntensityCondAlg::m_BPTX
Gaudi::Property< unsigned long > m_BPTX
Definition: BunchCrossingIntensityCondAlg.h:66
BunchCrossingIntensityCondAlg::tokenize
std::vector< float > tokenize(const std::string &pattern) const
internal methods:
Definition: BunchCrossingIntensityCondAlg.cxx:220
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
BunchCrossingIntensityCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm execute method.
Definition: BunchCrossingIntensityCondAlg.cxx:53
BunchCrossingIntensityCondAlg::m_lumiCondDataKey
SG::ReadCondHandleKey< LuminosityCondData > m_lumiCondDataKey
Definition: BunchCrossingIntensityCondAlg.h:51
BunchCrossingIntensityCondAlg::m_outputKey
SG::WriteCondHandleKey< BunchCrossingIntensityCondData > m_outputKey
Output conditions object.
Definition: BunchCrossingIntensityCondAlg.h:55
AsgConfigHelper::strtof
bool strtof(const std::string &input, T &f)
Definition: AsgEGammaConfigHelper.cxx:47
BunchCrossingIntensityCondAlg.h
Conditions algorithm to fill BunchCrossingIntensityCondData.
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
BunchCrossingIntensityCondData::m_MAX_BCID
static constexpr int m_MAX_BCID
Definition: BunchCrossingIntensityCondData.h:28
python.compressB64.c
def c
Definition: compressB64.py:93
ReadCellNoiseFromCoolCompare.blob2
blob2
Definition: ReadCellNoiseFromCoolCompare.py:306
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
BunchCrossingIntensityCondAlg::m_trigConfigSvc
const ServiceHandle< TrigConf::ILVL1ConfigSvc > m_trigConfigSvc
Definition: BunchCrossingIntensityCondAlg.h:58
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275