HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pmm2Status.cxx
Go to the documentation of this file.
1 //
32 
34 #include "Pmm2Status.h"
35 #include <iostream>
36 #include <iomanip>
37 
38 //namespace Pmm2
39 //{
40 
42 
43 //
45 //
46 UInt_t ReverseInt32(UInt_t x)
47 {
48  x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
49  x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
50  x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
51  x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
52  return((x >> 16) | (x << 16));
53 }
54 
55 //
57 //
58 UInt_t ReverseBits(UInt_t u32Value, int iBits)
59 {
60  UInt_t x = u32Value;
61  x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
62  x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
63  x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
64  x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
65  x = ((x >> 16) | (x << 16));
66  x = x >> (32 - iBits);
67  return x;
68 }
69 
70 //
72 //
73 char *decimal_to_bin(char * str,UInt_t n)
74 {
75  int c;
76  UInt_t d, count;
77  char *pointer;
78 
79  count = 0;
80  pointer = str;
81 
82  if ( pointer == NULL ) return (char*)NULL;
83 
84  for ( c = 31 ; c >= 0 ; c-- )
85  {
86  d = n >> c;
87 
88  if ( d & 1 )
89  *(pointer+count) = 1 + '0';
90  else
91  *(pointer+count) = 0 + '0';
92 
93  count++;
94  }
95  *(pointer+count) = '\0';
96 
97  return pointer;
98 }
99 
101 
102 ClassImp(Pmm2Status)
103 
104 // Constructor's
106 {
107  for(UInt_t i=0; i<sizeof(data)/sizeof(UInt_t); i++) data[i] = 0;
108 }
109 
110  Pmm2Status::Pmm2Status(UInt_t buff[],UInt_t len)
111 {
112  for(UInt_t i=0; i<sizeof(data)/sizeof(UInt_t); i++) data[i] = 0;
113  for(UInt_t i=0; i<len/sizeof(UInt_t); i++) {
114  if ( i < 18 )
115  data[i] = ReverseInt32(buff[i]); // Config0 , Config1
116  else
117  data[i] = buff[i]; // Config2 - trigger
118  }
119 }
120 
121 // Distructor
122 // Pmm2Status::~Pmm2Status()
123 // {
124 // //...
125 // }
126 
127 unsigned int Pmm2Status::getFpgaId() const
128 {
129  return FPGA_ID;
130 }
131 
132 // PMM2 Temparature sensor
134 {
135  double t;
136  int itemp;
137  itemp = Temp;
138  itemp = ReverseBits(itemp,12);
139  t = (double) itemp * 0.0625;
140  if (Tsign != 0 ) t *= -1;
141  return t;
142 }
143 
144 //
145 // Print Pmm2 Status in binary format
146 //
147  void Pmm2Status::Dump() const
148  {
149  UInt_t i,word;
150  char binstr[33];
151 
152  std::cout << "Pmm2 Status" << std::endl;
153  std::cout << std::setfill('0') << std::setiosflags(std::ios::uppercase);
154  for(i=0; i<sizeof(data)/sizeof(UInt_t); i++) {
155  if ( i < 18 )
156  word = ReverseInt32(data[i]);
157  else
158  word = data[i];
159  decimal_to_bin(binstr,word);
160  std::cout << "0x" << std::hex << std::setw(8) << word << std::dec
161  << " " << binstr << std::endl;
162  }
163  std::cout << std::setfill(' ') << std::resetiosflags(std::ios::uppercase);
164 
165  }
166 
167 
168 unsigned int Pmm2Status::getTrigger(int trig) const {
169  std::cout << "FW version: " << getFwVersion() << std::endl;
170  if(getFwVersion()<0x14111101){
171  switch(trig){
172  case 0: return triger[0];
173  case 1: return 0;
174  case 2: return triger[1];
175  case 3: return triger[2];
176  case 4: return triger[3];
177  case 5: return triger[4];
178  case 6: return 0;
179  case 7: return triger[5];
180  case 8: return triger[6];
181  case 9: return triger[7];
182  case 10: return triger[8];
183  case 11: return triger[9];
184  case 12: return triger[10];
185  case 13: return 0;
186  case 14: return triger[11];
187  case 15: return triger[12];
188  default: return 0;
189  }
190  }
191  if(getFwVersion()<0x15111101){
192  if(trig>0 && trig<20)
193  return triger[trig];
194  else
195  return 0;
196  }
197  return 0; // we newer come hire
198 }
199 
200 void Pmm2Status::print() const
201 {
202  std::cout << "Pmm2 Status " << std::endl
203  << std::setfill('0') << std::setiosflags(std::ios::uppercase)
204  << std::hex << std::setw(1) << "Fpga Id 0x" << getFpgaId()
205  << " FW Version 0x" << std::setw(8) << getFwVersion()
206  << " Temparature " << getTemperature()
207  << std::setfill(' ') << std::resetiosflags(std::ios::uppercase)
208  << std::dec << std::endl;
209 }
210 
211 
212 //} //namespace Pmm2
213 
214 // EOF Pmm2Status.cxx
unsigned int FPGA_ID
Definition: Pmm2Status.h:61
UInt_t ReverseInt32(UInt_t x)
Reverse bits in int32_t word.
Definition: Pmm2Status.cxx:46
unsigned int Temp
Definition: Pmm2Status.h:71
A class Pmm2Status is bits representation of pmm2 status register (0x400).
Definition: Pmm2Status.h:12
unsigned int data[39]
Definition: Pmm2Status.h:408
unsigned int getFwVersion() const
Definition: Pmm2Status.h:23
UInt_t ReverseBits(UInt_t u32Value, int iBits)
Reverse N bits word ( N <= 32 )
Definition: Pmm2Status.cxx:58
unsigned int getTrigger(int trig) const
Definition: Pmm2Status.cxx:168
unsigned int getFpgaId() const
Definition: Pmm2Status.cxx:127
double getTemperature() const
Definition: Pmm2Status.cxx:133
char * decimal_to_bin(char *str, UInt_t n)
Integer to Binary string.
Definition: Pmm2Status.cxx:73
void Dump() const
Definition: Pmm2Status.cxx:147
unsigned int Tsign
Definition: Pmm2Status.h:70
void print() const
Definition: Pmm2Status.cxx:200
unsigned int triger[20]
Definition: Pmm2Status.h:401