00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "RawData/RawRunCommentBlock.h"
00013
00014 enum EDebugRunCommentBlock {
00015 kdbg_ForceHexDump = 0x0001
00016 };
00017 UInt_t RawRunCommentBlock::fgDebugFlags = 0;
00018
00019 #include "MessageService/MsgService.h"
00020
00021 #include "MessageService/MsgFormat.h"
00022
00023 #include "RawData/RawBlockRegistry.h"
00024 REGISTERRAWBLOCK(RawRunCommentBlock,kMdBlockRunComment,0);
00025
00026 #include "RawData/littleendian_strings.h"
00027
00028 ClassImp(RawRunCommentBlock)
00029
00030 enum ERunStartBlkPos {
00031 indx_size = 0,
00032 indx_checksum = 1,
00033 indx_blockid = 2,
00034 zzzz_last_v1 = indx_blockid+1,
00035 indx_run = 3,
00036 indx_subrun = 4,
00037 indx_runtype = indx_subrun,
00038 indx_startsec = 5,
00039 indx_startnsec = 6,
00040 zzzz_last = 7
00041 };
00042
00043
00044
00045 RawRunCommentBlock::RawRunCommentBlock()
00046 : RawDataBlock(), fRunComment(0)
00047 {
00048
00049 }
00050
00051
00052 RawRunCommentBlock::RawRunCommentBlock(const Int_t *block)
00053 : RawDataBlock(block), fRunComment(0)
00054 {
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 }
00069
00070
00071 RawRunCommentBlock::RawRunCommentBlock(const VldContext& vldc, Int_t run,
00072 Short_t subrun, Short_t runtype,
00073 const Char_t* comment)
00074 : RawDataBlock(), fRunComment(0)
00075 {
00076
00077
00078 UInt_t nwdc = nwords_in_string(comment);
00079 fSize = zzzz_last + nwdc;
00080 if (fRawBlock) delete [] fRawBlock;
00081 fRawBlock = new Int_t [fSize];
00082
00083 fRawBlock[0] = fSize;
00084
00085
00086 RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00087 RawBlockProxy* rbp = rbr.LookUp("RawRunCommentBlock");
00088
00089 Bool_t isDCS = rbp->IsDCS();
00090 Int_t majorId = rbp->GetMajorId();
00091 Int_t minorId = 2;
00092 RawBlockId rbid(majorId,minorId,isDCS,
00093 vldc.GetDetector(),vldc.GetSimFlag());
00094 fRawBlock[2] = rbid.GetEncoded();
00095
00096 fRawBlock[indx_run] = run;
00097 fRawBlock[indx_subrun] = (subrun&0xffff)<<16 | (runtype&0xffff);
00098 fRawBlock[indx_startsec] = vldc.GetTimeStamp().GetSec();
00099 fRawBlock[indx_startnsec] = vldc.GetTimeStamp().GetNanoSec();
00100
00101 fRawBlock[fSize-1] = 0;
00102 pack_string_in_lel(fRawBlock+zzzz_last,comment);
00103
00104
00105 rdxsum_fill((long*)fRawBlock,0);
00106 }
00107
00108
00109 RawRunCommentBlock::RawRunCommentBlock(const VldContext& vldc,
00110 const Char_t* comment)
00111
00112 : RawDataBlock(), fRunComment(0)
00113 {
00114
00115
00116 UInt_t nwdc = nwords_in_string(comment);
00117 fSize = zzzz_last_v1 + nwdc;
00118 if (fRawBlock) delete [] fRawBlock;
00119 fRawBlock = new Int_t [fSize];
00120
00121 fRawBlock[0] = fSize;
00122
00123
00124 RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00125 RawBlockProxy* rbp = rbr.LookUp("RawRunCommentBlock");
00126
00127 Bool_t isDCS = rbp->IsDCS();
00128 Int_t majorId = rbp->GetMajorId();
00129 Int_t minorId = 1;
00130 RawBlockId rbid(majorId,minorId,isDCS,
00131 vldc.GetDetector(),vldc.GetSimFlag());
00132 fRawBlock[2] = rbid.GetEncoded();
00133
00134 fRawBlock[fSize-1] = 0;
00135 pack_string_in_lel(fRawBlock+zzzz_last_v1,comment);
00136
00137
00138 rdxsum_fill((long*)fRawBlock,0);
00139 }
00140
00141
00142 RawRunCommentBlock::~RawRunCommentBlock()
00143 {
00144
00145 if (fRunComment) {
00146 delete [] fRunComment;
00147 fRunComment = 0;
00148 }
00149 }
00150
00151
00152 RawRunCommentBlock& RawRunCommentBlock::operator=(const RawRunCommentBlock& rhs)
00153 {
00154
00155 if (this != &rhs) {
00156 RawDataBlock::operator=(rhs);
00157 if (fRunComment) { delete [] fRunComment; fRunComment = 0; }
00158 }
00159 return *this;
00160 }
00161
00162
00163 VldTimeStamp RawRunCommentBlock::GetTime() const
00164 {
00165
00166
00167 Int_t minor = GetBlockId().GetMinor();
00168
00169 if ( fSize >= zzzz_last && minor>=2 )
00170 return VldTimeStamp(fRawBlock[indx_startsec],fRawBlock[indx_startnsec]);
00171
00172 return VldTimeStamp((time_t)0,(Int_t)0);
00173 }
00174
00175
00176 Int_t RawRunCommentBlock::GetRun() const
00177 {
00178
00179
00180 Int_t minor = GetBlockId().GetMinor();
00181
00182 if ( fSize >= zzzz_last && minor>=2 ) return fRawBlock[indx_run];
00183 return -1;
00184 }
00185
00186
00187 Short_t RawRunCommentBlock::GetSubRun() const
00188 {
00189
00190
00191 Int_t minor = GetBlockId().GetMinor();
00192
00193 if ( fSize >= zzzz_last && minor>=2 )
00194 return (fRawBlock[indx_subrun]>>16)&0xffff;
00195 return -1;
00196 }
00197
00198
00199 Short_t RawRunCommentBlock::GetRunType() const
00200 {
00201
00202
00203 Int_t minor = GetBlockId().GetMinor();
00204
00205 if ( fSize >= zzzz_last && minor>= 2 )
00206 return fRawBlock[indx_runtype]&0xffff;
00207 return -1;
00208 }
00209
00210
00211 VldContext RawRunCommentBlock::GetVldContext() const
00212 {
00213
00214 RawBlockId rbid = GetBlockId();
00215 return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTime());
00216 }
00217
00218
00219 const Char_t* RawRunCommentBlock::GetRunComment() const
00220 {
00221
00222
00223 if (!fRunComment) {
00224
00225 Int_t minor = GetBlockId().GetMinor();
00226
00227 Int_t* insitu = fRawBlock+zzzz_last;
00228 if (minor<2) insitu = fRawBlock+zzzz_last_v1;
00229
00230 UInt_t nwd = (fRawBlock+fSize) - insitu;
00231 fRunComment = unpack_lel_to_string(insitu,nwd);
00232
00233
00234
00235 int nchar = nwd*sizeof(Int_t)/sizeof(Char_t) - 1;
00236 fRunComment[nchar] = '\0';
00237 for (int i=0; i<nchar; ++i) {
00238 Char_t c = fRunComment[i];
00239 if ( !isprint(c) && '\n'!=c ) fRunComment[i] = ' ';
00240 }
00241
00242 }
00243 return fRunComment;
00244 }
00245
00246
00247 std::ostream& RawRunCommentBlock::FormatToOStream(std::ostream& os,
00248 Option_t *option) const
00249 {
00250 if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00251
00252 RawDataBlock::FormatToOStream(os,option);
00253 if (option[0] == 'X') return os;
00254
00255
00256
00257 Int_t minor = GetBlockId().GetMinor();
00258 if (minor >= 2) {
00259 os << "Time " << GetTime().AsString("c") << endl;
00260 os << " Run " << GetRun()
00261 << " SubRun " << GetSubRun()
00262 << " RunType " << GetRunType() << endl;
00263 }
00264
00265 const Char_t* cmt = GetRunComment();
00266 const Char_t* linestart = " | ";
00267 os << linestart;
00268 while (*cmt != '\0') {
00269 os << *cmt;
00270 if (*cmt == '\n' && *(cmt+1) != '\0') os << linestart;
00271 ++cmt;
00272 }
00273 os << endl;
00274
00275 return os;
00276 }
00277
00278