FairRoot/PandaRoot
MvdTestBeam/Tools/mrftools.cxx
Go to the documentation of this file.
1 /*============================================================*/
2 /* mrftools.cpp */
3 /* Toolbox */
4 /* M.C. Mertens */
5 /*============================================================*/
6 
7 
8 #include "mrftools.h"
9 #include <climits>
10 
11 namespace mrftools {
12 
13 static const UInt_t UInt_t_bitlength = sizeof(UInt_t) * CHAR_BIT;
14 
15 bool getIntBit(const UInt_t& position, const UInt_t& value)
16 {
17  if (position < UInt_t_bitlength) {
18  return (value & (1 << position));
19  }
20  else {
21  return false;
22  }
23 }
24 
25 void setIntBit(const UInt_t& position, UInt_t& value, const bool& state)
26 {
27  if (position < UInt_t_bitlength) {
28  if (state) {
29  value |= (1 << position);
30  }
31  else {
32  value &= (~(1 << position));
33  }
34  }
35 }
36 
37 UInt_t shiftBy(const int& positions, const UInt_t& value)
38 {
39  if (positions < 0) {
40  return (value >> (-positions));
41  }
42  else if (positions > 0) {
43  return (value << positions);
44  }
45  else {
46  return value;
47  }
48 }
49 
50 unsigned int getIteratorItemCount(const std::map<std::string, TConfItem>::const_iterator& start, const std::map<std::string, TConfItem>::const_iterator& stop)
51 {
52  std::map<std::string, TConfItem>::const_iterator iter;
53  unsigned int count = 0;
54  for (iter = start; iter != stop; ++iter) {
55  ++count;
56  }
57  return count;
58 }
59 
60 unsigned int getIteratorItemCount(const std::map<std::string,std::map<std::string,TConfItem> >::const_iterator& start, const std::map<std::string,std::map<std::string,TConfItem> >::const_iterator& stop)
61 {
62  unsigned int count = 0;
63  std::map<std::string, std::map<std::string, TConfItem> >::const_iterator iter;
64  std::map<std::string,TConfItem>::const_iterator iter2;
65  for (iter=start; iter!=stop; ++iter) {
66  for (iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
67  ++count;
68  }
69  }
70  return count;
71 }
72 
73 UInt_t grayToBin(UInt_t gray)
74 {
75  //UInt_t result = 0;
76  //setIntBit(31, result, getIntBit(31, gray));
77  //for (unsigned int i = 30; i > 0; --i) {
78  // setIntBit(i, result, (getIntBit(i+1, result) && !(getIntBit(i, gray))) || (!(getIntBit(i+1, result)) && getIntBit(i, gray)));
79  //}
80  //setIntBit(0, result, (getIntBit(1, result) && !(getIntBit(0, gray))) || (!(getIntBit(1, result)) && getIntBit(0, gray)));
81 
82  //return result;
83 
84  for (UInt_t bit = 1U << 31; bit > 1; bit >>= 1)
85  {
86  if (gray & bit) gray ^= bit >> 1;
87  }
88  return gray;
89 }
90 
91 }
92 
PndTransMap * map
Definition: sim_emc_apd.C:99
static const UInt_t UInt_t_bitlength
UInt_t shiftBy(const int &positions, const UInt_t &value)
Shifts the bits in an integer value.
UInt_t grayToBin(UInt_t gray)
Converts gray encoded values to bianry values.
int count
bool getIntBit(const UInt_t &position, const UInt_t &value)
Retrieves a single bit from an integer value.
void setIntBit(const UInt_t &position, UInt_t &value, const bool &state)
Sets a single bit in an integer value.
unsigned int getIteratorItemCount(const std::map< std::string, TConfItem >::const_iterator &start, const std::map< std::string, TConfItem >::const_iterator &stop)