StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FTPV1P0_ZS_SR.cxx
1 /***************************************************************************
2  * $Id: FTPV1P0_ZS_SR.cxx,v 1.12 2014/06/25 15:33:16 jeromel Exp $
3  * Author: M.J. LeVine, H.Huemmler
4  ***************************************************************************
5  * Description: FTPC V1.0 Zero Suppressed Reader
6  *
7  *
8  * -------------change log ------------------------
9  * 18-01-00 MJL
10  * 11-07-00 JLK Added fee_pin_FTPC.h include for ZS Reader
11  *
12  ***************************************************************************
13  * $Log: FTPV1P0_ZS_SR.cxx,v $
14  * Revision 1.12 2014/06/25 15:33:16 jeromel
15  * Code not used but erradicated use of flush
16  *
17  * Revision 1.11 2007/12/24 06:04:13 fine
18  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
19  *
20  * Revision 1.10 2003/09/02 17:55:31 perev
21  * gcc 3.2 updates + WarnOff
22  *
23  * Revision 1.9 2002/05/24 14:35:30 jcs
24  * Use index pad_seq-1 when current sequence adjacent to previous sequence
25  *
26  * Revision 1.8 2002/03/11 16:40:24 jcs
27  * return false if no FTPADCD bank or no FTPADCX bank found for requested sector
28  *
29  * Revision 1.7 2001/06/30 02:39:47 jcs
30  * add forgotten include for assert.h
31  *
32  * Revision 1.6 2001/06/27 22:08:15 jcs
33  * Initialize pad_seq
34  *
35  * Revision 1.5 2001/06/25 23:01:21 jcs
36  * reconstruct from raw data if no FTPSEQD bank
37  *
38  * Revision 1.4 2001/06/19 20:51:22 jeromel
39  * Commited for Janet S.
40  *
41  * Revision 1.3 2000/08/18 15:38:58 ward
42  * New FTPC stuff from JKlay and Hummler.
43  *
44  * Revision 1.3 2000/07/11 14:44:06 jklay
45  * Geometry file included, so call to
46  * FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,Sequence **SeqData)
47  * can now be properly implemented
48  *
49  * Revision 1.2 2000/01/19 20:31:25 levine
50  * changed exit() to return -1 in
51  * FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,Sequence **SeqData)
52  *
53  * Revision 1.1 2000/01/18 18:01:19 levine
54  * Hummler's implementaiton of FTPC reader. Note that method
55  *
56  * FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
57  * Sequence **SeqData)
58  *
59  * causes return -1 since the required #include file has not yet been
60  * (correctly) implemented.
61  *
62  *
63  *
64  **************************************************************************/
65 #include <Stiostream.h>
66 #include <assert.h>
67 
68 #include "StDaqLib/GENERIC/EventReader.hh"
69 #include "FTPV1P0.hh"
70 #include "StDaqLib/FTPC/fee_pin_FTPC.h"
71 
72 using namespace OLDEVP;
73 
74 FTPV1P0_ZS_SR::FTPV1P0_ZS_SR(int s, FTPV1P0_Reader *det)
75 {
76 // cout << "Constructing FTPV1P0_ZS_SR" << endl;
77  sector = s;
78  detector = det;
79 
80  // NULLS in banks
81  // memset((char *)adcd_p, 0, sizeof(adcd_p));
82  // memset((char *)adcx_p, 0, sizeof(adcx_p));
83  // memset((char *)seqd_p, 0, sizeof(seqd_p));
84  adcd_p=0;
85  adcx_p=0;
86  seqd_p=0;
87 }
88 
89 int FTPV1P0_ZS_SR::initialize()
90 {
91  int i;
92  int row;
93  for (row=0; row<FTP_PADROWS; row++) {
94  Row_array[row].pad = &Pad_array[row][0];
95  Row_array[row].npads = 0; // have to fill in PadRow.npads as we go.
96  for (int pad=0; pad<FTP_MAXPADS; pad++) {
97  Pad_array[row][pad].nseq=0;
98  Pad_array[row][pad].seq= (Sequence *)0;
99  }
100  }
101 
102  // int rcb;
103  // store pointers to the ADCD, ADCX, SEQD banks
104  adcd_p = detector->getBankFTPADCD(sector);
105  if ((void *)adcd_p != NULL) {
106  // noop
107  }
108  else {
109  cout<<"No FTPADCD bank found for sector "<<sector<<endl;
110  return FALSE;
111  }
112  adcx_p = detector->getBankFTPADCX(sector);
113  if ((void *)adcx_p != NULL) {
114  // noop
115  }
116  else {
117  cout<<"No FTPADCX bank found for sector "<<sector<<endl;
118  return FALSE;
119  }
120  seqd_p = detector->getBankFTPSEQD(sector);
121  if ((void *)seqd_p != NULL) {
122  // search through the SEQD banks to build our tables of what's where
123 
124  int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
125  int len = seqd_p->header.BankLength - (sizeof(Bank_Header)/4);
126  int numseq = (4*len)/sizeof(short); // find # sequences this bank
127  // go through the SEQD twice. First time around just count the sequences
128  // so we can malloc the Sequence arrays as needed
129  for (i=0; i<numseq; i++) {
130  if (seqd_p->sequence[i]<0) { //padrow, pad
131  padrow = (seqd_p->sequence[i]>>8)& 0x7f;
132  padrow = ((int)(padrow-1)/6)%2+1;
133  pad = (seqd_p->sequence[i])& 0xff;
134  if (pad==255) break; //pad 255 exists only in extraneous last word
135  Row_array[padrow-1].npads++; //increment #pads in padrow
136  oldstart = 0;
137  }
138  else {
139  if (padrow <0 || pad <0) {
140  printf("encountered bad SEQD bank\n");
141  return FALSE;
142  }
143  unsigned short work = seqd_p->sequence[i];
144  int start = work>>6;
145  int len = work & 0x1f;
146  if (start >= oldstart) { // still on same pad
147  if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++;
148  // don't increment nseq if sequences are adjacent!
149  lastbin = start+len-1;
150  oldstart = start;
151  if (work & 0x20 ) {//last sequence ?
152  pad++; // default to next pad in this padrow
153  Row_array[padrow-1].npads++; //increment #pads in padrow
154  lastbin = -2; // set lastbin for new pad
155  oldstart=0;
156  }
157  }
158  else { // starting new pad without bit 5 set!
159  printf("new pad detected with bit 5 clear!\n");
160  return FALSE;
161  }
162  }
163  }
164  //allocate memory for Sequence arrays
165  // This stupid compiler thinks row's scope extends here, so I removed int
166  // The original line should go in when we upgrade to a better compiler
167  // for (int row=0; row<TPC_PADROWS; row++) {
168  for (row=0; row<FTP_PADROWS; row++) {
169  // int npads = Row_array[row].npads;
170  for (int pad=0; pad<FTP_MAXPADS; pad++) {
171  int nseq = Pad_array[row][pad].nseq;
172  if (nseq) { // only if there are sequences on this pad
173  Pad_array[row][pad].seq= (Sequence *)malloc(nseq*sizeof(Sequence));
174  if (Pad_array[row][pad].seq==NULL) {
175  cout << "failed to malloc() Sequence structures " << endl;
176  return FALSE;
177  }
178  }
179  }
180  }
181  //second pass
182  padrow=-1;
183  pad=-1;
184  lastbin=-2;
185  int pad_seq=0;
186  oldstart = 0;
187  len = seqd_p->header.BankLength - (sizeof(Bank_Header)/4);
188  numseq = (4*len)/sizeof(short); // find # sequences this bank
189  u_char *adc_locn = (u_char *)adcd_p->ADC;
190  for (i=0; i<numseq; i++) {
191  if (seqd_p->sequence[i]<0) { //padrow, pad
192  padrow = (seqd_p->sequence[i]>>8)& 0x7f;
193  padrow = ((int)(padrow-1)/6)%2+1;
194  pad = (seqd_p->sequence[i])& 0xff;
195  if (pad==255) break; //pad 255 exists only in extraneous last word
196  pad_seq = 0;
197  oldstart=0;
198  }
199  else {
200  unsigned short work = seqd_p->sequence[i];
201  int start = work>>6;
202  int len = work & 0x1f;
203  if (start >= oldstart) { // still on same pad
204  //is this sequence adjacent to previous one?
205  if (start>lastbin+1) { //no
206  Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
207  Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
208  Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
209  adc_locn +=len;
210  pad_seq++;
211  }
212  else { // yes: just update the length
213  Pad_array[padrow-1][pad-1].seq[pad_seq-1].Length += len;
214  adc_locn +=len;
215  }
216  lastbin = start+len-1;
217  if (work & 0x20) {//last sequence ?
218  pad++; // default to next pad in this padrow
219  pad_seq = 0;
220  lastbin = -2; // set lastbin for new pad
221  oldstart=0;
222  }
223  }
224  else { // starting new pad without bit 5 set!
225  printf("new pad detected with bit 5 clear!\n");
226  return FALSE;
227  }
228  }
229  }
230  return TRUE;
231  }
232  else {
233  //FTPSEQD bank doesn't exist
234  // set up raw data pointers
235  FTPV1P0_PADK_SR *padkr = detector->getPADKReader(sector);
236  if (!padkr) return FALSE;
237  classname(Bank_FTPADCR) *adcr =
238  detector->getBankFTPADCR(sector) ; //pointer to ADC raw bank
239  if (!adcr) return FALSE;
240  classname(Bank_FTPCPPR) *cppr =
241  detector->getBankFTPCPPR(sector) ; //pointer to CPP raw bank
242  if (!cppr) return FALSE;
243 
244  // go through the CPPR/ADCR banks
245  if (detector->ercpy->verbose)
246  printf("reconstructing from RAW banks: SEC %d\n",sector);
247  FTPPADK_entry ent;
248 
249  for (int row=1; row<=FTP_PADROWS; row++) {
250  for (int pad=1; pad<=FTP_MAXPADS; pad++) {
251  padkr->get(row, pad, &ent);
252 // if((ent.mz != mz+1) || (ent.rb != rcb+1)) continue;
253  struct ASIC_Cluster *clusters =
254  (ASIC_Cluster *)(cppr->entry + 32*ent.offset);
255 
256  int lastbin = -2, len = 0;
257  int i, start, stop=-1, newseq;
258 
259  for (i=0; i<FTP_MXSEQUENCE; i++) { //loop over ASIC sequences
260  start = clusters[i].start_time_bin;
261  if ((start < 0)||(start==255)||(start<=stop)) break;
262  //protect against hardware quirks in VRAM
263  newseq = (start>lastbin+1);//sequence not broken in pieces by MZ
264  stop = clusters[i].stop_time_bin;
265  //MJL: not used: len = stop - start + 1;
266  // catch bad values of start, stop
267  if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
268  struct EventInfo ei;
269  ei = detector->ercpy->getEventInfo();
270  printf("%s:%d: bad FTP cluster data detected\n",
271  __FILE__,__LINE__);
272  printf("evt# %d , sector %d, row %d, pad %d\n",
273  ei.EventSeqNo,sector,row,pad);
274 // ei.EventSeqNo,sector+1,row,pad); //JCS
275 
276  printf("cluster %d: start=0x%x stop=0x%x\n",
277  i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
278  break; //stop processing this pad
279  }
280  lastbin = stop;
281  if (newseq) Pad_array[row-1][pad-1].nseq++;
282  //update the cluster counter for this pad
283  // ...nseq now has CORRECT count of distinct ASIC sequences
284  } // loop over ASIC sequences
285  if (i==FTP_MXSEQUENCE) {
286  //did we overflow the ASIC cluster pointer array
287  // do the rest here by hand
288  }
289 
290  // finished scanning for total number of distinct sequences
291 
292  // this scan is only used to determine the number of sequences
293  int nseq = Pad_array[row-1][pad-1].nseq;
294  if (!nseq) continue; // only if there are sequences on this pad
295  Pad_array[row-1][pad-1].seq=
296  (Sequence *)malloc(nseq*sizeof(Sequence));
297  if (Pad_array[row-1][pad-1].seq==NULL) {
298  cout << "failed to malloc() Sequence structures " << endl;
299  return FALSE;
300  }
301  lastbin = -2;
302  len = 0;
303  int seqCnt = 0;
304 
305  // loop over sequences, filling in structs
306  for (i=0; seqCnt<nseq; i++) { //loop over ASIC sequences
307  if (i<FTP_MXSEQUENCE) {
308  start = clusters[i].start_time_bin;
309 
310  if ((start < 0)||(start==255)) break;
311  newseq = (start>lastbin+1);
312  //sequence not broken in pieces by MZ
313  stop = clusters[i].stop_time_bin;
314  len = stop - start + 1;
315  // catch bad values of start, stop
316  if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
317  struct EventInfo ei;
318  ei = detector->ercpy->getEventInfo();
319  printf("%s:%d: bad FTP cluster data detected\n",
320  __FILE__,__LINE__);
321  printf("evt# %d , sector %d, row %d, pad %d\n",
322  ei.EventSeqNo,sector,row,pad);
323 // ei.EventSeqNo,sector+1,row,pad); //JCS
324  printf("cluster %d: start=0x%x stop=0x%x\n",
325  i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
326  break; //stop processing this pad
327 
328  break; //stop processing this pad
329  }
330  lastbin = stop;
331  if (newseq) {
332  int offset = ent.offset * padkr->getADCBytes() + start;
333  Pad_array[row-1][pad-1].seq[seqCnt].startTimeBin = start;
334  Pad_array[row-1][pad-1].seq[seqCnt].Length = len;
335  Pad_array[row-1][pad-1].seq[seqCnt].FirstAdc =
336  (u_char *)(adcr->ADC + offset);
337  seqCnt++;
338  }
339  else { // continuation of previous sequence
340  assert( seqCnt>=1 && seqCnt<=nseq );
341  Pad_array[row-1][pad-1].seq[seqCnt-1].Length += len;
342  }
343  }
344  else {//did we overflow the ASIC cluster pointer array?
345 
346  }
347  } // loop on seq
348  } // loop on pad
349  } // loop on row
350  return TRUE;
351  }
352 }
353 
354 FTPV1P0_ZS_SR::~FTPV1P0_ZS_SR()
355 {
356 // cout << "Deleting FTPV1P0_ZS_SR" << endl;
357  //free memory allocated for Sequence arrays
358  for (int row=0; row<FTP_PADROWS; row++) {
359  for (int pad=0; pad<FTP_MAXPADS; pad++) {
360  void *memaddr = Pad_array[row][pad].seq;
361  if (memaddr) free(memaddr);
362  }
363  }
364 }
365 
366 int FTPV1P0_ZS_SR::getPadList(int PadRow, u_char **padList)
367 {
368  // Construct the padlist array for this PadRow
369  int pad;
370  if (PadRow == 0 || PadRow > FTP_PADROWS) return -1;
371 
372  // Fill in padrows
373  int npad=0;
374  for(pad=1; pad<=FTP_MAXPADS; pad++)
375  {
376  if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
377  }
378  // confusing syntax but correct
379  *padList = &padlist[PadRow-1][0];
380 
381  return npad;
382 }
383 
384 int FTPV1P0_ZS_SR::getSequences(int PadRow, int Pad, int *nSeq,
385  Sequence **SeqData)
386 {
387  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
388  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
389 
390  if (&nSeq) {
391  return 1; // If there are sequences, return 1.
392  } else { //This matches better with the ADCRawReader
393  return 0; //which returns 1 if raw ADC data exists.
394  }
395 }
396 
397 int FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
398  Sequence **SeqData)
399 {
400 //#ifdef REAL_FEE_PIN_FOR_FTPC
401  unsigned short PadRow = row_vs_fee_FTPC[Fee][Pin];
402  unsigned short Pad = pad_vs_fee_FTPC[Fee][Pin];
403  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
404  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
405  return 0;
406 //#else
407 // printf("There is no table of FEE connections --- I quit\n");
408 // return -1;
409 //#endif
410 }
411 
412 // Read the clusters (space points) found in the mezzanine cluster-finder
413 int FTPV1P0_ZS_SR::getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)
414 {
415  cout <<"getSpacePoints() method not implemented" <<endl;
416  return 0;
417 }
418 
419 
420 int FTPV1P0_ZS_SR::MemUsed()
421 {
422  return 0;
423 }
424 
Definition: FTPV1P0.hh:198