LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
BitField64.h
1 #ifndef UTIL_BitField64_H
2 #define UTIL_BitField64_H 1
3 
4 #include <iostream>
5 
6 #include <string>
7 #include <vector>
8 #include <map>
9 #include <sstream>
10 
11 #include "lcio.h"
12 #include "LCIOTypes.h"
13 
14 namespace UTIL {
15 
21  class LCTokenizer{
22 
23  std::vector< std::string >& _tokens ;
24  char _del ;
25  char _last ;
26 
27  public:
28 
30  LCTokenizer( std::vector< std::string >& tokens, char del )
31  : _tokens(tokens)
32  , _del(del),
33  _last(del) {
34  }
35 
37  void operator()(const char& c) {
38 
39  if( c != _del ) {
40 
41  if( _last == _del ) {
42  _tokens.push_back("") ;
43  }
44  _tokens.back() += c ;
45  }
46  _last = c ;
47  }
48 
49  };
50 
51 
56 
57  public :
58  virtual ~BitFieldValue() {}
59 
65  BitFieldValue( lcio::long64& bitfield, const std::string& name,
66  unsigned offset, int signedWidth ) ;
67 
68 
71  lcio::long64 value() const ;
72 
76 
80  operator lcio::long64() const { return value() ; }
81 
86  // operator int() const { return (int) value() ; }
87 
89  const std::string& name() const { return _name ; }
90 
92  unsigned offset() const { return _offset ; }
93 
95  unsigned width() const { return _width ; }
96 
98  bool isSigned() const { return _isSigned ; }
99 
101  lcio::ulong64 mask() const { return _mask ; }
102 
103 
104  protected:
105 
106  lcio::long64& _b ;
107  lcio::ulong64 _mask ;
108  std::string _name ;
109  unsigned _offset ;
110  unsigned _width ;
111  int _minVal ;
112  int _maxVal ;
113  bool _isSigned ;
114 
115  };
116 
132  class BitField64{
133 
134  friend std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
135 
136  public :
137 
138  typedef std::map<std::string, unsigned int> IndexMap ;
139 
140 
141  ~BitField64() { // clean up
142  for(unsigned i=0;i<_fields.size();i++){
143  delete _fields[i] ;
144  }
145  }
146 
161  BitField64( const std::string& initString ) : _value(0), _joined(0){
162 
163  init( initString ) ;
164  }
165 
168  lcio::long64 getValue() const { return _value ; }
169 
172  void setValue(lcio::long64 value ) { _value = value ; }
173 
176  void reset() { _value = 0 ; }
177 
180  BitFieldValue& operator[](size_t theIndex) {
181  return *_fields.at( theIndex ) ;
182  }
183 
186  const BitFieldValue& operator[](size_t theIndex) const {
187  return *_fields.at( theIndex ) ;
188  }
189 
192  unsigned highestBit() const ;
193 
195  size_t size() const { return _fields.size() ; }
196 
199  size_t index( const std::string& name) const ;
200 
203  BitFieldValue& operator[](const std::string& name) {
204 
205  return *_fields[ index( name ) ] ;
206  }
209  const BitFieldValue& operator[](const std::string& name) const {
210 
211  return *_fields[ index( name ) ] ;
212  }
213 
214 
217  unsigned lowWord() const { return unsigned( _value & 0xffffFFFF ) ; }
218 
221  unsigned highWord() const { return unsigned( _value >> 32 ) ; }
222 
223 
226  std::string fieldDescription() const ;
227 
230  std::string valueString() const ;
231 
232  protected:
233 
236  void addField( const std::string& name, unsigned offset, int width );
237 
241  void init( const std::string& initString) ;
242 
244  BitField64() : _value(0) , _joined(0) { }
245 
246 
247  // -------------- data members:--------------
248 
249  std::vector<BitFieldValue*> _fields ;
250  lcio::long64 _value ;
251  IndexMap _map ;
252  lcio::long64 _joined ;
253 
254 
255  };
256 
257 
258 
261  std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
262 
263 
264 } // end namespace
265 
266 #endif
267 
268 
269 
270 
BitFieldValue & operator=(lcio::long64 in)
Assignment operator for user convenience.
Definition: BitField64.cc:75
LCTokenizer(std::vector< std::string > &tokens, char del)
Only c'tor, give (empty) token vector and delimeter character.
Definition: BitField64.h:30
unsigned highestBit() const
Highest bit used in fields [0-63].
Definition: BitField64.cc:109
std::ostream & operator<<(std::ostream &os, const BitField64 &b)
Operator for dumping BitField64 to streams.
Definition: BitField64.cc:251
unsigned width() const
The field's width.
Definition: BitField64.h:95
unsigned long long ulong64
64 bit unsigned integer,e.g.to be used for masks
Definition: LCIOTypes.h:17
bool isSigned() const
True if field is interpreted as signed.
Definition: BitField64.h:98
BitFieldValue(lcio::long64 &bitfield, const std::string &name, unsigned offset, int signedWidth)
The default c'tor.
Definition: BitField64.cc:11
std::string fieldDescription() const
Return a valid description string of all fields.
Definition: BitField64.cc:136
size_t index(const std::string &name) const
Index for field named 'name'.
Definition: BitField64.cc:97
A bit field of 64bits that allows convenient declaration and manipulation of sub fields of various wi...
Definition: BitField64.h:132
Helper class for BitField64 that corresponds to one field value.
Definition: BitField64.h:55
lcio::ulong64 mask() const
The field's mask.
Definition: BitField64.h:101
std::string valueString() const
Return a string with a comma separated list of the current sub field values.
Definition: BitField64.cc:122
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
const std::string & name() const
fg: removed because it causes ambiguities with operator lcio::long64().
Definition: BitField64.h:89
BitFieldValue & operator[](size_t theIndex)
Acces to field through index.
Definition: BitField64.h:180
BitFieldValue & operator[](const std::string &name)
Access to field through name .
Definition: BitField64.h:203
lcio::long64 value() const
Returns the current field value.
Definition: BitField64.cc:56
BitField64(const std::string &initString)
The c'tor takes an initialization string of the form: <fieldDesc>[,<fieldDesc>...] fieldDesc = name:[start]:[-]length where: name: The name of the field start: The start bit of the field.
Definition: BitField64.h:161
void addField(const std::string &name, unsigned offset, int width)
Add an additional field to the list.
Definition: BitField64.cc:172
void operator()(const char &c)
Operator for use with algorithms, e.g.
Definition: BitField64.h:37
friend std::ostream & operator<<(std::ostream &os, const BitField64 &b)
Operator for dumping BitField64 to streams.
Definition: BitField64.cc:251
unsigned offset() const
The field's offset.
Definition: BitField64.h:92
unsigned highWord() const
The high word, bits 32-63.
Definition: BitField64.h:221
void reset()
Reset - same as setValue(0) - useful if the same encoder is used for many objects.
Definition: BitField64.h:176
void setValue(lcio::long64 value)
Set a new 64bit value.
Definition: BitField64.h:172
lcio::long64 getValue() const
Returns the current 64bit value.
Definition: BitField64.h:168
Helper class for string tokenization.
Definition: BitField64.h:21
BitField64()
No default c'tor.
Definition: BitField64.h:244
unsigned lowWord() const
The low word, bits 0-31.
Definition: BitField64.h:217
size_t size() const
Number of values.
Definition: BitField64.h:195
utility class to manage indexes according to Collection Parameters
Definition: IndexMap.h:21
const BitFieldValue & operator[](const std::string &name) const
Const Access to field through name .
Definition: BitField64.h:209
void init(const std::string &initString)
Decode the initialization string as described in the constructor.
Definition: BitField64.cc:195
const BitFieldValue & operator[](size_t theIndex) const
Const acces to field through index.
Definition: BitField64.h:186