Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RawTOFDigit.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawTOFDigit.cxx,v 1.5 2003/07/10 19:36:30 rhatcher Exp $
00003 // 
00004 // RawTOFDigit
00005 // 
00006 // RawTOFDigit is an unpacked extended VA + TOF digit
00007 //
00008 // Author:  R. Hatcher 2001.05.31
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    // Default constructor
00060 }
00061 
00062 //_____________________________________________________________________________
00063 RawTOFDigit::RawTOFDigit(const Int_t *&p, const RawDigitCrateStatus *cstat)
00064    : RawVaDigit(p,cstat)
00065 {
00066    // a RawTOFDigit looks like a RawVaDigit with extra words tacked
00067    // onto the end.
00068 
00069    // use fTDCArray just to reference back to real data in mother block
00070    // don't make any copy of the data
00071    fTDCArray = p;
00072    // advance pointer beyond entries
00073    int nskip = GetTdcArraySize();
00074    p += nskip;
00075 }
00076 
00077 //_____________________________________________________________________________
00078 RawTOFDigit::~RawTOFDigit()
00079 {
00080    // fTDCArray *isn't* an owned object ... don't delete it
00081 }
00082 
00083 //_____________________________________________________________________________
00084 Int_t RawTOFDigit::GetNumberOfEntries() const
00085 {
00086    // number of TDC channels read out per TOF "hit"
00087    // is dependent on the minor version id of the block
00088    // but for most cases actual count comes from header word
00089 
00090    const int cntMask  = 0x3f;
00091    const int cntShift = 8;
00092 
00093    static int nmsg = 5;
00094 
00095    // we can get this from the CrateStatus
00096    Int_t minor = fDigitCrateStatus->GetRawBlockId().GetMinor();
00097    switch (minor) {
00098    case 0:  
00099       // pull count size of block from header word
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       // pull count size of block from header word
00113       return (fTDCArray[0]>>cntShift)&cntMask;
00114       break;
00115    }
00116       
00117 }
00118 
00119 //_____________________________________________________________________________
00120 Int_t RawTOFDigit::GetTdcArraySize() const
00121 {
00122    // the size of the Tdc array is dependent on the minor 
00123    // version id of the block but for most cases actual count 
00124    // comes from header word plus one each for the header and trailer
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    // pull the "event counter" field from the trailer word
00153    // simply assume that minorid>0
00154 
00155    // skip past header + data words
00156    int indx = GetNumberOfEntries() + 1;
00157 
00158    return fTDCArray[indx]&0x00ffffff;
00159 }
00160 
00161 //_____________________________________________________________________________
00162 Bool_t RawTOFDigit::IsStructureOk() const
00163 {
00164    // verify that flag bits are all in the right places in the TDC block
00165    // simply assume minorid>0
00166 
00167    //           3         2         1
00168    //          10987654321098765432109876543210
00169    // header:  ggggg010cccccccc00nnnnnn--------
00170    // data:    ggggg00000cccccc-vuoaaaaaaaaaaaa
00171    // trailer: ggggg100eeeeeeeeeeeeeeeeeeeeeeee
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    // pull the "channel" field from the data word "indx"
00195    // simply assume that minorid>0
00196 
00197    if (indx<0 || indx>=GetNumberOfEntries()) return -1;
00198 
00199    const int chanMask  = 0x3f;
00200    const int chanShift = 16;
00201    // index past header word
00202    return (fTDCArray[indx+1]>>chanShift)&chanMask;
00203 
00204 }
00205 
00206 //_____________________________________________________________________________
00207 Short_t RawTOFDigit::GetTdcValue(Int_t indx) const
00208 {
00209    // pull the "adc" field from the data word "indx"
00210    // simply assume that minorid>0
00211 
00212    if (indx<0 || indx>=GetNumberOfEntries()) return -1;
00213 
00214    const int adcMask  = 0x0fff;
00215 
00216    // index past header word
00217    return fTDCArray[indx+1]&adcMask;
00218 
00219 }
00220 
00221 //_____________________________________________________________________________
00222 Bool_t RawTOFDigit::IsTdcValid(Int_t indx) const
00223 {
00224    // pull the "valid" field from the data word "indx"
00225    // simply assume that minorid>0
00226 
00227    if (indx<0 || indx>=GetNumberOfEntries()) return false;
00228 
00229    const int validMask  = BIT(14);
00230 
00231    // index past header word
00232    return fTDCArray[indx+1]&validMask;
00233 
00234 }
00235 
00236 //_____________________________________________________________________________
00237 Bool_t RawTOFDigit::IsTdcUnderThreshold(Int_t indx) const
00238 {
00239    // pull the "underthreshold" field from the data word "indx"
00240    // simply assume that minorid>0
00241 
00242    if (indx<0 || indx>=GetNumberOfEntries()) return true;
00243 
00244    const int underMask  = BIT(13);
00245 
00246    // index past header word
00247    return fTDCArray[indx+1]&underMask;
00248 
00249 }
00250 
00251 //_____________________________________________________________________________
00252 Bool_t RawTOFDigit::IsTdcOverflow(Int_t indx) const
00253 {
00254    // pull the "overflow" field from the data word "indx"
00255    // simply assume that minorid>0
00256 
00257    if (indx<0 || indx>=GetNumberOfEntries()) return true;
00258 
00259    const int overMask  = BIT(12);
00260 
00261    // index past header word
00262    return fTDCArray[indx+1]&overMask;
00263 
00264 }
00265 
00266 //_____________________________________________________________________________
00267 void RawTOFDigit::Print(Option_t* option) const
00268 {
00269    // print out the digit
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 //_____________________________________________________________________________

Generated on Mon Feb 15 11:07:29 2010 for loon by  doxygen 1.3.9.1