StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSVTReader.cxx
1 /***************************************************************************
2  *
3  *
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: Offline Wrapper for DAQ SVT reader classes
9  *
10  ***************************************************************************
11  *
12  *
13  *
14  **************************************************************************/
15 // non standard open,close,read
16 #include <string.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #include <assert.h>
20 #include "Stypes.h"
21 //
22 #include "StSVTReader.h"
23 #include "StDaqLib/SVT/SVTV1P0_Reader.hh"
24 
25 
26 
27 typedef EventInfo DAQEventInfo;
28 
29 //_____________________________________________________________________________
30 StSVTReader::StSVTReader(StDAQReader *daqr)
31 {
32  fDAQReader = daqr;
33  fWafer = -1999;
34  fSVTImpReader = 0;
35  fZeroSuppressedReader = 0;
36  fADCRawReader = 0;
37  fPedestalReader = 0;
38  fPedestalRMSReader = 0;
39  fGainReader = 0;
40  fCPPReader = 0;
41  fBadChannelReader = 0;
42  Update();
43 }
44 //_____________________________________________________________________________
45 void StSVTReader::Update()
46 {
47  setWafer(-1,-1,-1);
48 }
49 //_____________________________________________________________________________
50 StSVTReader::~StSVTReader()
51 {
52  close();
53 }
54 //_____________________________________________________________________________
55 int StSVTReader::close()
56 {
57  fWafer = -1999;
58 
59  delete fSVTImpReader; fSVTImpReader =0;
60  delete fZeroSuppressedReader; fZeroSuppressedReader =0;
61  delete fADCRawReader; fADCRawReader =0;
62  delete fPedestalReader; fPedestalReader =0;
63  delete fPedestalRMSReader; fPedestalRMSReader =0;
64  delete fGainReader ; fGainReader =0;
65  delete fCPPReader ; fCPPReader =0;
66  delete fBadChannelReader; fBadChannelReader =0;
67  return 0;
68  }
69 //_____________________________________________________________________________
70 int StSVTReader::setWafer(int barrel, int ladder, int wafer)
71 {
72  int waferIndex = getWaferIndex(barrel, ladder, wafer);
73 
74  if (waferIndex == fWafer) return waferIndex;
75 
76  delete fZeroSuppressedReader; fZeroSuppressedReader =0;
77  delete fADCRawReader; fADCRawReader =0;
78  delete fPedestalReader; fPedestalReader =0;
79  delete fPedestalRMSReader; fPedestalRMSReader =0;
80  delete fGainReader ; fGainReader =0;
81  delete fCPPReader ; fCPPReader =0;
82  delete fBadChannelReader; fBadChannelReader =0;
83 
84  if ((barrel == -1) && (ladder == -1) && (wafer == -1)) {
85  delete fSVTImpReader;
86  fSVTImpReader = ::getDetectorReader(fDAQReader->getEventReader(), "SVT");
87  fWafer = -1999;
88  }
89 
90  if ((barrel == -1) && (ladder == -1) && (wafer == -1)) return -1;
91 
92  fWafer = waferIndex;
93 
94  fZeroSuppressedReader = ((SVTV1P0_Reader*)fSVTImpReader)->getZeroSuppressedReader(barrel, ladder, wafer);
95  fADCRawReader = ((SVTV1P0_Reader*)fSVTImpReader)->getADCRawReader(barrel, ladder, wafer);
96  fPedestalReader = ((SVTV1P0_Reader*)fSVTImpReader)->getPedestalReader(barrel, ladder, wafer);
97  fPedestalRMSReader = ((SVTV1P0_Reader*)fSVTImpReader)->getPedestalRMSReader(barrel, ladder, wafer);
98  // fGainReader = ((SVTV1P0_Reader*)fSVTImpReader)->getGainReader(barrel, ladder, wafer);
99  fCPPReader = ((SVTV1P0_Reader*)fSVTImpReader)->getCPPReader(barrel, ladder, wafer);
100  // fBadChannelReader = ((SVTV1P0_Reader*)fSVTImpReader)->getBadChannelReader(barrel, ladder, wafer);
101 
102  mSCAZero = ((SVTV1P0_Reader*)fSVTImpReader)->getSCAZero();
103  mTimeZero = ((SVTV1P0_Reader*)fSVTImpReader)->getTimeZero();
104 
105  return waferIndex;
106 }
107 //_____________________________________________________________________________
108 
109 int StSVTReader::getWaferIndex(int barrel, int ladder, int wafer)
110 {
111  short index;
112  int numberOfLadders[3] = {8,12,16};
113  int numberOfWafers[3] = {4,6,7};
114  int numberOfHybrids = 2; if(numberOfHybrids) {/*touch*/}
115 
116  switch (barrel) {
117 
118  case 1:
119  index = (ladder-1)*numberOfWafers[barrel-1] + wafer;
120  break;
121 
122  case 2:
123  index = numberOfLadders[barrel-2]*numberOfWafers[barrel-2] +
124  (ladder-1)*numberOfWafers[barrel-1] + wafer;
125  break;
126 
127  case 3:
128  index = numberOfLadders[barrel-3]*numberOfWafers[barrel-3] +
129  numberOfLadders[barrel-2]*numberOfWafers[barrel-2] +
130  (ladder-1)*numberOfWafers[barrel-1] + wafer;
131  break;
132 
133  default:
134  // cout << "ERROR: There is NO barrel number " << barrel << " !!!" << endl;
135  index = -1;
136  break;
137  }
138 
139  if ((index < 1) || (index > 216)) index = -1;
140  return index;
141 }
142 
143 //_____________________________________________________________________________
144 int StSVTReader::getAnodeList(int barrel, int ladder, int wafer, int hybrid, unsigned char *&anodeList)
145 {
146  int waferIndex = setWafer(barrel, ladder, wafer);
147  if (waferIndex == -1) return -1;
148  if (!fZeroSuppressedReader) return -1;
149  return fZeroSuppressedReader->getPadList(hybrid, &anodeList);
150 }
151 //_____________________________________________________________________________
152 int StSVTReader::getSequences(int barrel, int ladder, int wafer, int hybrid, int Anode, int &nSeq,
153  TPCSequence *&SeqData)
154 {
155  int waferIndex = setWafer(barrel, ladder, wafer);
156  if (waferIndex == -1) return -1;
157  nSeq = 0; SeqData = 0;
158  if (!fZeroSuppressedReader) return -1;
159  Sequence *seq;
160  int iret = fZeroSuppressedReader->getSequences(hybrid,Anode,&nSeq,&seq);
161  assert (sizeof(TPCSequence)==sizeof(Sequence));
162  SeqData = (TPCSequence*)seq;
163  return iret;
164 }
165 
166 //_____________________________________________________________________________
167 int StSVTReader::getRawADC(int barrel, int ladder, int wafer, int hybrid, int Anode, int &nArray,
168  unsigned char *&Array)
169 {
170  int waferIndex = setWafer(barrel, ladder, wafer);
171  if (waferIndex == -1) return -1;
172  nArray = 0; Array=0;
173  if (!fADCRawReader) return -1;
174  int status = fADCRawReader->getSequences(hybrid,Anode,&nArray,&Array);
175  // if (nArray) cout << "StSVTReader::nArray = " << nArray << ", Array = " << Array << endl;
176  // cout << "StSVTReader::status = " << status << endl;
177  return status;
178 }
179 //_____________________________________________________________________________
180 int StSVTReader::getPedestals(int barrel, int ladder, int wafer, int hybrid, int Anode, int &nArray,
181  unsigned char *&Array)
182 {
183  int waferIndex = setWafer(barrel, ladder, wafer);
184  if (waferIndex == -1) return -1;
185  nArray = 0; Array=0;
186  if (!fPedestalReader) return -1;
187  return fPedestalReader->getSequences(hybrid,Anode,&nArray,&Array);
188 }
189 //_____________________________________________________________________________
190 int StSVTReader::getRMSPedestals(int barrel, int ladder, int wafer, int hybrid, int Anode, int &nArray,
191  unsigned char *&Array)
192 {
193  int waferIndex = setWafer(barrel, ladder, wafer);
194  if (waferIndex == -1) return -1;
195  nArray = 0; Array=0;
196  if (!fPedestalRMSReader) return -1;
197  return fPedestalRMSReader->getSequences(hybrid,Anode,&nArray,&Array);
198 }
199 //_____________________________________________________________________________
200 int StSVTReader::getGain(int barrel, int ladder, int wafer, int hybrid, int Anode, TPCGain *&gain)
201 {
202  int waferIndex = setWafer(barrel, ladder, wafer);
203  if (waferIndex == -1) return -1;
204  gain = 0;
205  if (!fGainReader) return -1;
206  struct Gain *gainqq;
207  int iret = fGainReader->getGain(hybrid,Anode,&gainqq);
208  assert(sizeof(TPCGain)==sizeof(struct Gain));
209  gain = (TPCGain*)gainqq;
210  return iret;
211 }
212 //_____________________________________________________________________________
213 int StSVTReader::getClusters(int barrel, int ladder, int wafer, int hybrid, int Anode, int &nClusters,
214  TPCCluster *&clusters)
215 {
216  int waferIndex = setWafer(barrel, ladder, wafer);
217  if (waferIndex == -1) return -1;
218  nClusters=0; clusters=0;
219  if (!fCPPReader) return -1;
220  struct ASIC_Cluster *clustersqq;
221  int iret = fCPPReader->getClusters(hybrid,Anode,&nClusters,&clustersqq);
222  assert(sizeof(TPCCluster)==sizeof(struct ASIC_Cluster));
223  clusters = (TPCCluster *)clustersqq;
224  return iret;
225 }
226 //_____________________________________________________________________________
227 int StSVTReader::IsBad(int barrel, int ladder, int wafer, int hybrid, int Anode)
228 {
229  int waferIndex = setWafer(barrel, ladder, wafer);
230  if (waferIndex == -1) return -1;
231  if (!fBadChannelReader) return 1;
232  return fBadChannelReader->IsBad(hybrid,Anode);
233 }
234 
235