00001
00002
00003
00004
00005
00006
00007
00008
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
00058 }
00059
00060
00061 RawQieErrorStatsBlock::RawQieErrorStatsBlock(const Int_t *block)
00062 : RawDataBlock(block), fUnpacked(false)
00063 {
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
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
00096
00097 fSize = zzzz_last + nerrtypes;
00098 if (fRawBlock) delete [] fRawBlock;
00099 fRawBlock = new Int_t [fSize];
00100
00101 fRawBlock[0] = fSize;
00102
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;
00125 }
00126
00127
00128 rdxsum_fill((long*)fRawBlock,0);
00129 }
00130
00131
00132 RawQieErrorStatsBlock::~RawQieErrorStatsBlock()
00133 {
00134
00135 }
00136
00137
00138 RawQieErrorStatsBlock&
00139 RawQieErrorStatsBlock::operator=( const RawQieErrorStatsBlock& rhs)
00140 {
00141
00142 if (this != &rhs) {
00143 RawDataBlock::operator=(rhs);
00144
00145 ClearAllMaps();
00146 }
00147 return *this;
00148 }
00149
00150
00151 VldTimeStamp RawQieErrorStatsBlock::GetStartTime() const
00152 {
00153
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
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
00174 if (fSize >= zzzz_last) return fRawBlock[indx_run];
00175 return -1;
00176 }
00177
00178
00179 Short_t RawQieErrorStatsBlock::GetSubRun() const
00180 {
00181
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
00190 if (fSize >= zzzz_last) return fRawBlock[indx_runtype]&0xffff;
00191 return -1;
00192 }
00193
00194
00195 Int_t RawQieErrorStatsBlock::GetNumberOfErrTypes() const
00196 {
00197
00198 if (fSize >= zzzz_last) return fRawBlock[indx_nerrtypes];
00199 return -1;
00200 }
00201
00202
00203 Int_t RawQieErrorStatsBlock::GetTotalErrChannels() const
00204 {
00205
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
00217 return GetErrorList(errcode).size();
00218 }
00219
00220
00221 const std::map<RawChannelId,UInt_t>&
00222 RawQieErrorStatsBlock::GetErrorList(RawQieDigit::EQieErrorCode errcode) const
00223 {
00224
00225 FillAllMaps();
00226 return GetNonConstListRef(errcode);
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
00246 RawBlockId rbid = GetBlockId();
00247 return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetEndTime());
00248 }
00249
00250
00251 void RawQieErrorStatsBlock::FillAllMaps() const
00252 {
00253
00254
00255 if ( fUnpacked ) return;
00256 fUnpacked = true;
00257
00258 Detector::Detector_t det = GetBlockId().GetDetector();
00259 Int_t indx_cur = zzzz_last - 1;
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
00294 UInt_t crate = funky & 0xFF;
00295 UInt_t chadd = funky >> 16;
00296
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
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
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++;
00369 }
00370 }
00371 return os;
00372 }
00373
00374