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

RawVarcErrorInTfBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawVarcErrorInTfBlock.cxx,v 1.16 2003/07/10 19:36:30 rhatcher Exp $
00003 // 
00004 // RawVarcErrorInTfBlock 
00005 // 
00006 // RawVarcErrorInTfBlock holds info on errors in the VARCs
00007 //
00008 // Author:  R. Hatcher 2001.08.20
00009 //
00011 
00012 #include "RawData/RawVarcErrorInTfBlock.h"
00013 
00014 UInt_t RawVarcErrorInTfBlock::fgDebugFlags = 0;
00015 enum EDebugVarcErrorInTfBlock {
00016   kdbg_ForceHexDump = 0x00000001
00017 };
00018 
00019 #include "TMath.h"
00020 
00021 #include "MessageService/MsgService.h"
00022 CVSID("$Id: RawVarcErrorInTfBlock.cxx,v 1.16 2003/07/10 19:36:30 rhatcher Exp $");
00023 
00024 #include "RawData/RawBlockRegistry.h"
00025 REGISTERRAWBLOCK(RawVarcErrorInTfBlock,kMdBlockVarcErrorInTf,0);
00026 
00027 ClassImp(RawVarcErrorInTfBlock)
00028 
00029 enum EVarcErrorInTfBlkPos {
00030    indx_size      =  0,
00031    indx_checksum  =  1,
00032    indx_blockid   =  2,
00033    indx_run       =  3,
00034    indx_subrun    =  4,
00035    indx_runtype   = indx_subrun,
00036    indx_sec       =  5,
00037    indx_nsec      =  6,
00038    indx_crateid   =  7,
00039    indx_tf        =  8,
00040    indx_nsparserr =  9,
00041    indx_netcerr   = 10,
00042    zzzz_last      = 11
00043 };
00044 
00045 enum EVarcErrPacking {
00046    errCodeMask = 0xffff,
00047    etcNumShift = 16,
00048    etcNumMask  = 0x0007,
00049    varcIdShift = 19,
00050    varcIdMask  = 0x0003,
00051    errSrcShift = 23,
00052    errSrcMask  = 0x0001,
00053    errSrcWasEtc   = 0,
00054    errSrcWasSpars = 1,
00055    tbIdShift   = 24,
00056    tbIdMask    = 0xffff
00057 };
00058 
00059 //_____________________________________________________________________________
00060 RawVarcErrorInTfBlock::RawVarcErrorInTfBlock()
00061    : fIndxToOffsetBuilt(false)
00062 {
00063    // Default constructor
00064 }
00065 
00066 //_____________________________________________________________________________
00067 RawVarcErrorInTfBlock::RawVarcErrorInTfBlock(const Int_t *block)
00068    : RawDataBlock(block), fIndxToOffsetBuilt(false)
00069 {
00070    //  stored block format is:
00071    //---------------------
00072    //  0   # words in block
00073    //  1   checksum
00074    //  2   Block Id
00075    //-----
00076    //  3   run #
00077    //  4   {subrun#| run type}
00078    //  5   time (sec)
00079    //  6   time (nsec)
00080    //  7   time frame #
00081    //  8   # of sparse errors
00082    //  9   # of etc errors
00083    //  * Followed by (for 2nd version of block):
00084    //  *   numSparsErrorValues + numEtcErrorValues longs packed as follows
00085    //  *   NOTE: these are interspersed!!!
00086    //  *
00087    //  * [0:15]  ETC_ERR  : error code from ETC/sparsifier error register, 16 bits
00088    //  * [16:18] ETC_NUM  : ETC number, 3 bits (0 for sparsifier errors)
00089    //  * [19:20] VARC_ID  : VARC ID, 2 bits
00090    //  * [21:22]          : unused, 2 bits
00091    //  * [23:23]          : error source 0=ETC 1=sparsifier
00092    //  * [24:31] TB_ID    : time block ID, 16 bits
00093 }
00094 
00095 //_____________________________________________________________________________
00096 RawVarcErrorInTfBlock::~RawVarcErrorInTfBlock()
00097 {
00098    // dtor
00099 }
00100 
00101 //____________________________________________________________________________
00102 RawVarcErrorInTfBlock& RawVarcErrorInTfBlock::operator=(const RawVarcErrorInTfBlock& rhs)
00103 {
00104    // deep copy assignment 
00105    if (this != &rhs) {
00106      RawDataBlock::operator=(rhs);
00107      // clear the unpacked info to allow it to be re-filled
00108      fIndxToOffsetBuilt = false;
00109      fIndxToOffsetSpars.clear();
00110      fIndxToOffsetEtc.clear();
00111    }
00112    return *this;
00113 }
00114 
00115 //_____________________________________________________________________________
00116 VldTimeStamp RawVarcErrorInTfBlock::GetTimeStamp() const
00117 {
00118    // get the timestamp
00119    if (fSize > indx_nsec) 
00120       return VldTimeStamp(fRawBlock[indx_sec],fRawBlock[indx_nsec]);
00121 
00122    return VldTimeStamp((time_t)0,(Int_t)0);
00123 }
00124 
00125 //_____________________________________________________________________________
00126 Int_t RawVarcErrorInTfBlock::GetRun() const
00127 {
00128    // get the run number
00129    if (fSize > indx_run) return fRawBlock[indx_run];
00130    return -1;
00131 }
00132 
00133 //_____________________________________________________________________________
00134 Short_t RawVarcErrorInTfBlock::GetSubRun() const
00135 {
00136    // get the subrun number
00137    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00138    return -1;
00139 }
00140 
00141 //_____________________________________________________________________________
00142 Short_t RawVarcErrorInTfBlock::GetRunType() const
00143 {
00144    // get the run type
00145    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00146    return -1;
00147 }
00148 
00149 //_____________________________________________________________________________
00150 Int_t RawVarcErrorInTfBlock::GetCrateId() const
00151 {
00152    // get the crate id
00153    if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00154    return -1;
00155 }
00156 
00157 //_____________________________________________________________________________
00158 Int_t RawVarcErrorInTfBlock::GetTimeFrame() const
00159 {
00160    // get the time frame
00161    if (fSize > indx_tf) return fRawBlock[indx_tf];
00162    return -1;
00163 }
00164 
00165 //_____________________________________________________________________________
00166 Int_t RawVarcErrorInTfBlock::GetNumberOfSparsErrors() const
00167 {
00168    // get the # of Sparsification errors
00169    if (fSize > indx_nsparserr) return fRawBlock[indx_nsparserr];
00170    return -1;
00171 }
00172 
00173 //_____________________________________________________________________________
00174 Int_t RawVarcErrorInTfBlock::GetNumberOfEtcErrors() const
00175 {
00176    // get the # of Etc errors
00177    if (fSize > indx_netcerr) return fRawBlock[indx_netcerr];
00178    return -1;
00179 }
00180 
00181 //_____________________________________________________________________________
00182 const Int_t* RawVarcErrorInTfBlock::GetErrorValues() const
00183 {
00184    // get ptr to the raw list of error values
00185    // since Spars and Etc errors are intermingled this is all we 
00186    // can do at this level
00187    if (fSize >= zzzz_last) return fRawBlock + zzzz_last;
00188    return 0;
00189 }
00190 
00191 //_____________________________________________________________________________
00192 Bool_t RawVarcErrorInTfBlock::UnpackSparsError(UInt_t indx, UShort_t& timeBlock, 
00193                                                UShort_t& varcId, UShort_t& errCode) const
00194 {
00195    // unpack the spars error at index "indx"
00196    // return "false" if there was a problem 
00197    // (indx out-of-range or source tagging wasn't as expected)
00198 
00199    if (!fIndxToOffsetBuilt) BuildIndxToOffset();
00200    Int_t offset = fSize+1;  // in case of bad indx
00201    if (indx < fIndxToOffsetSpars.size()) 
00202       offset = fIndxToOffsetSpars[indx];
00203 
00204    if (fSize >= offset) {
00205       Int_t value =  fRawBlock[offset];
00206       timeBlock = ( value >> tbIdShift   ) & tbIdMask;
00207       varcId    = ( value >> varcIdShift ) & varcIdMask;
00208       errCode   =   value                  & errCodeMask;
00209 
00210       return ( ((value>>errSrcShift)&errSrcMask) == errSrcWasSpars );
00211    }
00212    else {
00213       timeBlock = (UShort_t) -1;
00214       varcId    = (UShort_t) -1;
00215       errCode   = (UShort_t) -1;
00216       return false;
00217    }
00218 }
00219 
00220 //_____________________________________________________________________________
00221 Bool_t RawVarcErrorInTfBlock::UnpackEtcError(UInt_t indx, UShort_t& timeBlock, 
00222                                              UShort_t& varcId, UShort_t& etcNum,
00223                                              UShort_t& errCode) const
00224 {
00225    // unpack the spars error at index "indx"
00226    // return "false" if there was a problem 
00227    // (indx out-of-range or source tagging wasn't as expected)
00228 
00229    if (!fIndxToOffsetBuilt) BuildIndxToOffset();
00230    Int_t offset = fSize+1;  // in case of bad indx
00231    if (indx < fIndxToOffsetEtc.size()) 
00232       offset = fIndxToOffsetEtc[indx];
00233 
00234    if (fSize >= offset) {
00235       Int_t value =  fRawBlock[offset];
00236       timeBlock = ( value >> tbIdShift   ) & tbIdMask;
00237       varcId    = ( value >> varcIdShift ) & varcIdMask;
00238       etcNum    = ( value >> etcNumShift ) & etcNumMask;
00239       errCode   =   value                  & errCodeMask;
00240 
00241       return ( ((value>>errSrcShift)&errSrcMask) == errSrcWasEtc );
00242    }
00243    else {
00244       timeBlock = (UShort_t) -1;
00245       varcId    = (UShort_t) -1;
00246       etcNum    = (UShort_t) -1;
00247       errCode   = (UShort_t) -1;
00248       return false;
00249    }
00250 
00251 }
00252 
00253 //_____________________________________________________________________________
00254 std::ostream& RawVarcErrorInTfBlock::FormatToOStream(std::ostream& os, 
00255                                                      Option_t *option) const
00256 {
00257 
00258   if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00259 
00260    RawDataBlock::FormatToOStream(os,option);
00261    if (option[0] == 'X') return os;
00262    
00263    // additional block specific formatted output is done here
00264 
00265    os << " TimeStamp " << GetTimeStamp().AsString("c") 
00266       << " TimeFrame " << GetTimeFrame() << endl;
00267    os << " Run " << GetRun() 
00268       << " SubRun " << GetSubRun() 
00269       << " RunType " << GetRunType();
00270    int crateid = GetCrateId();
00271 
00272    // force everything unpacked in case of sizing errors
00273    if (!fIndxToOffsetBuilt) BuildIndxToOffset();
00274 
00275    int nerrSpars = TMath::Max(GetNumberOfSparsErrors(),
00276                               (Int_t)fIndxToOffsetSpars.size());;
00277    int nerrEtc   = TMath::Max(GetNumberOfEtcErrors(),
00278                               (Int_t)fIndxToOffsetEtc.size());
00279    os << " Crate " << (crateid&0x3f)
00280       << " (0x" << hex << crateid << dec << ") had: "
00281       << endl;
00282 
00283 
00284    if (nerrSpars) {
00285       os << "    SparsErrors: " << endl;
00286       for (int indxs = 0; indxs < nerrSpars; indxs++) {
00287          UShort_t timeBlock, varcId, errCode;
00288          Bool_t   unpk_ok = 
00289             UnpackSparsError(indxs,timeBlock,varcId,errCode);
00290          os << "   [" << setw(3) << indxs << "] "
00291             << ((unpk_ok) ? " " : "?")
00292             << " TB " << setw(5) << timeBlock
00293             << " VarcId " << varcId
00294             << " ErrorCode " << setw(5) << errCode 
00295             << " ( 0x" << hex << setw(4) << errCode << " )" << dec << endl;
00296       }
00297    }
00298    else {
00299       os << "    No Spars Errors" << endl;
00300    }
00301 
00302    if (nerrEtc) {
00303       os << "    EtcErrors: " << endl;
00304       for (int indxe = 0; indxe < nerrEtc; indxe++) {
00305          UShort_t timeBlock, varcId, etcNum, errCode;
00306          Bool_t   unpk_ok = 
00307             UnpackEtcError(indxe,timeBlock,varcId,etcNum,errCode);
00308          os << "   [" << setw(3) << indxe << "] "
00309             << ((unpk_ok) ? " " : "?")
00310             << " TB " << setw(5) << timeBlock
00311             << " VarcId " << varcId << " etcNum " << etcNum
00312             << " ErrorCode " << setw(5) << errCode
00313             << " ( 0x" << hex << setw(4) << errCode << " )" << dec << endl;
00314       }      
00315    }
00316    else {
00317       os << "    No Etc Errors" << endl;
00318    }
00319 
00320    return os;
00321 }
00322 
00323 //_____________________________________________________________________________
00324 void RawVarcErrorInTfBlock::BuildIndxToOffset() const
00325 {
00326    // build lookup so we can map "indx" to "offset" in error value
00327    // region for Spars and Etc errors
00328    if (fIndxToOffsetBuilt) return;  // already done
00329 
00330    fIndxToOffsetBuilt = true;
00331 
00332    UInt_t nspars = GetNumberOfSparsErrors();
00333    UInt_t netc   = GetNumberOfEtcErrors();
00334 
00335    UInt_t n = nspars + netc;
00336    for (UInt_t i=0; i<n; i++) {
00337       Int_t offset = zzzz_last + i;
00338       if (offset >= fSize) {
00339          // this shouldn't happen
00340          MSG("RawData",Msg::kError) 
00341             << "BuildIndxToOffset i " << i << " offset " << offset
00342             << " fSize " << fSize << endl;
00343       }
00344       Int_t value  = fRawBlock[offset];
00345       Int_t errSrc = (value>>errSrcShift)&errSrcMask;
00346       if      (errSrc == errSrcWasSpars)
00347          fIndxToOffsetSpars.push_back(offset);
00348       else if (errSrc == errSrcWasEtc)
00349          fIndxToOffsetEtc.push_back(offset);
00350       else
00351          MSG("RawData",Msg::kError) 
00352             << "BuildIndxToOffset entry " << i 
00353             << " was neither Spars nor Etc" << endl;
00354    }
00355    
00356    if (fIndxToOffsetSpars.size() != nspars ||
00357        fIndxToOffsetEtc.size()   != netc      ) 
00358           MSG("RawData",Msg::kError) 
00359              << endl
00360              << "BuildIndxToOffset size mismatch (unpacked,expected)" 
00361              << " Spars (" << fIndxToOffsetSpars.size() << "," << nspars << ")"
00362              << " Etc (" << fIndxToOffsetEtc.size() << "," << netc << ")"
00363              << endl;
00364 
00365    return;
00366 }
00367 //_____________________________________________________________________________

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