StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtHybridData.cc
1 /***************************************************************************
2  *
3  * $Id: StSvtHybridData.cc,v 1.11 2008/06/12 14:22:12 fisyak Exp $
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: SVT Hybrid Data BASE class
9  *
10  ***************************************************************************
11  *
12  * $Log: StSvtHybridData.cc,v $
13  * Revision 1.11 2008/06/12 14:22:12 fisyak
14  * Add default no. of anodes and timeBins
15  *
16  * Revision 1.10 2005/07/23 03:37:33 perev
17  * IdTruth + Cleanup
18  *
19  * Revision 1.9 2004/04/29 03:45:37 perev
20  * fill array by -1. walgrind complained non itializeds variable
21  *
22  * Revision 1.8 2003/09/17 12:57:51 munhoz
23  * initializing pointer seq[]
24  *
25  * Revision 1.7 2002/02/12 23:09:50 munhoz
26  * fixing problems for new compiler
27  *
28  * Revision 1.6 2002/01/05 21:44:06 caines
29  * Initialise TimeZero and first sca always
30  *
31  * Revision 1.5 2001/08/24 20:58:35 caines
32  * Zero Seq and nseq for getSequences
33  *
34  * Revision 1.4 2001/04/30 22:20:42 caines
35  * Add Anode to setList fn so works with ZSP data
36  *
37  * Revision 1.3 2000/11/30 20:39:12 caines
38  * Changed to allow us of database
39  *
40  * Revision 1.2 2000/07/30 21:13:04 munhoz
41  * adding correction for copy constructor and equal operator
42  *
43  * Revision 1.1.1.1 2000/03/10 14:26:21 munhoz
44  * SVT Class Library
45  *
46  **************************************************************************/
48 // //
49 // This is the class to access the data from each hybrid. //
50 // //
52 #include <assert.h>
53 #include <string.h>
54 #include "StSvtHybridData.hh"
55 #include "StSequence.hh"
56 
57 ClassImp(StSvtHybridData)
58 
59 //____________________________________________________________________________
61 {
62  // Default Constructor
63  mSCAZero =0;
64  mTimeZero = 0;
65 }
66 
67 //____________________________________________________________________________
68 StSvtHybridData::StSvtHybridData(int barrel, int ladder, int wafer, int hybrid) :
69  StSvtHybridObject(barrel, ladder, wafer, hybrid)
70 {
71  //This constructor has four input parameters: Barrel, Ladder, Wafer and Hybrid number (as expected).
72  mSCAZero = 0;
73  mTimeZero = 0;
74 }
75 
76 //____________________________________________________________________________
77 StSvtHybridData::~StSvtHybridData()
78 {
79 // delete [] anodeList;
80 // delete [] nSeq;
81 // for (int ianode=0;ianode<nAnodes;ianode++)
82 // if (seq[ianode]) delete seq[ianode];
83 // delete [] seq;
84 }
85 
86 //____________________________________________________________________________
87 StSvtHybridData::StSvtHybridData(const StSvtHybridData& hybrid)
88 {
89  // Copy Constructor
90  mBarrel = hybrid.mBarrel;
91  mLadder = hybrid.mLadder;
92  mWafer = hybrid.mWafer;
93  mHybrid = hybrid.mHybrid;
94  mTimeZero = hybrid.mTimeZero;
95  mSCAZero = hybrid.mSCAZero;
96 
97  seq = hybrid.seq;
98  anodeList = hybrid.anodeList;
99  lookUp = hybrid.lookUp;
100 }
101 
102 //____________________________________________________________________________
103 StSvtHybridData& StSvtHybridData::operator = (const StSvtHybridData& hybrid)
104 {
105  mBarrel = hybrid.mBarrel;
106  mLadder = hybrid.mLadder;
107  mWafer = hybrid.mWafer;
108  mHybrid = hybrid.mHybrid;
109  mTimeZero = hybrid.mTimeZero;
110  mSCAZero = hybrid.mSCAZero;
111  seq = hybrid.seq;
112  anodeList = hybrid.anodeList;
113  lookUp = hybrid.lookUp;
114  return *this;
115 }
116 
117 //____________________________________________________________________________
118 int StSvtHybridData::getAnodeList(int*& list)
119 {
120  // returns the number of anodes of a given hybrid that has one or more sequences of data.
121  // The anodeList contains the number (ID) of such anodes.
122  // In the case of raw data, it returns always 240 anodes.
123  if (!anodeList.size()) setAnodeList();
124  list = &anodeList[0];
125  return anodeList.size();
126 }
127 
128 //____________________________________________________________________________
129 int StSvtHybridData::getSequences(int anode, int& nSequence, StSequence*& sequence)
130 {
131  // provides the number of sequences each anode has (nSequences) and a list of the sequences (sequence).
132  // The structure StSequence (from StarClassLibrary) gives the first time bin of the sequence,
133  // the length of the sequence and a pointer for the first ADC of the sequence.
134 
135  nSequence = 0;
136  sequence = 0;
137  if (!lookUp.size()) setAnodeList();
138  if (anode>=(int)lookUp.size()) return 0;
139  int i = lookUp[anode];
140  assert(i<(int)seq.size());
141  if (i<0 ) return 0;
142  nSequence = seq[i].size();
143  sequence = &(seq[i][0]);
144  return 0;
145 }
146 
147 //____________________________________________________________________________
148 int StSvtHybridData::getListSequences(int listID, int& nSequence, StSequence*& sequence)
149 {
150  nSequence = 0;
151  sequence = NULL;
152  if(listID >= 0 && listID < (int)seq.size())
153  {
154  nSequence = seq[listID].size();
155  sequence = &seq[listID][0];
156  }
157  return 0;
158 }
159 //____________________________________________________________________________
160 int StSvtHybridData::getListTruth(int listID, int& nSequence, StMCTruth*& sequence)
161 {
162  nSequence = 0;
163  sequence = NULL;
164  if(listID >= 0 && listID < (int)seq.size())
165  {
166  nSequence = seq[listID].mTruth.size();
167  sequence = &seq[listID].mTruth[0];
168  }
169  if(!nSequence) sequence=0;
170  return 0;
171 }
172 
173 //____________________________________________________________________________
174 int StSvtHybridData::setListSequences(int listID, int Anode, int& nSequence, StSequence* tempSeq)
175 {
176 
177  int nAnodes = seq.size();
178  if (!nAnodes) {
179  nAnodes = 240;
180  seq.resize(0);
181  seq.resize(nAnodes);
182  anodeList.resize(0);
183  lookUp.resize(0);
184  }
185  // Resets the sequences for a given anode
186  if(listID >= 0 && listID < nAnodes){
187  seq[listID].resize(nSequence);
188  seq[listID].mAnode = Anode;
189  seq[listID].mTruth.resize(0);
190  memcpy(&(seq[listID][0]),tempSeq,nSequence*sizeof(StSequence));
191  }
192  return 0;
193 }
194 //____________________________________________________________________________
195 int StSvtHybridData::setListTruth(int listID, int Anode, int& nSequence, StMCTruth* tempTru)
196 {
197 
198  int nAnodes = seq.size();
199  // Resets the sequences for a given anode
200  if(listID >= 0 && listID < nAnodes){
201  assert(Anode==seq[listID].mAnode);
202  assert((int)seq[listID].size()==nSequence);
203  seq[listID].mTruth.resize(nSequence);
204  memcpy(&(seq[listID].mTruth[0]),tempTru,nSequence*sizeof(StMCTruth));
205  }
206  return 0;
207 }
208 
209 //____________________________________________________________________________
210 int StSvtHybridData::setAnodeList()
211 {
212  // Loops over anode list and removes from the list those anodes who no longer have any sequences on them
213 
214  int newTot=0;
215  int nAnodes = seq.size();
216  anodeList.resize(nAnodes);
217  int maxAnode = 0;
218  for(int i=0; i<nAnodes; i++){
219  if(!seq[i].size()) continue;
220  if (maxAnode<seq[i].mAnode) maxAnode=seq[i].mAnode;
221  if (newTot!=i) {
222  seq[newTot].mAnode = seq[i].mAnode;
223  seq[newTot].swap(seq[i]);
224  seq[newTot].mTruth.swap(seq[i].mTruth);
225  }
226  anodeList[newTot] = seq[newTot].mAnode;
227  newTot++;
228  }
229  nAnodes = newTot;
230  seq.resize(nAnodes);
231  anodeList.resize(nAnodes);
232  lookUp.resize(0);
233  lookUp.resize(maxAnode+1,-1);
234  for(int i=0; i<nAnodes; i++){lookUp[seq[i].mAnode] = i;}
235 
236  return 0;
237 }