StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTPCReader.cxx
1 /***************************************************************************
2  *
3  * $Id: StTPCReader.cxx,v 1.8 2004/03/10 05:59:04 jeromel Exp $
4  *
5  * Author: Victor Perev
6  ***************************************************************************
7  *
8  * Description: Offline Wrapper for DAQ reader classes
9  *
10  ***************************************************************************
11  *
12  * $Log: StTPCReader.cxx,v $
13  * Revision 1.8 2004/03/10 05:59:04 jeromel
14  * Implement SetSequenceMerging(). See comment in St_tpcdaq_Maker
15  *
16  * Revision 1.7 2004/03/04 21:51:27 ward
17  * Replaced MERGE_SEQUENCES with a StDAQMaker chain parameter, as suggested by Landgraf and Lauret.
18  *
19  * Revision 1.6 2003/04/29 16:22:44 perev
20  * non TPCoriented cleanup
21  *
22  * Revision 1.5 2003/04/22 20:12:43 ward
23  * So the chain can run when there is no TPC data.
24  *
25  * Revision 1.4 2003/03/24 18:12:10 ward
26  * Full support for EEMC from Herbert Ward.
27  *
28  * Revision 1.3 2002/10/13 20:43:36 ward
29  * Support for decoding DAQ100 data and writing it into a table.
30  *
31  * Revision 1.2 2000/07/13 22:29:52 perev
32  * Return kStErr when TPC data is not in event.
33  *
34  * Revision 1.1 2000/06/12 15:12:27 perev
35  * SVT + cleanup
36  *
37  *
38  **************************************************************************/
39 #include "Stypes.h"
40 
41 // non standard open,close,read
42 #include <string.h>
43 #include <stdio.h>
44 #include <errno.h>
45 #include <unistd.h>
46 #include <assert.h>
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <fcntl.h>
50 #include "Stypes.h"
51 
52 #include "StDaqLib/GENERIC/EventReader.hh"
53 #include "StDAQReader.h"
54 #include "StTPCReader.h"
55 
56 //_____________________________________________________________________________
57 StTPCReader::StTPCReader(StDAQReader *daqr,char mergeSequences)
58 {
59  mMergeSequences=mergeSequences; // won't do much since the entry point is different
60  ptrTPCP=NULL; // Herb Oct 2002 for DAQ100.
61  fDAQReader = daqr;
62  fSector = -1999;
63  fTPCImpReader = 0;
64  fZeroSuppressedReader = 0;
65  fADCRawReader = 0;
66  fPedestalReader = 0;
67  fPedestalRMSReader = 0;
68  fGainReader = 0;
69  fCPPReader = 0;
70  fBadChannelReader = 0;
71  Update();
72 }
73 //_____________________________________________________________________________
74 int StTPCReader::Update()
75 {
76  return setSector(-1);
77 }
78 //_____________________________________________________________________________
79 int StTPCReader::empty()
80 {
81  if(!fTPCImpReader) Update();
82  return (!fTPCImpReader);
83 }
84 //_____________________________________________________________________________
85 StTPCReader::~StTPCReader()
86 { close();}
87 
88 //_____________________________________________________________________________
89 int StTPCReader::close()
90 {
91  delete fZeroSuppressedReader; fZeroSuppressedReader = 0;
92  delete fADCRawReader ; fADCRawReader = 0;
93  delete fPedestalReader ; fPedestalReader = 0;
94  delete fPedestalRMSReader; fPedestalRMSReader = 0;
95  delete fGainReader; fGainReader = 0;
96  delete fCPPReader; fCPPReader = 0;
97  delete fBadChannelReader; fBadChannelReader = 0;
98  delete fTPCImpReader; fTPCImpReader = 0;
99  fSector=-1999;
100  ptrTPCP=NULL; // Herb Oct 2002 for DAQ100.
101  return 0;
102  }
103 //_____________________________________________________________________________
104 int StTPCReader::setSector(int sector)
105 {
106  if (fTPCImpReader && sector == fSector) return 0;
107 
108  delete fZeroSuppressedReader; fZeroSuppressedReader = 0;
109  delete fADCRawReader ; fADCRawReader = 0;
110  delete fPedestalReader ; fPedestalReader = 0;
111  delete fPedestalRMSReader; fPedestalRMSReader = 0;
112  delete fGainReader; fGainReader = 0;
113  delete fCPPReader; fCPPReader = 0;
114  delete fBadChannelReader; fBadChannelReader = 0;
115 
116  if (!fTPCImpReader || sector == -1) {
117  delete fTPCImpReader;
118  ptrTPCP=NULL; // Herb Oct 2002 for DAQ100.
119  fTPCImpReader = ::getDetectorReader(fDAQReader->getEventReader(),fDAQReader->getTPCVersion());
120  // assert(fTPCImpReader); We will depend on the "return 1" below. Herb Ward, Apr 22 2003.
121  fSector = -1999;
122  if(!fTPCImpReader) return 1;
123  ptrTPCP=fTPCImpReader->motherPointerBank; // Herb Oct 2002 for DAQ100.
124  if (sector == -1) return 0;
125  }
126 
127  fSector = sector;
128 
129  assert(fTPCImpReader); // Better than a crash.
130  assert( fSector<90 && (mMergeSequences==1||mMergeSequences==0) ); // See below getZeroSuppressedReader.
131  fZeroSuppressedReader = fTPCImpReader->getZeroSuppressedReader(fSector+100*mMergeSequences);
132  fADCRawReader = fTPCImpReader->getADCRawReader(fSector);
133  fPedestalReader = fTPCImpReader->getPedestalReader(fSector);
134  fPedestalRMSReader = fTPCImpReader->getPedestalRMSReader(fSector);
135  fGainReader = fTPCImpReader->getGainReader(fSector);
136  fCPPReader = fTPCImpReader->getCPPReader(fSector);
137  fBadChannelReader = fTPCImpReader->getBadChannelReader(fSector);
138 
139 
140  return 0;
141 }
142 //_____________________________________________________________________________
143 
144 int StTPCReader::getMaxPad(int padrow) const
145 {
146  const unsigned char PADS[45] = {
147  88, 96,104,112,118,126,134,142,150,
148  158,166,174,182, 98,100,102,104,106,
149  106,108,110,112,112,114,116,118,120,
150  122,122,124,126,128,128,130,132,134,
151  136,138,138,140,142,144,144,144,144};
152 
153  assert(padrow>0 && padrow <=45);
154  return PADS[padrow-1];
155 }
156 
157 //_____________________________________________________________________________
158 int StTPCReader::getPadList(int Sector, int PadRow, unsigned char *&padList)
159 {
160  if (setSector(Sector)) return -1;
161  if (!fZeroSuppressedReader) return -1;
162  return fZeroSuppressedReader->getPadList(PadRow, &padList);
163 }
164 //_____________________________________________________________________________
165  int StTPCReader::getSequences(int Sector, int PadRow, int Pad, int &nSeq,
166  TPCSequence *&SeqData)
167 {
168  if (setSector(Sector)) return -1;
169  nSeq = 0; SeqData = 0;
170  if (!fZeroSuppressedReader) return -1;
171  Sequence *seq;
172  int iret = fZeroSuppressedReader->getSequences(PadRow,Pad,&nSeq,&seq);
173  assert (sizeof(TPCSequence)==sizeof(Sequence));
174  SeqData = (TPCSequence*)seq;
175  return iret;
176 }
177 
178 //_____________________________________________________________________________
179 int StTPCReader::getRawADC(int Sector,int PadRow, int Pad, int &nArray,
180  unsigned char *&Array)
181 {
182  if (setSector(Sector)) return -1;
183  nArray = 0; Array=0;
184  if (!fADCRawReader) return -1;
185  return fADCRawReader->getSequences(PadRow,Pad,&nArray,&Array);
186 }
187 //_____________________________________________________________________________
188 int StTPCReader::getPedestals(int Sector,int PadRow, int Pad, int &nArray,
189  unsigned char *&Array)
190 {
191  if (setSector(Sector)) return -1;
192  nArray = 0; Array=0;
193  if (!fPedestalReader) return -1;
194  return fPedestalReader->getSequences(PadRow,Pad,&nArray,&Array);
195 }
196 //_____________________________________________________________________________
197 int StTPCReader::getRMSPedestals(int Sector,int PadRow, int Pad, int &nArray,
198  unsigned char *&Array)
199 {
200  if (setSector(Sector)) return -1;
201  nArray = 0; Array=0;
202  if (!fPedestalRMSReader) return -1;
203  return fPedestalRMSReader->getSequences(PadRow,Pad,&nArray,&Array);
204 }
205 //_____________________________________________________________________________
206 int StTPCReader::getGain(int Sector, int PadRow, int Pad, TPCGain *&gain)
207 {
208  if (setSector(Sector)) return -1;
209  gain = 0;
210  if (!fGainReader) return -1;
211  struct Gain *gainqq;
212  int iret = fGainReader->getGain(PadRow,Pad,&gainqq);
213  assert(sizeof(TPCGain)==sizeof(struct Gain));
214  gain = (TPCGain*)gainqq;
215  return iret;
216 }
217 //_____________________________________________________________________________
218 int StTPCReader::getClusters(int Sector, int PadRow, int Pad, int &nClusters,
219  TPCCluster *&clusters)
220 {
221  if (setSector(Sector)) return -1;
222  nClusters=0; clusters=0;
223  if (!fCPPReader) return -1;
224  struct ASIC_Cluster *clustersqq;
225  int iret = fCPPReader->getClusters(PadRow,Pad,&nClusters,&clustersqq);
226  assert(sizeof(TPCCluster)==sizeof(struct ASIC_Cluster));
227  clusters = (TPCCluster *)clustersqq;
228  return iret;
229 }
230 //_____________________________________________________________________________
231 int StTPCReader::IsBad(int Sector, int PadRow, int Pad)
232 {
233  if (setSector(Sector)) return -1;
234  if (!fBadChannelReader) return -1;
235  return fBadChannelReader->IsBad(PadRow,Pad);
236 }
237 
238 void StTPCReader::SetSequenceMerging (char mergeSequences)
239 {
240  mMergeSequences=mergeSequences;
241 }