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

RawTrcMonitorBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawTrcMonitorBlock.cxx,v 1.4 2005/07/22 19:12:14 rhatcher Exp $
00003 // 
00004 // RawTrcMonitorBlock 
00005 // 
00006 // RawTrcMonitorBlock holds info about the charge injection
00007 //
00008 // Author:  R. Hatcher 2001.08.20
00009 //
00011 
00012 #include "RawData/RawTrcMonitorBlock.h"
00013 
00014 UInt_t RawTrcMonitorBlock::fgDebugFlags = 0;
00015 enum DDebugTrcMonitorBlock {
00016   kdbg_ForceHexDump = 0x00000001
00017 };
00018 
00019 #include "MessageService/MsgFormat.h"
00020 #include "MessageService/MsgService.h"
00021 CVSID("$Id: RawTrcMonitorBlock.cxx,v 1.4 2005/07/22 19:12:14 rhatcher Exp $");
00022 
00023 #include "RawData/RawBlockRegistry.h"
00024 REGISTERRAWBLOCK(RawTrcMonitorBlock,kMdBlockTrcMonitor,0);
00025 
00026 ClassImp(RawTrcMonitorBlock)
00027 
00028 enum ETrcMonitorBlkPos {
00029    indx_size      = 0,
00030    indx_checksum  = 1,
00031    indx_blockid   = 2,
00032    indx_run       = 3,
00033    indx_subrun    = 4,
00034    indx_runtype   = indx_subrun,
00035    indx_crateid   = 5,
00036    indx_timeframe = 6,
00037    indx_nreports  = 7,
00038    zzzz_last      = 8
00039 };
00040 
00041 static RawTrcMonitorBlock::RawTrcStatusReport dummyTrcStatusReport;
00042 
00043 //_____________________________________________________________________________
00044 RawTrcMonitorBlock::RawTrcMonitorBlock()
00045 {
00046    // Default constructor
00047 }
00048 
00049 //_____________________________________________________________________________
00050 RawTrcMonitorBlock::RawTrcMonitorBlock(const Int_t *block)
00051    : RawDataBlock(block)
00052 {
00053    //  stored block format is:
00054    //---------------------
00055    //  0   # words in block
00056    //  1   checksum
00057    //  2   Block Id
00058    //-----
00059    //  3   run #
00060    //  4   {subrun#| run type}
00061    //  5   crate identifier
00062    //  6   timeframe #
00063    //  7   # of Trc status report blocks
00064    //  ..  { Trc status report sub-blocks }
00065 }
00066 
00067 //_____________________________________________________________________________
00068 RawTrcMonitorBlock::~RawTrcMonitorBlock()
00069 {
00070    // dtor
00071 }
00072 
00073 //_____________________________________________________________________________
00074 Int_t RawTrcMonitorBlock::GetRun() const
00075 {
00076    // get the run number
00077    if (fSize > indx_run) return fRawBlock[indx_run];
00078    return -1;
00079 }
00080 
00081 //_____________________________________________________________________________
00082 Short_t RawTrcMonitorBlock::GetSubRun() const
00083 {
00084    // get the subrun number
00085    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00086    return -1;
00087 }
00088 
00089 //_____________________________________________________________________________
00090 Short_t RawTrcMonitorBlock::GetRunType() const
00091 {
00092    // get the run type
00093    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00094    return -1;
00095 }
00096 
00097 //_____________________________________________________________________________
00098 Int_t RawTrcMonitorBlock::GetCrateId() const
00099 {
00100    // get the crate id
00101    if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00102    return -1;
00103 }
00104 
00105 //_____________________________________________________________________________
00106 Int_t RawTrcMonitorBlock::GetTimeFrameNum() const
00107 {
00108    // get the time frame #
00109    if (fSize > indx_timeframe) return fRawBlock[indx_timeframe];
00110    return -1;
00111 }
00112 
00113 //_____________________________________________________________________________
00114 Int_t RawTrcMonitorBlock::GetNumTrcStatusReports() const
00115 {
00116    // get the number of status report sub-blocks
00117 
00118    //if (fSize > indx_nreports) return fRawBlock[indx_nreports];
00119    //return -1;
00120   UnpackTrcStatusReports();
00121   return fTrcStatusReports.size();
00122 }
00123 
00124 //_____________________________________________________________________________
00125 const RawTrcMonitorBlock::RawTrcStatusReport& 
00126 RawTrcMonitorBlock::GetTrcStatusReport(UInt_t indx) const
00127 {
00128    // get the i-th status report sub-block
00129   size_t nreports = GetNumTrcStatusReports();
00130   if (indx >= nreports) {
00131     MSG("Raw",Msg::kWarning)
00132       << "GetStatusReport() can't get index " << indx
00133       << " as there are only " << nreports << endl;
00134     return dummyTrcStatusReport;
00135   }
00136   return fTrcStatusReports[indx];
00137 }
00138 
00139 //_____________________________________________________________________________
00140 std::ostream& RawTrcMonitorBlock::FormatToOStream(std::ostream& os, 
00141                                                         Option_t *option) const
00142 {
00143 
00144    if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00145 
00146    RawDataBlock::FormatToOStream(os,option);
00147    if (option[0] == 'X') return os;
00148 
00149    // additional block specific formatted output is done here
00150 
00151    os << " Run " << GetRun() 
00152       << " SubRun " << GetSubRun() 
00153       << " RunType " << GetRunType() << endl; 
00154    int crateid = GetCrateId();
00155    os << " Crate " << (crateid&0x3f)
00156       << " (0x" << hex << crateid << dec << ") had "
00157       << GetNumTrcStatusReports() << " reports: " << endl;
00158    for (int i = 0; i<GetNumTrcStatusReports(); i++) {
00159      const RawTrcStatusReport status = GetTrcStatusReport(i);
00160      os << "   report [" << setw(2) << i << "] " 
00161         << status.timestamp.AsString("c")
00162         << " swaps=" << int(status.numBufferSwaps)
00163         << " flags=0x" << hex << setfill('0') << int(status.flags&0xFF)
00164         << setfill(' ') << dec
00165         << endl;
00166    }
00167    return os;
00168 }
00169 
00170 //_____________________________________________________________________________
00171 void RawTrcMonitorBlock::UnpackTrcStatusReports() const
00172 {
00173    // unpack the Trc status sub-blocks
00174    if (!fTrcStatusReports.empty()) return;  // early exit if already unpacked
00175 
00176    UInt_t nexpected = 0, nseen = 0;
00177    if (fSize > indx_nreports) nexpected = fRawBlock[indx_nreports];
00178 
00179    Int_t *report_start = fRawBlock + indx_nreports + 1;
00180    Int_t *toofar       = fRawBlock + fSize;
00181 
00182    const size_t sizeTrcReportSubBlk = 3;
00183 
00184    while (report_start < toofar) {
00185      time_t sec    = report_start[0];
00186      Int_t  ns     = report_start[1];
00187      Int_t  packed = report_start[2]; 
00188      // packed is the two char flags and numBufferSwaps + 2 padding chars
00189      // structure mappings of chars to memory is tricky!
00190      // for gcc Linux on x86 architecture first char maps to *lowest* byte.
00191      // but despite documentation (and structure in mdBlockDefinitions.h
00192      // it appears to be filled via the following) the flags data 
00193      // appears to be in the top most byte, not the lowest.
00194      // but that assumes that the structure is filled on the same
00195      // a platform with the endian-ness and a byte swapping doesn't
00196      // occur somewhere in the game.
00197      char flags = (packed>>24) & 0xff;
00198      char nswap = (packed>>16) & 0xff;
00199 
00200      RawTrcStatusReport report;
00201      report.timestamp      = VldTimeStamp(sec,ns);
00202      report.flags          = flags;
00203      report.numBufferSwaps = nswap;
00204      fTrcStatusReports.push_back(report);
00205 
00206      ++nseen;
00207      report_start += sizeTrcReportSubBlk;
00208    }
00209 
00210    if (nseen != nexpected || report_start != toofar)
00211      MSG("Raw",Msg::kWarning)
00212        << "Unpacking reached end in an inconsistent manner"
00213        << " ptr @ " << report_start << " should be " << toofar
00214        << " saw " << nseen << " of " << nexpected << " expected"
00215        << " TrcStatusReports." << endl;
00216 
00217 }
00218 //_____________________________________________________________________________

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