StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFpdTriggerDetector.cxx
1 /***************************************************************************
2  *
3  * $Id: StFpdTriggerDetector.cxx,v 2.6 2007/07/11 23:06:45 perev Exp $
4  *
5  * Author: Akio Ogawa, Jul 2004
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StFpdTriggerDetector.cxx,v $
13  * Revision 2.6 2007/07/11 23:06:45 perev
14  * Cleanup+fix StXXXTriggerDetector
15  *
16  * Revision 2.5 2004/11/30 19:18:14 ullrich
17  * Fixed 2 bugs causing out of range errors reported in insure++ (Akio).
18  *
19  * Revision 2.4 2004/10/05 16:10:33 ullrich
20  * Corrected uninitialized for-loop variable.
21  *
22  * Revision 2.3 2004/10/05 15:48:05 fisyak
23  * typo fix
24  *
25  * Revision 2.2 2004/08/04 17:26:07 ullrich
26  * Fixed bug in assignement operator.
27  *
28  * Revision 2.1 2004/08/03 17:20:33 ullrich
29  * Initial Revision.
30  *
31  **************************************************************************/
32 
33 #include <algorithm>
34 #include "StFpdTriggerDetector.h"
35 #include "tables/St_dst_TrgDet_Table.h"
36 #include "StTriggerData.h"
37 
38 static const char rcsid[] = "$Id: StFpdTriggerDetector.cxx,v 2.6 2007/07/11 23:06:45 perev Exp $";
39 
40 ClassImp(StFpdTriggerDetector)
41 
43 {
44  clear();
45  init();
46 }
47 
48 StFpdTriggerDetector::StFpdTriggerDetector(const dst_TrgDet_st& t)
49 {
50  clear();
51  init();
52 }
53 
54 StFpdTriggerDetector::StFpdTriggerDetector(const StTriggerData& t)
55 {
56  clear();
57  init();
58  for(int ew=0; ew<2; ew++) {
59  for(unsigned int nstbps=0; nstbps<mMaxModule; nstbps++) {
60  int tst=(char*)&mAdc[ew][nstbps]-(char*)&mAdc[0][0];
61  assert(tst>=0 && tst<(int)sizeof(mAdc));
62  for(unsigned int tower=0; tower<mMaxTower[nstbps]; tower++){
63  mAdc[ew][nstbps][tower]=t.fpd((StBeamDirection)ew,nstbps,tower+1);
64  } }
65  for(unsigned int nstbps=0; nstbps<mMaxBoard; nstbps++) {
66  for(int bd=0; bd<mMaxBoard; bd++) {
67  int tst=(char*)&mLayer1[ew][nstbps][bd]-(char*)&mLayer1[0][0][0];
68  assert(tst>=0 && tst<(int)sizeof(mLayer1));
69  mLayer1[ew][nstbps][bd]=t.fpdLayer1DSM((StBeamDirection)ew,nstbps,bd);
70  }
71  mLayer2[ew][nstbps]=t.fpdLayer2DSM((StBeamDirection)ew,nstbps);
72  }
73  }
74 }
75 
76 StFpdTriggerDetector::StFpdTriggerDetector(const StFpdTriggerDetector& det)
77 {
78  init();
79  copy(det.mEN, det.mEN+mMaxNS, mEN);
80  copy(det.mES, det.mES+mMaxNS, mES);
81  copy(det.mET, det.mET+mMaxTB, mET);
82  copy(det.mEB, det.mEB+mMaxTB, mEB);
83  copy(det.mEPN, det.mEPN+mMaxPS, mEPN);
84  copy(det.mEPS, det.mEPS+mMaxPS, mEPS);
85  copy(det.mWN, det.mWN+mMaxNS, mWN);
86  copy(det.mWS, det.mWS+mMaxNS, mWS);
87  copy(det.mWT, det.mWT+mMaxTB, mWT);
88  copy(det.mWB, det.mWB+mMaxTB, mWB);
89  copy(det.mWPN, det.mWPN+mMaxPS, mWPN);
90  copy(det.mWPS, det.mWPS+mMaxPS, mWPS);
91  for (int i=0; i<2; i++)
92  for (int j=0; j<mMaxModule; j++) {
93  for (int k=0; k<mMaxBoard; k++) mLayer1[i][j][k] = det.mLayer1[i][j][k] ;
94  mLayer2[i][j] = det.mLayer2[i][j];
95  }
96 }
97 
99 StFpdTriggerDetector::operator=(const StFpdTriggerDetector& det)
100 {
101  if (this != &det) {
102  init();
103  copy(det.mEN, det.mEN+mMaxNS, mEN);
104  copy(det.mES, det.mES+mMaxNS, mES);
105  copy(det.mET, det.mET+mMaxTB, mET);
106  copy(det.mEB, det.mEB+mMaxTB, mEB);
107  copy(det.mEPN, det.mEPN+mMaxPS, mEPN);
108  copy(det.mEPS, det.mEPS+mMaxPS, mEPS);
109  copy(det.mWN, det.mWN+mMaxNS, mWN);
110  copy(det.mWS, det.mWS+mMaxNS, mWS);
111  copy(det.mWT, det.mWT+mMaxTB, mWT);
112  copy(det.mWB, det.mWB+mMaxTB, mWB);
113  copy(det.mWPN, det.mWPN+mMaxPS, mWPN);
114  copy(det.mWPS, det.mWPS+mMaxPS, mWPS);
115  for (int i=0; i<2; i++)
116  for (int j=0; j<mMaxModule; j++) {
117  for (int k=0; k<mMaxBoard; k++) mLayer1[i][j][k] = det.mLayer1[i][j][k] ;
118  mLayer2[i][j] = det.mLayer2[i][j];
119  }
120  }
121  return *this;
122 }
123 
124 StFpdTriggerDetector::~StFpdTriggerDetector() {/* noop */}
125 
126 void
127 StFpdTriggerDetector::init()
128 {
129  mMaxTower[0]=mMaxNS; mMaxTower[1]=mMaxNS;
130  mMaxTower[2]=mMaxTB; mMaxTower[3]=mMaxTB;
131  mMaxTower[4]=mMaxPS; mMaxTower[5]=mMaxPS;
132  mAdc[0][0]=mEN ;mAdc[0][1]=mES ;mAdc[0][2]=mET;mAdc[0][3]=mEB;
133  mAdc[0][4]=mEPN;mAdc[0][5]=mEPS;
134  mAdc[1][0]=mWN ;mAdc[1][1]=mWS ;mAdc[1][2]=mWT;mAdc[1][3]=mWB;
135  mAdc[1][4]=mWPN;mAdc[1][5]=mWPS;
136 }
137 
138 void
139 StFpdTriggerDetector::clear()
140 {
141  memset(mBeg,0,mEnd-mBeg);
142 }
143 
144 unsigned int
145 StFpdTriggerDetector::numberOfTowers(unsigned int nstbps) const
146 {
147  if (nstbps<mMaxModule)
148  return mMaxTower[nstbps];
149  else
150  return 0;
151 }
152 
153 unsigned int
154 StFpdTriggerDetector::numberOfModules() const {return mMaxModule;}
155 
156 unsigned int
157 StFpdTriggerDetector::numberOfLayer1Boards() const {return mMaxBoard;}
158 
159 unsigned int
160 StFpdTriggerDetector::adc(StBeamDirection ew, unsigned int nstbps, unsigned int tower) const
161 {
162  if (nstbps<mMaxModule) {
163  if (tower < mMaxTower[nstbps])
164  return static_cast<unsigned int>(mAdc[ew][nstbps][tower]);
165  }
166  return 0;
167 }
168 
169 unsigned int
170 StFpdTriggerDetector::layer1(StBeamDirection ew, unsigned int nstbps, unsigned int board) const
171 {
172  if (nstbps<mMaxModule && board<mMaxBoard)
173  return static_cast<unsigned int>(mLayer1[ew][nstbps][board]);
174  return 0;
175 }
176 
177 unsigned int
178 StFpdTriggerDetector::layer2(StBeamDirection ew, unsigned int nstbps) const
179 {
180  if (nstbps<mMaxModule)
181  return static_cast<unsigned int>(mLayer2[ew][nstbps]);
182  return 0;
183 }
184 
185 void
186 StFpdTriggerDetector::setAdc(StBeamDirection ew, unsigned int nstbps, unsigned int tower, unsigned char v)
187 {
188  if (nstbps<mMaxModule)
189  if (tower < mMaxTower[nstbps])
190  mAdc[ew][nstbps][tower]=v;
191 }
192 
193 void
194 StFpdTriggerDetector::setLayer1(StBeamDirection ew, unsigned int nstbps, unsigned int board, unsigned short v)
195 {
196  if (nstbps<mMaxModule && board<mMaxBoard)
197  mLayer1[ew][nstbps][board]=v;
198 }
199 
200 void
201 StFpdTriggerDetector::setLayer2(StBeamDirection ew, unsigned int nstbps, unsigned short v)
202 {
203  if (nstbps<mMaxModule)
204  mLayer2[ew][nstbps]=v;
205 }
206 
207 void
208 StFpdTriggerDetector::dump() const
209 {
210  printf("StFpdTriggerDetector::dump()\n");
211  printf("numberOfModules()=%d numberOfLayer1Boards()=%d\n",numberOfModules(),numberOfLayer1Boards());
212  for(int ew=0; ew<2; ew++){
213  if(ew==0) printf("East\n");
214  else printf("West\n");
215  for(unsigned int nstbps=0; nstbps<numberOfModules(); nstbps++){
216  printf("Module=%d numberOfTowers=%d\n",nstbps,numberOfTowers(nstbps));
217  for(unsigned int tower=0; tower<numberOfTowers(nstbps); tower++){
218  printf("%4d ",adc((StBeamDirection)ew,nstbps,tower));
219  if(numberOfTowers(nstbps)==49 && tower%7==6) printf("\n");
220  if(numberOfTowers(nstbps)==25 && tower%5==4) printf("\n");
221  if(numberOfTowers(nstbps)==7 && tower%7==6) printf("\n");
222  }
223  printf("Layer1=");
224  for(unsigned int bd=0; bd<numberOfLayer1Boards(); bd++){
225  printf("%4d ",layer1((StBeamDirection)ew,nstbps,bd));
226  }
227  printf("\nLayer2=%d\n",layer2((StBeamDirection)ew,nstbps));
228  }
229  }
230 }