38 #include "StFmsTriggerDetector.h"
39 #include "StTriggerData.h"
43 static const char rcsid[] =
"$Id: StFmsTriggerDetector.cxx,v 2.9 2010/01/25 17:25:00 ullrich Exp $";
50 memset(mBeg,0,mEnd-mBeg);
55 StFmsTriggerDetector::StFmsTriggerDetector(
const StTriggerData& t)
58 const unsigned char *c=0;
59 const unsigned short *s=0;
60 const unsigned int *i=0;
62 memset(mBeg,0,mEnd-mBeg);
65 mNumQTdata = (int)t.nQTdata();
66 if ( !(mMaxLine>=mNumQTdata)){
67 {LOG_ERROR <<
"StFmsTriggerDetector::StFmsTriggerDetector() mMaxLine < mNumQTdata" << endm;}
70 i = t.QTdata();
if (i && mNumQTdata>0) memcpy(mQTdata,i, mNumQTdata*
sizeof(
int ));
72 c = t.getDsm_FMS() ;
if (c) memcpy(mDSM ,c,
sizeof(mDSM ));
73 c = t.getDsm01_FMS();
if (c) memcpy(mDSM01 ,c,
sizeof(mDSM01));
74 c = t.getDsm02_FMS();
if (c) memcpy(mDSM02 ,c,
sizeof(mDSM02));
75 s = t.getDsm1_FMS() ;
if (s) memcpy(mDSM1 ,s,
sizeof(mDSM1 ));
76 s = t.getDsm2_FMS() ;
if (s) memcpy(mDSM2 ,s,
sizeof(mDSM2 ));
80 StFmsTriggerDetector::~StFmsTriggerDetector() {}
83 StFmsTriggerDetector::clearFlag() {
89 StFmsTriggerDetector::decode()
93 if (mNumQTdata==0)
return;
94 memset(mADC,0,
sizeof(mADC));
95 memset(mTDC,0,
sizeof(mTDC));
96 int header=1, nline=0, iline;
98 for (
int i=0; i<static_cast<int>(mNumQTdata-1); i++){
99 unsigned int d = mQTdata[i];
104 if (crate-mOffsetCrate<0 || crate-mOffsetCrate>mMaxCrate){
105 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Wrong QT crate#=" <<crate<< endm;}
107 if (addr-mOffsetAddr<0 || addr-mOffsetAddr>mMaxAddr){
108 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Wrong QT Addr#=" <<addr<< endm;}
110 if (nline<0 || nline>32){
111 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Wrong QT # of lines=" <<nline<< endm;}
113 if (nline>0) {header=0; iline=0;}
118 unsigned short dcard = getQT8(d);
119 unsigned short dch = getCHA(d);
120 if (dcard>mMaxDCard){
121 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Wrong QT DCard=" <<dcard<< endm;}
124 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Wrong QT DChan=" <<dch<< endm;}
126 int tst=(
char*)&mADC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]
127 -(
char*)&mADC[0][0][0][0];
128 if ( ! (tst>=0 && tst<(
int)
sizeof(mADC)) ){
129 {LOG_ERROR <<
"StFmsTriggerDetector::decode() Sanity check failed in" << endm;}
132 mADC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]=getADC(d);
133 mTDC[crate-mOffsetCrate][addr-mOffsetAddr][dcard][dch]=getTDC(d);
135 if (nline==iline) header=1;
141 StFmsTriggerDetector::hit(
int line)
const
143 if (line>=0 && line<mMaxLine && line<(
int)mNumQTdata)
return mQTdata[line];
148 StFmsTriggerDetector::adc(
int crate,
int addr,
int dcard,
int dch)
150 if (mNumHeader==-1) decode();
151 crate -= mOffsetCrate;
153 if (crate >= 0 && crate < mMaxCrate &&
154 addr >= 0 && addr < mMaxAddr &&
155 dcard >= 0 && dcard < mMaxDCard &&
156 dch >= 0 && dch < mMaxChan ){
157 return mADC[crate][addr][dcard][dch];
160 {LOG_WARN <<
"StFmsTriggerDetector::adc() arguments out of range" << endm;}
166 StFmsTriggerDetector::tdc(
int crate,
int addr,
int dcard,
int dch)
168 if (mNumHeader==-1) decode();
169 crate -= mOffsetCrate;
171 if (crate >= 0 && crate < mMaxCrate &&
172 addr >= 0 && addr < mMaxAddr &&
173 dcard >= 0 && dcard < mMaxDCard &&
174 dch >= 0 && dch < mMaxChan ){
175 return mTDC[crate][addr][dcard][dch];
178 {LOG_WARN <<
"StFmsTriggerDetector::tdc() arguments out of range" << endm;}
184 StFmsTriggerDetector::dump()
186 cout <<
"FMS data dump" << endl;
187 cout <<
"mNumHeader = "<<mNumHeader<<endl;
188 if (mNumHeader==-1) decode();
189 cout <<
"Number of data lines = " << mNumQTdata << endl;
191 printf(
"Number of header lines = %d\n", mNumHeader);
192 printf(
"Last check line (should be 0xAC10) = %x\n",mQTdata[mNumQTdata-1]);
194 for(
int crate=0; crate<mMaxCrate; crate++){
195 for(
int addr=0; addr<mMaxAddr; addr++){
196 for(
int dcard=0; dcard<mMaxDCard; dcard++){
197 printf(
"Crate=%5d Addr=%5x DCard=%5d %4d %4d %4d %4d %4d %4d %4d %4d\n",
198 crate+mOffsetCrate, addr+mOffsetAddr, dcard,
199 mADC[crate][addr][dcard][0], mADC[crate][addr][dcard][1],
200 mADC[crate][addr][dcard][2], mADC[crate][addr][dcard][3],
201 mADC[crate][addr][dcard][4], mADC[crate][addr][dcard][5],
202 mADC[crate][addr][dcard][6], mADC[crate][addr][dcard][7]);
207 for(
int crate=0; crate<mMaxCrate; crate++){
208 for(
int addr=0; addr<mMaxAddr; addr++){
209 for(
int dcard=0; dcard<mMaxDCard; dcard++){
210 printf(
"Crate=%5d Addr=%5x DCard=%5d %4d %4d %4d %4d %4d %4d %4d %4d\n",
211 crate+mOffsetCrate, addr+mOffsetAddr, dcard,
212 mTDC[crate][addr][dcard][0], mTDC[crate][addr][dcard][1],
213 mTDC[crate][addr][dcard][2], mTDC[crate][addr][dcard][3],
214 mTDC[crate][addr][dcard][4], mTDC[crate][addr][dcard][5],
215 mTDC[crate][addr][dcard][6], mTDC[crate][addr][dcard][7]);