ATLAS Offline Software
SiDetectorElementStatus.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SiDetectorElementStatus.h
8 // (c) ATLAS Detector software
10 
11 
12 #ifndef INDETREADOUTGEOMETRY_SIDETECTORELEMENTINFO_H
13 #define INDETREADOUTGEOMETRY_SIDETECTORELEMENTINFO_H
14 
15 #include <vector>
16 #include <utility>
20 
21 
22 // @TODO remove in the future once new Pixel and SCT conditions summary information is fully validated
23 //#ifndef DO_VALIDATE_STATUS_ARRAY
24 //# define DO_VALIDATE_STATUS_ARRAY
25 //#endif
26 
27 #ifdef DO_VALIDATE_STATUS_ARRAY
28 #define VALIDATE_STATUS_ARRAY_ACTIVATED true
29 #include <stdexcept>
30 namespace dbg {
31  void break_point( bool input1, bool input2, const char *label);
32  void break_point( double input1, double input2, const char *label);
33  void break_point( uint64_t input1, uint64_t input2, const char *label);
34 
35 
36 }
37 
38 #define VALIDATE_STATUS_ARRAY( use_info, info_val, summary_val) \
39  { \
40  auto is_good = summary_val; \
41  auto is_good_precomp = (use_info) ? info_val : is_good; \
42  if (is_good != is_good_precomp) { \
43  dbg::break_point(is_good, is_good_precomp,#info_val); \
44  [[maybe_unused]] auto is_good_precomp2 = info_val; \
45  [[maybe_unused]] auto is_good2 = summary_val; \
46  throw std::logic_error("Inconsistent conditions summary information." ); \
47  } } \
48  do { } while (0)
49 #else
50 #define VALIDATE_STATUS_ARRAY_ACTIVATED false
51 #define VALIDATE_STATUS_ARRAY( use_info, info_val, summary_val) do { } while (0)
52 #endif
53 
54 
55 // @TODO move to namespace InDetDD ?
56 namespace InDet {
57  class SiDetectorDesign;
58 
59  // @TODO or use bitset ?
60  using ChipFlags_t = unsigned short;
61 
63  public:
65  : m_detectorElements(&detector_elements), m_badCells(new std::vector<std::vector<unsigned short> >()), m_owner(true) {}
66 
67  SiDetectorElementStatus(const SiDetectorElementStatus &si_detector_element_status)
68  : m_detectorElements(si_detector_element_status.m_detectorElements),
69  m_elementStatus( si_detector_element_status.m_elementStatus ),
70  m_elementChipStatus( si_detector_element_status.m_elementChipStatus ),
71  // cppcheck-suppress copyCtorPointerCopying
72  m_badCells( si_detector_element_status.m_badCells ),
73  m_owner( false )
74  {
75  }
76 
78  const std::vector<std::vector<unsigned short> > &bad_cells)
79  : m_detectorElements(&detector_elements),
80  m_badCells(const_cast<std::vector<std::vector<unsigned short> > *>(&bad_cells)), // const_cast but not owned object treated as const.
81  m_owner(false)
82  {}
83 
84  virtual ~SiDetectorElementStatus() { if (m_owner) delete m_badCells; }
85 
87 
88  unsigned int numberOfChips(const IdentifierHash& hash) const {
89  return numberOfChips(getDetectorElement(hash)->design());
90  }
92  return m_detectorElements->at(hash.value());
93  }
94  const std::vector<InDetDD::SiDetectorElement*> &getDetectorElements() const {
95  return *m_detectorElements;
96  }
97  bool isGood(IdentifierHash hash) const {
98  return m_elementStatus.at(hash.value());
99  }
100  bool isChipGood(IdentifierHash hash, unsigned int chip) const {
101 #ifndef NDEBUG
102  assert( m_elementStatus.empty() || (chip < numberOfChips(hash) && ((1<<(numberOfChips(hash)-1) ) <= std::numeric_limits<ChipFlags_t>::max())));
103 #endif
104  return m_elementChipStatus.empty() || m_elementChipStatus.at(hash.value()) & (1<<chip);
105  }
106 
107  bool isCellGood(IdentifierHash hash, unsigned short cell_i) const {
108  const std::vector<unsigned short> &bad_cells= std::as_const(m_badCells)->at(hash);
109  return !std::binary_search(bad_cells.begin(),bad_cells.end(),cell_i);
110  }
111 
115 
116  const std::vector<bool> &getElementStatus() const { return m_elementStatus; }
117  std::vector<bool> &getElementStatus() { return m_elementStatus; }
118  const std::vector<ChipFlags_t> &getElementChipStatus() const { return m_elementChipStatus; }
119  std::vector<ChipFlags_t> &getElementChipStatus() { return m_elementChipStatus; }
120  const std::vector<std::vector<unsigned short> > &getBadCells() const { return *m_badCells; }
121 
125  std::vector<std::vector<unsigned short> > &getBadCells() { if (!m_owner) { copyBadCells(); } return *m_badCells; }
126 
127  protected:
128  virtual unsigned int numberOfChips(const InDetDD::SiDetectorDesign& design) const = 0;
129  private:
130  static void notOwningBadCells() ;
131  void copyBadCells() {
132  m_badCells = new std::vector<std::vector<unsigned short> > (*m_badCells);
133  m_owner=true;
134  }
135 
137  std::vector<bool> m_elementStatus;
138  std::vector<ChipFlags_t> m_elementChipStatus;
139  std::vector<std::vector<unsigned short> > *m_badCells = nullptr;
140  bool m_owner = false;
141  };
142 
143 } // namespace InDetDD
144 
145 #include "AthenaKernel/CLASS_DEF.h"
146 CLASS_DEF( InDet::SiDetectorElementStatus , 154354418 , 1 )
147 
148 CONDCONT_MIXED_DEF( InDet::SiDetectorElementStatus, 207353830 );
149 
150 #endif // INDETREADOUTGEOMETRY_SIDETECTORELEMENTINFO_H
xAOD::short
short
Definition: Vertex_v1.cxx:165
InDet::SiDetectorElementStatus::getElementStatus
const std::vector< bool > & getElementStatus() const
Definition: SiDetectorElementStatus.h:116
max
#define max(a, b)
Definition: cfImp.cxx:41
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
InDet::SiDetectorElementStatus::m_elementChipStatus
std::vector< ChipFlags_t > m_elementChipStatus
Definition: SiDetectorElementStatus.h:138
InDet::SiDetectorElementStatus::isChipGood
bool isChipGood(IdentifierHash hash, unsigned int chip) const
Definition: SiDetectorElementStatus.h:100
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::SiDetectorElementStatus::SiDetectorElementStatus
SiDetectorElementStatus(const InDetDD::SiDetectorElementCollection &detector_elements, const std::vector< std::vector< unsigned short > > &bad_cells)
Definition: SiDetectorElementStatus.h:77
InDet::SiDetectorElementStatus::m_elementStatus
std::vector< bool > m_elementStatus
Definition: SiDetectorElementStatus.h:137
InDet::SiDetectorElementStatus::getDetectorElement
const InDetDD::SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementStatus.h:91
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
InDet::SiDetectorElementStatus::getElementChipStatus
std::vector< ChipFlags_t > & getElementChipStatus()
Definition: SiDetectorElementStatus.h:119
InDet::SiDetectorElementStatus::m_badCells
std::vector< std::vector< unsigned short > > * m_badCells
Definition: SiDetectorElementStatus.h:139
InDet::SiDetectorElementStatus::getBadCells
const std::vector< std::vector< unsigned short > > & getBadCells() const
Definition: SiDetectorElementStatus.h:120
InDet::SiDetectorElementStatus::isCellGood
bool isCellGood(IdentifierHash hash, unsigned short cell_i) const
Definition: SiDetectorElementStatus.h:107
SH::Meta::dbg
std::string dbg(const Meta &obj, unsigned verbosity=0)
the debugging info of this object
Definition: Meta.cxx:28
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
InDet::SiDetectorElementStatus::numberOfChips
virtual unsigned int numberOfChips(const InDetDD::SiDetectorDesign &design) const =0
InDet::SiDetectorElementStatus::~SiDetectorElementStatus
virtual ~SiDetectorElementStatus()
Definition: SiDetectorElementStatus.h:84
skel.input1
tuple input1
Definition: skel.GENtoEVGEN.py:770
InDet::SiDetectorElementStatus::merge
SiDetectorElementStatus & merge(const SiDetectorElementStatus &a)
bitwise AND of module and chip status bits.
Definition: SiDetectorElementStatus.cxx:28
InDet::SiDetectorElementStatus::SiDetectorElementStatus
SiDetectorElementStatus(const InDetDD::SiDetectorElementCollection &detector_elements)
Definition: SiDetectorElementStatus.h:64
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
vector
Definition: MultiHisto.h:13
InDet::SiDetectorElementStatus::operator=
SiDetectorElementStatus & operator=(const SiDetectorElementStatus &)=delete
InDet::SiDetectorElementStatus::SiDetectorElementStatus
SiDetectorElementStatus(const SiDetectorElementStatus &si_detector_element_status)
Definition: SiDetectorElementStatus.h:67
InDet::SiDetectorElementStatus::m_detectorElements
const InDetDD::SiDetectorElementCollection * m_detectorElements
Definition: SiDetectorElementStatus.h:136
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
InDet::SiDetectorElementStatus::getElementStatus
std::vector< bool > & getElementStatus()
Definition: SiDetectorElementStatus.h:117
InDet::SiDetectorElementStatus::notOwningBadCells
static void notOwningBadCells()
Definition: SiDetectorElementStatus.cxx:82
InDet::SiDetectorElementStatus::isGood
bool isGood(IdentifierHash hash) const
Definition: SiDetectorElementStatus.h:97
IdentifierHash.h
InDet::SiDetectorElementStatus::getDetectorElements
const std::vector< InDetDD::SiDetectorElement * > & getDetectorElements() const
Definition: SiDetectorElementStatus.h:94
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SiDetectorElementCollection.h
InDet::SiDetectorElementStatus::m_owner
bool m_owner
Definition: SiDetectorElementStatus.h:140
SiDetectorElement.h
CONDCONT_MIXED_DEF
CONDCONT_MIXED_DEF(InDet::SiDetectorElementStatus, 207353830)
a
TList * a
Definition: liststreamerinfos.cxx:10
InDet::SiDetectorElementStatus::numberOfChips
unsigned int numberOfChips(const IdentifierHash &hash) const
Definition: SiDetectorElementStatus.h:88
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
InDet::SiDetectorElementStatus::getElementChipStatus
const std::vector< ChipFlags_t > & getElementChipStatus() const
Definition: SiDetectorElementStatus.h:118
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
InDet::ChipFlags_t
unsigned short ChipFlags_t
Definition: SiDetectorElementStatus.h:60
InDet::SiDetectorElementStatus::copyBadCells
void copyBadCells()
Definition: SiDetectorElementStatus.h:131
InDet::SiDetectorElementStatus::getBadCells
std::vector< std::vector< unsigned short > > & getBadCells()
Get a non-const bad cells container owned by this instance.
Definition: SiDetectorElementStatus.h:125
IdentifierHash
Definition: IdentifierHash.h:38
InDetDD::SiDetectorDesign
Definition: SiDetectorDesign.h:50
CLASS_DEF.h
macros to associate a CLID to a type