00001
00002
00003
00004
00005
00006
00007
00008
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
00047 }
00048
00049
00050 RawTrcMonitorBlock::RawTrcMonitorBlock(const Int_t *block)
00051 : RawDataBlock(block)
00052 {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 }
00066
00067
00068 RawTrcMonitorBlock::~RawTrcMonitorBlock()
00069 {
00070
00071 }
00072
00073
00074 Int_t RawTrcMonitorBlock::GetRun() const
00075 {
00076
00077 if (fSize > indx_run) return fRawBlock[indx_run];
00078 return -1;
00079 }
00080
00081
00082 Short_t RawTrcMonitorBlock::GetSubRun() const
00083 {
00084
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
00093 if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00094 return -1;
00095 }
00096
00097
00098 Int_t RawTrcMonitorBlock::GetCrateId() const
00099 {
00100
00101 if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00102 return -1;
00103 }
00104
00105
00106 Int_t RawTrcMonitorBlock::GetTimeFrameNum() const
00107 {
00108
00109 if (fSize > indx_timeframe) return fRawBlock[indx_timeframe];
00110 return -1;
00111 }
00112
00113
00114 Int_t RawTrcMonitorBlock::GetNumTrcStatusReports() const
00115 {
00116
00117
00118
00119
00120 UnpackTrcStatusReports();
00121 return fTrcStatusReports.size();
00122 }
00123
00124
00125 const RawTrcMonitorBlock::RawTrcStatusReport&
00126 RawTrcMonitorBlock::GetTrcStatusReport(UInt_t indx) const
00127 {
00128
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
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
00174 if (!fTrcStatusReports.empty()) return;
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
00189
00190
00191
00192
00193
00194
00195
00196
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