ATLAS Offline Software
Loading...
Searching...
No Matches
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>
15#include "CoralBase/AttributeListException.h"
16
17namespace {
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
32 std::numeric_limits<int>::max() - 1, // ns
33 std::numeric_limits<int>::max() - 1 // LB
34 );
35 }
36
37}
38
40
41
42 if (m_mode == 2) {
43 ATH_CHECK( m_trigConfigSvc.retrieve() );
44 }
45
46 ATH_CHECK( m_fillParamsFolderKey.initialize( m_mode == 0 || m_mode == 1 ) );
47 ATH_CHECK( m_lumiCondDataKey.initialize( m_mode == 3 ) );
48 ATH_CHECK( m_outputKey.initialize() );
49 return StatusCode::SUCCESS;
50}
51
52
53StatusCode 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
220std::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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Conditions algorithm to fill BunchCrossingIntensityCondData.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
const ServiceHandle< TrigConf::ILVL1ConfigSvc > m_trigConfigSvc
SG::ReadCondHandleKey< CondAttrListCollection > m_fillParamsFolderKey
Input conditions object.
virtual StatusCode initialize() override
Gaudi initialize method.
SG::ReadCondHandleKey< LuminosityCondData > m_lumiCondDataKey
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm execute method.
Gaudi::Property< unsigned long > m_fBCT
SG::WriteCondHandleKey< BunchCrossingIntensityCondData > m_outputKey
Output conditions object.
std::vector< float > tokenize(const std::string &pattern) const
internal methods:
Gaudi::Property< unsigned long > m_BPTX
This class is a collection of AttributeLists where each one is associated with a channel number.
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Read little-endian values through possibly unaligned pointers.
int lb
Definition globals.cxx:23
float get_unaligned_float(const uint8_t *ATH_RESTRICT &p)
Read a little-endian float value from a possibly unaligned pointer.
Definition run.py:1
#define ATH_RESTRICT
Definition restrict.h:31