StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SVTV1P0_ADCR_SR.cxx
1 /***************************************************************************
2  *
3  * $Id: SVTV1P0_ADCR_SR.cxx,v 1.5 2007/12/24 06:04:27 fine Exp $
4  *
5  * Author: Jeff Landgraf, M.J. LeVine, Marcelo Munhoz, J. Schambach
6  *
7  ***************************************************************************
8  *
9  * Description: // SVT ADC Raw Reader
10  *
11  ***************************************************************************
12  *
13  * $Log: SVTV1P0_ADCR_SR.cxx,v $
14  * Revision 1.5 2007/12/24 06:04:27 fine
15  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
16  *
17  * Revision 1.4 2003/09/02 17:55:33 perev
18  * gcc 3.2 updates + WarnOff
19  *
20  * Revision 1.3 2001/05/10 15:19:08 jschamba
21  * unscrambling of Format = 2 data was done each time initialize was called. Rewrite header
22  * to indicate Format = 0 after unscrambling prevents this.
23  *
24  * Revision 1.2 2001/04/18 19:47:25 ward
25  * StDaqLib/SVT stuff from Jo Schambach.
26  *
27  * Revision 1.1 2000/06/06 18:08:31 jml
28  * Initial version of SVT Readers (author: marcello munholz, helen caines)
29  *
30  *
31  **************************************************************************/
32 #include <Stiostream.h>
33 
34 
35 #include "StDaqLib/GENERIC/EventReader.hh"
36 #include "SVTV1P0.hh"
37 
38 //==================== ADC Raw Reader =============================
39 
40 using namespace OLDEVP;
41 
42 SVTV1P0_ADCR_SR::SVTV1P0_ADCR_SR(int w, SVTV1P0_Reader *det)
43 {
44  // cout << "Constructing SVTV1P0_ADCR_SR" << endl;
45  barrel = 0;
46  ladder = 0;
47  wafer = w;
48  detector = det;
49 
50  // NULLS in banks array
51  banks = (classname(Bank_SVTADCR) *)NULL;
52 }
53 
54 SVTV1P0_ADCR_SR::SVTV1P0_ADCR_SR(int b, int l, int w, SVTV1P0_Reader *det)
55 {
56  // cout << "Constructing SVTV1P0_ADCR_SR" << endl;
57  barrel = b;
58  ladder = l;
59  wafer = w;
60  detector = det;
61 
62  // NULLS in banks array
63  banks = (classname(Bank_SVTADCR) *)NULL;
64 }
65 
66 int SVTV1P0_ADCR_SR::initialize()
67 {
68  // get a sector reader for ANODK
69  anodkr = detector->getANODKReader();
70  if (!anodkr) return FALSE;
71 
72  int hypersector, rcb, mz;
73 
74  ANODK_entry ent;
75  // store pointers to the ADCR banks
76  int hybrid = 1; // both hybrids are in same bank
77  if (barrel)
78  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
79  else
80  anodkr->get(wafer, hybrid, &ent);
81 
82  hypersector = ent.hypersector;
83  rcb = ent.rb;
84  mz = ent.mz;
85 
86  /*
87  printf("SVTV1P0_ADCR_SR::wafer = %d, hybrid = %d, hypersector = %d, rcb = %d, mz = %d\n",
88  wafer,hybrid,hypersector,rcb,mz);
89  */
90 
91  if ((hypersector) && (rcb) && (mz)) {
92  banks = detector->getBankSVTADCR(hypersector,rcb,mz);
93 
94  if (banks) {
95  // check the format number for different raw data formats:
96  if (banks->header.FormatNumber == 2) {
97  // new format of raw data, need to convert it:
98  u_char *adc_old = (u_char *)banks->ADC;
99  u_char adc_new[6][256][128];
100  for (hybrid=0; hybrid<6; hybrid++) {
101  u_char *ptr0 = adc_old + hybrid*128*256;
102  u_char *ptr64 = adc_old + hybrid*128*256 + 1;
103  u_char *ptr128 = adc_old + hybrid*128*256 + 2;
104  u_char *ptr192 = adc_old + hybrid*128*256 + 3;
105  for (int anode=0; anode<64; anode++)
106  for (int tb=0; tb<128; tb++) {
107  adc_new[hybrid][anode][tb] = *ptr0;
108  adc_new[hybrid][anode+64][tb] = *ptr64;
109  adc_new[hybrid][anode+128][tb] = *ptr128;
110  adc_new[hybrid][anode+192][tb] = *ptr192;
111  ptr0+=4; ptr64+=4; ptr128+=4; ptr192+=4;
112  }
113  }
114  memcpy((void *)adc_old, (const void *)adc_new, 6*256*128);
115  // since this now looks like unscrambled (format 0) data
116  // change the format number in the header to 0
117  banks->header.FormatNumber = 0;
118  } // ...if (banks->header.FormatNumber == 2
119  } // ...if (banks
120  }
121  else
122  return FALSE;
123 
124  return TRUE;
125 }
126 
127 SVTV1P0_ADCR_SR::~SVTV1P0_ADCR_SR()
128 {
129  // cout << "Deleting SVTV1P0_ADCR_SR" << endl;
130 }
131 
132 int SVTV1P0_ADCR_SR::getPadList(int hybrid, u_char **anodeList)
133 {
134  // Construct the anodelist array for this PadRow
135  int i;
136  ANODK_entry ent;
137 
138  // Fill in padrows
139  int j=0;
140  for(i=1; i<=SVT_ANODES; i++)
141  {
142  if (barrel)
143  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
144  else
145  anodkr->get(wafer, hybrid, &ent);
146 
147  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0)) continue;
148  anodelist[hybrid-1][j++] = i;
149  }
150  // confusing syntax but correct
151  *anodeList = &anodelist[hybrid-1][0];
152  return j;
153 }
154 
155 int SVTV1P0_ADCR_SR::getSequences(int hybrid, int Anode, int *nArray,
156  u_char **Array)
157 {
158  ANODK_entry ent;
159  if (barrel)
160  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
161  else
162  anodkr->get(wafer, hybrid, &ent);
163 
164  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0))
165  {
166  *nArray = 0;
167  *Array = NULL;
168  spERROR(ERR_BANK);
169  return -1;
170  }
171 
172  int offset = (ent.offset * anodkr->getADCBytes() * SVT_MZANODES) +
173  (anodkr->getADCBytes() * (Anode-1));
174  *nArray = anodkr->getADCBytes();
175 
176  // printf("Offset = %d\n",offset);
177  // printf("array coord: rb=%d, mz=%d\n",ent.rb,ent.mz);
178 
179  if (banks != NULL)
180  {
181  *Array = (((u_char *)banks->ADC) + offset);
182  // cout << "SVTV1P0_ADCR_SR::Array = " << *Array << endl;
183  return 1;
184  }
185 
186  return 0;
187 }
188 
189 int SVTV1P0_ADCR_SR::MemUsed()
190 {
191  return 0;
192 }
193 
194 //==================== Pedestal Reader ===========================
195 
196 SVTV1P0_PEDR_SR::SVTV1P0_PEDR_SR(int w, SVTV1P0_Reader *det)
197 {
198  // cout << "Constructing SVTV1P0_PEDR_SR" << endl;
199  barrel = 0;
200  ladder = 0;
201  wafer = w;
202  detector = det;
203 
204  // NULLS in banks array
205  banks = (classname(Bank_SVTPEDR) *)NULL;
206  numEvents = 0;
207 }
208 
209 SVTV1P0_PEDR_SR::SVTV1P0_PEDR_SR(int b, int l, int w, SVTV1P0_Reader *det)
210 {
211  // cout << "Constructing SVTV1P0_PEDR_SR" << endl;
212  barrel = b;
213  ladder = l;
214  wafer = w;
215  detector = det;
216 
217  // NULLS in banks array
218  banks = (classname(Bank_SVTPEDR) *)NULL;
219  numEvents = 0;
220 }
221 
222 int SVTV1P0_PEDR_SR::initialize()
223 {
224  // get a sector reader for ANODK
225  anodkr = detector->getANODKReader();
226  if (!anodkr) return FALSE;
227 
228  int hypersector, rcb, mz;
229 
230  ANODK_entry ent;
231  // store pointers to the PEDR banks
232  int hybrid = 1; // both hybrids are in same bank
233  if (barrel)
234  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
235  else
236  anodkr->get(wafer, hybrid, &ent);
237 
238  hypersector = ent.hypersector;
239  rcb = ent.rb;
240  mz = ent.mz;
241 
242  banks = detector->getBankSVTPEDR(hypersector,rcb,mz);
243 
244  if (banks != NULL) {
245  numEvents = banks->NumEvents;
246  // check the format number for different raw data formats:
247  if (banks->header.FormatNumber == 2) {
248  // new format of raw data, need to convert it:
249  u_char *adc_old = (u_char *)banks->pedestal;
250  u_char adc_new[6][256][128];
251  for (hybrid=0; hybrid<6; hybrid++) {
252  u_char *ptr0 = adc_old + hybrid*128*256;
253  u_char *ptr64 = adc_old + hybrid*128*256 + 1;
254  u_char *ptr128 = adc_old + hybrid*128*256 + 2;
255  u_char *ptr192 = adc_old + hybrid*128*256 + 3;
256  for (int anode=0; anode<64; anode++)
257  for (int tb=0; tb<128; tb++) {
258  adc_new[hybrid][anode][tb] = *ptr0;
259  adc_new[hybrid][anode+64][tb] = *ptr64;
260  adc_new[hybrid][anode+128][tb] = *ptr128;
261  adc_new[hybrid][anode+192][tb] = *ptr192;
262  ptr0+=4; ptr64+=4; ptr128+=4; ptr192+=4;
263  }
264  }
265  memcpy((void *)adc_old, (const void *)adc_new, 6*256*128);
266  // since this now looks like unscrambled (format 0) data
267  // change the format number in the header to 0
268  banks->header.FormatNumber = 0;
269  } // ...if (banks->header.FormatNumber == 2
270  } // ...if (banks != NULL
271 
272  return TRUE;
273 }
274 
275 SVTV1P0_PEDR_SR::~SVTV1P0_PEDR_SR()
276 {
277  // cout << "Deleting SVTV1P0_PEDR_SR" << endl;
278 }
279 
280 int SVTV1P0_PEDR_SR::getPadList(int hybrid, u_char **anodeList)
281 {
282  // Construct the anodelist array for this PadRow
283  int i;
284  ANODK_entry ent;
285 
286  // Fill in padrows
287  int j=0;
288  for(i=1; i<=SVT_ANODES; i++)
289  {
290  if (barrel)
291  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
292  else
293  anodkr->get(wafer, hybrid, &ent);
294 
295  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0)) continue;
296  anodelist[hybrid-1][j++] = i;
297  }
298  // confusing syntax but correct
299  *anodeList = &anodelist[hybrid-1][0];
300  return j;
301 }
302 
303 int SVTV1P0_PEDR_SR::getSequences(int hybrid, int Anode, int *nArray,
304  u_char **Array)
305 {
306  ANODK_entry ent;
307  if (barrel)
308  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
309  else
310  anodkr->get(wafer, hybrid, &ent);
311 
312  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0))
313  {
314  *nArray = 0;
315  *Array = NULL;
316  spERROR(ERR_BANK);
317  return -1;
318  }
319 
320  int offset = (ent.offset * anodkr->getPEDBytes() * SVT_MZANODES) +
321  (anodkr->getPEDBytes() * (Anode-1));
322  *nArray = anodkr->getPEDBytes();
323 
324  if (banks != NULL) {
325  // printf("Offset = %d\n",offset);
326  // printf("array coord: rb=%d, mz=%d\n",ent.rb,ent.mz);
327  *Array = (((u_char *)banks->pedestal) + offset);
328  return 1;
329  }
330  return 0;
331 }
332 
333 int SVTV1P0_PEDR_SR::getNumberOfEvents()
334 {
335  return numEvents;
336 }
337 
338 int SVTV1P0_PEDR_SR::MemUsed()
339 {
340  return 0;
341 }
342 
343 
344 //==================== RMS Reader =============================
345 
346 SVTV1P0_PRMS_SR::SVTV1P0_PRMS_SR(int w, SVTV1P0_Reader *det)
347 {
348  // cout << "Constructing SVTV1P0_PRMS_SR" << endl;
349  barrel = 0;
350  ladder = 0;
351  wafer = w;
352  detector = det;
353 
354  // NULLS in banks array
355  banks = (classname(Bank_SVTRMSR) *)NULL;
356  numEvents = 0;
357 
358 }
359 
360 SVTV1P0_PRMS_SR::SVTV1P0_PRMS_SR(int b, int l, int w, SVTV1P0_Reader *det)
361 {
362  // cout << "Constructing SVTV1P0_PRMS_SR" << endl;
363  barrel = b;
364  ladder = l;
365  wafer = w;
366  detector = det;
367 
368  // NULLS in banks array
369  banks = (classname(Bank_SVTRMSR) *)NULL;
370  numEvents = 0;
371 }
372 
373 int SVTV1P0_PRMS_SR::initialize()
374 {
375  // get a sector reader for ANODK
376  anodkr = detector->getANODKReader();
377  if (!anodkr) return FALSE;
378 
379  int hypersector, rcb, mz;
380 
381  ANODK_entry ent;
382  // store pointers to the ADCR banks
383  int hybrid = 1;
384  if (barrel)
385  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
386  else
387  anodkr->get(wafer, hybrid, &ent);
388 
389  hypersector = ent.hypersector;
390  rcb = ent.rb;
391  mz = ent.mz;
392 
393  banks = detector->getBankSVTRMSR(hypersector,rcb,mz);
394 
395  if (banks != NULL) {
396  numEvents = banks->NumEvents;
397 
398  // check the format number for different raw data formats:
399  if (banks->header.FormatNumber == 2) {
400  // new format of raw data, need to convert it:
401  u_char *adc_old = (u_char *)banks->pedRMSt16;
402  u_char adc_new[6][256][128];
403  for (hybrid=0; hybrid<6; hybrid++) {
404  u_char *ptr0 = adc_old + hybrid*128*256;
405  u_char *ptr64 = adc_old + hybrid*128*256 + 1;
406  u_char *ptr128 = adc_old + hybrid*128*256 + 2;
407  u_char *ptr192 = adc_old + hybrid*128*256 + 3;
408  for (int anode=0; anode<64; anode++)
409  for (int tb=0; tb<128; tb++) {
410  adc_new[hybrid][anode][tb] = *ptr0;
411  adc_new[hybrid][anode+64][tb] = *ptr64;
412  adc_new[hybrid][anode+128][tb] = *ptr128;
413  adc_new[hybrid][anode+192][tb] = *ptr192;
414  ptr0+=4; ptr64+=4; ptr128+=4; ptr192+=4;
415  }
416  }
417  memcpy((void *)adc_old, (const void *)adc_new, 6*256*128);
418  // since this now looks like unscrambled (format 0) data
419  // change the format number in the header to 0
420  banks->header.FormatNumber = 0;
421  } // ...if (banks->header.FormatNumber == 2
422  } // ...if (banks !=NULL
423 
424  return TRUE;
425 }
426 
427 SVTV1P0_PRMS_SR::~SVTV1P0_PRMS_SR()
428 {
429  // cout << "Deleting SVTV1P0_PRMS_SR" << endl;
430 }
431 
432 int SVTV1P0_PRMS_SR::getPadList(int hybrid, u_char **anodeList)
433 {
434  // Construct the anodelist array for this PadRow
435  int i;
436  ANODK_entry ent;
437 
438  // Fill in padrows
439  int j=0;
440  for(i=1; i<=SVT_ANODES; i++)
441  {
442  if (barrel)
443  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
444  else
445  anodkr->get(wafer, hybrid, &ent);
446 
447  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0)) continue;
448  anodelist[hybrid-1][j++] = i;
449  }
450  // confusing syntax but correct
451  *anodeList = &anodelist[hybrid-1][0];
452  return j;
453 }
454 
455 int SVTV1P0_PRMS_SR::getSequences(int hybrid, int Anode, int *nArray,
456  u_char **Array)
457 {
458  ANODK_entry ent;
459  if (barrel)
460  anodkr->get(barrel, ladder, wafer, hybrid, &ent);
461  else
462  anodkr->get(wafer, hybrid, &ent);
463 
464  if((ent.mz == 0) || (ent.rb == 0) || (ent.hypersector == 0))
465  {
466  *nArray = 0;
467  *Array = NULL;
468  spERROR(ERR_BANK);
469  return -1;
470  }
471 
472  int offset = (ent.offset * anodkr->getRMSBytes() * SVT_MZANODES) +
473  (anodkr->getRMSBytes() * (Anode-1));
474  *nArray = anodkr->getRMSBytes();
475 
476  if (banks != NULL)
477  {
478  // printf("Offset = %d\n",offset);
479  // printf("array coord: rb=%d, mz=%d\n",ent.rb,ent.mz);
480  *Array = (((u_char *)banks->pedRMSt16) + offset);
481  return 1;
482  }
483  return 0;
484 }
485 
486 int SVTV1P0_PRMS_SR::getNumberOfEvents()
487 {
488  return numEvents;
489 }
490 
491 int SVTV1P0_PRMS_SR::MemUsed()
492 {
493  return 0;
494 }
495 
496 
Definition: SVTV1P0.hh:222