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

RawQieErrorStatsBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawQieErrorStatsBlock.cxx,v 1.3 2005/01/14 00:20:18 rhatcher Exp $
00003 // 
00004 // RawQieErrorStatsBlock 
00005 // 
00006 // RawQieErrorStatsBlock holds the Qie Error statistics info
00007 //
00008 // Author:  R. Hatcher 2005.01.11
00009 //
00011 
00012 #include "RawData/RawQieErrorStatsBlock.h"
00013 
00014 enum EDebugQieErrorStatsBlock {
00015    kdbg_ForceHexDump  = 0x0001
00016 };
00017 UInt_t RawQieErrorStatsBlock::fgDebugFlags = 0;
00018 
00019 #include "MessageService/MsgStream.h"
00020 #include "MessageService/MsgFormat.h"
00021 
00022 #include "MessageService/MsgService.h"
00023 CVSID("$Id: RawQieErrorStatsBlock.cxx,v 1.3 2005/01/14 00:20:18 rhatcher Exp $");
00024 
00025 #include "RawData/RawBlockRegistry.h"
00026 REGISTERRAWBLOCK(RawQieErrorStatsBlock,kMdBlockQieErrorStats,0);
00027 
00028 ClassImp(RawQieErrorStatsBlock)
00029 
00030 enum EErrorStatsBlkPos {
00031    indx_size      =  0,
00032    indx_checksum  =  1,
00033    indx_blockid   =  2,
00034    indx_run       =  3,
00035    indx_subrun    =  4,
00036    indx_runtype   = indx_subrun,
00037    indx_startsec  =  5,
00038    indx_startnsec =  6,
00039    indx_endsec    =  7,
00040    indx_endnsec   =  8,
00041    indx_nerrtypes =  9,
00042    zzzz_last      = 11
00043 };
00044 
00045 //_____________________________________________________________________________
00046 
00047 static Int_t knownListOrder[] = { RawQieDigit::kParityError,
00048                                   RawQieDigit::kCapIdError,
00049                                   RawQieDigit::kMisCountError };
00050 static Int_t nknownLists = sizeof(knownListOrder)/sizeof(Int_t);
00051 static Int_t unknownListCode = 0x7FFFFFFF;
00052 
00053 //_____________________________________________________________________________
00054 RawQieErrorStatsBlock::RawQieErrorStatsBlock() 
00055   : RawDataBlock(), fUnpacked(false)
00056 {
00057    // Default constructor
00058 }
00059 
00060 //_____________________________________________________________________________
00061 RawQieErrorStatsBlock::RawQieErrorStatsBlock(const Int_t *block)
00062   : RawDataBlock(block), fUnpacked(false)
00063 {
00064    //  stored block format is:
00065    //---------------------
00066    //  0   # words in block
00067    //  1   checksum
00068    //  2   Block Id
00069    //-----
00070    //  3   run #
00071    //  4   {subrun#| run type}
00072    //  5   start time (sec)
00073    //  6   start time (nsec)
00074    //  7   end time (sec)
00075    //  8   end time (nsec)
00076    //  9   # of error types
00077    // 10   NPE = # of errors of type: parity
00078    // 11   channel w/ parity error upper 16=chadd, lower 16=crate#
00079    // 12   # errors on this channel
00080    // ..   {channel / count}  pairs
00081    // 12+2*NPE:  NCE = # of error of type: cap id
00082    // ..
00083    // 12+2*NPE+1+2*NCE:  NWE = # of errors of type: word count
00084    // ..
00085 }
00086 
00087 //_____________________________________________________________________________
00088 RawQieErrorStatsBlock::RawQieErrorStatsBlock(const VldContext& vldc_start, 
00089                                              const VldTimeStamp& time_end, 
00090                                              Int_t run,
00091                                              Short_t subrun, Short_t runtype,
00092                                              Int_t nerrtypes)
00093   : RawDataBlock(), fUnpacked(false)
00094 {
00095    // Component ctor
00096 
00097    fSize = zzzz_last + nerrtypes;
00098    if (fRawBlock) delete [] fRawBlock;
00099    fRawBlock = new Int_t [fSize];
00100 
00101    fRawBlock[0] = fSize;
00102 // fRawBlock[1] = checksum... see below
00103 
00104    RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00105    RawBlockProxy*    rbp = rbr.LookUp("RawQieErrorStatsBlock");
00106 
00107    Bool_t isDCS   = rbp->IsDCS();
00108    Int_t  majorId = rbp->GetMajorId();
00109    Int_t  minorId = 0;
00110    RawBlockId rbid(majorId,minorId,isDCS,
00111                    vldc_start.GetDetector(),vldc_start.GetSimFlag());
00112    fRawBlock[2] = rbid.GetEncoded();
00113 
00114    fRawBlock[indx_run]        = run;
00115    fRawBlock[indx_subrun]     = (subrun&0xffff)<<16 | (runtype&0xffff);
00116    fRawBlock[indx_startsec]   = vldc_start.GetTimeStamp().GetSec();
00117    fRawBlock[indx_startnsec]  = vldc_start.GetTimeStamp().GetNanoSec();
00118    fRawBlock[indx_endsec]     = time_end.GetSec();
00119    fRawBlock[indx_endnsec]    = time_end.GetNanoSec();
00120    fRawBlock[indx_nerrtypes]  = nerrtypes;
00121 
00122    for (Int_t i=0; i<nerrtypes; i++) {
00123       Int_t ioff = zzzz_last + i;
00124       fRawBlock[ioff+0] = 0;   // error counts for each type
00125    }
00126 
00127    // fill checksum
00128    rdxsum_fill((long*)fRawBlock,0); 
00129 }
00130 
00131 //_____________________________________________________________________________
00132 RawQieErrorStatsBlock::~RawQieErrorStatsBlock()
00133 {
00134    // dtor
00135 }
00136 
00137 //_____________________________________________________________________________
00138 RawQieErrorStatsBlock& 
00139 RawQieErrorStatsBlock::operator=( const RawQieErrorStatsBlock& rhs)
00140 {
00141    // deep copy assignment
00142    if (this != &rhs) {
00143      RawDataBlock::operator=(rhs);
00144      // clear the unpacked info to allow it to be re-filled
00145      ClearAllMaps();
00146    }
00147    return *this;
00148 }
00149 
00150 //_____________________________________________________________________________
00151 VldTimeStamp RawQieErrorStatsBlock::GetStartTime() const
00152 {
00153    // get the start time
00154    if (fSize >= zzzz_last) 
00155       return VldTimeStamp(fRawBlock[indx_startsec],fRawBlock[indx_startnsec]);
00156 
00157    return VldTimeStamp((time_t)0,(Int_t)0);
00158 }
00159 
00160 //_____________________________________________________________________________
00161 VldTimeStamp RawQieErrorStatsBlock::GetEndTime() const
00162 {
00163    // get the end time
00164    if (fSize >= zzzz_last) 
00165       return VldTimeStamp(fRawBlock[indx_endsec],fRawBlock[indx_endnsec]);
00166 
00167    return VldTimeStamp((time_t)0,(Int_t)0);
00168 }
00169 
00170 //_____________________________________________________________________________
00171 Int_t RawQieErrorStatsBlock::GetRun() const
00172 {
00173    // get the run number
00174    if (fSize >= zzzz_last) return fRawBlock[indx_run];
00175    return -1;
00176 }
00177 
00178 //_____________________________________________________________________________
00179 Short_t RawQieErrorStatsBlock::GetSubRun() const
00180 {
00181    // get the subrun number
00182    if (fSize >= zzzz_last) return (fRawBlock[indx_subrun]>>16)&0xffff;
00183    return -1;
00184 }
00185 
00186 //_____________________________________________________________________________
00187 Short_t RawQieErrorStatsBlock::GetRunType() const
00188 {
00189    // get the run type
00190    if (fSize >= zzzz_last) return fRawBlock[indx_runtype]&0xffff;
00191    return -1;
00192 }
00193 
00194 //_____________________________________________________________________________
00195 Int_t RawQieErrorStatsBlock::GetNumberOfErrTypes() const
00196 {
00197    // get the number of error types reported by block
00198    if (fSize >= zzzz_last) return fRawBlock[indx_nerrtypes];
00199    return -1;
00200 }
00201 
00202 //_____________________________________________________________________________
00203 Int_t RawQieErrorStatsBlock::GetTotalErrChannels() const
00204 {
00205    // get the total number of channels with error
00206    if (fSize >= zzzz_last) {
00207      Int_t pairs =  fSize - (zzzz_last-1) - GetNumberOfErrTypes();
00208      return pairs >> 1;
00209    }
00210    return -1;
00211 }
00212 
00213 //_____________________________________________________________________________
00214 Int_t RawQieErrorStatsBlock::GetNumOfErrChannels(RawQieDigit::EQieErrorCode errcode) const
00215 {
00216    // get the number of channels with errors of a particular type
00217    return GetErrorList(errcode).size();
00218 }
00219 
00220 //_____________________________________________________________________________
00221 const std::map<RawChannelId,UInt_t>& 
00222 RawQieErrorStatsBlock::GetErrorList(RawQieDigit::EQieErrorCode errcode) const
00223 {
00224    // get the unpacked list
00225    FillAllMaps();  // unpack the data
00226    return GetNonConstListRef(errcode);  // const-ness when returned!
00227 }
00228 
00229 //_____________________________________________________________________________
00230 std::map<RawChannelId,UInt_t>& 
00231 RawQieErrorStatsBlock::GetNonConstListRef(Int_t errcode) const
00232 {
00233 
00234    switch ( errcode ) {
00235    case RawQieDigit::kParityError:   return fParityErrorList;
00236    case RawQieDigit::kCapIdError:    return fCapIdErrorList;
00237    case RawQieDigit::kMisCountError: return fMisCountErrorList;
00238    default:                          return fUnknownErrorList;
00239    }
00240 }
00241 
00242 //_____________________________________________________________________________
00243 VldContext RawQieErrorStatsBlock::GetVldContext() const
00244 {
00245    // build validity context
00246    RawBlockId rbid = GetBlockId();
00247    return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetEndTime());
00248 }
00249 
00250 //_____________________________________________________________________________
00251 void RawQieErrorStatsBlock::FillAllMaps() const
00252 {
00253    // unpack the data
00254 
00255    if ( fUnpacked ) return; // already unpacked
00256    fUnpacked = true;
00257 
00258    Detector::Detector_t det = GetBlockId().GetDetector();
00259    Int_t indx_cur = zzzz_last - 1; // just before first sublist
00260 
00261    for (int isublist = 0; isublist < GetNumberOfErrTypes(); ++isublist ) {
00262      Int_t listKey = unknownListCode;
00263      if ( isublist < nknownLists ) {
00264        listKey = knownListOrder[isublist];
00265      }
00266      else {
00267        MSG("RawData",Msg::kWarning)
00268          << "RawQieErrorStatsBlock has " << GetNumberOfErrTypes()
00269          << " sub-lists, but unpacker was expecting no more than "
00270          << knownListOrder << endl;
00271      }
00272      if ( fSize < indx_cur ) {
00273        MSG("RawData",Msg::kWarning)
00274          << "RawQieErrorStatsBlock  fSize=" << fSize
00275          << " but expected sub-list to start at index=" << indx_cur
00276          << endl;
00277        return;
00278      }
00279      Int_t nInList = fRawBlock[indx_cur++];
00280      std::map<RawChannelId,UInt_t>& curList = GetNonConstListRef(listKey);
00281      for (int inlist = 0; inlist < nInList; ++inlist) {
00282        if ( fSize < indx_cur ) {
00283          MSG("RawData",Msg::kWarning)
00284            << "RawQieErrorStatsBlock  fSize=" << fSize
00285            << " but saw end before processing inlist=" << inlist
00286            << " of sub-list=" << isublist
00287            << endl;
00288          return;
00289            
00290        }
00291        Int_t funky = fRawBlock[indx_cur++];
00292        Int_t count = fRawBlock[indx_cur++];
00293        // Geoff says these have no extraneous bits (error bits)
00294        UInt_t crate = funky & 0xFF;
00295        UInt_t chadd = funky >> 16;
00296        // only for QIE!
00297        RawChannelId rcid(det,ElecType::kQIE,crate,chadd);
00298        curList[rcid] = count;
00299      }
00300 
00301    }
00302 
00303    if ( indx_cur != fSize ) {
00304      MSG("RawData",Msg::kWarning)
00305        << "RawQieErrorStatsBlock  fSize=" << fSize
00306        << " but finished at index=" << indx_cur
00307        << endl;
00308    }
00309 
00310 }
00311 
00312 //_____________________________________________________________________________
00313 void RawQieErrorStatsBlock::ClearAllMaps() const
00314 {
00315    // clear the unpacked data
00316 
00317    fUnpacked = false;
00318    fParityErrorList.clear();
00319    fCapIdErrorList.clear();
00320    fMisCountErrorList.clear();
00321    fUnknownErrorList.clear();
00322 
00323 }
00324 
00325 //_____________________________________________________________________________
00326 std::ostream& RawQieErrorStatsBlock::FormatToOStream(std::ostream& os, 
00327                                                   Option_t *option) const
00328 {
00329 
00330    if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00331 
00332    RawDataBlock::FormatToOStream(os,option);
00333    if (option[0] == 'X') return os;
00334 
00335    os << " Start " << GetStartTime().AsString("c") << endl;
00336    os << " End   " << GetEndTime().AsString("c") << endl;
00337    os << " Run " << GetRun() 
00338       << " SubRun " << GetSubRun() 
00339       << " RunType " << GetRunType() << endl; 
00340    os << "   " << GetNumberOfErrTypes() << " error types, "
00341       << GetTotalErrChannels() << " total channels: " << endl;
00342 
00343    for (int iList = 0; iList<=nknownLists; iList++) {
00344      Int_t keyList = unknownListCode;
00345      if (iList<nknownLists) keyList = knownListOrder[iList];
00346 
00347      RawQieDigit::EQieErrorCode errcode = (RawQieDigit::EQieErrorCode)keyList;
00348 
00349      const std::map<RawChannelId,UInt_t>& listChannels = GetErrorList(errcode);
00350      size_t nentries = listChannels.size();
00351 
00352      // if the unknown error code list is empty don't print it
00353      if ( keyList == unknownListCode && nentries == 0 ) break;
00354 
00355      os << "   List of errors of type: "
00356         << RawQieDigit::AsString(errcode)
00357         << " (" << nentries << " entries)"
00358         << endl;
00359 
00360      std::map<RawChannelId,UInt_t>::const_iterator mapItr = 
00361        listChannels.begin(); 
00362      while ( mapItr != listChannels.end() ) {
00363        RawChannelId rcid = mapItr->first;
00364        UInt_t count      = mapItr->second;
00365        os << "     " << rcid.AsString("ec")
00366           << "     " << setw(8) << count
00367           << endl;
00368        mapItr++;  // move on
00369      }
00370    }
00371    return os;
00372 }
00373 
00374 //_____________________________________________________________________________

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