00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <algorithm>
00057 #include "StL0Trigger.h"
00058 #include "StTriggerData.h"
00059 #include "tables/St_dst_L0_Trigger_Table.h"
00060 #include "tables/St_dst_TrgDet_Table.h"
00061
00062 #if !defined(ST_NO_NAMESPACES)
00063 using std::fill_n;
00064 using std::copy;
00065 #endif
00066
00067 static const char rcsid[] = "$Id: StL0Trigger.cxx,v 2.12 2006/07/18 14:41:01 ullrich Exp $";
00068
00069 ClassImp(StL0Trigger)
00070
00071 StL0Trigger::StL0Trigger()
00072 {
00073 mMwcCtbMultiplicity = 0;
00074 mMwcCtbDipole = 0;
00075 mMwcCtbTopology = 0;
00076 mMwcCtbMoment = 0;
00077 fill_n(mCoarsePixelArray, static_cast<int>(mMaxPixels), 0);
00078 mDsmInput = 0;
00079 mDetectorBusy = 0;
00080 mTriggerToken = 0;
00081 mDsmAddress = 0;
00082 mAddBits = 0;
00083 fill_n(mLastDsmArray, static_cast<unsigned short>(mMaxLastDsm), 0);
00084 fill_n(mBcDataArray, static_cast<unsigned short>(mMaxBcData), 0);
00085 }
00086
00087 void StL0Trigger::set(const dst_L0_Trigger_st *t)
00088 {
00089 if (!t) return;
00090 if (TestBit(1)) return;
00091 SetBit(1);
00092 mTriggerWord = t->TriggerWd;
00093 mTriggerActionWord = t->TriggerActionWd;
00094 mMwcCtbMultiplicity = t->MWC_CTB_mul;
00095 mMwcCtbDipole = t->MWC_CTB_dipole;
00096 mMwcCtbTopology = t->MWC_CTB_topology;
00097 mMwcCtbMoment = t->MWC_CTB_moment;
00098 copy(t->CPA+0, t->CPA+mMaxPixels, mCoarsePixelArray);
00099 mDsmInput = t->DSMInput;
00100 mDetectorBusy = t->DetectorBusy;
00101 mTriggerToken = t->TrgToken;
00102 mDsmAddress = t->DSMAddress;
00103 mAddBits = t->addBits;
00104 }
00105
00106 void StL0Trigger::set(const dst_TrgDet_st* n)
00107 {
00108
00109 if (!n) return;
00110 if (TestBit(2)) return;
00111 SetBit(2);
00112 copy(n->lastDSM+0, n->lastDSM+mMaxLastDsm, mLastDsmArray);
00113 copy(n->BCdata +0, n->BCdata+mMaxBcData , mBcDataArray );
00114 }
00115
00116 void StL0Trigger::set(const StTriggerData* t)
00117 {
00118
00119 if(t){
00120 SetBit(2);
00121 mTriggerWord = t->triggerWord();
00122 mTriggerActionWord = t->actionWord();
00123 mMwcCtbMultiplicity=0;
00124 mMwcCtbDipole=0;
00125 mMwcCtbTopology=0;
00126 mMwcCtbMoment=0;
00127 mDsmInput=t->dsmInput();
00128 mDetectorBusy=0;
00129 mTriggerToken=t->trgToken();
00130 mDsmAddress=t->dsmAddress();
00131 mAddBits = t->mAddBits();
00132 for(int i=0; i<mMaxLastDsm; i++){mLastDsmArray[i]=t->lastDSM(i);}
00133 for(int i=0; i<mMaxBcData; i++){mBcDataArray[i]=t->bcData(i);}
00134 }
00135 }
00136
00137 StL0Trigger::~StL0Trigger() { }
00138
00139 unsigned int
00140 StL0Trigger::coarsePixelArraySize() {return mMaxPixels;}
00141
00142 int
00143 StL0Trigger::coarsePixelArray(unsigned int i)
00144 {
00145 if (i < mMaxPixels)
00146 return mCoarsePixelArray[i];
00147 else
00148 return 0;
00149 }
00150
00151 unsigned int
00152 StL0Trigger::lastDsmArraySize() const {return mMaxLastDsm;}
00153
00154 unsigned short
00155 StL0Trigger::lastDsmArray(unsigned int i)
00156 {
00157 if (i < mMaxLastDsm)
00158 return mLastDsmArray[i];
00159 else
00160 return 0;
00161 }
00162
00163 unsigned int
00164 StL0Trigger::bcDataArraySize() const {return mMaxBcData;}
00165
00166 unsigned short
00167 StL0Trigger::bcDataArray(unsigned int i)
00168 {
00169 if (i < mMaxBcData)
00170 return mBcDataArray[i];
00171 else
00172 return 0;
00173 }
00174
00175 int
00176 StL0Trigger::mwcCtbMultiplicity() const { return mMwcCtbMultiplicity;}
00177
00178 int
00179 StL0Trigger::mwcCtbDipole() const { return mMwcCtbDipole;}
00180
00181 int
00182 StL0Trigger::mwcCtbTopology() const { return mMwcCtbTopology;}
00183
00184 int
00185 StL0Trigger::mwcCtbMoment() const { return mMwcCtbMoment;}
00186
00187 unsigned short
00188 StL0Trigger::dsmInput() const {return mDsmInput;}
00189
00190 unsigned char
00191 StL0Trigger::detectorBusy() const {return mDetectorBusy;}
00192
00193 unsigned short
00194 StL0Trigger::triggerToken() const {return mTriggerToken;}
00195
00196 unsigned short
00197 StL0Trigger::dsmAddress() const {return mDsmAddress;}
00198
00199 unsigned char
00200 StL0Trigger::addBits() const {return mAddBits;}
00201
00202 void
00203 StL0Trigger::setMwcCtbMultiplicity(int val) { mMwcCtbMultiplicity = val; }
00204
00205 void
00206 StL0Trigger::setMwcCtbDipole(int val) { mMwcCtbDipole = val; }
00207
00208 void
00209 StL0Trigger::setMwcCtbTopology(int val) { mMwcCtbTopology = val; }
00210
00211 void
00212 StL0Trigger::setMwcCtbMoment(int val) { mMwcCtbMoment = val; }
00213
00214 void
00215 StL0Trigger::setCoarsePixelArray(unsigned int i, int val)
00216 {
00217 if (i < mMaxPixels)
00218 mCoarsePixelArray[i] = val;
00219 }
00220
00221 void
00222 StL0Trigger::setDsmInput(unsigned short val) {mDsmInput = val;}
00223
00224 void
00225 StL0Trigger::setDetectorBusy(unsigned char val) {mDetectorBusy = val;}
00226
00227 void
00228 StL0Trigger::setTriggerToken(unsigned short val) {mTriggerToken = val;}
00229
00230 void
00231 StL0Trigger::setDsmAddress(unsigned short val) {mDsmAddress = val;}
00232
00233 void
00234 StL0Trigger::setAddBits(unsigned char val) {mAddBits = val;}
00235
00236
00237 void
00238 StL0Trigger::setLastDsmArray(unsigned int i, unsigned short val)
00239 {
00240 if (i < mMaxLastDsm)
00241 mLastDsmArray[i] = val;
00242 }
00243
00244 void
00245 StL0Trigger::setBcDataArray(unsigned int i, unsigned short val)
00246 {
00247 if (i < mMaxBcData)
00248 mBcDataArray[i] = val;
00249 }
00250
00251 unsigned int
00252 StL0Trigger::bunchCrossingId7bit(int runNumber) const
00253 {
00254 unsigned int b7dat = mBcDataArray[2];
00255
00256
00257
00258
00259
00260
00261
00262
00263 if (runNumber>4000000)
00264 return b7dat & 0x7f;
00265
00266
00267
00268
00269
00270
00271 int b7=0, ibits;
00272 if(runNumber<3010000) { ibits=7; }
00273 else { ibits=6; }
00274
00275 for (int i=0; i<7; i++) {
00276 b7 += (!((b7dat>>(ibits-i)) & 0x1) << (i)) & 0x7f;
00277 }
00278 return b7;
00279 }
00280
00281 unsigned int
00282 StL0Trigger::bunchCrossingId() const
00283 {
00284 unsigned long long bxinghi,bxing1,bxinglo,bxing,bx0,bx1,bx2;
00285 int b120;
00286 bxinghi = mBcDataArray[3];
00287 bxing1 = mBcDataArray[10];
00288 bxinglo = (bxing1 << 16) + mBcDataArray[11];
00289 bxing = (bxinghi << 32) + bxinglo;
00290 bx0 = bxing;
00291 bx1 = bx0/120;
00292 bx2 = bx1 * 120;
00293 b120 = bx0 - bx2;
00294 return static_cast<unsigned int>(b120);
00295 }
00296
00297 int
00298 StL0Trigger::spinBits(int runNumber) const
00299 {
00300 int ldsm0,spin1,spin2,spin3,spin4;
00301 if (runNumber<4000000){
00302 ldsm0 = mLastDsmArray[0];
00303 spin1 = (ldsm0>>8) & 0x1;
00304 spin2 = (ldsm0>>9) & 0x1;
00305 spin3 = (ldsm0>>10) & 0x1;
00306 spin4 = (ldsm0>>11) & 0x1;
00307 return spin1+spin2*2+spin3*4+spin4*8;
00308 }
00309 else {
00310 ldsm0 = (mLastDsmArray[7]/16)%256;
00311 spin1 = (ldsm0/ 2)%2;
00312 spin2 = (ldsm0/ 4)%2;
00313 spin3 = (ldsm0/32)%2;
00314 spin4 = (ldsm0/64)%2;
00315 return spin1+spin2*2+spin3*4+spin4*8;
00316 }
00317 }
00318
00319 int
00320 StL0Trigger::spinBitYellowUp(int runNumber) const
00321 {
00322 if (runNumber<4000000){
00323 return (mLastDsmArray[0]>>8) & 0x1;
00324 }
00325 else {
00326 int ldsm0 = (mLastDsmArray[7]/16)%256;
00327 return (ldsm0/2)%2;
00328 }
00329 }
00330
00331 int
00332 StL0Trigger::spinBitYellowDown(int runNumber) const
00333 {
00334 if (runNumber<4000000){
00335 return (mLastDsmArray[0]>>9) & 0x1;
00336 }
00337 else {
00338 int ldsm0 = (mLastDsmArray[7]/16)%256;
00339 return (ldsm0/ 4)%2;
00340 }
00341 }
00342
00343 int
00344 StL0Trigger::spinBitBlueUp(int runNumber) const
00345 {
00346 if (runNumber<4000000){
00347 return (mLastDsmArray[0]>>9) & 0x1;
00348 }
00349 else {
00350 int ldsm0 = (mLastDsmArray[7]/16)%256;
00351 return (ldsm0/32)%2;
00352 }
00353 }
00354
00355 int
00356 StL0Trigger::spinBitBlueDown(int runNumber) const
00357 {
00358 if (runNumber<4000000){
00359 return (mLastDsmArray[0]>>10) & 0x1;
00360 }
00361 else {
00362 int ldsm0 = (mLastDsmArray[7]/16)%256;
00363 return (ldsm0/64)%2;
00364 }
00365 }