00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "RawData/RawTOFDigit.h"
00013
00014 #include "MessageService/MsgService.h"
00015 CVSID("$Id: RawTOFDigit.cxx,v 1.5 2003/07/10 19:36:30 rhatcher Exp $");
00016
00017 #include "MessageService/MsgFormat.h"
00018 #include "MessageService/MsgStream.h"
00019
00020 ClassImp(RawTOFDigit)
00021
00022
00023 ostream& operator<<(ostream& os, const RawTOFDigit& r)
00024 {
00025 MsgFormat ifmt("%2d");
00026 MsgFormat ecfmt("%3d");
00027 MsgFormat adcfmt("%5d");
00028 MsgFormat timefmt("%10d");
00029 MsgFormat hexfmt("%8.8x");
00030
00031 os << " " << r.GetName()
00032 << " ErrorCode " << ecfmt(r.fErrorCode)
00033 << " ADC: " << adcfmt(r.fAdc) << " Time " << timefmt(r.fTdc);
00034 os << " TDC: " << r.GetNumberOfEntries()
00035 <<" entries (" << ((r.IsStructureOk()) ? "ok" : "bad structure")
00036 << "), tdc evt counter " << r.GetTdcEventCounter() << endl;
00037 int n = r.GetNumberOfEntries();
00038 if (n>0)
00039 os << " channel value valid under over" << endl;
00040 for (int i=0; i<n; i++) {
00041 os << " [" << ifmt(i) << "]" << ecfmt(r.GetTdcChannel(i))
00042 << " " << adcfmt(r.GetTdcValue(i))
00043 << " " << (int)r.IsTdcValid(i)
00044 << " " << (int)r.IsTdcUnderThreshold(i)
00045 << " " << (int)r.IsTdcOverflow(i);
00046 }
00047 int NN = r.GetTdcArraySize();
00048 os << " raw tdc block: ";
00049 for (int II=0; II<NN; II++)
00050 os << " 0x" << hexfmt(r.GetTdcArray()[II]);
00051 os << endl;
00052
00053 return os;
00054 }
00055
00056
00057 RawTOFDigit::RawTOFDigit()
00058 {
00059
00060 }
00061
00062
00063 RawTOFDigit::RawTOFDigit(const Int_t *&p, const RawDigitCrateStatus *cstat)
00064 : RawVaDigit(p,cstat)
00065 {
00066
00067
00068
00069
00070
00071 fTDCArray = p;
00072
00073 int nskip = GetTdcArraySize();
00074 p += nskip;
00075 }
00076
00077
00078 RawTOFDigit::~RawTOFDigit()
00079 {
00080
00081 }
00082
00083
00084 Int_t RawTOFDigit::GetNumberOfEntries() const
00085 {
00086
00087
00088
00089
00090 const int cntMask = 0x3f;
00091 const int cntShift = 8;
00092
00093 static int nmsg = 5;
00094
00095
00096 Int_t minor = fDigitCrateStatus->GetRawBlockId().GetMinor();
00097 switch (minor) {
00098 case 0:
00099
00100 return (fTDCArray[0]>>cntShift)&cntMask;
00101 break;
00102 default:
00103 if (nmsg > 0) {
00104 MSG("RawData",Msg::kWarning)
00105 << "RawTOFDigit::GetNumberOfEntries() unknown minor version "
00106 << minor << ", assume std TDC header format" << endl;
00107 nmsg--;
00108 if (nmsg==0)
00109 MSG("RawData",Msg::kWarning)
00110 << " ... last warning" << endl;
00111 }
00112
00113 return (fTDCArray[0]>>cntShift)&cntMask;
00114 break;
00115 }
00116
00117 }
00118
00119
00120 Int_t RawTOFDigit::GetTdcArraySize() const
00121 {
00122
00123
00124
00125
00126 static int nmsg = 5;
00127
00128 Int_t minor = fDigitCrateStatus->GetRawBlockId().GetMinor();
00129 switch (minor) {
00130 case 0:
00131 return 2+GetNumberOfEntries();
00132 break;
00133 default:
00134 if (nmsg > 0) {
00135 MSG("RawData",Msg::kWarning)
00136 << "RawTOFDigit::GetTdcArraySize() unknown minor version "
00137 << minor << ", assume std TDC header format" << endl;
00138 nmsg--;
00139 if (nmsg==0)
00140 MSG("RawData",Msg::kWarning)
00141 << " ... last warning" << endl;
00142 }
00143 return 2+GetNumberOfEntries();
00144 break;
00145 }
00146
00147 }
00148
00149
00150 Int_t RawTOFDigit::GetTdcEventCounter() const
00151 {
00152
00153
00154
00155
00156 int indx = GetNumberOfEntries() + 1;
00157
00158 return fTDCArray[indx]&0x00ffffff;
00159 }
00160
00161
00162 Bool_t RawTOFDigit::IsStructureOk() const
00163 {
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 bool isokay = true;
00174
00175 const Int_t *p = fTDCArray;
00176
00177 if ((*p&0x0700c000) != 0x02000000) isokay = false;
00178 p++;
00179
00180 int n = GetNumberOfEntries();
00181 for (int i=0; i<n; i++) {
00182 if ((*p&0x07c00000) != 0x00000000) isokay = false;
00183 p++;
00184 }
00185
00186 if ((*p&0x07000000) != 0x04000000) isokay = false;
00187
00188 return isokay;
00189 }
00190
00191
00192 Short_t RawTOFDigit::GetTdcChannel(Int_t indx) const
00193 {
00194
00195
00196
00197 if (indx<0 || indx>=GetNumberOfEntries()) return -1;
00198
00199 const int chanMask = 0x3f;
00200 const int chanShift = 16;
00201
00202 return (fTDCArray[indx+1]>>chanShift)&chanMask;
00203
00204 }
00205
00206
00207 Short_t RawTOFDigit::GetTdcValue(Int_t indx) const
00208 {
00209
00210
00211
00212 if (indx<0 || indx>=GetNumberOfEntries()) return -1;
00213
00214 const int adcMask = 0x0fff;
00215
00216
00217 return fTDCArray[indx+1]&adcMask;
00218
00219 }
00220
00221
00222 Bool_t RawTOFDigit::IsTdcValid(Int_t indx) const
00223 {
00224
00225
00226
00227 if (indx<0 || indx>=GetNumberOfEntries()) return false;
00228
00229 const int validMask = BIT(14);
00230
00231
00232 return fTDCArray[indx+1]&validMask;
00233
00234 }
00235
00236
00237 Bool_t RawTOFDigit::IsTdcUnderThreshold(Int_t indx) const
00238 {
00239
00240
00241
00242 if (indx<0 || indx>=GetNumberOfEntries()) return true;
00243
00244 const int underMask = BIT(13);
00245
00246
00247 return fTDCArray[indx+1]&underMask;
00248
00249 }
00250
00251
00252 Bool_t RawTOFDigit::IsTdcOverflow(Int_t indx) const
00253 {
00254
00255
00256
00257 if (indx<0 || indx>=GetNumberOfEntries()) return true;
00258
00259 const int overMask = BIT(12);
00260
00261
00262 return fTDCArray[indx+1]&overMask;
00263
00264 }
00265
00266
00267 void RawTOFDigit::Print(Option_t* option) const
00268 {
00269
00270 RawVaDigit::Print(option);
00271
00272 int nvalues = GetNumberOfEntries();
00273 int evtcntr = GetTdcEventCounter();
00274 bool isok = IsStructureOk();
00275 cout << " has " << nvalues << " values ("
00276 << "evtcntr: " << evtcntr << ","
00277 << ((isok) ? "isok" : "badbits") << ")" << endl;
00278 if (nvalues)
00279 cout << " indx chan value valid thrsh overflow" << endl;
00280 for (int i=0; i<nvalues; i++) {
00281 cout << " [" << setw(3) << i << "]"
00282 << " " << setw(4) << GetTdcChannel(i)
00283 << " " << setw(5) << GetTdcValue(i)
00284 << ((IsTdcValid(i)) ? " yes" : " no")
00285 << ((IsTdcUnderThreshold(i)) ? " under" : " above")
00286 << ((IsTdcOverflow(i)) ? " yes" : " no")
00287 << endl;
00288 }
00289
00290 #ifdef TOOVERBOSE
00291 int arraysize = GetTdcArraySize();
00292 const Int_t* array = GetTdcArray();
00293 for (int i=0; i<arraysize; i++) {
00294 cout << " 0x" << setfill('0') << hex << setw(8)
00295 << array[i] << setfill(' ') << dec;
00296 }
00297 cout << endl;
00298 #endif
00299
00300 }
00301
00302