StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFTPCReader.cxx
1 /***************************************************************************
2  *
3  * $Id: StFTPCReader.cxx,v 1.5 2001/07/26 13:52:33 oldi Exp $
4  *
5  * Author: Holm Huemmler
6  ***************************************************************************
7  *
8  * Description: Offline Wrapper for DAQ reader classes
9  *
10  ***************************************************************************
11  *
12  * $Log: StFTPCReader.cxx,v $
13  * Revision 1.5 2001/07/26 13:52:33 oldi
14  * Bug fix to circumvent crashes due to missing FTPC data.
15  *
16  * Revision 1.4 2001/06/25 22:55:35 jcs
17  * cleanup code
18  *
19  * Revision 1.3 2001/06/19 21:12:07 jeromel
20  * Code update (Janet S.)
21  *
22  * Revision 1.2 2000/06/12 15:04:02 perev
23  * SVT + cleanup
24  *
25  * Revision 1.1 2000/01/24 14:39:33 perev
26  * FTPC (HolmMade) is added
27  *
28  *
29  **************************************************************************/
30 
31 // non standard open,close,read
32 #include <string.h>
33 #include <stdio.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <assert.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include "Stypes.h"
41 
42 #include "StDaqLib/GENERIC/EventReader.hh"
43 #include "StDAQReader.h"
44 #include "StFTPCReader.h"
45 
46 //
47 
48 typedef EventInfo DAQEventInfo;
49 //_____________________________________________________________________________
50 StFTPCReader::StFTPCReader(StDAQReader *daqr)
51 {
52  simu=0;
53  fDAQReader = daqr;
54  fSector = -1999;
55  fFTPCImpReader = 0;
56  fZeroSuppressedReader = 0;
57  fADCRawReader = 0;
58  fPedestalReader = 0;
59  fPedestalRMSReader = 0;
60  fGainReader = 0;
61  fCPPReader = 0;
62  fBadChannelReader = 0;
63  Update();
64 }
65 //_____________________________________________________________________________
66 StFTPCReader::StFTPCReader(unsigned short *fcl_ftpcsqndx, int nSeq,
67  char *fcl_ftpcadc, int nAdc)
68 {
69  simu=1;
70  m_ftpcsqndx=fcl_ftpcsqndx;
71  m_ftpcadc=fcl_ftpcadc;
72  m_numSqndx=nSeq;
73  m_numAdc=nAdc;
74 
75  mSecReader=0;
76  fSector = -1999;
77  Update();
78 }
79 //_____________________________________________________________________________
80 void StFTPCReader::Update()
81 {
82  setSector(-1);
83 }
84 //_____________________________________________________________________________
85 StFTPCReader::~StFTPCReader()
86 {
87  if(simu)
88  {
89  delete mSecReader;
90  }
91  else
92  {
93  close();
94  }
95 }
96 //_____________________________________________________________________________
97 bool StFTPCReader::checkForData()
98 {
99  if (fFTPCImpReader) {
100  return TRUE;
101  }
102 
103  else {
104  return FALSE;
105  }
106 }
107 //_____________________________________________________________________________
108 int StFTPCReader::close()
109 {
110  delete fZeroSuppressedReader; fZeroSuppressedReader = 0;
111  delete fADCRawReader ; fADCRawReader = 0;
112  delete fPedestalReader ; fPedestalReader = 0;
113  delete fPedestalRMSReader; fPedestalRMSReader = 0;
114  delete fGainReader; fGainReader = 0;
115  delete fCPPReader; fCPPReader = 0;
116  delete fBadChannelReader; fBadChannelReader = 0;
117  delete fFTPCImpReader; fFTPCImpReader = 0;
118  fSector=-1999;
119  return 0;
120 }
121 //_____________________________________________________________________________
122 int StFTPCReader::setSector(int sector)
123 {
124  if (sector == fSector) return 0;
125 
126  if(simu)
127  {
128 
129  delete mSecReader;
130  mSecReader = 0;
131 
132  if (sector == -1) {
133  fSector = -1999;
134  return 0;
135  }
136 
137  fSector = sector;
138 
139  mSecReader = new StFssSectorReader(fSector, m_ftpcsqndx, m_numSqndx, m_ftpcadc, m_numAdc);
140  mSecReader->initialize();
141  }
142  else
143  {
144  delete fZeroSuppressedReader; fZeroSuppressedReader = 0;
145  delete fADCRawReader ; fADCRawReader = 0;
146  delete fPedestalReader ; fPedestalReader = 0;
147  delete fPedestalRMSReader; fPedestalRMSReader = 0;
148  delete fGainReader; fGainReader = 0;
149  delete fCPPReader; fCPPReader = 0;
150  delete fBadChannelReader; fBadChannelReader = 0;
151 
152  if (sector == -1) {
153  delete fFTPCImpReader;
154  fFTPCImpReader = ::getDetectorReader(fDAQReader->getEventReader(),"FTPC");
155  fSector = -1999;
156  if(!fFTPCImpReader) return 1;
157  return 0;
158  }
159 
160  fSector = sector;
161 
162 
163  fZeroSuppressedReader = fFTPCImpReader->getZeroSuppressedReader(fSector);
164  fADCRawReader = fFTPCImpReader->getADCRawReader(fSector);
165  fPedestalReader = fFTPCImpReader->getPedestalReader(fSector);
166  fPedestalRMSReader = fFTPCImpReader->getPedestalRMSReader(fSector);
167  fGainReader = fFTPCImpReader->getGainReader(fSector);
168  fCPPReader = fFTPCImpReader->getCPPReader(fSector);
169  fBadChannelReader = fFTPCImpReader->getBadChannelReader(fSector);
170  }
171  return 0;
172 }
173 //_____________________________________________________________________________
174 int StFTPCReader::getPadList(int Sector, int PadRow, unsigned char *&padList)
175 {
176  setSector(Sector);
177 
178  if(simu)
179  {
180  if (!mSecReader)
181  return -1;
182  return mSecReader->getPadList(PadRow, &padList);
183  }
184  else
185  {
186  if (!fZeroSuppressedReader) return -1;
187  return fZeroSuppressedReader->getPadList(PadRow, &padList);
188  }
189 }
190 //_____________________________________________________________________________
191 int StFTPCReader::getSequences(int Sector, int PadRow, int Pad, int *nSeq,
192  TPCSequence *&SeqData)
193 {
194  setSector(Sector);
195  *nSeq = 0; SeqData = 0;
196  int iret=0;
197  Sequence *seq;
198 
199  if(simu)
200  {
201  if (!mSecReader)
202  return -1;
203  iret = mSecReader->getSequences(PadRow,Pad,nSeq,&seq);
204  }
205  else
206  {
207  if (!fZeroSuppressedReader) return -1;
208  iret = fZeroSuppressedReader->getSequences(PadRow,Pad,nSeq,&seq);
209  }
210  assert (sizeof(TPCSequence)==sizeof(Sequence));
211  SeqData = (TPCSequence*)seq;
212  return iret;
213 }
214 
215 //_____________________________________________________________________________
216 int StFTPCReader::getRawADC(int Sector,int PadRow, int Pad, int &nArray,
217  unsigned char *&Array)
218 {
219  if(simu)
220  {
221  return -1;
222  }
223  else
224  {
225  setSector(Sector);
226  nArray = 0; Array=0;
227  if (!fADCRawReader) return -1;
228  return fADCRawReader->getSequences(PadRow,Pad,&nArray,&Array);
229  }
230 }
231 //_____________________________________________________________________________
232 int StFTPCReader::getPedestals(int Sector,int PadRow, int Pad, int &nArray,
233  unsigned char *&Array)
234 {
235  if(simu)
236  {
237  return -1;
238  }
239  else
240  {
241  setSector(Sector);
242  nArray = 0; Array=0;
243  if (!fPedestalReader) return -1;
244  return fPedestalReader->getSequences(PadRow,Pad,&nArray,&Array);
245  }
246 }
247 //_____________________________________________________________________________
248 int StFTPCReader::getRMSPedestals(int Sector,int PadRow, int Pad, int &nArray,
249  unsigned char *&Array)
250 {
251  if(simu)
252  {
253  return -1;
254  }
255  else
256  {
257  setSector(Sector);
258  nArray = 0; Array=0;
259  if (!fPedestalRMSReader) return -1;
260  return fPedestalRMSReader->getSequences(PadRow,Pad,&nArray,&Array);
261  }
262 }
263 //_____________________________________________________________________________
264 int StFTPCReader::getGain(int Sector, int PadRow, int Pad, TPCGain *&gain)
265 {
266  if(simu)
267  {
268  return -1;
269  }
270  else
271  {
272  setSector(Sector);
273  gain = 0;
274  if (!fGainReader) return -1;
275  struct Gain *gainqq;
276  int iret = fGainReader->getGain(PadRow,Pad,&gainqq);
277  assert(sizeof(TPCGain)==sizeof(struct Gain));
278  gain = (TPCGain*)gainqq;
279  return iret;
280  }
281 }
282 //_____________________________________________________________________________
283 int StFTPCReader::getClusters(int Sector, int PadRow, int Pad, int &nClusters,
284  TPCCluster *&clusters)
285 {
286  if(simu)
287  {
288  return -1;
289  }
290  else
291  {
292  setSector(Sector);
293  nClusters=0; clusters=0;
294  if (!fCPPReader) return -1;
295  struct ASIC_Cluster *clustersqq;
296  int iret = fCPPReader->getClusters(PadRow,Pad,&nClusters,&clustersqq);
297  assert(sizeof(TPCCluster)==sizeof(struct ASIC_Cluster));
298  clusters = (TPCCluster *)clustersqq;
299  return iret;
300  }
301 }
302 //_____________________________________________________________________________
303 int StFTPCReader::IsBad(int Sector, int PadRow, int Pad)
304 {
305  if(simu)
306  {
307  return -1;
308  }
309  else
310  {
311  setSector(Sector);
312  if (!fBadChannelReader) return 1;
313  return fBadChannelReader->IsBad(PadRow,Pad);
314  }
315 }
316 
317