Algorithm execute method.
37 {
38
39 SG::WriteCondHandle<BunchCrossingCondData> writeHdl(
m_outputKey, ctx);
40 if (writeHdl.isValid()) {
42 return StatusCode::SUCCESS;
43 }
44
45
46
48
49
50 auto bccd=std::make_unique<BunchCrossingCondData>();
51
53 const TrigConf::L1BunchGroupSet* bgs{nullptr};
56 if (! bgsh.isValid()) {
58 return StatusCode::FAILURE;
59 }
60 bgs = *bgsh;
61 } else {
63 }
64
65 if (bgs->
size() >= 2) {
68 bccd->m_beam1.set(pos);
69 bccd->m_beam2.set(pos);
70 bccd->m_luminous.set(pos);
71 }
72 }
73 else {
75 }
76
77
78 if (bgs->
size() >= 15) {
80 bccd->m_beam1.set(pos);
81 }
83 bccd->m_beam2.set(pos);
84 }
85 }
86
88
89 const auto& thisevt = ctx.eventID();
90 EventIDRange
range = EventIDRange(EventIDBase(thisevt.run_number(), EventIDBase::UNDEFEVT,
91 EventIDBase::UNDEFNUM, 0, thisevt.lumi_block()),
92 EventIDBase(thisevt.run_number(), EventIDBase::UNDEFEVT,
93 EventIDBase::UNDEFNUM, 0, thisevt.lumi_block()+1));
94 writeHdl.addDependency(range);
95 }
96
99 writeHdl.addDependency(prefLumiHdl);
100
101
102 float avMu = prefLumiHdl->lbAverageInteractionsPerCrossing();
103 const auto& lumiVec = prefLumiHdl->lbLuminosityPerBCIDVector();
104 float cutLumi = avMu/1000.f*prefLumiHdl->muToLumi();
105
107 if (lumiVec[bcid] > cutLumi) {
108 bccd->m_beam1.set(bcid);
109 bccd->m_beam2.set(bcid);
110 bccd->m_luminous.set(bcid);
111 }
112 }
113
115 }
116
118
119 std::string sbunches;
120 const AthenaAttributeList* attrList = nullptr;
121
123
125 bool foundInDigitization = false;
126
129 writeHdl.addDependency(fillParamsHdl);
130 const AthenaAttributeList* attrList=*fillParamsHdl;
131
132 if (attrList) {
133 ATH_MSG_INFO(
"Got AttributeList with size " << attrList->size());
134 try {
135 const coral::Attribute& attr=(*attrList)[std::string("BeamIntensityPattern")];
136 if (!attr.isNull()) {
137 sbunches = attr.data< std::string >();
138 foundInDigitization = true;
139 ATH_MSG_DEBUG(
"Read BeamIntensityPattern from Digitization folder");
140 }
141 } catch (coral::AttributeListException& e) {
142 ATH_MSG_DEBUG(
"Could not read from Digitization folder: " <<
e.what());
143 }
144 }
145 }
146
147
148 if (!foundInDigitization) {
150
151 if (bsMetadata.isValid() && !bsMetadata->empty()) {
152 const ByteStreamMetadata*
metadata = bsMetadata->at(0);
153 const std::vector<std::string>& freeStrings =
metadata->getFreeMetaDataStrings();
154
155 for (const std::string& str : freeStrings) {
156 if (
str.starts_with(
"IOVMeta./Digitization/Parameters=")) {
157 size_t eqPos =
str.find(
'=');
158 if (eqPos != std::string::npos && eqPos + 1 <
str.size()) {
160
161 try {
162 nlohmann::json iovMetadata = nlohmann::json::parse(jsonStr);
163
164 if (iovMetadata.contains("iovs") && iovMetadata["iovs"].is_array() && !iovMetadata["iovs"].empty()) {
165 const auto& firstIov = iovMetadata["iovs"][0];
166 if (firstIov.contains("attrs")) {
167 for (
const auto& chanItem : firstIov[
"attrs"].
items()) {
168 const auto& chanAttrs = chanItem.value();
169 if (chanAttrs.contains("BeamIntensityPattern")) {
170 sbunches = chanAttrs["BeamIntensityPattern"].get<std::string>();
171 ATH_MSG_INFO(
"Read BeamIntensityPattern from ByteStream metadata");
172 break;
173 }
174 }
175 if (!sbunches.empty()) break;
176 }
177 }
178 } catch (const std::exception& e) {
179 ATH_MSG_WARNING(
"Failed to parse IOV metadata from ByteStream: " <<
e.what());
180 }
181 }
182 }
183 }
184 }
185
186 if (sbunches.empty()) {
187 ATH_MSG_ERROR(
"Could not read BeamIntensityPattern from either Digitization folder or ByteStream metadata");
188 return StatusCode::FAILURE;
189 }
190 }
191
192 const float minBunchIntensity=0.001;
193 std::vector<float> bunches=
tokenize(sbunches);
194 if (!bunches.empty()) {
195
197
199
200
201
203 const int pos1 =
i % bunches.size();
204 const int pos2 = bunches.size() - 1 - (
i % bunches.size() );
205 if( bunches[ pos1 ] > minBunchIntensity) {
206 bccd->m_beam1.set(i);
207 bccd->m_beam2.set(i);
208 bccd->m_luminous.set(i);
209 }
210 if( bunches[ pos2 ] > minBunchIntensity) {
214 }
215 }
216
217 } else {
218
219
222 const int pos =
i % bunches.size();
223 if( bunches[ pos ] > minBunchIntensity) {
224 bccd->m_beam1.set(i);
225 bccd->m_beam2.set(i);
226 bccd->m_luminous.set(i);
227 }
228 }
229 }
230
232 }
233 else {
234 ATH_MSG_INFO(
"Bunch structure information not found in metadata");
235 ATH_MSG_INFO(
"Will consider all BCIDs as single filled bunches (no trains)");
236 bccd->m_beam1.set();
237 bccd->m_beam2.set();
238 bccd->m_luminous.set();
239 }
240 }
241 else {
243 writeHdl.addDependency(fillParamsHdl);
244 attrList = *fillParamsHdl;
245
246 if ((*attrList)["BCIDmasks"].isNull()) {
248 return StatusCode::FAILURE;
249 }
250
251
252
253 cool::UInt32 nb1 = (*attrList)["Beam1Bunches"].data<cool::UInt32>();
254 cool::UInt32 nb2 = (*attrList)["Beam2Bunches"].data<cool::UInt32>();
255 cool::UInt32 ncol = (*attrList)["LuminousBunches"].data<cool::UInt32>();
256
260
261 const coral::Blob&
blob = (*attrList)[
"BCIDmasks"].data<coral::Blob>();
262
265
266 if (
static_cast<cool::UInt32
>(
blob.size() ) != 2 * (nb1 + nb2 + ncol)) {
268 return StatusCode::SUCCESS;
269 }
271
272 for (
size_t idx=0;
idx<nb1;++
idx) {
274 bccd->m_beam1.set(bcid);
275 }
276
277
278 for (
size_t idx=nb1;
idx<nb2;++
idx) {
280 bccd->m_beam2.set(bcid);
281 }
282
283
284 for (
size_t idx=nb2;
idx<ncol;++
idx) {
286 bccd->m_luminous.set(bcid);
287 }
288 }
289 else {
291
292
295 return StatusCode::FAILURE;
296 }
299 if (blobAddr[bcid] & 0x1) {
300 bccd->m_beam1.set(bcid);
301 }
302 if (blobAddr[bcid] & 0x2) {
303 bccd->m_beam2.set(bcid);
304 }
305 if ((blobAddr[bcid] & 0x3) == 0x3) {
306 bccd->m_luminous.set(bcid);
307 }
308 }
309
310
311 if (bccd->m_beam1.count()!= nb1) {
312 ATH_MSG_WARNING(
"Found " << bccd->m_beam1.count() <<
" bunches in beam1, expected " << nb1);
313 }
314
315 if (bccd->m_beam2.count()!= nb2) {
316 ATH_MSG_WARNING(
"Found " << bccd->m_beam2.count() <<
" bunches in beam2, expected " << nb2);
317 }
318
319 if (bccd->m_luminous.count()!= ncol) {
320 ATH_MSG_WARNING(
"Found " << bccd->m_luminous.count() <<
" colliding bunches, expected " << ncol);
321 }
322 }
323
325 }
326 }
327
328 ATH_CHECK( writeHdl.record (std::move (bccd)) );
329 return StatusCode::SUCCESS;
330}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
SG::ReadHandleKey< ByteStreamMetadataContainer > m_byteStreamMetadataKey
ByteStream metadata (for reading IOV metadata from BS files in MC mode)
std::vector< float > tokenize(const std::string &pattern) const
This helper function is used to convert a string of type "[0.0, 0.0, 1.0, 1.0, 1.0]" into a vector of...
Gaudi::Property< bool > m_isRun1
Gaudi::Property< int > m_mode
SG::WriteCondHandleKey< BunchCrossingCondData > m_outputKey
Output conditions object.
Gaudi::Property< unsigned > m_maxBunchSpacing
Gaudi::Property< unsigned > m_minBunchesPerTrain
std::vector< bunchTrain_t > findTrains(const std::bitset< BunchCrossingCondData::m_MAX_BCID > &pairsToConsume, const int maxSpacingInTrain, const unsigned minBunchesPerTrain) const
internal methods:
SG::ReadCondHandleKey< TrigConf::L1BunchGroupSet > m_bunchGroupCondDataKey
SG::ReadCondHandleKey< LuminosityCondData > m_lumiCondDataKey
const ServiceHandle< TrigConf::ILVL1ConfigSvc > m_trigConfigSvc
SG::ReadCondHandleKey< AthenaAttributeList > m_fillParamsFolderKey
Input conditions object.
static constexpr int m_MAX_BCID
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
static constexpr unsigned int TOTAL_LHC_BCIDS
std::size_t size() const
Accessor to the number of defined bunchgroups.
const std::shared_ptr< L1BunchGroup > & getBunchGroup(const std::string &name) const
Accessor to the bunchgroup by name.
setEventNumber setTimeStamp bcid