AliPhysics  7baac56 (7baac56)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RingBits.C
Go to the documentation of this file.
2 {
3  UShort_t q = (r == 'I' || r == 'i') ? 0 : 1;
4  UShort_t c = 1 << (d-1);
5  UShort_t t = 1 << (c+q-1);
6 
7  return t;
8  // return (1 << q) | (1 << (d+1));
9 
10 }
11 void Decode(UShort_t bits, UShort_t& d, Char_t& r)
12 {
13  if (bits & 0x1) { d = 1; r = 'I'; }
14  else if (bits & 0x6) { d = 2; r = (bits & 0x2 ? 'I' : 'O'); }
15  else if (bits & 0x18) { d = 3; r = (bits & 0x8 ? 'I' : 'O'); }
16 }
17 
18 const Char_t* ShowBits(UShort_t bits, Char_t* buf)
19 {
20  // Char_t buf[7];
21  // for (Int_t i = 0; i < 6; i++) buf[i] = ' ';
22  for (Int_t i = 0; i < 6; i++) {
23  buf[5-i] = (bits & (1 << i)) ? '1' : '0';
24  }
25  buf[6] = '\0';
26  return buf;
27 }
28 
30 {
31  UShort_t bits = Encode(d, r);
32  UShort_t rd = 0;
33  Char_t rr = 0;
34  Char_t buf[7];
35  Decode(bits, rd, rr);
36  ShowBits(bits, buf);
37 
38  Printf("FMD%d%c -> 0x%02x (%s) -> FMD%d%c", d, r, bits, buf, rd, rr);
39 }
40 
41 enum {/*
42  kFMD1i = 0x05,
43  kFMD1 = kFMD1i,
44  kFMD2i = 0x09,
45  kFMD2o = 0x0a,
46  kFMD2 = kFMD2i|kFMD2o,
47  kFMD3i = 0x11,
48  kFMD3o = 0x12,
49  kFMD3 = kFMD3i|kFMD3o*/
50  kFMD1I=0x01,
52  kFMD2I=0x02,
53  kFMD2O=0x04,
55  kFMD3I=0x08,
56  kFMD3O=0x10,
58 };
59 
61 {
62  return (m & t) == t;
63 }
64 void TestEnum(UShort_t e, const char* n)
65 {
66  Printf(" %10s | %5x | %5x | %5x | %5x | %5x |",
67  n, T(e,kFMD1I), T(e,kFMD2I), T(e,kFMD2O), T(e,kFMD3I), T(e,kFMD3O));
68 }
69 void TestEnums()
70 {
71  Printf(" Enum | FMD1i | FMD2i | FMD2o | FMD3i | FMD3o |");
72  TestEnum(kFMD1I, "FMD1i");
73  TestEnum(kFMD1, "FMD1");
74  TestEnum(kFMD2I, "FMD2i");
75  TestEnum(kFMD2O, "FMD2o");
76  TestEnum(kFMD2, "FMD2");
77  TestEnum(kFMD3I, "FMD3i");
78  TestEnum(kFMD3O, "FMD3o");
79  TestEnum(kFMD3, "FMD3");
80  TestEnum(kFMD3|kFMD2, "FMD23");
81  TestEnum(kFMD1|kFMD2, "FMD12");
82  TestEnum(kFMD3|kFMD2O, "FMD32o");
83  TestEnum(kFMD3I|kFMD2O, "FMD3i2o");
84  TestEnum(kFMD1I|kFMD2O, "FMD1i2o");
85  TestEnum(kFMD1I|kFMD2O|kFMD3I, "FMD3i2o1i");
86  TestEnum(kFMD1I|kFMD2I|kFMD3I, "FMD3i2i1i");
87  TestEnum(kFMD2O|kFMD3O, "FMD3o2o");
88  TestEnum(0xff, "All");
89 }
90 
91 void RingBits()
92 {
93  TestOne(1, 'I');
94  TestOne(2, 'I');
95  TestOne(2, 'O');
96  TestOne(3, 'I');
97  TestOne(3, 'O');
98 
99  TestEnums();
100 }
Definition: RingBits.C:57
char Char_t
Definition: External.C:18
Definition: RingBits.C:54
TCanvas * c
Definition: TestFitELoss.C:172
UShort_t T(UShort_t m, UShort_t t)
Definition: RingBits.C:60
void TestEnums()
Definition: RingBits.C:69
int Int_t
Definition: External.C:63
void RingBits()
Definition: RingBits.C:91
Definition: RingBits.C:51
void Decode(UShort_t bits, UShort_t &d, Char_t &r)
Definition: RingBits.C:11
const Char_t * ShowBits(UShort_t bits, Char_t *buf)
Definition: RingBits.C:18
UShort_t Encode(UShort_t d, Char_t r)
Definition: RingBits.C:1
void TestOne(UShort_t d, Char_t r)
Definition: RingBits.C:29
unsigned short UShort_t
Definition: External.C:28
void TestEnum(UShort_t e, const char *n)
Definition: RingBits.C:64