ATLAS Offline Software
Loading...
Searching...
No Matches
LArConditionsContainerDB.h
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5*/
6
7
8#ifndef LARRAWCONDITIONS_LARCONDITIONSCONTAINERDB_H
9#define LARRAWCONDITIONS_LARCONDITIONSCONTAINERDB_H
10
39
42#include <map>
43#include <unordered_map>
44#include <vector>
45
46template<class T>
48{
49public:
50
52 typedef typename Traits::FebId FebId;
56 typedef typename std::map<FebId, ChannelVectorPointer > ConditionsMap;
57 typedef typename std::unordered_map<FebId, ChannelVectorPointer > ConditionsHashMap;
58 typedef typename ChannelVector::const_iterator ConstChannelIt;
59 typedef typename ChannelVector::iterator ChannelIt;
60 typedef typename ConditionsMap::const_iterator ConstConditionsMapIterator;
61 typedef typename ConditionsMap::iterator ConditionsMapIterator;
62 typedef typename ConditionsMap::size_type size_type;
63 typedef std::vector<FebId> FebIdVec;
64 typedef typename Traits::Reference Reference;
66 typedef typename Traits::Pointer Pointer;
68
70 template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
72 {
73 public:
75 iteratorT(MAP_ITERATOR febit,
76 CHAN_ITERATOR chanit,
77 MAP_ITERATOR febendit,
78 const LArOnlineID_Base* onlineHelper);
79 iteratorT(MAP_ITERATOR febit,
80 CHAN_ITERATOR chanit,
81 MAP_ITERATOR febendit,
82 const LArOnlineID_Base* onlineHelper,
83 const FebIdVec& febIds);
84 REFERENCE operator*() const;
85 POINTER operator->() const;
88 bool operator!=(const iteratorT& a) const;
89 bool operator==(const iteratorT& a) const;
90 FebId getFebId() const;
91 int getChannel() const;
94
95 private:
96 CHAN_ITERATOR m_channelIt;
97 MAP_ITERATOR m_febIt;
98 // m_lastFebit is initialized with m_febMap.end()...
99 //...and decremented to point to the last filled FEB.
100 MAP_ITERATOR m_lastFebIt;
103 unsigned int m_febIdsIndex;
104
105
106 };
107
109 ChannelIt,
110 Pointer,
112
117
119 LArConditionsContainerDB(unsigned int gain = 0);
120
122 void set(const FebId id, const int channel, const T& payload);
123
125 ConstReference get(const FebId id, const int channel) const;
126
128 Reference getNonConst(const FebId id, const int channel);
129
132 bool exist(FebId id) const;
133
135 const_iterator begin(const LArOnlineID_Base* onlineHelper) const;
136 const_iterator end (const LArOnlineID_Base* onlineHelper) const;
137
138 iterator begin(const LArOnlineID_Base* onlineHelper);
139 iterator end (const LArOnlineID_Base* onlineHelper);
140
142 const_iterator begin(const LArOnlineID_Base* onlineHelper,
143 const FebIdVec& febIds) const;
144
145 iterator begin(const LArOnlineID_Base* onlineHelper,
146 const FebIdVec& febIds);
147
149 size_type size() const;
150
152 int getGain() const ;
153
155 void setGain(int g) ;
156
158 void add(const LArConditionsContainerDB<T>* p);
159
161 void add(FebId id, ChannelVectorPointer channelVec);
162
164 void erase(FebId id);
165
166protected:
167
168 // Store the FEB -> ChannelVector mapping twice: once as an ordered map
169 // (this will be used for iteration) and once as an unordered_map
170 // (this will be used for fast lookup).
173
174 unsigned int m_gain;
175
176private:
177 //Dummy iterators to mark the beginning and the end of an empty container instance
180};
181
182
183
184template<class T>
185inline
187 :
188 m_gain(gain)
189{}
190
191
192template<class T>
193inline
196{
197 if (m_febMap.size()==0) { //no elements yet, begin() and end() have to be identical
198 return m_dummyConstIt;
199 }
200 else {
201 return const_iterator(m_febMap.begin(),
202 m_febMap.begin()->second->begin(),
203 m_febMap.end(),
204 onlineHelper); }
205}
206
207template<class T>
208inline
211{
212 if (m_febMap.size()==0) { //no elements yet, begin() and end() have to be identical
213 return m_dummyIt;
214 }
215 else {
216 return iterator(m_febMap.begin(),
217 m_febMap.begin()->second->begin(),
218 m_febMap.end(),
219 onlineHelper); }
220}
221
222template<class T>
223inline
226 const FebIdVec& febIds) const
227{
228 if (m_febMap.size()==0) { //no elements yet, begin() and end() have to be identical
229 return m_dummyConstIt;
230 }
231 else {
232 if(febIds.size()==0) return end(onlineHelper);
233
235 for (FebId id : febIds) {
236 it2 = m_febMap.find(id);
237 if( it2 != m_febMap.end()) break;
238 }
239 if( it2 == m_febMap.end()) return end(onlineHelper);
240
241 return const_iterator( it2,
242 it2->second->begin(),
243 m_febMap.end(),
244 onlineHelper,
245 febIds);
246 }
247}
248
249
250template<class T>
251inline
254 const FebIdVec& febIds)
255{
256 if (m_febMap.size()==0) { //no elements yet, begin() and end() have to be identical
257 return m_dummyIt;
258 }
259 else {
260 if(febIds.size()==0) return end(onlineHelper);
261
262 ConditionsMapIterator it2 = m_febMap.end() ;
263 for (FebId id : febIds) {
264 it2 = m_febMap.find(id);
265 if( it2 != m_febMap.end()) break;
266 }
267 if( it2 == m_febMap.end()) return end(onlineHelper);
268
269 return iterator( it2,
270 it2->second->begin(),
271 m_febMap.end(),
272 onlineHelper,
273 febIds);
274 }
275}
276
277
278
279template<class T>
280inline
283{
284 if (m_febMap.size()==0) {
285 return m_dummyConstIt;
286 }
287 else {
288 ConstConditionsMapIterator feb_end_it=m_febMap.end();
289 ConstConditionsMapIterator last_feb_it=feb_end_it;
290 last_feb_it--;
291 return const_iterator(last_feb_it,
292 last_feb_it->second->end(),
293 feb_end_it,
294 onlineHelper);
295 }
296}
297
298
299template<class T>
300inline
303{
304 if (m_febMap.size()==0) {
305 return m_dummyIt;
306 }
307 else {
308 ConditionsMapIterator feb_end_it=m_febMap.end();
309 ConditionsMapIterator last_feb_it=feb_end_it;
310 last_feb_it--;
311 return iterator(last_feb_it,
312 last_feb_it->second->end(),
313 feb_end_it,
314 onlineHelper);
315 }
316}
317
318
319
320#define ITERATORT iteratorT<MAP_ITERATOR, CHAN_ITERATOR, POINTER, REFERENCE>
321
322template<class T>
323template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
324inline
326 m_channelIt(),
327 m_febIt(),
328 m_onlineHelper(0),
329 m_febIdsIndex(0)
330{}
331
332template<class T>
333template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
334inline
336 (MAP_ITERATOR febit,
337 CHAN_ITERATOR chanit,
338 MAP_ITERATOR febendit,
339 const LArOnlineID_Base* onlineHelper) :
340 m_channelIt(chanit),
341 m_febIt(febit),
342 m_lastFebIt(febendit),
343 m_onlineHelper(onlineHelper),
344 m_febIdsIndex(0)
345{ m_lastFebIt--; }
346
347template<class T>
348template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
349inline
351 (MAP_ITERATOR febit,
352 CHAN_ITERATOR chanit,
353 MAP_ITERATOR febendit,
354 const LArOnlineID_Base* onlineHelper,
355 const FebIdVec& febIds)
356 :
357 m_channelIt(chanit),
358 m_febIt(febit),
359 m_lastFebIt(febendit),
360 m_onlineHelper(onlineHelper),
361 m_febIds(febIds.size()),
362 m_febIdsIndex(0)
363{
364 // Save last feb it for id match below
365 MAP_ITERATOR lastFeb = m_lastFebIt;
366
367 // decrement iterator to point to the last valid feb
368 m_lastFebIt--;
369
370 // If there is a non-zero vector of feb ids, sort them, save them
371 // into local vector and move feb iterator to the first valid
372 // febId
373 if (febIds.size() && m_febIt != lastFeb) {
374 typename FebIdVec::const_iterator it = febIds.begin();
375 typename FebIdVec::const_iterator last = febIds.end();
376 std::set<FebId> febIdsSet;
377 for (; it != last; ++it) febIdsSet.insert(*it);
378 typename std::set<FebId>::const_iterator itSet = febIdsSet.begin();
379 typename std::set<FebId>::const_iterator lastSet = febIdsSet.end();
380 for (unsigned int i = 0; itSet != lastSet; ++itSet, ++i) m_febIds[i] = (*itSet);
381
382 // Move set index to point where id is <= to the first febId
383 m_febIdsIndex = std::lower_bound(m_febIds.begin(), m_febIds.end(), m_febIt->first)
384 - m_febIds.begin();
385
386 // We now require an id match, or one of the two iterators hits the end
387
388 // If febId is not the one found, iterate until a match is found
389 while (m_febIt != lastFeb && m_febIdsIndex < m_febIds.size() &&
390 m_febIds[m_febIdsIndex] != m_febIt->first) {
391 // If not equal, then we need to move iterator forward
392 // for the smaller of the two febids
393 if (m_febIt->first < m_febIds[m_febIdsIndex]) {
394 ++m_febIt; // Move to next feb in container
395 }
396 else {
397 ++m_febIdsIndex; // Move to next feb in selection
398 }
399
400 }
401
402 if (m_febIt == lastFeb || m_febIdsIndex == m_febIds.size()) {
403 // no match - set iterators to the end
404 m_channelIt = m_lastFebIt->second->end();
405 m_febIt = m_lastFebIt;
406 return;
407 }
408 if (m_febIds[m_febIdsIndex] != m_febIt->first) {
409 std::cout << "LArConditionsContainerDB<T>::iteratorT constructor - ERROR: NO MATCH FOUND"
410 << std::endl;
411 }
412 }
413}
414
415
416template<class T>
417template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
418inline
419REFERENCE
421{return *m_channelIt; }
422
423template<class T>
424template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
425inline
426POINTER
428{
429 auto& ref = *m_channelIt;
430 return &ref;
431}
432
433template<class T>
434template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
435inline
438{
439
440 // Increment to next channel within the currect feb vector
441 ++m_channelIt;
442 if (m_channelIt == m_febIt->second->end() && m_febIt != m_lastFebIt) {
443
444 // Have reached last channel of a FEB vector but not yet in LAST FEB vector
445
446 // If there is a non-zero feb id vector, then we require a match
447 // of feb ids with those in the vector
448 if (m_febIds.size()) {
449 // Get map end - it is 'one past' the saved last m_lastFebIt
450 MAP_ITERATOR lastFeb = m_lastFebIt;
451 ++lastFeb;
452
453 // Move the feb vector index forward
454 ++m_febIdsIndex;
455
456 // Now if not at end, iterate until the next match is found
457 while (m_febIt != lastFeb && m_febIdsIndex < m_febIds.size() &&
458 m_febIds[m_febIdsIndex] != m_febIt->first) {
459 // If not equal, then we need to move iterator forward
460 // for the smaller of the two febids
461 if (m_febIt->first < m_febIds[m_febIdsIndex]) {
462 ++m_febIt; // Move to next feb in container
463 }
464 else {
465 ++m_febIdsIndex; // Move to next feb in selection
466 }
467
468 }
469 if (m_febIt == lastFeb || m_febIdsIndex == m_febIds.size()) {
470 // no match - set iterators to the end
471 m_channelIt = m_lastFebIt->second->end();
472 m_febIt = m_lastFebIt;
473 return (*this);
474 }
475
476 // Print out warning if no match found
477 if (m_febIds[m_febIdsIndex] != m_febIt->first) {
478 std::cout << "LArConditionsContainerDB<T>::iteratorT constructor - ERROR: NO MATCH FOUND"
479 << std::endl;
480 }
481 }
482 else {
483 // Simple iteration
484 ++m_febIt;
485 }
486 m_channelIt = m_febIt->second->begin();
487 }
488 return *this;
489}
490
491template<class T>
492template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
493inline
496{
497 iteratorT tmp = *this;
498 operator++();
499 return tmp;
500}
501
502template<class T>
503template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
504inline
505bool
507 (const iteratorT& a) const
508{ return (m_channelIt==a.m_channelIt) && (m_febIt==a.m_febIt); }
509
510template<class T>
511template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
512inline
513bool
515 (const iteratorT& a) const
516{ return !(*this == a); }
517
518template<class T>
519template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
520inline
523 return m_febIt->first;
524}
525
526template<class T>
527template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
528inline
529int
531 return (m_channelIt - m_febIt->second->begin());
532}
533
534template<class T>
535template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
536inline
539{
540 return (HWIdentifier(m_febIt->first));
541}
542
543template<class T>
544template <class MAP_ITERATOR, class CHAN_ITERATOR, class POINTER, class REFERENCE>
545inline
548{
549 // Construct channel id
550 if (m_onlineHelper) {
551 int chan = m_channelIt - m_febIt->second->begin();
552 return (m_onlineHelper->channel_Id(febId(), chan));
553 }
555 return (result); // return invalid one if helper is not available
556}
557
558#undef ITERATORT
559
560
561
562template<class T>
563inline
564void
565LArConditionsContainerDB<T>::set(const FebId febId, const int channel, const T& payload)
566{
567 typename ConditionsHashMap::iterator it = m_febHashMap.find (febId);
568 if (it == m_febHashMap.end()) {
569 // Should never get here
570 std::cout << "LArConditionsContainerDB<T>::set ERROR could not find FEB ID "
571 << febId << std::endl;
572 return;
573 }
574
575 // Set payload
576 (*(it->second))[channel] = payload;
577}
578
579
580template<class T>
581inline
583LArConditionsContainerDB<T>::get(const FebId febId, const int channel) const
584{
585 // The get/set methods used to cache the iterator in m_febMap where the
586 // last access was found. That, however, is not at all thread-safe
587 // (and was in fact observed to lead to incorrect results in MT jobs).
588 // We need to get rid of the caching, but we'll also introduce
589 // m_febHashMap to try to reduce the lookup overhead.
590 // If this turns out to be a hot spot, then the iterator could
591 // be returned to the caller via a cookie.
592 typename ConditionsHashMap::const_iterator it = m_febHashMap.find (febId);
593 if (it == m_febHashMap.end()) {
594 // Unknown FEB
595 return Traits::empty();
596 }
597
598 const ConstChannelVector& vec = *it->second;
599 // First check the size - channel vec may be empty
600 if (channel < static_cast<int>(vec.size())) {
601 return vec[channel];
602 }
603 else {
604 return Traits::empty();
605 }
606}
607
608template<class T>
609inline
611LArConditionsContainerDB<T>::getNonConst(const FebId febId, const int channel)
612{
613 typename ConditionsHashMap::iterator it = m_febHashMap.find (febId);
614 if (it == m_febHashMap.end()) {
615 throw std::runtime_error ("Unknown FEB");
616 }
617
618 ChannelVector& vec = *it->second;
619 // Note: channel vec should always be full for non-const access
620 return vec[channel];
621}
622
623template<class T>
624inline
625bool
627{
628 return m_febHashMap.find (id) != m_febHashMap.end();
629}
630
631template<class T>
632inline
634{
635 m_gain = g;
636 return;
637}
638
639template<class T>
640inline
643{
644 return (m_febMap.size());
645}
646
647template<class T>
648inline
650{
651 return m_gain;
652}
653
654
655template<class T>
656inline
658{
659 // copy the data to this container. FEB by FEB.
660 // if FEB id exist, the old data will be overwritten.
661
662 for (const auto& pp : p->m_febMap) {
663 m_febMap[pp.first] = pp.second;
664 m_febHashMap[pp.first] = pp.second;
665 }
666}
667
668template<class T>
669inline
670void
672{
673 m_febMap[id] = channelVec;
674 m_febHashMap[id] = channelVec;
675}
676
677template<class T>
678inline
679void
681{
682 m_febMap.erase(id);
683 m_febHashMap.erase(id);
684}
685
686
687#endif
const boost::regex ref(r_ef)
std::vector< size_t > vec
#define ITERATORT
This file defines the template class used for I/O of conditions data.
static Double_t a
if(febId1==febId2)
bool operator==(const iteratorT &a) const
bool operator!=(const iteratorT &a) const
iteratorT(MAP_ITERATOR febit, CHAN_ITERATOR chanit, MAP_ITERATOR febendit, const LArOnlineID_Base *onlineHelper)
iteratorT(MAP_ITERATOR febit, CHAN_ITERATOR chanit, MAP_ITERATOR febendit, const LArOnlineID_Base *onlineHelper, const FebIdVec &febIds)
LArConditionsContainerDB template class Author: Walter Lampl Initial Version: April,...
std::map< FebId, ChannelVectorPointer > ConditionsMap
const_iterator end(const LArOnlineID_Base *onlineHelper) const
void erase(FebId id)
erase element for this FebId
iteratorT< ConditionsMapIterator, ChannelIt, Pointer, Reference > iterator
void set(const FebId id, const int channel, const T &payload)
Setter.
ConditionsMap::iterator ConditionsMapIterator
Traits::ChannelVector ChannelVector
Traits::ConstChannelVector ConstChannelVector
size_type size() const
Size of map.
Traits::ChannelVectorPointer ChannelVectorPointer
Traits::ConstReference ConstReference
LArConditionsSubsetTraits< T > Traits
Reference getNonConst(const FebId id, const int channel)
non-const get function (might extend FEB map)
ChannelVector::const_iterator ConstChannelIt
void add(const LArConditionsContainerDB< T > *p)
const ConditionsMap& getConditionsMap()const { return m_febMap ;} ;
LArConditionsContainerDB(unsigned int gain=0)
Constructor with gain.
std::unordered_map< FebId, ChannelVectorPointer > ConditionsHashMap
ConstReference get(const FebId id, const int channel) const
Getter.
iteratorT< ConstConditionsMapIterator, ConstChannelIt, ConstPointer, ConstReference > const_iterator
bool exist(FebId id) const
Do conditions for FebId?
int getGain() const
access to gain
const_iterator begin(const LArOnlineID_Base *onlineHelper) const
Iterator over all channels.
ConditionsMap::const_iterator ConstConditionsMapIterator
ChannelVector::iterator ChannelIt
ConditionsMap::size_type size_type
Traits class giving the types to use for the objects contained within the subset.
const std::vector< T > ConstChannelVector
Helper for the Liquid Argon Calorimeter cell identifiers.
TGCHBChip operator++(TGCHBChip &rs, int)