00001
00002
00003
00004
00005
00006
00007
00008
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
00055 }
00056
00057
00058 RawVtmTimeInfoBlock::RawVtmTimeInfoBlock(const Int_t *block)
00059 : RawDataBlock(block), fCrateId()
00060 {
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 }
00080
00081
00082 RawVtmTimeInfoBlock::~RawVtmTimeInfoBlock()
00083 {
00084
00085 }
00086
00087
00088 RawVtmTimeInfoBlock& RawVtmTimeInfoBlock::operator=(const RawVtmTimeInfoBlock& rhs)
00089 {
00090
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
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
00112 if (fSize > indx_run) return fRawBlock[indx_run];
00113 return -1;
00114 }
00115
00116
00117 Short_t RawVtmTimeInfoBlock::GetSubRun() const
00118 {
00119
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
00128 if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00129 return -1;
00130 }
00131
00132
00133 Int_t RawVtmTimeInfoBlock::GetCrateIdInfo() const
00134 {
00135
00136 if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00137 return -1;
00138 }
00139
00140
00141 Int_t RawVtmTimeInfoBlock::GetTimeFrameNum() const
00142 {
00143
00144 if (fSize > indx_tf) return fRawBlock[indx_tf];
00145 return -1;
00146 }
00147
00148
00149 Int_t RawVtmTimeInfoBlock::GetLastRFClock() const
00150 {
00151
00152 if (fSize > indx_lastrfclock) return fRawBlock[indx_lastrfclock];
00153 return -1;
00154 }
00155
00156
00157 Int_t RawVtmTimeInfoBlock::GetSpillTimeRF() const
00158 {
00159
00160 if (fSize > indx_spilltimerf) return fRawBlock[indx_spilltimerf];
00161 return -1;
00162 }
00163
00164
00165 Int_t RawVtmTimeInfoBlock::GetSpillTimeGPS() const
00166 {
00167
00168 if (fSize > indx_spilltimegps) return fRawBlock[indx_spilltimegps];
00169 return -1;
00170 }
00171
00172
00173 Int_t RawVtmTimeInfoBlock::GetClockStatus() const
00174 {
00175
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
00190 Int_t status = GetClockStatus();
00191
00192 return ((1<<15) & status);
00193 }
00194
00195
00196 Bool_t RawVtmTimeInfoBlock::ModuleInError(UShort_t indx) const
00197 {
00198
00199 Int_t status = GetClockStatus();
00200
00201 if (indx > 14) return true;
00202 return ((1<<indx) & status);
00203 }
00204
00205
00206 std::vector<UShort_t> RawVtmTimeInfoBlock::ErrorModules() const
00207 {
00208
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
00222 if (fSize > indx_endlasttf) return fRawBlock[indx_endlasttf];
00223 return -1;
00224 }
00225
00226
00227 VldContext RawVtmTimeInfoBlock::GetVldContext() const
00228 {
00229
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
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
00296 if (!fCrateId.IsNull()) return;
00297 fCrateId = RawChannelId(GetBlockId().GetDetector(),GetCrateIdInfo(),0x1fff);
00298 }
00299
00300