StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SSD_Reader.cxx
1 #include "SSD_Reader.hh"
2 #include "StDaqLib/EVP/ssdReader.h"
3 
4 #include <assert.h>
5 #include <math.h>
6 #include <ctime>
7 
8 static unsigned short log8to10_table[256] = {
9  0, 1, 2, 3, 4, 5, 6, 7,
10  8, 9, 10, 11, 12, 13, 14, 15,
11  16, 17, 18, 19, 20, 21, 22, 23,
12  24, 25, 26, 27, 28, 29, 30, 31,
13  32, 33, 34, 35, 36, 37, 38, 39,
14  40, 41, 42, 43, 44, 45, 46, 47,
15  48, 49, 50, 51, 52, 53, 54, 55,
16  56, 57, 58, 59, 60, 61, 62, 63,
17  64, 65, 66, 67, 68, 69, 70, 71,
18  72, 73, 74, 75, 76, 77, 78, 79,
19  80, 81, 82, 83, 84, 85, 86, 87,
20  88, 89, 90, 91, 92, 93, 94, 95,
21  96, 97, 98, 99, 100, 101, 102, 103,
22  104, 105, 106, 107, 108, 110, 112, 114,
23  116, 118, 120, 122, 124, 127, 129, 131,
24  133, 136, 138, 140, 143, 145, 147, 150,
25  152, 155, 158, 160, 163, 166, 168, 171,
26  174, 177, 180, 182, 185, 188, 192, 195,
27  198, 201, 204, 208, 211, 214, 218, 221,
28  225, 228, 232, 236, 240, 243, 247, 251,
29  255, 259, 263, 267, 271, 275, 280, 284,
30  288, 293, 297, 302, 306, 311, 316, 321,
31  325, 330, 335, 341, 346, 351, 356, 362,
32  367, 373, 379, 384, 390, 396, 402, 408,
33  414, 420, 427, 433, 439, 446, 452, 459,
34  466, 473, 480, 487, 494, 502, 509, 517,
35  525, 532, 540, 548, 556, 564, 573, 581,
36  589, 598, 607, 615, 624, 634, 643, 652,
37  662, 672, 681, 691, 701, 711, 722, 732,
38  743, 753, 764, 775, 786, 798, 809, 821,
39  833, 845, 857, 870, 882, 895, 907, 920,
40  934, 947, 961, 975, 989, 1003, 1017, 1023 };
41 
42 // #include <mapPad.h>
43 // #include <mapTime.h>
44 
45 using namespace OLDEVP;
46 
47 int SSD_Reader::ssdData(int ladder,
48  char eastWest,
49  int channel,
50  int &data,
51  int &ped,
52  int &noise) {
53 
54  int cnt=0,strip,pad,i,det,pos,mtime,time,daqLadder;
55  static unsigned int cache1[12288];
56  static unsigned int cache2[12288];
57  static int daqLadderInit=-1;
58 
59  data = -1; ped = -1; noise= -1;
60 
61  // Set daqLadder.
62  daqLadder = SSDDaqLadder(eastWest,ladder);
63 
64 
65 
66  // For speed, we cache the data for one ladder. Adapted from Boucham's special.C.
67  if(daqLadderInit!=daqLadder) {
68  daqLadderInit=daqLadder;
69  for(i=0;i<12288;i++) { cache1[i]=0; cache2[i]=0; } // This is necessary -- not all members are reset if ssd.mode==0.
70  if(ssd.mode==0) { // real data
71  pos=0;
72  for(time=0;time<192;time++) { // Though "time" is not used explicitly, it's involved in incrementeing "pos".
73  for(pad=0;pad<64;pad++) {
74  if (!ssd.counts[daqLadder][pad]) continue;
75  for(mtime=0;mtime<ssd.counts[daqLadder][pad];mtime++) {
76  if (time==ssd.strip[daqLadder][pad][mtime])
77  {
78  det=pos/768; strip=pos%768;
79  assert(pos>=0&&pos<12288);
80  cache1[pos]=log8to10_table[ssd.adc[daqLadder][pad][mtime]];
81  cnt++;
82  } // if(time
83  } // for(mtime
84  pos++;
85  } // for(pad
86  } // for(time
87  } else if(ssd.mode==1) { // pedestal data
88  pos=0;
89  for(time=0;time<192;time++) {
90  for(pad=0;pad<64;pad++) {
91  cache1[pos]=ssd.adc[daqLadder][pad][time];
92  cache2[pos]=ssd.strip[daqLadder][pad][time]; // "strip"s role in ped data is completely different than in real data.
93  pos++;
94  }
95  }
96  } else {
97  assert(0); // unknown value of ssd.mode
98  }
99  } // if(daqLadderInit ...
100 
101  if(ssd.mode==0) {
102  data=cache1[channel];
103  } else if(ssd.mode==1) {
104  ped=cache1[channel];
105  noise=cache2[channel];
106  } else {
107  assert(0); // unknown value of ssd.mode
108  }
109 
110  return ssd.mode ;
111 }
112 
113 SSD_Reader::SSD_Reader(EventReader *er) {
114 
115  //static int call=0;
116 
117  char *datap; // ,ew;
118 
119  datap=er->getDATAP();
120  if (datap) {
121 
122  std::time_t utime = er->getEventInfo().UnixTime;
123  std::tm *time = gmtime(&utime);
124 
125  //LDate = (((1900+time->tm_year)*100 + 1 + time->tm_mon)*100 + time->tm_mday)*100;
126  //LDate = yyyymmdd
127  //year 2005 = 105
128  //month : starts from 0
129  LDate = (1900+time->tm_year)*10000 + (1 + time->tm_mon)*100 + time->tm_mday;
130  LTime = (time->tm_hour*100 + time->tm_min)*100 + time->tm_sec;
131  //cout << "year=" << time->tm_year << " month = " << time->tm_mon << " day=" << time->tm_mday << endl;
132 #ifndef NEW_DAQ_READER_DAQLIB
133  OLDEVP::ssdReader(datap); // call the "event pool" code
134  }
135 #else
136  else {
137  daqReader *rdr=er->getDaqReader(); assert(rdr);
138  ::ssdReader((char*)rdr); // call the "event pool" code
139  }
140 #endif
141 }
142 
143 int SSD_Reader::SSDDaqLadder(char eastWest, int ladder)
144 {
145  int daqLadder=-1;
146  //cout <<"LDate =" << LDate << endl;
147  if ( (LDate < 20040731) && (LTime < 1)){
148  // Year4 data format stops on July 31st 2004
149  // cout << "SSD_Reader::SSDDaqLadder : Year4 data " << endl;
150  switch(eastWest) {
151  case 'E':
152  switch(ladder) {
153  case 1: daqLadder=38; break;
154  case 2: daqLadder=36; break;
155  case 3: daqLadder=39; break;
156  case 9: daqLadder=29; break;
157  case 10: daqLadder=26; break;
158  case 11: daqLadder=28; break;
159  case 12: daqLadder=23; break;
160  case 13: daqLadder=20; break;
161  case 19: daqLadder=30; break;
162  case 20: daqLadder=33; break;
163  }
164  break;
165 
166  case 'W':
167  switch(ladder) {
168  case 1: daqLadder=18; break;
169  case 2: daqLadder=16; break;
170  case 3: daqLadder=19; break;
171  case 9: daqLadder= 9; break;
172  case 10: daqLadder= 6; break;
173  case 11: daqLadder= 8; break;
174  case 12: daqLadder= 3; break;
175  case 13: daqLadder= 0; break;
176  case 19: daqLadder=10; break;
177  case 20: daqLadder=13; break;
178  }
179  break;
180  default: assert(0); // Someone called this function with a bad value of eastWest.
181  }
182  }
183  if ((LDate >= 20040731) && (LDate <= 20050731))
184  {
185  // Year 2005 data format post July 31st 2004
186  //cout << "SSD_Reader::SSDDaqLadder : Year5 data " << endl;
187  switch(eastWest) {
188  case 'E':
189  switch(ladder) {
190  case 1: daqLadder=27; break;
191  case 2: daqLadder=29; break;
192  case 3: daqLadder=26; break;
193  case 4: daqLadder=28; break;
194  case 5: daqLadder=25; break;
195  case 6: daqLadder=22; break;
196  case 7: daqLadder=24; break;
197  case 8: daqLadder=21; break;
198  case 9: daqLadder=23; break;
199  case 10: daqLadder=20; break;
200  case 11: daqLadder=30; break;
201  case 12: daqLadder=33; break;
202  case 13: daqLadder=31; break;
203  case 14: daqLadder=34; break;
204  case 15: daqLadder=32; break;
205  case 16: daqLadder=35; break;
206  case 17: daqLadder=38; break;
207  case 18: daqLadder=36; break;
208  case 19: daqLadder=39; break;
209  case 20: daqLadder=37; break;
210  }
211  break;
212 
213  case 'W':
214  switch(ladder) {
215  case 1: daqLadder=7; break;
216  case 2: daqLadder=9; break;
217  case 3: daqLadder=6; break;
218  case 4: daqLadder=8; break;
219  case 5: daqLadder=5; break;
220  case 6: daqLadder=2; break;
221  case 7: daqLadder=4; break;
222  case 8: daqLadder=1; break;
223  case 9: daqLadder=3; break;
224  case 10: daqLadder=0; break;
225  case 11: daqLadder=10; break;
226  case 12: daqLadder=13; break;
227  case 13: daqLadder=11; break;
228  case 14: daqLadder=14; break;
229  case 15: daqLadder=12; break;
230  case 16: daqLadder=15; break;
231  case 17: daqLadder=18; break;
232  case 18: daqLadder=16; break;
233  case 19: daqLadder=19; break;
234  case 20: daqLadder=17; break;
235  }
236  break;
237  default: assert(0); // Someone called this function with a bad value of eastWest.
238  }
239  }
240  if(LDate > 20060731) {
241  // Year 2007 data format post July 31st 2006
242  //cout << "SSD_Reader::SSDDaqLadder : Year7 data " << endl;
243  switch(eastWest) {
244  case 'E':
245  switch(ladder) {
246  case 1: daqLadder=27; break;
247  case 2: daqLadder=29; break;
248  case 3: daqLadder=26; break;
249  case 4: daqLadder=28; break;
250  case 5: daqLadder=25; break;
251  case 6: daqLadder=22; break;
252  case 7: daqLadder=24; break;
253  case 8: daqLadder=21; break;
254  case 9: daqLadder=23; break;
255  case 10: daqLadder=20; break;
256  case 11: daqLadder=30; break;
257  case 12: daqLadder=33; break;
258  case 13: daqLadder=31; break;
259  case 14: daqLadder=34; break;
260  case 15: daqLadder=32; break;
261  case 16: daqLadder=35; break;
262  case 17: daqLadder=38; break;
263  case 18: daqLadder=36; break;
264  case 19: daqLadder=39; break;
265  case 20: daqLadder=37; break;
266  }
267  break;
268 
269  case 'W':
270  switch(ladder) {
271  case 1: daqLadder=17; break;
272  case 2: daqLadder=19; break;
273  case 3: daqLadder=16; break;
274  case 4: daqLadder=18; break;
275  case 5: daqLadder=15; break;
276  case 6: daqLadder=12; break;
277  case 7: daqLadder=14; break;
278  case 8: daqLadder=11; break;
279  case 9: daqLadder=13; break;
280  case 10: daqLadder=10; break;
281  case 11: daqLadder=0; break;
282  case 12: daqLadder=3; break;
283  case 13: daqLadder=1; break;
284  case 14: daqLadder=4; break;
285  case 15: daqLadder=2; break;
286  case 16: daqLadder=5; break;
287  case 17: daqLadder=8; break;
288  case 18: daqLadder=6; break;
289  case 19: daqLadder=9; break;
290  case 20: daqLadder=7; break;
291  }
292  break;
293  default: assert(0); // Someone called this function with a bad value of eastWest.
294  }
295  }
296  // Check ladder and eastWest args. Also check completeness of above switches.
297  assert(daqLadder>=0 && daqLadder < 40);
298  return daqLadder;
299 }