ATLAS Offline Software
LArBadChanBitPackingBase.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 template<class T>
7 void TLArBadChanBitPackingBase<T>::addBit( typename T::ProblemType pb, const std::string& name,
8  GainDependence gaindep)
9 {
10  m_enumVec.push_back( std::make_pair( pb, gaindep));
11  m_nameVec.push_back(name);
12 }
13 
14 
15 template<class T>
16 const std::string& TLArBadChanBitPackingBase<T>::stringName( typename T::ProblemType pb) const
17 {
18  return m_nameVec.at(index(pb));
19 }
20 
21 template<class T>
22 std::pair<bool, typename T::ProblemType>
23 TLArBadChanBitPackingBase<T>::enumName( const std::string& str) const
24 {
25  typename std::map<std::string, typename T::ProblemType>::const_iterator i = m_nameMap.find( str);
26  if (i != m_nameMap.end()) { return std::make_pair(true,i->second);}
27  else return std::make_pair(false, (typename T::ProblemType) 0);
28 }
29 
30 
31 template<class T>
32 void TLArBadChanBitPackingBase<T>::setBit( typename T::ProblemType pb, LArBadChannel::BitWord& word, bool value) const {
33  LArBadChannel::BitWord mask = 1;
34  mask = mask << m_bitPos[static_cast<LArBadChannel::PosType>(pb)]; // all at 0 except pb bit
35  if (value) word |= mask;
36  else word &= ~mask;
37 }
38 
39 template<class T>
40 bool TLArBadChanBitPackingBase<T>::setBit( const std::string& name,
41  LArBadChannel::BitWord& word, bool value) const
42 {
43  std::pair<bool, typename T::ProblemType> res = enumName( name);
44  if (res.first) { // name corresponds to enum
45  setBit( res.second, word, value);
46  return true;
47  }
48  else return false; // name not recognized
49 }
50 
51 template<class T>
52 void TLArBadChanBitPackingBase<T>::setBit( typename T::ProblemType pb, LArBadChannel& word, bool value) const
53 {
54  setBit( pb, word.packedDataRef(), value);
55 }
56 
57 template<class T>
58 bool TLArBadChanBitPackingBase<T>::setBit( const std::string& name, LArBadChannel& word, bool value) const
59 {
60  return setBit( name, word.packedDataRef(), value);
61 }
62 
63 template<class T>
64 std::string TLArBadChanBitPackingBase<T>::stringStatus( const LArBadChannel& bc) const
65 {
66  std::string res;
67  for (unsigned int i=0; i<m_enumVec.size(); ++i) {
68  if ( ! bc.statusOK( m_enumVec.at(i).first )) {
69  if (!res.empty()) res += " ";
70  res += m_nameVec.at(i);
71  }
72  }
73  return res;
74 }
75 
76 template<class T>
77 void TLArBadChanBitPackingBase<T>::initMasks()
78 {
79  for( typename std::vector< std::pair<typename T::ProblemType, GainDependence> >::const_iterator iter = m_enumVec.begin();
80  iter != m_enumVec.end(); ++iter) //loop over all problems
81  {
82  // set the appropriate bits in each mask according to the GainDependence of the T::ProblemType
83  if(iter->second == independent)
84  {
85  setBit(iter->first, m_highGainMask);
86  setBit(iter->first, m_mediumGainMask);
87  setBit(iter->first, m_lowGainMask);
88  }
89  else if(iter->second == high)
90  setBit(iter->first, m_highGainMask);
91  else if(iter->second == medium)
92  setBit(iter->first, m_mediumGainMask);
93  else if(iter->second == low)
94  setBit(iter->first, m_lowGainMask);
95  }
96 }