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

RawVtmTimeInfoBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawVtmTimeInfoBlock.cxx,v 1.5 2005/06/07 21:47:32 rhatcher Exp $
00003 // 
00004 // RawVtmTimeInfoBlock 
00005 // 
00006 // RawVtmTimeInfoBlock holds a latched time counter in NearDet VTM
00007 //
00008 // Author:  R. Hatcher 2003.02.18
00009 //
00011 
00012 #include "RawData/RawVtmTimeInfoBlock.h"
00013 
00014 enum EDebugVtmTimeInfoBlock {
00015    kdbg_ForceHexDump  = 0x0001
00016 };
00017 UInt_t RawVtmTimeInfoBlock::fgDebugFlags = 0;
00018 
00019 #include <vector>
00020 
00021 #include "MessageService/MsgStream.h"
00022 #include "MessageService/MsgService.h"
00023 #include "MessageService/MsgFormat.h"
00024 CVSID("$Id: RawVtmTimeInfoBlock.cxx,v 1.5 2005/06/07 21:47:32 rhatcher Exp $");
00025 
00026 #include "RawData/RawBlockRegistry.h"
00027 REGISTERRAWBLOCK(RawVtmTimeInfoBlock,kMdBlockVtmTimeInfo,0);
00028 
00029 ClassImp(RawVtmTimeInfoBlock)
00030 
00031 enum EVtmTimeInfoBlkPos {
00032    indx_size          =  0,
00033    indx_checksum      =  1,
00034    indx_blockid       =  2,
00035    indx_run           =  3,
00036    indx_subrun        =  4,
00037    indx_runtype       = indx_subrun,
00038    indx_sec           =  5,
00039    indx_nsec          =  6,
00040    indx_crateid       =  7,
00041    indx_tf            =  8,
00042    indx_lastrfclock   =  9,
00043    indx_spilltimerf   = 10,
00044    indx_spilltimegps  = 11,
00045    indx_clockstatus   = 12,
00046    indx_endlasttf     = 13,
00047    zzzz_last          = 14
00048 };
00049 
00050 //_____________________________________________________________________________
00051 RawVtmTimeInfoBlock::RawVtmTimeInfoBlock()
00052   : RawDataBlock(), fCrateId()
00053 {
00054    // Default constructor
00055 }
00056 
00057 //_____________________________________________________________________________
00058 RawVtmTimeInfoBlock::RawVtmTimeInfoBlock(const Int_t *block)
00059   : RawDataBlock(block), fCrateId()
00060 {
00061    //  stored block format is:
00062    //---------------------
00063    //  0   # words in block
00064    //  1   checksum
00065    //  2   Block Id
00066    //-----
00067    //  3   run #
00068    //  4   subRunAndType
00069    //  5   timestamp sec
00070    //  6   timestamp nsec
00071    //  7   crateIdentifier
00072    //  8   timeFrameNumber
00073    //  9   lastRFClock
00074    // 10   spillTimeRF
00075    // 11   spillTimeGPS
00076    // 12   clockStatus   (version 2 and above)
00077    // 13   endLastTF     (version 3 and above)
00078 
00079 }
00080 
00081 //_____________________________________________________________________________
00082 RawVtmTimeInfoBlock::~RawVtmTimeInfoBlock()
00083 {
00084   // dtor
00085 }
00086 
00087 //____________________________________________________________________________
00088 RawVtmTimeInfoBlock& RawVtmTimeInfoBlock::operator=(const RawVtmTimeInfoBlock& rhs)
00089 {
00090    // deep copy assignment 
00091    if (this != &rhs) {
00092      RawDataBlock::operator=(rhs);
00093      fCrateId = rhs.fCrateId;
00094    }
00095    return *this;
00096 }
00097 
00098 //_____________________________________________________________________________
00099 VldTimeStamp RawVtmTimeInfoBlock::GetTimeStamp() const
00100 {
00101    // get the timestamp
00102    if (fSize > indx_nsec) 
00103       return VldTimeStamp(fRawBlock[indx_sec],fRawBlock[indx_nsec]);
00104 
00105    return VldTimeStamp((time_t)0,(Int_t)0);
00106 }
00107 
00108 //_____________________________________________________________________________
00109 Int_t RawVtmTimeInfoBlock::GetRun() const
00110 {
00111    // get the run number
00112    if (fSize > indx_run) return fRawBlock[indx_run];
00113    return -1;
00114 }
00115 
00116 //_____________________________________________________________________________
00117 Short_t RawVtmTimeInfoBlock::GetSubRun() const
00118 {
00119    // get the subrun number
00120    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00121    return -1;
00122 }
00123 
00124 //_____________________________________________________________________________
00125 Short_t RawVtmTimeInfoBlock::GetRunType() const
00126 {
00127    // get the run type
00128    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00129    return -1;
00130 }
00131 
00132 //_____________________________________________________________________________
00133 Int_t RawVtmTimeInfoBlock::GetCrateIdInfo() const
00134 {
00135    // get the crate id info (packed)
00136    if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00137    return -1;
00138 }
00139 
00140 //_____________________________________________________________________________
00141 Int_t RawVtmTimeInfoBlock::GetTimeFrameNum() const
00142 {
00143    // get the time frame
00144    if (fSize > indx_tf) return fRawBlock[indx_tf];
00145    return -1;
00146 }
00147 
00148 //_____________________________________________________________________________
00149 Int_t RawVtmTimeInfoBlock::GetLastRFClock() const
00150 {
00151    // get the RF clock counter at end of time frame
00152    if (fSize > indx_lastrfclock) return fRawBlock[indx_lastrfclock];
00153    return -1;
00154 }
00155 
00156 //_____________________________________________________________________________
00157 Int_t RawVtmTimeInfoBlock::GetSpillTimeRF() const
00158 {
00159    // get the latched timestamp counter at spill gate
00160    if (fSize > indx_spilltimerf) return fRawBlock[indx_spilltimerf];
00161    return -1;
00162 }
00163 
00164 //_____________________________________________________________________________
00165 Int_t RawVtmTimeInfoBlock::GetSpillTimeGPS() const
00166 {
00167    // get the latched GPS 10Mhz dounter at spill gate
00168    if (fSize > indx_spilltimegps) return fRawBlock[indx_spilltimegps];
00169    return -1;
00170 }
00171 
00172 //_____________________________________________________________________________
00173 Int_t RawVtmTimeInfoBlock::GetClockStatus() const
00174 {
00175    // get the latched bits from each mtm and vtm
00176    const Int_t badValue = -1;
00177    if (GetMinorId() <= 1 || fSize <= indx_clockstatus) {
00178      MSG("RawData",Msg::kWarning)
00179        << "GetClockStatus() not available fSize " << fSize
00180        << " MinorId " << GetMinorId() << endl;
00181      return badValue;
00182    }
00183    return fRawBlock[indx_clockstatus];
00184 }
00185 
00186 //_____________________________________________________________________________
00187 Bool_t RawVtmTimeInfoBlock::VtmInError() const
00188 {
00189   // return whether the was in an error state
00190   Int_t status = GetClockStatus();
00191   // the modules are bits 0-14, vtm is bit 15
00192   return ((1<<15) & status);
00193 }
00194 
00195 //_____________________________________________________________________________
00196 Bool_t RawVtmTimeInfoBlock::ModuleInError(UShort_t indx) const
00197 {
00198   // return whether a module was in an error state
00199   Int_t status = GetClockStatus();
00200   // the modules are only bit 0-14
00201   if (indx > 14) return true;
00202   return ((1<<indx) & status);
00203 }
00204 
00205 //_____________________________________________________________________________
00206 std::vector<UShort_t> RawVtmTimeInfoBlock::ErrorModules() const
00207 {
00208   // return list of module that were in the error state
00209   std::vector<UShort_t> mdlsInError;
00210 
00211   for (unsigned short mdl = 0; mdl < 15; ++mdl) {
00212     if ( ModuleInError(mdl) ) mdlsInError.push_back(mdl);
00213   }
00214 
00215   return mdlsInError;
00216 }
00217 
00218 //_____________________________________________________________________________
00219 Int_t RawVtmTimeInfoBlock::GetLastRFClockFromPrevTF() const
00220 {
00221    // get the RF clock at the counter reset on the previous time frame
00222    if (fSize > indx_endlasttf) return fRawBlock[indx_endlasttf];
00223    return -1;
00224 }
00225 
00226 //_____________________________________________________________________________
00227 VldContext RawVtmTimeInfoBlock::GetVldContext() const
00228 {
00229    // build validity context
00230   RawBlockId rbid = GetBlockId();
00231   return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTimeStamp());
00232 }
00233 
00234 //_____________________________________________________________________________
00235 std::ostream& RawVtmTimeInfoBlock::FormatToOStream(ostream& os,
00236                                                    Option_t *option) const
00237 {
00238    if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00239 
00240    RawDataBlock::FormatToOStream(os,option);
00241    if (option[0] == 'X') return os;
00242 
00243    // additional block specific formatted output is done here
00244 
00245    os << " TimeStamp " << GetTimeStamp().AsString("c")
00246       << " TimeFrame " << GetTimeFrameNum() << endl;
00247    os << " Run " << GetRun()
00248       << " SubRun " << GetSubRun()
00249       << " RunType " << GetRunType();
00250    int crateid = GetCrateIdInfo();
00251 
00252    os << " Crate " << (crateid&0x3f)
00253       << " (0x" << hex << crateid << dec << ") had: " << endl
00254       << " LastTimeStamp " << setw(8) << GetLastTimeStamp()
00255       << " SpillTimeRF "   << setw(8) << GetSpillTimeRF()
00256       << " SpillTimeGPS "  << setw(8) << GetSpillTimeGPS()
00257       << endl;
00258 
00259    int minor = GetMinorId();
00260 
00261    if (minor > 1) {
00262      os << " ClockStatus 0x" 
00263         << std::hex << std::setfill('0') 
00264         << setw(8) << GetClockStatus()
00265         << std::setfill(' ') << std::dec;
00266 
00267      if ( ! VtmInError() ) os << " Vtm Okay,";
00268      else                  os << " Vtm Error,";
00269 
00270      std::vector<UShort_t> mdlsInError = ErrorModules();
00271      unsigned int nerr = mdlsInError.size();
00272      if ( nerr == 0 ) os << " No Module Errors";
00273      else {
00274        if ( nerr == 1 ) os << " Error in Module " << mdlsInError[0];
00275        else {
00276          os << " Errors in Modules:";
00277          for (unsigned short i = 0; i < nerr; ++i)
00278            os << " " << mdlsInError[i];
00279        }
00280      }
00281      os << "." << endl;
00282    }
00283    if (minor > 2) {
00284      os << " LastRFClockFromPrevTF " 
00285         << setw(10) << GetLastRFClockFromPrevTF()
00286         << endl;
00287    }
00288 
00289    return os;
00290 }
00291 
00292 //_____________________________________________________________________________
00293 void RawVtmTimeInfoBlock::FillCrateId() const
00294 {
00295    // unpack crate info
00296    if (!fCrateId.IsNull()) return;
00297    fCrateId = RawChannelId(GetBlockId().GetDetector(),GetCrateIdInfo(),0x1fff);
00298 }
00299 
00300 //_____________________________________________________________________________

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