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