StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TPCV2P0_ZS_SR.cxx
1 /***************************************************************************
2  * $Id: TPCV2P0_ZS_SR.cxx,v 1.29 2008/01/20 00:35:42 perev Exp $
3  * Author: M.J. LeVine
4  ***************************************************************************
5  * Description: TPC V2.0 Zero Suppressed Reader
6  *
7  *
8  * change log
9  * 28-May-99 MJL on encountering a missing TPCSEQD bank,
10  * tries to fill in the Pad_array structs using the RAW banks (if present)
11  * 31-May-99 MJL terminate on encountering pad 255
12  * 03-Jun-99 MJL added return TRUE to TPCV2P0_ZS_SR::initialize()
13  * 10-Jun-99 IS (Iwona Sakrejda) - The compiler we are using currently in Root
14  * cannot contain the scope of the "for" loop index within parenthesis.
15  * So if the next loop uses same index, it cannot be Declared again.
16  * I made 2 for rcg and marked them both in the code.
17  * 20-Jun-99 MJL corrected Iwona's fix, which depends on the "leak" out of the
18  * 'for' scope to define the variable elsewhere. At the very least this makes
19  * gdb very confused. Now the offending rcb is defined outside the scope of
20  * all for loops
21  * 21-Jun-99 MJL change behavior on discovering a "bit 5" error.
22  * Now skip sequences
23  * until next "switch=1" sequence
24  * 23-Jun-99 MJL most output now supressed with EventReader.verbose
25  * 07-Jul-99 MJL if no banks found for a given rcb,mz just skip it.
26  * No longer return FALSE
27  * 27-Jul-99 MJL init RowSpacePts = 0 to make destructor robust
28  * 29-Aug-99 MJL #include <Stiostream.h> for HP platform
29  * 07-Feb-00 MJL add diagnostics when bad cluster data encountered
30  * 23-Feb-00 MJL fix bug (~line 229) which didn't handle split sequences
31  * correctly. Thanks to Herb Ward.
32  * 24-Feb-00 MJL clean up loop structure, add comments everywhere
33  * 28-Feb-00 MJL protect against hardware quirks in VRAM
34  * 29-Feb-00 MJL change loop logic line 220 (test seqCnt, not i)
35  *
36  ***************************************************************************
37  * $Log: TPCV2P0_ZS_SR.cxx,v $
38  * Revision 1.29 2008/01/20 00:35:42 perev
39  * Supress redundant print
40  *
41  * Revision 1.28 2007/12/24 06:04:33 fine
42  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
43  *
44  * Revision 1.27 2004/03/25 21:07:32 ward
45  * Suppress more debug messages.
46  *
47  * Revision 1.26 2004/03/24 18:44:58 ward
48  * Suppress debug messages.
49  *
50  * Revision 1.25 2004/03/10 05:53:08 jeromel
51  * Left a debug line in (to remove later)
52  *
53  * Revision 1.24 2004/03/04 21:51:29 ward
54  * Replaced MERGE_SEQUENCES with a StDAQMaker chain parameter, as suggested by Landgraf and Lauret.
55  *
56  * Revision 1.23 2004/02/03 20:07:18 jml
57  * added MERGE_SEQUENCES define
58  *
59  * Revision 1.22 2003/10/01 20:55:06 ward
60  * Protection against empty TPCSEQD banks.
61  *
62  * Revision 1.21 2003/09/02 17:55:33 perev
63  * gcc 3.2 updates + WarnOff
64  *
65  * Revision 1.20 2000/11/15 21:02:02 ward
66  * Another .daq corruption check. It is on the TPCSEQD bank.
67  *
68  * Revision 1.19 2000/11/07 16:30:27 ward
69  * New check for .daq corruption, with kStErr from St_tpcdaq_Maker.
70  *
71  * Revision 1.18 2000/07/05 09:17:26 ward
72  * Fixed a one-off subscripting err & removed ref to a deleted obj.
73  *
74  * Revision 1.17 2000/06/22 21:19:16 ward
75  * added stop<start to bad cluster criteria
76  *
77  * Revision 1.16 2000/02/29 20:20:29 levine
78  * corrected loop logic line 220
79  *
80  * Revision 1.15 2000/02/28 22:02:51 levine
81  * add protection against illegal CPP sequences - was causing unitialized pointers
82  *
83  * Revision 1.14 2000/02/08 21:34:06 levine
84  * added diagnostics for bad cluster pointers
85  *
86  * Revision 1.13 2000/01/04 20:55:05 levine
87  * Implemented memory-mapped file access in EventReader.cxx. Old method
88  * (via seeks) is still possible by setting mmapp=0 in
89  *
90  * getEventReader(fd,offset,(const char *)logfile,mmapp);
91  *
92  *
93  * but memory-mapped access is much more effective.
94  *
95  * Revision 1.12 1999/12/09 02:50:41 levine
96  * #define changed to get rid of unused fee array defs for TPCv?P0_ZS_SR.cxx
97  * only
98  *
99  * Revision 1.11 1999/12/07 23:10:46 levine
100  * changes to silence the gcc compiler warnings
101  *
102  * Revision 1.10 1999/09/02 21:47:12 fisyak
103  * HP corrections
104  *
105  * Revision 1.9 1999/07/27 23:08:08 levine
106  * bug fix: initialize RowSpacePts[] =0 to make destructor robust
107  *
108  * Revision 1.8 1999/07/21 21:15:41 levine
109  *
110  * TPCV2P0_ZS_SR.cxx changed to include the TPCV2P0_ZS_SR::getSpacePts()
111  * (cluster-finder reader). TPCV1P0_ZS_SR.cxx changed to include empty
112  * version of the same method.
113  *
114  * Revision 1.7 1999/07/07 19:55:43 levine
115  * Now behaves correctly when encountering a partially populated (e.g., one RB) sector
116  *
117  * Revision 1.6 1999/07/02 04:43:24 levine
118  * Many changes -
119  * navigates to head of TPCP bank independent of position.
120  * move declarations out of loops where they were upsetting some compilers
121  * suppress output from class libraries with run-time switch EventReader.verbose
122  * added TPCV2P0_CPP_SR::getAsicParams()
123  *
124  *
125  **************************************************************************/
126 #include <Stiostream.h>
127 #include <assert.h>
128 #include "StDaqLib/GENERIC/EventReader.hh"
129 #include "TPCV2P0.hh"
130 
131 #define MAKE_THE_DAMNED_COMPILER_SILENT
132 // #define MERGE_SEQUENCES replaced by mMergeSequences, Herb Ward, Mar 4 2004.
133 
134 #include "fee_pin.h"
135 //
136 using namespace OLDEVP;
137 
138 TPCV2P0_ZS_SR::TPCV2P0_ZS_SR(int s, TPCV2P0_Reader *det, char mergeSequences)
139 {
140  assert(mergeSequences==0||mergeSequences==1);
141  mMergeSequences=mergeSequences;
142 
143  sector = s-1; // convert the sector into internal representation
144  detector = det;
145  if (detector->ercpy->verbose){
146  cout << "Constructing TPCV2P0_ZS_SR" << endl
147  << " MergeSequence is " << (mMergeSequences?"ON":"OFF") << endl;
148  }
149 
150  // NULLS in banks array
151  memset((char *)adcd_p, 0, sizeof(adcd_p));
152  memset((char *)adcx_p, 0, sizeof(adcx_p));
153  memset((char *)seqd_p, 0, sizeof(seqd_p));
154 
155  for(int ii=TPC_PADROWS-1;ii>=0;ii--) RowSpacePts[ii]=0;
156 
157 }
158 
159 int TPCV2P0_ZS_SR::initialize()
160 {
161  for (int row=0; row<TPC_PADROWS; row++) {
162  for (int pad=0; pad<TPC_MAXPADS; pad++) {
163  Pad_array[row][pad].nseq=0;
164  Pad_array[row][pad].seq= (Sequence *)0;
165  }
166  }
167 
168  // *** DEBUG LINE *** COMMENT LATER ***
169 //VP cout << "TPCV2P0_ZS_SR::initialize : mMergeSequences=" << (mMergeSequences?"ON":"OFF") << endl;
170 
171  int rcb; // define for following for loops
172  // store pointers to the ADCD, ADCX, SEQD banks
173  for(rcb = 0; rcb < 6; rcb++)
174  {
175  for(int mz = 0; mz < 3; mz++)
176  {
177  adcd_p[rcb][mz] = detector->getBankTPCADCD(sector,rcb,mz);
178  if ((void *)adcd_p[rcb][mz] != NULL) {
179  // if (detector->ercpy->verbose) printf("found ADCD RB%d MZ%d\n",rcb+1,mz+1);
180  fflush(stdout);
181  }
182  adcx_p[rcb][mz] = detector->getBankTPCADCX(sector,rcb,mz);
183  if ((void *)adcx_p[rcb][mz] != NULL) {
184  // if (detector->ercpy->verbose) printf("found ADCX RB%d MZ%d\n",rcb+1,mz+1);
185  fflush(stdout);
186  }
187  seqd_p[rcb][mz] = detector->getBankTPCSEQD(sector,rcb,mz);
188  if ((void *)seqd_p[rcb][mz] != NULL) {
189  // if (detector->ercpy->verbose) printf("found SEQD RB%d MZ%d\n",rcb+1,mz+1);
190  fflush(stdout);
191  }
192  }
193  }
194 
195 
196  // search through the SEQD banks to build our tables of what's where
197 
198  // This stupid compiler thinks rcb's scope extends here, so I removed int
199  // The original line should go in when we upgrade to a better compiler
200  // for(int rcb = 0; rcb < 6; rcb++) {
201  for(rcb = 0; rcb < 6; rcb++) {
202  for(int mz = 0; mz < 3; mz++) {
203  if (seqd_p[rcb][mz] == (classname(Bank_TPCSEQD) *)NULL) {
204  //TPCSEQD bank doesn't exist
205  // set up raw data pointers
206  TPCV2P0_PADK_SR *padkr = detector->getPADKReader(sector);
207  // if (!padkr) return FALSE;
208  if (!padkr) continue;
209  classname(Bank_TPCADCR) *adcr =
210  detector->getBankTPCADCR(sector,rcb,mz) ; //pointer to ADC raw bank
211  // if (!adcr) return FALSE;
212  if (!adcr) continue;
213  classname(Bank_TPCCPPR) *cppr =
214  detector->getBankTPCCPPR(sector,rcb,mz) ; //pointer to CPP raw bank
215  // if (!cppr) return FALSE;
216  if (!cppr) continue;
217 
218  // go through the CPPR/ADCR banks
219  if (detector->ercpy->verbose)
220  printf("reconstructing from RAW banks: SEC%d RB%d MZ%d\n",sector,rcb+1,mz+1);
221  PADK_entry ent;
222 
223  for (int row=1; row<=TPC_PADROWS; row++) {
224  for (int pad=1; pad<=tpcRowLen[row-1]; pad++) {
225  padkr->get(row, pad, &ent);
226  if((ent.mz != mz+1) || (ent.rb != rcb+1)) continue;
227  struct ASIC_Cluster *clusters =
228  (ASIC_Cluster *)(cppr->entry + 32*ent.offset);
229 
230  int lastbin = -2, len = 0;
231  int i, start, stop=-1, newseq;
232  for (i=0; i<TPC_MXSEQUENCE; i++) { //loop over ASIC sequences
233  start = clusters[i].start_time_bin;
234  if ((start < 0)||(start==511)||(start<=stop)) break;
235  //protect against hardware quirks in VRAM
236  newseq = (start>lastbin+1);//sequence not broken in pieces by MZ
237  stop = clusters[i].stop_time_bin;
238  //MJL: not used: len = stop - start + 1;
239  // catch bad values of start, stop
240  if ( stop<start || start<0 || start>511 || stop<0 || stop>511) {
241  struct EventInfo ei;
242  ei = detector->ercpy->getEventInfo();
243  printf("%s:%d: bad TPC cluster data detected\n",
244  __FILE__,__LINE__);
245  printf("evt# %d , sector %d, RB %d, MZ %d row %d, pad %d\n",
246  ei.EventSeqNo,sector+1,rcb+1,mz+1,row,pad);
247  printf("cluster %d: start=0x%x stop=0x%x\n",
248  i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
249  break; //stop processing this pad
250  }
251  lastbin = stop;
252  if (newseq) Pad_array[row-1][pad-1].nseq++;
253  //update the cluster counter for this pad
254  // ...nseq now has CORRECT count of distinct ASIC sequences
255  } // loop over ASIC sequences
256  if (i==TPC_MXSEQUENCE) {
257  //did we overflow the ASIC cluster pointer array
258  // do the rest here by hand
259  }
260 
261  // finished scanning for total number of distinct sequences
262  // this scan is only used to determine the number of sequences
263  int nseq = Pad_array[row-1][pad-1].nseq;
264  if (!nseq) continue; // only if there are sequences on this pad
265  Pad_array[row-1][pad-1].seq=
266  (Sequence *)malloc(nseq*sizeof(Sequence));
267  if (Pad_array[row-1][pad-1].seq==NULL) {
268  cout << "failed to malloc() Sequence structures " << endl;
269  return FALSE;
270  }
271  lastbin = -2;
272  len = 0;
273  int seqCnt = 0;
274 
275  // loop over sequences, filling in structs
276  for (i=0; seqCnt<nseq; i++) { //loop over ASIC sequences
277  if (i<TPC_MXSEQUENCE) {
278  start = clusters[i].start_time_bin;
279  if ((start < 0)||(start==511)) break;
280  newseq = (start>lastbin+1);
281  //sequence not broken in pieces by MZ
282  stop = clusters[i].stop_time_bin;
283  len = stop - start + 1;
284  // catch bad values of start, stop
285  if ( stop<start || start<0 || start>511 || stop<0 || stop>511) {
286  struct EventInfo ei;
287  ei = detector->ercpy->getEventInfo();
288  printf("%s:%d: bad TPC cluster data detected\n",
289  __FILE__,__LINE__);
290  printf("evt# %d , sector %d, RB %d, MZ %d row %d, pad %d\n",
291  ei.EventSeqNo,sector+1,rcb+1,mz+1,row,pad);
292  printf("cluster %d: start=0x%x stop=0x%x\n",
293  i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
294  break; //stop processing this pad
295  }
296  lastbin = stop;
297  if (newseq) {
298  int offset = ent.offset * padkr->getADCBytes() + start;
299  Pad_array[row-1][pad-1].seq[seqCnt].startTimeBin = start;
300  Pad_array[row-1][pad-1].seq[seqCnt].Length = len;
301  Pad_array[row-1][pad-1].seq[seqCnt].FirstAdc =
302  (u_char *)(adcr->ADC + offset);
303  seqCnt++;
304  }
305  else { // continuation of previous sequence
306  assert( seqCnt>=1 && seqCnt<=nseq );
307  Pad_array[row-1][pad-1].seq[seqCnt-1].Length += len;
308  }
309  }
310  else {//did we overflow the ASIC cluster pointer array?
311  // do the rest here by hand (TBDL)
312  }
313  } // loop on seq
314  } // loop on pad
315  } // loop on row
316  } // if TPCSEQD doesn't exist
317  // use this loop when SEQD exists:
318  else { //TPCSEQD bank exists
319  // if (detector->ercpy->verbose) printf("TPCSEQD found sector %d RB%d MZ%d\n",sector+1,rcb+1,mz+1);
320 
321  int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
322  int len = seqd_p[rcb][mz]->header.BankLength - (sizeof(Bank_Header)/4);
323  int numseq = (4*len)/sizeof(short); // find # sequences this bank
324  // go through the SEQD twice:
325  // First: malloc the Sequence arrays needed
326  // Second: fill in the Sequence structs
327 
328  // get a pointer to the CPPr bank for debugging only
329  // classname(Bank_TPCCPPR) *cppr =
330  //detector->getBankTPCCPPR(sector,rcb,mz) ; //pointer to CPP raw bank
331  // get a pointer to the PADK bank for debugging only
332  // TPCV2P0_PADK_SR *padkr = detector->getPADKReader(sector);
333 
334  int i=0,iOld=-1; // Herb, 02nov2000
335  while (i<numseq) { // loop over the #sequences in TPCSEQD
336  if(i<=iOld) return FALSE; // Herb, 02nov2000, as a check for corruption in .daq file
337  iOld=i; // Herb, 02nov2000
338  if (seqd_p[rcb][mz]->sequence[i]<0) { //padrow, pad
339  padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
340  pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
341  if (pad==255) break;
342  //pad 255 exists only in extraneous last word
343  oldstart = 0;
344  lastbin = -2;
345  i++;
346  }
347  else { // start|lastseq|len
348  if (padrow <0 || pad <0) {
349  printf("encountered bad SEQD bank RB %d, Mezz %d\n", rcb+1, mz+1);
350  return FALSE;
351  }
352 
353  unsigned short work = seqd_p[rcb][mz]->sequence[i];
354  int start = work>>6;
355  int len = work & 0x1f;
356  if (start >= oldstart) { // still on same pad
357 
358  if(mMergeSequences) { if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++; }
359  else { Pad_array[padrow-1][pad-1].nseq++; }
360 
361  // don't increment nseq if sequences are adjacent!
362  lastbin = start+len-1;
363  oldstart = start;
364  if (work & 0x20 ) {//last sequence ?
365  assert(padrow>=1&&pad>=1); // Herb_Oct_01_2003, added this assert.
366  int nseq = Pad_array[padrow-1][pad-1].nseq;
367  if (nseq) { // only if there are sequences on this pad
368  //allocate memory for Sequence arrays
369  if (Pad_array[padrow-1][pad-1].seq) {
370  printf("ERROR DETECTED: Pad_array[%d][%d] already malloced\n",
371  padrow-1,pad-1);
372  return FALSE; // Herb, 15nov2000. Causes root4star to skip the event.
373  }
374  Pad_array[padrow-1][pad-1].seq=
375  (Sequence *)malloc(nseq*sizeof(Sequence));
376  if (Pad_array[padrow-1][pad-1].seq==NULL) {
377  cout << "failed to malloc() Sequence structures " << endl;
378  return FALSE;
379  }
380  }
381  pad++; // default to next pad in this padrow
382  lastbin = -2; // set lastbin for new pad
383  oldstart=0;
384  }
385  i++;
386  continue;
387  }
388  else { // starting new pad without bit 5 set!
389  if (detector->ercpy->verbose) printf("new pad detected with bit 5 clear!\n");
390  fflush(stdout);
391  // for debug only:
392  // classname(Bank_TPCPADK) *padk = detector->getBankTPCPADK(sector, rcb, mz);
393 
394  while (seqd_p[rcb][mz]->sequence[i]>0 && i<numseq) i++; // skip until "switch=1"
395  // return FALSE;
396  assert(padrow>=1&&pad>=1); // Herb_Oct_01_2003, added this assert.
397  int nseq = Pad_array[padrow-1][pad-1].nseq;
398  if (nseq) { // only if there are sequences on this pad
399  // allocate memory for Sequence arrays
400  // make sure we don't do it more than once
401  if (Pad_array[padrow-1][pad-1].seq==NULL) {
402  Pad_array[padrow-1][pad-1].seq=
403  (Sequence *)malloc(nseq*sizeof(Sequence));
404  if (Pad_array[padrow-1][pad-1].seq==NULL) {
405  cout << "failed to malloc() Sequence structures " << endl;
406  return FALSE;
407  }
408  }
409  } // if (nseq)
410  } // else { ...starting new pad without bit 5 set
411  } // else { ...start|lastseq|len
412  } // while (i<numseq)
413  int nseq;
414 
415  if (padrow <1 || pad <1) { // Jerome and Herb, Oct 1 2003.
416  nseq = 0;
417  // if (iOld==-1) (void) printf("Did not loop over bank TPCSEQD");
418  // else (void) printf("Sequence=%d for SEQD bank\n",numseq);
419  } else {
420  nseq = Pad_array[padrow-1][pad-1].nseq;
421  }
422 
423  if (nseq) { // only if there are sequences on this pad
424  // allocate memory for Sequence arrays
425  // make sure we don't do it more than once
426  if (Pad_array[padrow-1][pad-1].seq==NULL) {
427  Pad_array[padrow-1][pad-1].seq=
428  (Sequence *)malloc(nseq*sizeof(Sequence));
429  if (Pad_array[padrow-1][pad-1].seq==NULL) {
430  cout << "failed to malloc() Sequence structures " << endl;
431  return FALSE;
432  }
433  }// if Pad_array[padrow-1][pad-1].seq==NULL
434  }// if (nseq)
435 
436  // process TPCSEQD to fill in the Pad_array[][].seq structs
437  u_char *adc_locn = (u_char *)adcd_p[rcb][mz]->ADC;
438  padrow=-1; pad=-1; lastbin=-2; oldstart = 0; i=0;
439  int pad_seq;
440 
441  while (i<numseq) {
442  if (seqd_p[rcb][mz]->sequence[i]<0) { //padrow, pad
443  padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
444  pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
445  if (pad==255) break; //pad 255 exists only in extraneous last word
446  pad_seq = 0;
447  oldstart=0;
448  lastbin = -2;
449  i++;
450  }
451  else { // (start|lastseq|len)
452  unsigned short work = seqd_p[rcb][mz]->sequence[i];
453  int start = work>>6;
454  int len = work & 0x1f;
455 
456  if (start >= oldstart) { // still on same pad
457  //is this sequence adjacent to previous one?
458 
459  if(mMergeSequences) { // Replaces an ifdef MERGE_SEQUENCES, Herb Ward, Mar 4 2004
460  if (start>lastbin+1) { // Not adjoining previous sequence, no merge!
461  if (pad_seq>=Pad_array[padrow-1][pad-1].nseq) {
462  printf("sequence overrun %s %d row %d pad %d seq %d\n",
463  __FILE__,__LINE__,padrow,pad,pad_seq);
464  }
465 
466  Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
467  Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
468  Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
469  adc_locn +=len;
470  pad_seq++;
471  }
472  else { // Merge sequence!
473  assert ( pad_seq>=1 && pad_seq<=Pad_array[padrow-1][pad-1].nseq);
474 
475  if (pad_seq>Pad_array[padrow-1][pad-1].nseq)
476  printf("sequence overrun %s %d row %d pad %d seq %d\n",
477  __FILE__,__LINE__,padrow,pad,pad_seq);
478  Pad_array[padrow-1][pad-1].seq[pad_seq-1].Length += len;
479  adc_locn +=len;
480  }
481  } else { // if(mMergeSequences Herb replaces an #else, Mar 4 2004.
482 
483  if (pad_seq>=Pad_array[padrow-1][pad-1].nseq) {
484  printf("sequence overrun %s %d row %d pad %d seq %d\n",
485  __FILE__,__LINE__,padrow,pad,pad_seq);
486  }
487 
488  Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
489  Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
490  Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
491  adc_locn +=len;
492  pad_seq++;
493  } // if(mMergeSequences) Herb Ward, Mar 4 2004.
494 
495  lastbin = start+len-1;
496  oldstart = start;
497  if (work & 0x20) {//last sequence ?
498  pad++; // default to next pad in this padrow
499  pad_seq = 0;
500  lastbin = -2; // set lastbin for new pad
501  oldstart=0;
502  }
503  i++;
504  }
505  else { // starting new pad without bit 5 set!
506  if (detector->ercpy->verbose) {
507  printf("new pad detected with bit 5 clear!\n");
508  fflush(stdout);
509  }
510  // skip until next "switch=1"
511  while (seqd_p[rcb][mz]->sequence[i]>0 && i<numseq) i++;
512  } // new pad starting with bit 5 set
513  } // (start|lastseq|len)
514  } // while (i<numseq)
515  }//TPCSEQD bank exists
516  }// loop over mz
517  }// loop over rcb
518 
519  return TRUE;
520 }
521 
522 TPCV2P0_ZS_SR::~TPCV2P0_ZS_SR()
523 {
524 
525  // Herb commented this Jul 4 2000, because Victor
526  // deletes the reader object object before calling this function (see
527  // StDAQReader::readEvent), so that ercpy is not defined.
528  // if (detector->ercpy->verbose) cout << "Deleting TPCV2P0_ZS_SR" << endl;
529 
530 
531  //free memory allocated for Sequence arrays
532  for (int row=0; row<TPC_PADROWS; row++) {
533  for (int pad=0; pad<tpcRowLen[row]; pad++) { // Herb changed "row-1" to "row", Jul 4 2000.
534  void *memaddr = Pad_array[row][pad].seq;
535  if (memaddr) free(memaddr);
536  }
537  }
538  for (int rrow=0; rrow<TPC_PADROWS; rrow++) {
539  if (RowSpacePts[rrow]) free(RowSpacePts[rrow]);
540  }
541 }
542 
543 int TPCV2P0_ZS_SR::getPadList(int PadRow, u_char **padList)
544 {
545  // Construct the padlist array for this PadRow
546  int pad;
547  if (PadRow == 0 || PadRow > TPC_PADROWS) return -1;
548 
549  // Fill in padrows
550  int npad=0;
551  for (pad=1; pad<=tpcRowLen[PadRow-1]; pad++)
552  {
553  if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
554  }
555  // confusing syntax but correct
556  *padList = &padlist[PadRow-1][0];
557 
558  return npad;
559 }
560 
561 int TPCV2P0_ZS_SR::getSequences(int PadRow, int Pad, int *nSeq,
562  Sequence **SeqData)
563 {
564  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
565  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
566  return 0;
567 }
568 
569 int TPCV2P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
570  Sequence **SeqData)
571 {
572  unsigned short PadRow = row_vs_fee[Fee][Pin];
573  unsigned short Pad = pad_vs_fee[Fee][Pin];
574  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
575  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
576  return 0;
577 }
578 
579 
580 // Read the clusters (space points) found in the mezzanine cluster-finder
581 int TPCV2P0_ZS_SR::getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)
582 {
583  int rb, row;
584  classname(Bank_TPCMZCLD) *cld;
585  int numSpPts = 0; // keep running total for malloc
586 
587  for (row=0; row<TPC_PADROWS; nsptrow[row++]=0);
588 
589  for (rb=0; rb<6; rb++) {
590  for (int mz=0; mz<3; mz++) {
591  //pointer to TPCMZCLD bank
592  cld_p[rb][mz] = detector->getBankTPCMZCLD(sector,rb,mz) ;
593  cld = cld_p[rb][mz];
594  if (!cld) continue;
595  int *ptr = (int *)&cld->stuff;
596  for (int ir=0; ir<cld->NumRows; ir++){
597  int row = *ptr++;
598  int nsp = *ptr++; // bump pointer to beginning of space points
599  nsptrow[row-1] += nsp; // add num space pts to running total
600  ptr += 2*nsp;
601  }
602  }
603  }
604  if (detector->ercpy->verbose) cout << "sector "<<sector<<": found "
605  <<numSpPts<<" space pts" <<endl;
606 
607  for (row=0; row<TPC_PADROWS; row++) {
608  RowSpacePts[row] = (SpacePt *)malloc(nsptrow[row]*sizeof(struct SpacePt));
609  if (RowSpacePts[row]==NULL) {
610  cout << "failed to malloc() Space Point structures " << endl;
611  return FALSE;
612  }
613  }
614 
615  for (rb=0; rb<6; rb++) {
616  for (int mz=0; mz<3; mz++) {
617  cld = cld_p[rb][mz]; // pointer to TPCMZCLD bank
618  if (!cld) continue;
619  int *ptr = &cld->stuff[0];
620  for (int ir=0; ir<cld->NumRows; ir++){
621  int row = *ptr++;
622  int nsp = *ptr++; // bump pointer to beginning of space points
623  for (int isp=0; isp<nsp; isp++, ptr+=2) {
624  RowSpacePts[row-1][isp] = *(SpacePt *)ptr;
625  }
626  }
627  }
628  }
629  *nSpacePts = nsptrow[PadRow-1];
630  *SpacePts = RowSpacePts[PadRow-1];
631  return TRUE;
632 }
633 
634 
635 int TPCV2P0_ZS_SR::MemUsed()
636 {
637  return 0;
638 }
639 
Definition: rb.hh:21
Definition: TPCV1P0.hh:217