StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFtpcSequencer.cc
1 //==================================================================================================
2 // Writes Embedded data into FTPC SlowSimulator Sequences (as in StFtpcSlowSimMaker/StFtpcRawWriter.cc)
3 //
4 // Author: Frank Simon (fsimon@bnl.gov)
5 //==================================================================================================
6 
8 
19 #include "StFtpcSequencer.hh"
20 #include "Stiostream.h"
21 #include "StChain.h"
22 
23 // Message System
24 #include "StMessMgr.h"
25 
27 StFtpcSequencer::StFtpcSequencer(St_fcl_ftpcndx *ftpcndxIn,
28  St_fcl_ftpcsqndx *ftpcsqndxIn,
29  St_fcl_ftpcadc *ftpcadcIn)
30 {
31  // make sure the sequences exist
32  if ((!ftpcndxIn)||(!ftpcsqndxIn)||(!ftpcadcIn)) {
33  LOG_WARN << "StFtpcSequencer: Output sequences missing, bailing out!" << endm;
34  return;
35  }
36 
37  ftpcndx=ftpcndxIn;
38  ftpcsqndx=ftpcsqndxIn;
39  ftpcadc=ftpcadcIn;
40 
41  ndx=ftpcndx->GetTable();
42  numNdx=ftpcndx->GetNRows();
43  maxNdx=ftpcndx->GetTableSize();
44  sqndx=ftpcsqndx->GetTable();
45  numSqndx=ftpcsqndx->GetNRows();
46  maxSqndx=ftpcsqndx->GetTableSize();
47  adc=ftpcadc->GetTable();
48  numAdc=ftpcadc->GetNRows();
49  maxAdc=ftpcadc->GetTableSize();
50 }
51 
52 
55 {
56  ftpcndx->SetNRows(numNdx);
57  ftpcsqndx->SetNRows(numSqndx);
58  ftpcadc->SetNRows(numAdc);
59 
60  LOG_INFO << "FTPC Sequencer finishing: Setting NRows ndx " << numNdx << " sqndx " << numSqndx << " adc " << numAdc << endm;
61 
62 }
63 
65 int StFtpcSequencer::writeArray(const int *cArray,
66  const int numberPadrows,
67  const int numberSectors,
68  const int numberPads,
69  const int numberTimebins)
70 {
71 
72  // make sure the array that is supposed to be written out exists
73  if (!cArray) {
74  LOG_WARN << "FtpcSequencer: ADC array does not exist, bailing out!" << endm;
75  return kStOk;
76  }
77  if ((!ftpcndx)||(!ftpcsqndx)||(!ftpcadc)) {
78  LOG_WARN << "StFtpcSequencer: Output sequences missing, bailing out!" << endm;
79  return kStOk;
80  }
81 
82 
83  int pixelPerSeq=0;
84  int startPixel=0;
85  int seqIndex=0;
86  int adcIndex=0;
87  int seqFlag=0;
88  int padFlag;
89  int lastPad;
90 
91 
92  // set ASIC parameters for zero suppression
93  Double_t thHigh = 5;
94  Double_t thLow = 2;
95  Int_t minAboveLow = 2;
96 
97 
98 
99  Int_t validSeq = 0;
100  Int_t nAboveLow = 0;
101  Int_t highReached = 0;
102  pixelPerSeq=0;
103  startPixel=0;
104  seqIndex=0;
105  adcIndex=0;
106  seqFlag=0;
107 
108  LOG_INFO << "FtpcSequencer using threshold high:" << thHigh << " and threshold low "<< thLow<<endm;
109 
110 
111  // Fill sequences
112 
113  ndx[0].index=0;
114  for (int row=0; row<numberPadrows; row++) {
115  for (int sec=0; sec<numberSectors; sec++) {
116  lastPad=-100;
117  for (int pad=0; pad<numberPads; pad++) {
118  padFlag=0;
119 
120  for (int bin=0; bin<numberTimebins; bin++) {
121  int i=bin
122  +numberTimebins*pad
123  +numberTimebins*numberPads*sec
124  +numberTimebins*numberPads*numberSectors*row;
125 
126  if((int) cArray[i] < thLow) {
127  validSeq = 0;
128  nAboveLow = 0;
129  highReached = 0;
130  }
131 
132  if((int) cArray[i] >= thLow) {
133 
134  // Check if sequence is valid, apply ASIC parameters
135  if (!validSeq){
136  for (int t = bin; t < numberTimebins; t ++) {
137  int s = t
138  +numberTimebins*pad
139  +numberTimebins*numberPads*sec
140  +numberTimebins*numberPads*numberSectors*row;
141  if (cArray[s]>= thLow) nAboveLow++;
142  if (cArray[s]>= thHigh) highReached = 1;
143  if (highReached && (nAboveLow >= minAboveLow)) {
144  validSeq = 1;
145  t = numberTimebins;
146  }
147  if (cArray[s]< thLow) {
148  validSeq=0;
149  bin = t;
150  t = numberTimebins;
151  }
152  }
153 
154  }
155 
156 
157  if (!validSeq) continue;
158 
159  // beginning of second FTPC?
160  if(row>=10 && ndx[1].index==0) {
161  if(maxNdx<2) {
162  LOG_WARN << "ndx overflow!" << endm;
163  }
164  else {
165  // set index for second FTPC
166  ndx[1].index=seqIndex;
167  }
168  }
169 
170  // beginning of new sequence?
171  if(seqFlag == 0 || pixelPerSeq == 32) {
172  // is there a previous sequence?
173  if(pixelPerSeq > 0) {
174  // set index for previous sequence
175  sqndx[seqIndex++].index = (pixelPerSeq-1) + (startPixel<<6);
176  if(seqIndex >= maxSqndx) {
177  // reset overflow
178  seqIndex=maxSqndx -1;
179  LOG_WARN << "sqndx overflow!" << endm;
180  }
181 
182  pixelPerSeq=0;
183 
184  }
185 
186  // set beginning of this sequence
187  startPixel=bin;
188 
189  // first sequence on pad?
190  if(padFlag == 0) {
191  // make previous sequence last sequence on pad
192  if(seqIndex>0) {
193  sqndx[seqIndex-1].index += 32;
194  }
195  if(pad != lastPad+1) {
196  // set index for new pad
197  sqndx[seqIndex++].index = 32768 + pad + 256*(6*row + sec);
198  if(seqIndex >= maxSqndx) {
199  // reset overflow
200  seqIndex=maxSqndx;
201  LOG_WARN << "sqndx overflow!" << endm;
202  }
203  }
204  lastPad=pad;
205  }
206  }
207 
208 
209  adc[adcIndex++].data=(char) cArray[i];
210  if(adcIndex >= maxAdc) {
211  // reset overflow
212  adcIndex=maxAdc -1;
213  LOG_WARN << "adc overflow!" << endm;
214  }
215  pixelPerSeq++;
216  seqFlag=1;
217  padFlag=1;
218  }
219  else {
220  seqFlag=0;
221  }
222  }
223  }
224  }
225  }
226 
227  // is there a sequence?
228  if(pixelPerSeq > 0) {
229  // set index for last sequence
230  sqndx[seqIndex++].index = (pixelPerSeq-1) + (startPixel<<6)+32;
231 
232  // set table lengths
233  numNdx = 2;
234  numSqndx = seqIndex;
235  numAdc = adcIndex;
236  }
237  else {
238  LOG_WARN << "Error! No sequences filled!" << endm;
239  }
240 
241  LOG_INFO << "FtpcSequencer done, getting table sizes: NRows ndx " << numNdx << " sqndx " << numSqndx << " adc " << numAdc << endm;
242 
243 
244  return kStOk;
245 }
246 
247  /***************************************************************************
248  *
249  * $Id: StFtpcSequencer.cc,v 1.4 2007/01/15 15:02:12 jcs Exp $
250  *
251  * $Log: StFtpcSequencer.cc,v $
252  * Revision 1.4 2007/01/15 15:02:12 jcs
253  * replace printf, cout and gMesMgr with Logger
254  *
255  * Revision 1.3 2003/09/22 13:13:39 fsimon
256  * Fixed code to eliminate compiler warning
257  *
258  * Revision 1.2 2003/09/02 17:58:15 perev
259  * gcc 3.2 updates + WarnOff
260  *
261  * Revision 1.1 2003/02/14 18:11:25 fsimon
262  * Initial commit of FTPC embedding code
263  *
264  *
265  ***************************************************************************/
int writeArray(const int *cArray, const int numberPadrows, const int numberSectors, const int numberPads, const int numberTimebins)
writeArray method, fills zero-suppressed sequences from ADC array
~StFtpcSequencer()
destructor, sets size of sequence arrays
Definition: Stypes.h:41
StFtpcSequencer(St_fcl_ftpcndx *ftpcndxIn, St_fcl_ftpcsqndx *ftpcsqndxIn, St_fcl_ftpcadc *ftpcadcIn)
constructor, checks the existence of output sequences