ATLAS Offline Software
Loading...
Searching...
No Matches
TileOFC2DBAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5//=== Event Info
8
9//=== AttributeList
10//#include "CoralBase/Attribute.h"
11#include "CoralBase/Blob.h"
12#include "CoralBase/AttributeListSpecification.h"
14
15//=== Tile includes
16#include "TileOFC2DBAlg.h"
20
21#include <vector>
22
23TileOFC2DBAlg::TileOFC2DBAlg(const std::string& name, ISvcLocator* pSvcLocator)
24 : AthAlgorithm(name, pSvcLocator)
25 , m_regSvc("IOVRegistrationSvc", name)
26
27{
28 declareProperty("OF2", m_of2 = true,"true => OF2, false => OF1");
33 declareProperty("FixedPhases", m_fixedPhases = true, "calculate OFCs for fixed phases" );
34 declareProperty("RunType", m_runType = "PHY", "PHY or LAS");
35
36 declareProperty("FixedPhasesNumber", m_nFixedPhases = 100);
37 declareProperty("PhaseStep", m_phaseStep = 0.5);
38 declareProperty("MaxChan", m_maxChan = 1, "Number of channels for which OFCs will be created with fixed phases");
39 declareProperty("Modules", m_modules = {"AUX01"}, "Modules for which OFC should be stored in DB");
40 declareProperty("CreateAllModules", m_creatAllModules = true, "All missing modules is written to DB with zero size (empty)");
41}
42
45
46
47//____________________________________________________________________________
49
50 ATH_MSG_INFO( "Initializing for " << m_runType );
51
52 //=== EventInfo key
53 ATH_CHECK( m_eventInfoKey.initialize() );
54
55 //=== get TileToolTiming
56 CHECK( m_tileToolTiming.retrieve() );
57
58 //=== get TileCondToolOfc
59 CHECK( m_tileCondToolOfc.retrieve() );
60
61 //=== IOVRegistrationSvc
62 CHECK( m_regSvc.retrieve() );
63
64 std::map<std::string, unsigned int> roses = { {"AUX", 0}, {"LBA", 1}, {"LBC", 2}, {"EBA", 3}, {"EBC", 4} };
65
66 msg(MSG::INFO) << "OFC will be stored in DB for the following modules:";
67 for (const std::string& module : m_modules) {
68 msg(MSG::INFO) << " " << module;
69 m_drawerIdxs.push_back( TileCalibUtils::getDrawerIdx(roses[module.substr(0, 3)], std::stoi(module.substr(3, 2)) - 1) );
70 }
71 msg(MSG::INFO) << endmsg;
72
73 if (m_creatAllModules) ATH_MSG_INFO("All other missing modules will be stored in DB with zero size");
74
75 return StatusCode::SUCCESS;
76}
77
78//
79//_________________________________________________________________________
80StatusCode TileOFC2DBAlg::execute(const EventContext& ctx) {
81
82 //=== print run/evt/lbn/time info for each event
84 ATH_CHECK( eventInfo.isValid() );
85
86 ATH_MSG_DEBUG( "Event: ["
87 << eventInfo->runNumber() << ","
88 << eventInfo->eventNumber() << ":"
89 << eventInfo->timeStamp() << "]" );
90
91
92 //=== Create conditions objects only at run == ?, event == ?
93 if (1 != eventInfo->eventNumber()) {
94 ATH_MSG_DEBUG( "Event NOT selected for creating conditions objects " );
95 return StatusCode::SUCCESS;
96 } else {
97 ATH_MSG_DEBUG( "Creating conditions objects " );
98 }
99
100 //unsigned int objVersion = (m_of2) ? 3 : 1;
101 unsigned int objVersion = 3; // non efficient, but allows to keep dG also for OF1
102
103 //=== build the IOV range
105
106 //=== build COOL folder name based on ???????
107 std::string folder("/TILE/ONL01/FILTER/");
108 if (m_of2) folder += "OF2/" + m_runType;
109 else folder += "OF1/" + m_runType;
110 m_folders.insert(folder);
111
112 //=== create the folder layout
113 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
114 spec->extend("TileCalibBlobOfc", "blob");
115
116 //=== create the collection of attribute lists
117 CondAttrListCollection* attrListColl = new CondAttrListCollection(true);
118
119 float zeroPhase(0.0);
121 ATH_CHECK( m_tileCondToolOfc->getOfcWeights(0, 0, 0, zeroPhase, true, weights, ctx) );
122 int ndig = weights.n_samples;
123
124 // ---------- create fixed phases
125 if (m_fixedPhases) {
126 ATH_MSG_DEBUG( "Fixed phases: " << m_fixedPhases
127 << ", number of fixed phases: " << m_nFixedPhases
128 << ", phase step: " << m_phaseStep);
129
130 std::vector<float> phases;
131 phases.reserve(m_nFixedPhases * 2 + 1);
132
133 //=== create attribute list
134 coral::AttributeList ofcList(*spec);
135 coral::Blob& blob = ofcList["TileCalibBlobOfc"].data<coral::Blob>();
136
137 std::vector<bool> coolChannelCreated(TileCalibUtils::MAX_DRAWERIDX, false);
138
139 for (int iPhase = - m_nFixedPhases; iPhase <= m_nFixedPhases; ++iPhase) {
140 phases.push_back(iPhase * m_phaseStep);
141 }
142
143 int nPhases = phases.size();
144 TileCalibDrawerOfc* drawerOfc;
145
146 for (unsigned int drawerIdx : m_drawerIdxs) {
147 coolChannelCreated[drawerIdx] = true;
148 drawerOfc = TileCalibDrawerOfc::getInstance(blob, objVersion, ndig, -nPhases, m_maxChan, TileCalibUtils::MAX_GAIN); // nPhases, nChann, nGains
149
150 drawerOfc->setPhases(0, 0, phases);
151
152 for (unsigned int channel = 0; channel < m_maxChan; ++channel) {
153 for (unsigned int gain = 0; gain < TileCalibUtils::MAX_GAIN; ++gain) {
154
155 for (float phase : phases) {
156 ATH_CHECK( m_tileCondToolOfc->getOfcWeights(drawerIdx, channel, gain, phase, m_of2, weights, ctx) );
157 for (int isam = 0; isam < ndig; isam++) {
158 drawerOfc->setOfc(TileCalibDrawerOfc::FieldA, channel, gain, phase, isam, weights.w_a[isam]);
159 drawerOfc->setOfc(TileCalibDrawerOfc::FieldB, channel, gain, phase, isam, weights.w_b[isam]);
160 drawerOfc->setOfc(TileCalibDrawerOfc::FieldG, channel, gain, phase, isam, weights.g[isam]);
161 if (objVersion == 3) {
162 drawerOfc->setOfc(TileCalibDrawerOfc::FieldC, channel, gain, phase, isam, weights.w_c[isam]);
163 drawerOfc->setOfc(TileCalibDrawerOfc::FieldDG, channel, gain, phase, isam, weights.dg[isam]);
164 }
165 }
166
167
168 if (msgLvl(MSG::DEBUG)) {
169
170 msg(MSG::DEBUG) << " N Samples " << ndig
171 << " channel " << channel
172 << " drawerIdx " << drawerIdx
173 << " gain " << gain
174 << " phase = " << phase << endmsg;
175
176 msg(MSG::DEBUG) << "gain " << gain << " w_a, phase " << phase << " ";
177 for (int isam = 0; isam < ndig; ++isam)
178 msg(MSG::DEBUG) << " " << weights.w_a[isam];
179 msg(MSG::DEBUG) << endmsg;
180
181 msg(MSG::DEBUG) << "gain " << gain << " w_b, phase " << phase << " ";
182 for (int isam = 0; isam < ndig; isam++)
183 msg(MSG::DEBUG) << " " << weights.w_b[isam];
184 msg(MSG::DEBUG) << endmsg;
185
186 if (m_of2) {
187 msg(MSG::DEBUG) << "gain " << gain << " w_c, phase " << phase << " ";
188 for (int isam = 0; isam < ndig; isam++)
189 msg(MSG::DEBUG) << " " << weights.w_c[isam];
190 msg(MSG::DEBUG) << endmsg;
191 }
192
193 msg(MSG::DEBUG) << "gain " << gain << " g, phase " << phase << " ";
194 for (int isam = 0; isam < ndig; isam++)
195 msg(MSG::DEBUG) << " " << weights.g[isam];
196 msg(MSG::DEBUG) << endmsg;
197
198 }
199
200 }
201 }
202
203
204 }
205
206 //=== use DrawerHash as channel number
207 attrListColl->add(drawerIdx, ofcList);
208
209 //=== add the IOV range for this collection
210 attrListColl->add(drawerIdx, range);
211 // drawerOfc->dump();
212 delete drawerOfc;
213
214 }
215
216 //=== Create empty blobs for all COOL channels (for missing drawers)
217 if (m_creatAllModules) {
218 for (unsigned int coolChannel = 0; coolChannel < TileCalibUtils::MAX_DRAWERIDX; ++coolChannel) {
219 if (coolChannelCreated[coolChannel]) continue;
220 //=== create attribute list for this drawer
221 coral::AttributeList ofcList(*spec);
222 //coral::Blob& blob=ofcList["TileCalibBlobOfc"].data<coral::Blob>();
223 attrListColl->add(coolChannel, ofcList);
224 attrListColl->add(coolChannel, range);
225 }
226 }
227
228 } else { // take best phase from DB and calculate OFCs for each channel
229
230 std::vector<float> phases(TileCalibUtils::MAX_CHAN);
231
232 //=== create attribute list
233 coral::AttributeList ofcList(*spec);
234 coral::Blob& blob = ofcList["TileCalibBlobOfc"].data<coral::Blob>();
235
236 //=== create an OFC blob interpreter
237 TileCalibDrawerOfc* drawerOfc = TileCalibDrawerOfc::getInstance(blob, objVersion, ndig, -48, 256, 2); // nPhases, nChann, nGains
238
239 for (unsigned int channel = 0; channel < TileCalibUtils::MAX_CHAN; ++channel)
240 phases[channel] = (float) channel;
241
242 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
243 for (unsigned int drawer = 0; drawer < TileCalibUtils::getMaxDrawer(ros); ++drawer) {
244 unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
245 drawerOfc->setPhases(drawerIdx, 0, phases);
246
247 for (unsigned int channel = 0; channel < TileCalibUtils::MAX_CHAN; ++channel) {
248
249 for (unsigned int gain = 0; gain < TileCalibUtils::MAX_GAIN; ++gain) {
250
251 float phase = m_tileToolTiming->getSignalPhase(drawerIdx, channel, gain);
252 ATH_MSG_DEBUG( "m_tileToolTiming:"
253 << " drawerIdx " << drawerIdx
254 << " channel " << channel
255 << " gain " << gain
256 << " phase " << phase );
257
258 ATH_CHECK( m_tileCondToolOfc->getOfcWeights(drawerIdx, channel, gain, phase, m_of2, weights, ctx) );
259 ATH_MSG_DEBUG( " N Samples " << ndig
260 << " ros " << ros
261 << " drawer " << drawer
262 << " channel " << channel
263 << " drawerIdx " << drawerIdx
264 << " gain " << gain
265 << " phase = " << phase );
266
267 double w_a_sum = 0, w_b_sum = 0, w_c_sum = 0;
268 for (int isam = 0; isam < ndig; isam++) {
269 if (m_of2) {
270 ATH_MSG_DEBUG( " sampling " << isam
271 << " w_a " << weights.w_a[isam]
272 << " w_b " << weights.w_b[isam]
273 << " w_c " << weights.w_c[isam]
274 << " g " << weights.g[isam] );
275
276 } else {
277 ATH_MSG_DEBUG( " sampling " << isam
278 << " w_a " << weights.w_a[isam]
279 << " w_b " << weights.w_b[isam]
280 << " g " << weights.g[isam] );
281
282 }
283
284 w_a_sum += weights.w_a[isam];
285 w_b_sum += weights.w_b[isam];
286 w_c_sum += weights.w_c[isam];
287
288 drawerOfc->setOfc(0, drawerIdx, gain, channel, isam, weights.w_a[isam]);
289 drawerOfc->setOfc(1, drawerIdx, gain, channel, isam, weights.w_b[isam]);
290 if (m_of2) {
291 drawerOfc->setOfc(2, drawerIdx, gain, channel, isam, weights.w_c[isam]);
292 drawerOfc->setOfc(3, drawerIdx, gain, channel, isam, weights.g[isam]);
293 } else {
294 drawerOfc->setOfc(2, drawerIdx, gain, channel, isam, weights.g[isam]);
295 }
296 }
297
298 if (m_of2) ATH_MSG_DEBUG( " *** SUM: a,b,c " << w_a_sum << " " << w_b_sum << " " << w_c_sum );
299
300 } // for ... gain
301 } // for ... channel
302
303 //=== use DrawerHash as channel number
304 attrListColl->add(drawerIdx, ofcList);
305
306 //=== add the IOV range for this collection
307 attrListColl->add(drawerIdx, range);
308 // drawerOfc->dump();
309 } // for ... drawer
310 } // for ... ros
311 delete drawerOfc;
312 }
313
314 //=== add the comment in the comment channel
315 coral::AttributeList attrList(*spec);
316 coral::Blob& blob = attrList["TileCalibBlobOfc"].data<coral::Blob>();
317 const char* user = getenv("USER");
318 TileCalibDrawerCmt* comment = TileCalibDrawerCmt::getInstance(blob, (user ? user : "tilecomm"), "OFC weights calculated by TileCondToolOfc");
319 delete comment;
320 attrListColl->add(TileCalibUtils::getCommentChannel(), attrList);
321 attrListColl->add(TileCalibUtils::getCommentChannel(), range);
322
323 spec->release();
324 // cppcheck-suppress memleak
325 spec = nullptr;
326
327 //=== recored collection in store gate
328 CHECK( detStore()->record(attrListColl, folder) );
329
330 //=======================================
331 //=== Print conditions data in detector store
332 //=======================================
333 ATH_MSG_DEBUG( "Calling printCondObjects" );
334
336
337 return StatusCode::SUCCESS;
338}
339
340//
341//________________________________________________________________________
343
344 ATH_MSG_INFO( "in finalize()" );
345
346 //=== Register objects in DB
348
349 ATH_MSG_DEBUG( "Register OK " );
350
351 return StatusCode::SUCCESS;
352}
353
354
355//
356//___________________________________________________________________
358
359 ATH_MSG_DEBUG( "entering registerCondObject " );
360
361 for (std::set<std::string>::const_iterator iFolder = m_folders.begin();
362 iFolder != m_folders.end(); ++iFolder) {
363
364 const CondAttrListCollection* attrListColl = nullptr;
365 CHECK( detStore()->retrieve(attrListColl, *iFolder) );
366
367 if (nullptr == attrListColl) {
368 ATH_MSG_ERROR( "Has not retrieved AttributeListCollection (ptr is 0) from " << *iFolder );
369 return (StatusCode::FAILURE);
370 } else {
371 ATH_MSG_DEBUG( "Retrieved AttributeListCollection from " << *iFolder );
372 }
373
374 //=== register in COOL
375 std::string tag = "";
376 CHECK( m_regSvc->registerIOV("CondAttrListCollection", *iFolder, tag) );
377
378 ATH_MSG_DEBUG( "Registered folder " << *iFolder << " with tag " << tag );
379
380 } //end iFolder
381
382 return StatusCode::SUCCESS;
383}
384
385//
386//__________________________________________________________________
388
389 ATH_MSG_INFO( "in printCondObjects()" );
390
391 //=== loop over all folders
392 for (std::set<std::string>::const_iterator iFolder = m_folders.begin();
393 iFolder != m_folders.end(); ++iFolder) {
394
395 ATH_MSG_DEBUG( "Printing content of folder: " << *iFolder );
396
397 //=== determine blob name
398 std::string blobName("TileCalibBlob");
399 if (iFolder->find("/TILE/ONL01/FILTER") != std::string::npos) {
400 blobName += "Ofc";
401 }
402
403 ATH_MSG_DEBUG( "The blob name is: " << blobName );
404
405 const CondAttrListCollection* attrListColl(nullptr);
406 CHECK( detStore()->retrieve(attrListColl, *iFolder) );
407
408 if (!attrListColl) {
409 ATH_MSG_ERROR("Has not retrieved AttributeListCollection (ptr is 0) from " << *iFolder );
410 return StatusCode::FAILURE;
411 }
412
413 //=== find the general comment
414 std::string generalComment("");
416 if (iComment != attrListColl->end()) {
417 const coral::Blob& blob = (iComment->second)[blobName].data<coral::Blob>();
419 generalComment = cmt->getFullComment();
420 delete cmt;
421 }
422
423 //=== loop over collection
424 CondAttrListCollection::const_iterator iColl = attrListColl->begin();
425 CondAttrListCollection::const_iterator last = attrListColl->end();
426 for (; iColl != last; ++iColl) {
427
428 //=== do not print comment channel
429 if (iColl == iComment) continue;
430
431 //=== try to find comment for this drawer
432 const coral::Blob& blob = (iColl->second)[blobName].data<coral::Blob>();
433 //=== do not print empty blobs
434 if (!blob.size()) {
435 continue;
436 }
437
439 std::ostringstream attrStr1;
440 (*iColl).second.toOutputStream(attrStr1);
441 ATH_MSG_DEBUG( "ChanNum " << (*iColl).first << " Attribute list " << attrStr1.str() );
442
443 // Print out range if it exits
444 CondAttrListCollection::ChanNum chanNum = (*iColl).first;
445 CondAttrListCollection::iov_const_iterator iovIt = attrListColl->chanIOVPair(chanNum);
446 if (iovIt != attrListColl->iov_end()) {
447 const IOVRange& range = (*iovIt).second;
448 if (range.start().isTimestamp()) {
449 ATH_MSG_DEBUG( "Range timestamp :"
450 << " since " << range.start().timestamp()
451 << " till " << range.stop().timestamp() );
452
453 } else {
454 ATH_MSG_DEBUG( "Range R/LB :"
455 << " since " << range.start().run() << " " << range.start().event()
456 << " till " << range.stop().run() << " " << range.stop().event() );
457 }
458 } else {
459 ATH_MSG_DEBUG( "No range found " );
460 }
461
462 //=== print the comment
463 std::string comment = cmt->getFullComment();
464 if (comment.empty()) {
465 comment = generalComment;
466 }
467 ATH_MSG_DEBUG( "Comment: " << comment );
468 delete cmt;
469
470 }
471 } //end iFolder
472
473 return StatusCode::SUCCESS;
474}
475
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
iov_const_iterator iov_end() const
iov_const_iterator chanIOVPair(ChanNum chanNum) const
Access to Chan/IOV pairs via channel number: returns map iterator.
ChanAttrListMap::const_iterator const_iterator
ChanIOVMap::const_iterator iov_const_iterator
const_iterator chanAttrListPair(ChanNum chanNum) const
Access to Chan/AttributeList pairs via channel number: returns map iterator.
Validity Range object.
Definition IOVRange.h:30
Basic time unit for IOVSvc.
Definition IOVTime.h:33
static constexpr uint32_t MAXRUN
Definition IOVTime.h:48
static constexpr uint32_t MINEVENT
Definition IOVTime.h:50
static constexpr uint32_t MAXEVENT
Definition IOVTime.h:51
static constexpr uint32_t MINRUN
Definition IOVTime.h:44
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class to store comments in BLOB without any data.
static const TileCalibDrawerCmt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerCmt.
static TileCalibDrawerOfc * getInstance(coral::Blob &blob, uint16_t objVersion, uint32_t nSamples, int32_t nPhases, uint16_t nChans, uint16_t nGains, std::string_view author="", std::string_view comment="", uint64_t timeStamp=0)
Returns a pointer to a non-const TileCalibDrawerOfc.
static const unsigned int MAX_DRAWERIDX
Maximal drawer index.
static const unsigned int MAX_ROS
Number of ROSs.
static const unsigned int MAX_GAIN
Number of gains per channel.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
static unsigned int getCommentChannel()
Returns the COOL channel number for the comment channel.
static const unsigned int MAX_CHAN
Number of channels in drawer.
std::string m_runType
std::set< std::string > m_folders
ToolHandle< ITileCondToolOfc > m_tileCondToolOfc
UnsignedIntegerProperty m_runIOVUntil
UnsignedIntegerProperty m_lbnIOVUntil
StatusCode finalize()
TileOFC2DBAlg(const std::string &name, ISvcLocator *pSvcLocator)
UnsignedIntegerProperty m_maxChan
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
ToolHandle< TileCondToolTiming > m_tileToolTiming
StatusCode initialize()
ServiceHandle< IIOVRegistrationSvc > m_regSvc
UnsignedIntegerProperty m_runIOVSince
StatusCode registerCondObjects()
UnsignedIntegerProperty m_lbnIOVSince
std::vector< unsigned int > m_drawerIdxs
std::vector< std::string > m_modules
StatusCode printCondObjects()
StatusCode execute(const EventContext &ctx)
Execute method.