StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TPCV1P0_ZS_SR.cxx
1 /***************************************************************************
2  * $Id: TPCV1P0_ZS_SR.cxx,v 1.12 2014/06/25 15:33:16 jeromel Exp $
3  * Author: M.J. LeVine
4  ***************************************************************************
5  * Description: TPC V1.0 Zero Suppressed Reader
6  *
7  *
8  * -------------change log ------------------------
9  * 31-May-99 MJL terminate on encountering pad 255
10  * 03-Jun-99 MJL added return TRUE to TPCV1P0_ZS_SR::initialize()
11  * 10-Jun-99 IS (Iwona Sakrejda) - The compiler we are using currently in Root
12  * cannot contain the scope of the "for" loop index within parenthesis.
13  * So if the next loop uses same index, it cannot be Declared again.
14  * I made 3 changes: 2 for rcg, one for row and marked them all in the code.
15  * 23-Jun-99 MJL change declaration of row, rcb outside of all for loops
16  ***************************************************************************
17  * $Log: TPCV1P0_ZS_SR.cxx,v $
18  * Revision 1.12 2014/06/25 15:33:16 jeromel
19  * Code not used but erradicated use of flush
20  *
21  * Revision 1.11 2007/12/24 06:04:32 fine
22  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
23  *
24  * Revision 1.10 2004/03/24 18:44:58 ward
25  * Suppress debug messages.
26  *
27  * Revision 1.9 2003/09/02 17:55:33 perev
28  * gcc 3.2 updates + WarnOff
29  *
30  * Revision 1.8 1999/12/09 02:50:41 levine
31  * #define changed to get rid of unused fee array defs for TPCv?P0_ZS_SR.cxx
32  * only
33  *
34  * Revision 1.7 1999/12/07 23:10:45 levine
35  * changes to silence the gcc compiler warnings
36  *
37  * Revision 1.6 1999/09/02 21:47:11 fisyak
38  * HP corrections
39  *
40  * Revision 1.5 1999/07/21 21:15:40 levine
41  * TPCV2P0_ZS_SR.cxx changed to include the TPCV2P0_ZS_SR::getSpacePts()
42  * (cluster-finder reader). TPCV1P0_ZS_SR.cxx changed to include empty
43  * version of the same method.
44  *
45  * Revision 1.4 1999/07/02 04:43:23 levine
46  * Many changes -
47  * navigates to head of TPCP bank independent of position.
48  * move declarations out of loops where they were upsetting some compilers
49  * suppress output from class libraries with run-time switch EventReader.verbose
50  * added TPCV2P0_CPP_SR::getAsicParams()
51  *
52  *
53  **************************************************************************/
54 #include <Stiostream.h>
55 
56 #include "StDaqLib/GENERIC/EventReader.hh"
57 #include "TPCV1P0.hh"
58 #define MAKE_THE_DAMNED_COMPILER_SILENT
59 #include "fee_pin.h"
60 
61 using namespace OLDEVP;
62 
63 
64 TPCV1P0_ZS_SR::TPCV1P0_ZS_SR(int s, TPCV1P0_Reader *det)
65 {
66  cout << "Constructing TPCV1P0_ZS_SR" << endl;
67  sector = s-1; // convert the sector into internal representation
68  detector = det;
69 
70  // NULLS in banks array
71  memset((char *)adcd_p, 0, sizeof(adcd_p));
72  memset((char *)adcx_p, 0, sizeof(adcx_p));
73  memset((char *)seqd_p, 0, sizeof(seqd_p));
74 }
75 
76 int TPCV1P0_ZS_SR::initialize()
77 {
78 
79 
80  int row;
81  for (row=0; row<TPC_PADROWS; row++) {
82  Row_array[row].pad = &Pad_array[row][0];
83  Row_array[row].npads = 0; // have to fill in PadRow.npads as we go.
84  for (int pad=0; pad<TPC_MAXPADS; pad++) {
85  Pad_array[row][pad].nseq=0;
86  Pad_array[row][pad].seq= (Sequence *)0;
87  }
88  }
89 
90  int rcb;
91  // store pointers to the ADCD, ADCX, SEQD banks
92  for(rcb = 0; rcb < 6; rcb++)
93  {
94  for(int mz = 0; mz < 3; mz++)
95  {
96  adcd_p[rcb][mz] = detector->getBankTPCADCD(sector,rcb,mz);
97  if ((void *)adcd_p[rcb][mz] != NULL) {
98  // printf("found ADCD RB%d MZ%d\n",rcb+1,mz+1);
99  // noop
100  }
101  adcx_p[rcb][mz] = detector->getBankTPCADCX(sector,rcb,mz);
102  if ((void *)adcx_p[rcb][mz] != NULL) {
103  // printf("found ADCX RB%d MZ%d\n",rcb+1,mz+1);
104  // noop
105  }
106  seqd_p[rcb][mz] = detector->getBankTPCSEQD(sector,rcb,mz);
107  if ((void *)seqd_p[rcb][mz] != NULL) {
108  // printf("found SEQD RB%d MZ%d\n",rcb+1,mz+1);
109  // noop
110  }
111  }
112  }
113 
114 
115  // search through the SEQD banks to build our tables of what's where
116 
117  // This stupid compiler thinks rcb's scope extends here, so I removed int
118  // The original line should go in when we upgrade to a better compiler
119  // for(int rcb = 0; rcb < 6; rcb++) {
120  for( rcb = 0; rcb < 6; rcb++) {
121  for(int mz = 0; mz < 3; mz++) {
122  if (seqd_p[rcb][mz] == (classname(Bank_TPCSEQD) *)NULL) continue;
123  printf("TPCSEQD found sector %d RB%d MZ%d\n",sector+1,rcb+1,mz+1);
124  int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
125  int len = seqd_p[rcb][mz]->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 (int i=0; i<numseq; i++) {
130  if (seqd_p[rcb][mz]->sequence[i]<0) { //padrow, pad
131  padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
132  pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
133  if (pad==255) break; //pad 255 exists only in extraneous last word
134  Row_array[padrow-1].npads++; //increment #pads in padrow
135  oldstart = 0;
136  }
137  else {
138  if (padrow <0 || pad <0) {
139  printf("encountered bad SEQD bank RB %d, Mezz %d\n", rcb+1, mz+1);
140  return FALSE;
141  }
142  unsigned short work = seqd_p[rcb][mz]->sequence[i];
143  int start = work>>6;
144  int len = work & 0x1f;
145  if (start >= oldstart) { // still on same pad
146  if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++;
147  // don't increment nseq if sequences are adjacent!
148  lastbin = start+len-1;
149  oldstart = start;
150  if (work & 0x20 ) {//last sequence ?
151  pad++; // default to next pad in this padrow
152  Row_array[padrow-1].npads++; //increment #pads in padrow
153  lastbin = -2; // set lastbin for new pad
154  oldstart=0;
155  }
156  }
157  else { // starting new pad without bit 5 set!
158  printf("new pad detected with bit 5 clear!\n");
159  return FALSE;
160  }
161  }
162  }
163  }
164  }
165 
166  //allocate memory for Sequence arrays
167  // This stupid compiler thinks row's scope extends here, so I removed int
168  // The original line should go in when we upgrade to a better compiler
169  // for (int row=0; row<TPC_PADROWS; row++) {
170  for (row=0; row<TPC_PADROWS; row++) {
171  // int npads = Row_array[row].npads;
172  for (int pad=0; pad<TPC_MAXPADS; pad++) {
173  int nseq = Pad_array[row][pad].nseq;
174  if (nseq) { // only if there are sequences on this pad
175  Pad_array[row][pad].seq= (Sequence *)malloc(nseq*sizeof(Sequence));
176  if (Pad_array[row][pad].seq==NULL) {
177  cout << "failed to malloc() Sequence structures " << endl;
178  return FALSE;
179  }
180  }
181  }
182  }
183  //second pass
184  // This stupid compiler thinks rcb's scope extends here, so I removed int
185  // The original line should go in when we upgrade to a better compiler
186  // for(int rcb = 0; rcb < 6; rcb++) {
187  for(rcb = 0; rcb < 6; rcb++) {
188  for(int mz = 0; mz < 3; mz++) {
189  if (seqd_p[rcb][mz] == (classname(Bank_TPCSEQD) *)NULL) continue;
190  int padrow=-1, pad=-1, lastbin=-2, pad_seq, oldstart = 0;
191  int len = seqd_p[rcb][mz]->header.BankLength - (sizeof(Bank_Header)/4);
192  int numseq = (4*len)/sizeof(short); // find # sequences this bank
193  u_char *adc_locn = (u_char *)adcd_p[rcb][mz]->ADC;
194  for (int i=0; i<numseq; i++) {
195  if (seqd_p[rcb][mz]->sequence[i]<0) { //padrow, pad
196  padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
197  pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
198  if (pad==255) break; //pad 255 exists only in extraneous last word
199  pad_seq = 0;
200  oldstart=0;
201  }
202  else {
203  unsigned short work = seqd_p[rcb][mz]->sequence[i];
204  int start = work>>6;
205  int len = work & 0x1f;
206  if (start >= oldstart) { // still on same pad
207  //is this sequence adjacent to previous one?
208  if (start>lastbin+1) { //no
209  Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
210  Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
211  Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
212  adc_locn +=len;
213  pad_seq++;
214  }
215  else { // yes: just update the length
216  Pad_array[padrow-1][pad-1].seq[pad_seq].Length += len;
217  adc_locn +=len;
218  }
219  lastbin = start+len-1;
220  if (work & 0x20) {//last sequence ?
221  pad++; // default to next pad in this padrow
222  pad_seq = 0;
223  lastbin = -2; // set lastbin for new pad
224  oldstart=0;
225  }
226  }
227  else { // starting new pad without bit 5 set!
228  printf("new pad detected with bit 5 clear!\n");
229  return FALSE;
230  }
231  }
232  }
233  }
234  }
235  return TRUE;
236 }
237 
238 TPCV1P0_ZS_SR::~TPCV1P0_ZS_SR()
239 {
240  cout << "Deleting TPCV1P0_ZS_SR" << endl;
241  //free memory allocated for Sequence arrays
242  for (int row=0; row<TPC_PADROWS; row++) {
243  for (int pad=0; pad<TPC_MAXPADS; pad++) {
244  void *memaddr = Pad_array[row][pad].seq;
245  if (memaddr) free(memaddr);
246  }
247  }
248 }
249 
250 int TPCV1P0_ZS_SR::getPadList(int PadRow, u_char **padList)
251 {
252  // Construct the padlist array for this PadRow
253  int pad;
254  if (PadRow == 0 || PadRow > TPC_PADROWS) return -1;
255 
256  // Fill in padrows
257  int npad=0;
258  for(pad=1; pad<=TPC_MAXPADS; pad++)
259  {
260  if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
261  }
262  // confusing syntax but correct
263  *padList = &padlist[PadRow-1][0];
264 
265  return npad;
266 }
267 
268 int TPCV1P0_ZS_SR::getSequences(int PadRow, int Pad, int *nSeq,
269  Sequence **SeqData)
270 {
271  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
272  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
273  return 0;
274 }
275 
276 int TPCV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
277  Sequence **SeqData)
278 {
279  unsigned short PadRow = row_vs_fee[Fee][Pin];
280  unsigned short Pad = pad_vs_fee[Fee][Pin];
281  *nSeq = Pad_array[PadRow-1][Pad-1].nseq; // number of sequences this pad
282  *SeqData = Pad_array[PadRow-1][Pad-1].seq; // pass back pointer to Sequence array
283  return 0;
284 }
285 
286 // Read the clusters (space points) found in the mezzanine cluster-finder
287 int TPCV1P0_ZS_SR::getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)
288 {
289  cout <<"getSpacePoints() method not implemented" <<endl;
290  return 0;
291 }
292 
293 
294 int TPCV1P0_ZS_SR::MemUsed()
295 {
296  return 0;
297 }
298