DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
BitField64.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 
12 #ifndef DDSEGMENTATION_BITFIELD64_H
13 #define DDSEGMENTATION_BITFIELD64_H 1
14 
15 #include <iostream>
16 
17 #include <string>
18 #include <vector>
19 #include <map>
20 #include <sstream>
21 
23 
25 namespace dd4hep {
26 
28  namespace DDSegmentation {
29 
31 
37 
40 
41  public :
42 
43  BitFieldValue() = delete ;
44 
46  BitFieldValue( CellID& bitfield, const BitFieldElement& bv ) :
47  _value( bitfield ), _bv( bv) {}
48 
51  FieldID value() const { return _bv.value( _value ) ; }
52 
54  FieldID value(CellID id) const { return _bv.value( id ) ; }
55 
58  _bv.set( _value, in ) ;
59  return *this ;
60  }
61 
65  operator FieldID() const { return value() ; }
66 
68  const std::string& name() const { return _bv.name() ; }
69 
71  unsigned offset() const { return _bv.offset() ; }
72 
74  unsigned width() const { return _bv.width() ; }
75 
77  bool isSigned() const { return _bv.isSigned() ; }
78 
80  CellID mask() const { return _bv.mask() ; }
81 
83  int minValue() const { return _bv.minValue(); }
84 
86  int maxValue() const { return _bv.maxValue(); }
87 
88  } ;
89 
90 
92 
110  class BitField64{
111 
112  friend std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
113 
114  public :
115 
116  virtual ~BitField64() {
117  if( _owner)
118  delete _coder ;
119  };
120 
122  BitField64() = delete ;
123 
138  BitField64( const std::string& initString ){
139  _coder = new BitFieldCoder( initString ) ;
140  }
141 
143  BitField64( const BitFieldCoder* coder ) : _owner(false), _coder( coder ) {
144  }
145 
146 
149  CellID getValue() const { return _value ; }
150 
153  void setValue(CellID value ) { _value = ( _coder->mask() & value ) ; }
154 
157  void setValue(unsigned low_Word, unsigned high_Word ) {
158  setValue( ( low_Word & 0xffffffffULL ) | ( ( high_Word & 0xffffffffULL ) << 32 ) ) ;
159  }
160 
162  BitField64& operator()(CellID val) { setValue( val ) ; return *this ; }
163 
166  void reset() { _value = 0 ; }
167 
170  BitFieldValue operator[](size_t idx) {
171  return BitFieldValue( _value, _coder->operator[]( idx ) ) ;
172  }
173 
174  // /** Const acces to field through index
175  // */
176  // const BitFieldValue& operator[](size_t idx) const {
177 
178  // return BitFieldValue( _value, _coder->operator[]( idx ) ) ;
179  // }
180 
183  unsigned highestBit() const { return _coder->highestBit() ; }
184 
186  size_t size() const { return _coder->size() ; }
187 
190  size_t index( const std::string& name) const { return _coder->index( name ) ; }
191 
194  BitFieldValue operator[](const std::string& name) {
195  return BitFieldValue( _value, _coder->operator[]( name ) ) ;
196  }
197  // /** Const Access to field through name .
198  // */
199  // const BitFieldValue& operator[](const std::string& name) const {
200 
201  // return BitFieldValue( _value, _coder->operator[]( name ) );
202  // }
203 
204 
207  unsigned lowWord() const { return unsigned( _value & 0xffffFFFFUL ) ; }
208 
211  unsigned highWord() const { return unsigned(_value >> 32) ; }
212 
213 
216  std::string fieldDescription() const { return _coder->fieldDescription() ; }
217 
220  std::string valueString() const ;
221 
222  // const std::vector<BitFieldValue*>& fields() const {
223  // return _coder->fields() ;
224  // }
225 
226  protected:
227 
228  // -------------- data members:--------------
229  bool _owner{true} ;
232 
233  };
234 
235 
238  std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
239 
240 
241 
242  } // end namespace
243 
244  using DDSegmentation::BitField64 ;
245 } // end namespace
246 
247 #endif
248 
249 
250 
251 
dd4hep::DDSegmentation::BitField64::operator[]
BitFieldValue operator[](size_t idx)
Definition: BitField64.h:170
dd4hep::DDSegmentation::BitFieldElement::offset
unsigned offset() const
Definition: BitFieldCoder.h:64
dd4hep::DDSegmentation::BitFieldValue::value
FieldID value(CellID id) const
Calculate Field value given an external 64 bit bitmap value.
Definition: BitField64.h:54
dd4hep::DDSegmentation::BitFieldElement
Helper class for BitFieldCoder that corresponds to one field value.
Definition: BitFieldCoder.h:32
dd4hep::DDSegmentation::BitField64::highestBit
unsigned highestBit() const
Definition: BitField64.h:183
dd4hep::DDSegmentation::BitField64::~BitField64
virtual ~BitField64()
Definition: BitField64.h:116
dd4hep::DDSegmentation::BitFieldValue::value
FieldID value() const
Definition: BitField64.h:51
dd4hep::DDSegmentation::BitField64::_value
CellID _value
Definition: BitField64.h:230
dd4hep::DDSegmentation::BitFieldValue::minValue
int minValue() const
Definition: BitField64.h:83
dd4hep::DDSegmentation::BitFieldElement::isSigned
bool isSigned() const
Definition: BitFieldCoder.h:70
dd4hep::DDSegmentation::BitFieldValue
Lightweight helper class for BitField64 that corresponds to one field value.
Definition: BitField64.h:36
dd4hep::DDSegmentation::BitFieldValue::isSigned
bool isSigned() const
Definition: BitField64.h:77
dd4hep::DDSegmentation::BitFieldElement::maxValue
int maxValue() const
Definition: BitFieldCoder.h:79
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::DDSegmentation::BitField64::operator()
BitField64 & operator()(CellID val)
Definition: BitField64.h:162
dd4hep::DDSegmentation::BitField64::operator<<
friend std::ostream & operator<<(std::ostream &os, const BitField64 &b)
Definition: BitField64.cpp:27
dd4hep::DDSegmentation::BitField64::index
size_t index(const std::string &name) const
Definition: BitField64.h:190
dd4hep::DDSegmentation::BitField64
A bit field of 64bits that allows convenient declaration.
Definition: BitField64.h:110
dd4hep::DDSegmentation::BitField64::reset
void reset()
Definition: BitField64.h:166
dd4hep::DDSegmentation::BitField64::fieldDescription
std::string fieldDescription() const
Definition: BitField64.h:216
dd4hep::DDSegmentation::BitFieldElement::value
FieldID value(CellID bitfield) const
calculate this field's value given an external 64 bit bitmap
Definition: BitFieldCoder.cpp:45
dd4hep::DDSegmentation::BitField64::setValue
void setValue(unsigned low_Word, unsigned high_Word)
Definition: BitField64.h:157
dd4hep::DDSegmentation::BitField64::operator[]
BitFieldValue operator[](const std::string &name)
Definition: BitField64.h:194
dd4hep::DDSegmentation::BitFieldValue::mask
CellID mask() const
Definition: BitField64.h:80
dd4hep::DDSegmentation::BitFieldCoder::highestBit
unsigned highestBit() const
Definition: BitFieldCoder.cpp:86
dd4hep::DDSegmentation::BitField64::valueString
std::string valueString() const
Definition: BitField64.cpp:12
dd4hep::DDSegmentation::FieldID
int64_t FieldID
Definition: BitFieldCoder.h:25
dd4hep::DDSegmentation::BitField64::setValue
void setValue(CellID value)
Definition: BitField64.h:153
dd4hep::DDSegmentation::BitFieldElement::set
void set(CellID &bitfield, FieldID value) const
Definition: BitFieldCoder.cpp:57
dd4hep::DDSegmentation::BitFieldValue::maxValue
int maxValue() const
Definition: BitField64.h:86
dd4hep::DDSegmentation::BitFieldElement::name
const std::string & name() const
Definition: BitFieldCoder.h:61
dd4hep::DDSegmentation::BitFieldValue::BitFieldValue
BitFieldValue(CellID &bitfield, const BitFieldElement &bv)
only c'tor with reference to bitfield and BitFieldElement
Definition: BitField64.h:46
dd4hep::DDSegmentation::BitFieldValue::operator=
BitFieldValue & operator=(FieldID in)
Definition: BitField64.h:57
dd4hep::DDSegmentation::BitFieldValue::width
unsigned width() const
Definition: BitField64.h:74
dd4hep::DDSegmentation::BitFieldElement::width
unsigned width() const
Definition: BitFieldCoder.h:67
dd4hep::DDSegmentation::BitFieldValue::BitFieldValue
BitFieldValue()=delete
dd4hep::DDSegmentation::BitField64::BitField64
BitField64(const std::string &initString)
Definition: BitField64.h:138
dd4hep::DDSegmentation::BitFieldValue::_bv
const BitFieldElement & _bv
Definition: BitField64.h:39
BitFieldCoder.h
dd4hep::DDSegmentation::BitFieldElement::mask
CellID mask() const
Definition: BitFieldCoder.h:73
dd4hep::DDSegmentation::BitFieldValue::offset
unsigned offset() const
Definition: BitField64.h:71
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::BitField64::_owner
bool _owner
Definition: BitField64.h:229
dd4hep::DDSegmentation::BitFieldCoder::index
size_t index(const std::string &name) const
Definition: BitFieldCoder.cpp:74
dd4hep::DDSegmentation::BitField64::getValue
CellID getValue() const
Definition: BitField64.h:149
dd4hep::DDSegmentation::BitField64::_coder
const BitFieldCoder * _coder
Definition: BitField64.h:231
dd4hep::DDSegmentation::BitField64::highWord
unsigned highWord() const
Definition: BitField64.h:211
dd4hep::DDSegmentation::BitField64::size
size_t size() const
Definition: BitField64.h:186
dd4hep::DDSegmentation::BitFieldElement::minValue
int minValue() const
Definition: BitFieldCoder.h:76
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::BitFieldCoder::fieldDescription
std::string fieldDescription() const
Definition: BitFieldCoder.cpp:113
dd4hep::DDSegmentation::BitFieldValue::name
const std::string & name() const
Definition: BitField64.h:68
dd4hep::DDSegmentation::BitFieldCoder::size
size_t size() const
Definition: BitFieldCoder.h:192
dd4hep::DDSegmentation::BitField64::BitField64
BitField64()=delete
dd4hep::DDSegmentation::BitFieldValue::_value
CellID & _value
Definition: BitField64.h:38
dd4hep::DDSegmentation::BitFieldCoder::mask
CellID mask() const
Definition: BitFieldCoder.h:223
dd4hep::DDSegmentation::BitField64::lowWord
unsigned lowWord() const
Definition: BitField64.h:207
dd4hep::DDSegmentation::operator<<
std::ostream & operator<<(std::ostream &os, const BitField64 &b)
Definition: BitField64.cpp:27
dd4hep::DDSegmentation::BitField64::BitField64
BitField64(const BitFieldCoder *coder)
Initialize from existing BitFieldCoder.
Definition: BitField64.h:143