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