00001
00002
00003
00004
00005
00006
00007
00008
00010 #include "DataUtil/RawRecCounts.h"
00011
00012 #include <cstdio>
00013 #include <iomanip>
00014
00015 #include "TSystem.h"
00016 #include "TFile.h"
00017 #include "TROOT.h"
00018
00019 #include "MessageService/MsgService.h"
00020 #include "MinosObjectMap/MomNavigator.h"
00021 #include "JobControl/JobCModuleRegistry.h"
00022
00023 #include "RawData/RawRecord.h"
00024 #include "RawData/RawDaqSnarlHeader.h"
00025 #include "RawData/RawDigitDataBlock.h"
00026 #include "RawData/RawDigit.h"
00027
00028 using namespace std;
00029
00030 JOBMODULE(RawRecCounts, "RawRecCounts",
00031 "print at EndJob first/last VldContext");
00032 CVSID("$Id: RawRecCounts.cxx,v 1.6 2007/01/30 14:26:51 rhatcher Exp $");
00033
00034 static const VldContext defaultVldContext(Detector::kUnknown,
00035 SimFlag::kUnknown,
00036 VldTimeStamp((time_t)0,0));
00037
00038
00039
00040 RawRecCounts::RawRecCounts()
00041 : fFirstVldc(defaultVldContext), fLastVldc(defaultVldContext),
00042 fFirstSnarlVldc(defaultVldContext), fLastSnarlVldc(defaultVldContext),
00043 fNumRecords(0), fNumRecSets(0), fFirstSnarl(-1), fLastSnarl(-1),
00044
00045 fRunningStatus(0), fFileRootVersion(0)
00046 {
00047
00048
00049
00050 ClearStatus();
00051 }
00052
00053
00054
00055 RawRecCounts::~RawRecCounts()
00056 {
00057
00058
00059
00060 }
00061
00062
00063
00064 void RawRecCounts::EndJob()
00065 {
00066
00067
00068
00069
00070 Report();
00071
00072 }
00073
00074
00075
00076 JobCResult RawRecCounts::Ana(const MomNavigator* mom)
00077 {
00078
00079
00080
00081
00082 fNumRecSets++;
00083 if (fRunningStatus>0 && fNumRecSets%fRunningStatus == 0)
00084 MSG("DataUtil",Msg::kInfo)
00085 << "\r processed " << fNumRecSets << " record sets\r" << flush;
00086
00087 TObject *tobj = 0;
00088 TIter reciter = mom->FragmentIter();
00089 while ( ( tobj = reciter() ) ) {
00090 RawRecord *rawrec = dynamic_cast<RawRecord*>(tobj);
00091 if (!rawrec) continue;
00092
00093
00094 const Registry& registry = rawrec->GetTempTags();
00095 const char* tmpfile = 0;
00096 registry.Get("file",tmpfile);
00097
00098 const char* basename = gSystem->BaseName(tmpfile);
00099 std::string thisfile = basename;
00100 if ( thisfile != fCurrentFile ) {
00101 if ( fCurrentFile != "" ) Report();
00102 ClearStatus();
00103 fCurrentFile = thisfile;
00104
00105
00106 TSeqCollection* listOfFiles = gROOT->GetListOfFiles();
00107 TIter fileItr(listOfFiles);
00108 TFile* afile = 0;
00109 std::string currentBaseName = gSystem->BaseName(fCurrentFile.c_str());
00110
00111 while ( ( afile = (TFile*)fileItr.Next() ) ) {
00112 std::string fname = afile->GetName();
00113 std::string fbasename = gSystem->BaseName(fname.c_str());
00114
00115 if ( currentBaseName == fbasename ) {
00116 fFileRootVersion = afile->GetVersion();
00117 }
00118 }
00119 }
00120
00121
00122 fNumRecords++;
00123
00124 const RawHeader *rawhead = rawrec->GetRawHeader();
00125 const RawDaqSnarlHeader *rawdaqsnarlhead =
00126 dynamic_cast<const RawDaqSnarlHeader*>(rawhead);
00127
00128 if (fFirstVldc == defaultVldContext)
00129 fFirstVldc = rawhead->GetVldContext();
00130 fLastVldc = rawhead->GetVldContext();
00131
00132 if (rawdaqsnarlhead) {
00133 if (fFirstSnarlVldc == defaultVldContext) {
00134 fFirstSnarlVldc = rawdaqsnarlhead->GetVldContext();
00135 fFirstSnarl = rawdaqsnarlhead->GetSnarl();
00136 }
00137 fLastSnarlVldc = rawhead->GetVldContext();
00138 fLastSnarl = rawdaqsnarlhead->GetSnarl();
00139 }
00140
00141 ProcessBlocksInRecord(rawrec);
00142
00143 }
00144
00145 return JobCResult::kPassed;
00146 }
00147
00148
00149 void RawRecCounts::ClearStatus()
00150 {
00151
00152
00153
00154 fFirstVldc = defaultVldContext;
00155 fLastVldc = defaultVldContext;
00156 fFirstSnarlVldc = defaultVldContext;
00157 fLastSnarlVldc = defaultVldContext;
00158
00159 fNumRecords = 0;
00160 fNumRecSets = 0;
00161 fFirstSnarl = -1;
00162 fLastSnarl = -1;
00163 }
00164
00165
00166
00167 void RawRecCounts::ProcessBlocksInRecord(const RawRecord* rawrec)
00168 {
00169
00170
00171
00172
00173 TIter rbitr = rawrec->GetRawBlockIter();
00174 const RawDataBlock* rdb = 0;
00175 while ( ( rdb = dynamic_cast<const RawDataBlock*>(rbitr()) ) ) {
00176 CountRawBlockTypes(rdb);
00177 }
00178 }
00179
00180
00181
00182 void RawRecCounts::CountRawBlockTypes(const RawDataBlock* rdb)
00183 {
00184
00185
00186
00187
00188 string name = rdb->GetName();
00189 if ( fRawBlockCounts.find(name) == fRawBlockCounts.end() )
00190 fRawBlockCounts[name] = 0;
00191 fRawBlockCounts[name] += 1;
00192
00193 }
00194
00195
00196
00197 const Registry& RawRecCounts::DefaultConfig() const
00198 {
00199
00200
00201
00202 static Registry r;
00203
00204
00205 std::string name = this->GetName();
00206 name += ".config.default";
00207 r.SetName(name.c_str());
00208
00209
00210 r.UnLockValues();
00211 r.Set("RunningStatus", 0);
00212 r.LockValues();
00213
00214 return r;
00215 }
00216
00217
00218
00219 void RawRecCounts::Config(const Registry& r)
00220 {
00221
00222
00223
00224 int tmpi;
00225 if (r.Get("RunningStatus",tmpi)) { fRunningStatus = tmpi; }
00226 }
00227
00228
00229
00230 void RawRecCounts::Report()
00231 {
00232
00233
00234
00235
00236 int rvi = fFileRootVersion;
00237 int rvmajor = rvi/10000;
00238 int rvminor = rvi/100 - 100*rvmajor;
00239 int rvtiny = rvi%100;
00240 string rootVersionString = Form("v%02d-%02d-%02d",rvmajor,rvminor,rvtiny);
00241
00242 MSG("DataUtil",Msg::kInfo)
00243 << endl << endl
00244 << "RawRecCounts Report: " << fCurrentFile << endl
00245 << " root version: " << rootVersionString
00246 << endl << endl;
00247
00248 MSG("DataUtil",Msg::kInfo)
00249 << " VldContexts: " << endl
00250 << " First: " << fFirstVldc << endl
00251 << " First Snarl: " << fFirstSnarlVldc
00252 << " # " << setw(10) << fFirstSnarl << endl
00253 << " Last: " << fLastVldc << endl
00254 << " Last Snarl: " << fLastSnarlVldc
00255 << " # " << setw(10) << fLastSnarl << endl
00256 << " in " << fNumRecords << " records of "
00257 << fNumRecSets << " record sets " << endl
00258 << endl;
00259
00260 std::map<std::string,int>::iterator mitr = fRawBlockCounts.begin();
00261 for ( ; mitr != fRawBlockCounts.end(); mitr++) {
00262 MSG("DataUtil",Msg::kInfo)
00263 << " " << setw(30) << left << (*mitr).first << " "
00264 << setw(10) << right << (*mitr).second
00265 << resetiosflags(ios::adjustfield)
00266 << endl;
00267 }
00268
00269 MSG("DataUtil",Msg::kInfo)
00270 << endl
00271 << "RawRecCounts done"
00272 << endl << endl;
00273
00274 }
00275