00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "JobControl/JobCModuleRegistry.h"
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "OfflineTrigger/OltDataIntegrity.h"
00014 #include "MessageService/MsgService.h"
00015 #include "RawData/RawRecord.h"
00016 #include "RawData/RawHeader.h"
00017 #include "RawData/RawDataBlock.h"
00018 #include "RawData/RawDaqHeaderBlock.h"
00019 #include "RawData/RawSnarlHeaderBlock.h"
00020 #include "RawData/RawChannelId.h"
00021 #include "RawData/RawVaDigit.h"
00022 #include "RawData/RawQieDigit.h"
00023 #include "RawData/RawDigitDataBlock.h"
00024 #include "RawData/RawRunCommentBlock.h"
00025 #include "RawData/RawRunConfigBlock.h"
00026
00027 #include "Persistency/PerOutputStreamManager.h"
00028 #include "Persistency/PerOutputStream.h"
00029 #include "Rotorooter/RotoObjectifier.h"
00030 #include "Plex/PlexHandle.h"
00031 #include "Plex/PlexSEIdAltL.h"
00032 #include "Validity/VldContext.h"
00033
00034 #include "TString.h"
00035 #include "TFile.h"
00036 #include "TTree.h"
00037 #include <string>
00038
00039 #include <algorithm>
00040 #include <cstdio>
00041 #include <cstring>
00042 #include <iostream>
00043 #include <fstream>
00044 #ifndef __CINT__
00045 #include "OnlineUtil/mdBlockDefinitions.h"
00046 #endif
00047 ClassImp(OltDataIntegrity)
00048
00049
00050
00051 CVSID("$Id: OltDataIntegrity.cxx,v 1.1 2003/08/27 12:52:06 phil.adamson Exp $");
00052 JOBMODULE(OltDataIntegrity,"OltDataIntegrity","The Offline Trigger Block Scanner");
00053
00054
00055
00056
00057
00058 OltDataIntegrity::OltDataIntegrity()
00059 {
00060 fRecord = 0;
00061 }
00062
00063 OltDataIntegrity::~OltDataIntegrity()
00064 {
00065 TDirectory *save = gDirectory;
00066 fFile->cd();
00067 fTree->Write();
00068 fFile->Close();
00069 save->cd();
00070 }
00071
00072 JobCResult OltDataIntegrity::Reco(MomNavigator* mom)
00073 {
00074
00075
00076 TIter iter = mom->FragmentIter();
00077 while (TObject *obj = iter.Next()) {
00078 RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00079 if (rawrec) {
00080 ++fRecord;
00081 MSG("Olt",Msg::kVerbose) <<"---------------New Record---------------"<<endl;
00082 TIter recit = rawrec->GetRawBlockIter();
00083 while (TObject *obj = recit.Next()) {
00084 RawDataBlock *rawdata = dynamic_cast<RawDataBlock *>(obj);
00085 if (rawdata) {
00086 if (rawdata->InheritsFrom("RawSnarlHeaderBlock")) {
00087 RawSnarlHeaderBlock *rshb =dynamic_cast<RawSnarlHeaderBlock *>(rawdata);
00088 fTimeframe = rshb->GetTimeFrameNo();
00089 int run = rshb->GetRun();
00090 int subrun = rshb->GetSubRun();
00091 if ((run!=fRun)||(subrun!=fSubRun)) {
00092 MSG("Olt",Msg::kInfo)<<"Now starting run "<<run<<":"<<subrun<<endl;
00093 fRun = run;
00094 fSubRun = subrun;
00095 }
00096 }
00097
00098 MSG("Olt",Msg::kVerbose) <<fRecord<<": "<<rawdata->GetBlockId()<<endl;
00099 RawDigitDataBlock *rddb = dynamic_cast<RawDigitDataBlock *>(rawdata);
00100 if (rddb) {
00101 TIter it = rddb->GetDatumIter();
00102 while (TObject *obj = it.Next()) {
00103 RawVaDigit *rvd = dynamic_cast<RawVaDigit *>(obj);
00104 if (rvd) {
00105 int tb = (rvd->GetTDC()/16000000);
00106 fTimeBlockHits[0][tb] = fTimeBlockHits[0][tb] + 1;
00107 fTimeBlockHits[0][40] = fTimeBlockHits[0][40] + 1;
00108 }
00109 RawQieDigit *rqd = dynamic_cast<RawQieDigit *>(obj);
00110 if (rqd) {
00111 int error = rqd->GetErrorCode();
00112 RawChannelId rcid = rqd->GetChannel();
00113 int crate = rcid.GetCrate();
00114 int tb = rqd->GetTDC()/int(1000000*77.0/58.0);
00115 fTimeBlockHits[crate][tb] = fTimeBlockHits[crate][tb] + 1;
00116 fTimeBlockHits[crate][40] = fTimeBlockHits[crate][40] + 1;
00117 if (error) {
00118 MSG("Olt",Msg::kInfo)<<"Run "<<fRun<<":"<<fSubRun<<" Timeframe "<<fTimeframe<<" QIE error "<<error<<" in channel "<<rcid<<endl;
00119 }
00120 }
00121 }
00122 }
00123 }
00124 }
00125 }
00126 }
00127
00128 if (fTimeframe&&(fTimeframe%fCheckPeriod==0)) {
00129
00130 for (int crate=0;crate<3;crate++) {
00131 for (int tb = 0; tb<40; tb++) {
00132 if (float(fTimeBlockHits[crate][tb])/float(fTimeBlockHits[crate][40])
00133 <fTBThresh)
00134 MSG("Olt",Msg::kInfo) << "Warning: at tf " <<fTimeframe<< " Crate "
00135 <<crate<<" Timeblock "
00136 <<tb<<" has only "
00137 <<float(fTimeBlockHits[crate][tb])/float(fTimeBlockHits[crate][40])
00138 <<" of the hits"<<endl;
00139 fTimeBlockHits[crate][tb]=0;
00140 }
00141 fTimeBlockHits[crate][40] = 0;
00142 }
00143 }
00144 return JobCResult::kAOK;
00145 }
00146
00147
00148
00149 const Registry& OltDataIntegrity::DefaultConfig() const
00150 {
00151
00152 static Registry r;
00153
00154
00155 std::string name = this->JobCModule::GetName();
00156 name += ".config.default";
00157 r.SetName(name.c_str());
00158
00159
00160 r.UnLockValues();
00161 r.Set("DumpData", true);
00162 r.Set("NumDump",10);
00163 r.Set("DoTree", false);
00164 r.Set("StartTF",0);
00165 r.Set("OutFile","di.root");
00166 r.Set("CheckPeriod",10);
00167 r.Set("TBThresh",0.01);
00168 r.LockValues();
00169
00170 return r;
00171 }
00172
00173
00174
00175 void OltDataIntegrity::Config(const Registry& r)
00176 {
00177 int tmpb;
00178 cout<<"Teapots\n";
00179 cout<<r<<endl;
00180 if (r.Get("DumpData",tmpb)) { cout<<"Hello "<<tmpb<<endl;fDump = bool(tmpb); }
00181 if (r.Get("DoTree",tmpb)) fDoTree = bool(tmpb);
00182 if (r.Get("StartTF",tmpb)) fStartTF = tmpb;
00183 if (r.Get("NumDump",tmpb)) fNumDump = tmpb;
00184
00185 const char *s;
00186 if (r.Get("OutFile",s)) fFileName = std::string(s);
00187 TDirectory *save = gDirectory;
00188 fFile = new TFile(fFileName.c_str(),"RECREATE");
00189 fTree = new TTree("ditree","Data Integrity Tree");
00190 save->cd();
00191
00192 double f;
00193 if (r.Get("CheckPeriod",tmpb)) fCheckPeriod = tmpb;
00194 if (r.Get("TBThresh",f)) fTBThresh = f;
00195 }
00196