00001
00002
00003
00004
00005
00006
00007
00009 #include "Filtration/FiltTriggerPrescale.h"
00010 #include <cstdio>
00011 using namespace std;
00012
00013
00014 #include "TFile.h"
00015 #include "TStyle.h"
00016 #include "TMath.h"
00017 #include "TString.h"
00018
00019
00020 #include "MessageService/MsgService.h"
00021 #include "MinosObjectMap/MomNavigator.h"
00022 #include "Util/UtilString.h"
00023
00024 #include "RawData/RawRecord.h"
00025 #include "RawData/RawDaqSnarlHeader.h"
00026 #include "RawData/RawTriggerCodes.h"
00027
00028
00029 #include "JobControl/JobCommand.h"
00030 #include "JobControl/JobCModuleRegistry.h"
00031
00032 CVSID("$Id: FiltTriggerPrescale.cxx,v 1.2 2005/06/02 06:50:29 rhatcher Exp $");
00033 JOBMODULE(FiltTriggerPrescale,"FiltTriggerPrescale","Select events on prescaled trigger counts.\n");
00034
00035
00036
00037 FiltTriggerPrescale::FiltTriggerPrescale()
00038 {
00039 fRecordSets = fSnarls = fSnarlsPassed = fNoSnarlRecSets = 0;
00040 for (int i=0; i<32; ++i) {
00041 fN[i] = fM[i] = fTrigSeen[i] = fTrigPass[i] = 0;
00042 }
00043 }
00044
00045
00046
00047 const Registry& FiltTriggerPrescale::DefaultConfig() const
00048 {
00049
00050
00051
00052 static Registry r;
00053
00054
00055 std::string name = this->GetName();
00056 name += ".config.default";
00057 r.SetName(name.c_str());
00058
00059
00060 r.UnLockValues();
00061
00062 for (int ibit=0; ibit<32; ++ibit) {
00063 UInt_t oneBit = 1 << ibit;
00064 RawTriggerCodes::TrigBits_t tbit =
00065 static_cast<RawTriggerCodes::TrigBits_t>(oneBit);
00066 std::string trigName = RawTriggerCodes::AsString(tbit);
00067 int defaultN = 1;
00068 int defaultM = 1;
00069
00070
00071
00072 if ( trigName.find("TrigBit") == 0 || trigName.find("0x") == 0 ) {
00073 trigName = "TrigBit" + UtilString::ToString(ibit);
00074 defaultN = 0;
00075 defaultM = 0;
00076 }
00077
00078 std::string nName = trigName + "_N";
00079 std::string mName = trigName + "_M";
00080 r.Set(nName.c_str(),defaultN);
00081 r.Set(mName.c_str(),defaultM);
00082 }
00083
00084 r.LockValues();
00085
00086 return r;
00087 }
00088
00089
00090
00091 void FiltTriggerPrescale::Config(const Registry& r)
00092 {
00093
00094
00095
00096
00097
00098 int tmpn, tmpm;
00099
00100 for (int ibit=0; ibit<32; ++ibit) {
00101 UInt_t oneBit = 1 << ibit;
00102 RawTriggerCodes::TrigBits_t tbit =
00103 static_cast<RawTriggerCodes::TrigBits_t>(oneBit);
00104 std::string trigName = RawTriggerCodes::AsString(tbit);
00105
00106
00107 if ( trigName.find("TrigBit") == 0 || trigName.find("0x") == 0 ) {
00108 trigName = "TrigBit" + UtilString::ToString(ibit);
00109 }
00110
00111 std::string nName = trigName + "_N";
00112 std::string mName = trigName + "_M";
00113 if (r.Get(nName.c_str(),tmpn)) { fN[ibit] = tmpn; }
00114 if (r.Get(mName.c_str(),tmpm)) { fM[ibit] = tmpm; }
00115 }
00116
00117 }
00118
00119
00120
00121 void FiltTriggerPrescale::Report()
00122 {
00123 MSG("Filt",Msg::kInfo)
00124 << "Report For FiltTriggerPrescale Module:" << endl;
00125
00126
00127
00128
00129 MSG("Filt",Msg::kInfo)
00130 << " Processed " << fRecordSets << " record-sets "
00131 << "(" << fNoSnarlRecSets << " without snarls)." << endl;
00132
00133 MSG("Filt",Msg::kInfo)
00134 << " bit# triggerName passed/ seen N/ M"
00135 << endl;
00136 for ( int ibit=0; ibit<32; ++ibit) {
00137 UInt_t nPass = fTrigPass[ibit];
00138 UInt_t mSeen = fTrigSeen[ibit];
00139 UInt_t n = fN[ibit];
00140 UInt_t m = fM[ibit];
00141 if ( nPass == 0 && mSeen == 0 && n == 0 && m == 0 ) continue;
00142
00143 UInt_t oneBit = 1 << ibit;
00144 RawTriggerCodes::TrigBits_t tbit =
00145 static_cast<RawTriggerCodes::TrigBits_t>(oneBit);
00146 std::string trigName = RawTriggerCodes::AsString(tbit);
00147
00148 double passFrac = (mSeen>0) ? (double)nPass/(double)mSeen : -1;
00149 double targFrac = (m >0) ? (double)n /(double)m : -1;
00150
00151 MSG("Filt",Msg::kInfo)
00152 << " [" << setw(2) << right << ibit << left << "] "
00153 << setw(12) << trigName << " "
00154 << right
00155 << " " << setw(8) << nPass << "/" << setw(8) << mSeen
00156 << " (" << setw(10) << passFrac << ")"
00157 << " " << setw(4) << n << "/" << setw(4) << m
00158 << " (" << setw(10) << targFrac << ")"
00159 << left
00160 << endl;
00161 }
00162 double totPassFrac =
00163 (fSnarls>0) ? (double)fSnarlsPassed/(double)fSnarls : -1;
00164 MSG("Filt",Msg::kInfo)
00165 << " "
00166 << setw(12) << "-all triggers-"
00167 << right
00168 << " " << setw(8) << fSnarlsPassed << "/" << setw(8) << fSnarls
00169 << " (" << setw(10) << totPassFrac << ")"
00170 << endl;
00171
00172 MSG("Filt",Msg::kInfo) << endl;
00173 }
00174
00175
00176
00177 void FiltTriggerPrescale::EndJob()
00178 {
00179 Report();
00180 }
00181
00182
00183
00184 JobCResult FiltTriggerPrescale::Ana(const MomNavigator *mom)
00185 {
00186
00187 JobCResult result = JobCResult::kFailed;
00188 int snarlsInRecSet = 0;
00189
00190
00191 fRecordSets++;
00192
00193 TObject* recObj = 0;
00194 TIter recItr = mom->FragmentIter();
00195 while ( ( recObj = recItr.Next() ) ) {
00196 RawRecord* rawrec = dynamic_cast<RawRecord*>(recObj);
00197 if (!rawrec) continue;
00198
00199
00200
00201 const RawDaqSnarlHeader* snarlHdr =
00202 dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetHeader());
00203
00204 if ( snarlHdr ) {
00205 fSnarls++;
00206 snarlsInRecSet++;
00207 bool passSnarl = false;
00208
00209 int snarlNum = snarlHdr->GetSnarl();
00210 int trigSrc = snarlHdr->GetTrigSrc();
00211 const VldContext& vldc = snarlHdr->GetVldContext();
00212 std::string detName = Detector::AsString(vldc.GetDetector());
00213
00214 for (int ibit=0; ibit<32; ++ibit) {
00215 UInt_t oneBit = 1 << ibit;
00216 if ( oneBit & trigSrc ) {
00217 fTrigSeen[ibit]++;
00218 bool passBit = false;
00219 if ( fM[ibit] > 0 ) {
00220 UInt_t modSnarlNum = snarlNum%fM[ibit];
00221 if ( modSnarlNum < fN[ibit] ) passBit = true;
00222 }
00223
00224 RawTriggerCodes::TrigBits_t tbit =
00225 static_cast<RawTriggerCodes::TrigBits_t>(oneBit);
00226 std::string trigName = RawTriggerCodes::AsString(tbit);
00227 MSG("Filt",Msg::kDebug )
00228 << " " << detName
00229 << " Run " << snarlHdr->GetRun()
00230 << " Snarl " << snarlNum
00231 << " had TrigBit \"" << trigName << "\""
00232 << " : "
00233 << (passBit?"Passed":"Failed")
00234 << endl;
00235
00236 if ( passBit ) {
00237 passSnarl = true;
00238 fTrigPass[ibit]++;
00239 }
00240 }
00241 }
00242 if ( passSnarl ) {
00243 fSnarlsPassed++;
00244 result = JobCResult::kPassed;
00245 }
00246
00247 MSG("Filt",Msg::kSynopsis )
00248 << " " << detName
00249 << " Run " << snarlHdr->GetRun()
00250 << " SubRun " << snarlHdr->GetSubRun()
00251 << " Snarl " << snarlNum
00252 << " TrigSrc " << Form("0x%08x",trigSrc)
00253 << " : "
00254 << (passSnarl?"Passed":"Failed")
00255 << endl;
00256
00257 }
00258 }
00259
00260
00261 if ( snarlsInRecSet == 0 ) {
00262 fNoSnarlRecSets++;
00263 MSG("Filt",Msg::kSynopsis )
00264 << GetName()
00265 << " RecordSet contained no DaqSnarl "
00266 << endl;
00267 return JobCResult::kPassed;
00268 }
00269 if ( snarlsInRecSet > 1 ) {
00270 MSG("Filt",Msg::kWarning )
00271 << GetName()
00272 << " RecordSet contained more than one DaqSnarl "
00273 << endl;
00274 }
00275 return result;
00276 }
00277
00278