00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023 #include <cassert>
00024
00025 #include "Algorithm/AlgConfig.h"
00026 #include "Algorithm/AlgFactory.h"
00027 #include "Algorithm/AlgHandle.h"
00028 #include "Calibrator/Calibrator.h"
00029 #include "CandData/CandHeader.h"
00030 #include "CandData/CandRecord.h"
00031 #include "CandDigit/CandDigitListHandle.h"
00032 #include "CandDigit/CandDigitList.h"
00033 #include "CandDigit/DigitListModule.h"
00034 #include "Candidate/CandContext.h"
00035 #include "JobControl/JobCModuleRegistry.h"
00036 #include "JobControl/JobCommand.h"
00037 #include "MessageService/MsgService.h"
00038 #include "MinosObjectMap/MomNavigator.h"
00039 #include "RawData/RawDaqSnarlHeader.h"
00040 #include "RawData/RawRecord.h"
00041 #include "Validity/VldContext.h"
00042
00043 ClassImp(DigitListModule)
00044
00045
00046 CVSID("$Id: DigitListModule.cxx,v 1.28 2007/03/24 20:40:30 gmieg Exp $");
00047 JOBMODULE(DigitListModule, "DigitListModule",
00048 "Builds Raw and MC Truth CandDigitLists from RawRerootRecord");
00049
00050
00051 DigitListModule::DigitListModule()
00052 {
00053 MSG("Digit", Msg::kVerbose) << "DigitListModule::Constructor\n";
00054 }
00055
00056
00057 DigitListModule::~DigitListModule()
00058 {
00059 MSG("Digit", Msg::kVerbose) << "DigitListModule::Destructor\n";
00060 }
00061
00062
00063 void DigitListModule::BeginJob()
00064 {
00065 MSG("Digit", Msg::kVerbose) << "DigitListModule::BeginJob\n";
00066
00067
00068 const char *tmps = 0;
00069
00070 const char *digitlistalgorithm = 0;
00071 const char *digitlistalgconfig = 0;
00072
00073 Registry &r = GetConfig();
00074 if (r.Get("DigitListAlgorithm", tmps)) digitlistalgorithm = tmps;
00075 if (r.Get("DigitListAlgConfig", tmps)) digitlistalgconfig = tmps;
00076
00077
00078 AlgFactory &af = AlgFactory::GetInstance();
00079
00080
00081 AlgHandle ahdl = af.GetAlgHandle(digitlistalgorithm,
00082 digitlistalgconfig);
00083 AlgConfig &acdl = ahdl.GetAlgConfig();
00084
00085 const char *digitalgorithm = 0;
00086 const char *digitalgconfig = 0;
00087
00088 if (acdl.Get("DigitAlgorithm", tmps)) digitalgorithm = tmps;
00089 if (acdl.Get("DigitAlgConfig", tmps)) digitalgconfig = tmps;
00090
00091
00092 AlgHandle ahd = af.GetAlgHandle(digitalgorithm, digitalgconfig);
00093
00094 }
00095
00096
00097 void DigitListModule::Config(const Registry& )
00098 {
00099 MSG("Digit", Msg::kDebug) << "DigitListModule::Config" << endl;
00100 }
00101
00102
00103 const Registry& DigitListModule::DefaultConfig() const
00104 {
00105 MSG("Digit", Msg::kDebug)
00106 << "DigitListModule::DefaultConfig" << endl;
00107
00108 static Registry r;
00109
00110 std::string name = this->JobCModule::GetName();
00111 name += ".config.default";
00112 r.SetName(name.c_str());
00113
00114 r.UnLockValues();
00115 r.Set("ListsToMake", DigitListModule::kDataList);
00116 r.Set("NameDataList", "canddigitlist");
00117 r.Set("NameMCList", "candmcdigitlist");
00118 r.Set("TitleDataList", "Created by DigitListModule from raw data");
00119 r.Set("TitleMCList", "Created by DigitListModule from MCTruth data");
00120 r.Set("DigitListAlgorithm", "AlgDigitList");
00121 r.Set("DigitListAlgConfig", "default");
00122 r.Set("MCDigitListAlgorithm", "AlgMCDigitList");
00123 r.Set("MCDigitListAlgConfig", "default");
00124 r.LockValues();
00125
00126 return r;
00127 }
00128
00129
00130 JobCResult DigitListModule::Get(MomNavigator *mom)
00131 {
00132 JobCResult result(JobCResult::kPassed);
00133
00134 MSG("Digit", Msg::kVerbose) << "DigitListModule::Get\n";
00135
00136
00137
00138
00139 RawRecord *rawrec =
00140 dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00141
00142 if (!rawrec) {
00143 MAXMSG("Digit", Msg::kWarning,100)
00144 << "No RawRecord in DaqSnarl stream in MOM." << endl;
00145
00146 rawrec = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,
00147 "LightInjection"));
00148 if (!rawrec)
00149 rawrec = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,
00150 "DaqMonitor"));
00151 if (!rawrec)
00152 rawrec = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00153 }
00154
00155 if (!rawrec) {
00156 MAXMSG("Digit", Msg::kWarning,100)
00157 << "No RawRecord in MOM." << endl;
00158 result.SetWarning().SetFailed();
00159 return result;
00160 }
00161
00162 VldContext vldc = rawrec->GetRawHeader()->GetVldContext();
00163 Int_t run = -1;
00164 Int_t snarl = -1;
00165
00166
00167
00168 Calibrator::Instance().Reset(vldc);
00169
00170 const RawDaqSnarlHeader* snarlHdr =
00171 dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00172 if (snarlHdr) {
00173 run = snarlHdr->GetRun();
00174 snarl = snarlHdr->GetSnarl();
00175 } else {
00176 const RawDaqHeader* daqHdr =
00177 dynamic_cast<const RawDaqHeader*>(rawrec->GetRawHeader());
00178 if (daqHdr) {
00179 MSG("Digit", Msg::kWarning)
00180 << "RawRecord only had a RawDaqHeader"
00181 << " - CandHeader will have bogus Snarl #'s"
00182 << endl;
00183 run = daqHdr->GetRun();
00184 } else {
00185 MSG("Digit", Msg::kWarning)
00186 << "RawRecord didn't have RawDaq[Snarl]Header"
00187 << " - CandHeader will have bogus Run/Snarl #'s"
00188 << endl;
00189 cout << " List of RawDataBlocks in RawRecord:" << endl;
00190 TIter rbi = rawrec->GetRawBlockIter();
00191 TObject *tobj;
00192 RawDataBlock *rb;
00193 while ( (tobj = rbi()) ) {
00194 rb = dynamic_cast<RawDataBlock *>(tobj);
00195 if (!rb) continue;
00196 cout << " " << rb->ClassName() << " : "
00197 << rb->GetName()
00198 << " 0x" << hex << rb->GetBlockId().GetEncoded() << dec
00199 << endl;
00200 }
00201 }
00202 }
00203
00204
00205 CandRecord *candrec = dynamic_cast<CandRecord *>
00206 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00207 if (candrec == 0) {
00208 MSG("Digit", Msg::kDebug)
00209 << "No PrimaryCandidateRecord in MOM. Create a new one."
00210 << endl;
00211
00212
00213 CandHeader *head = new CandHeader(vldc,run,snarl);
00214
00215
00216 candrec = new CandRecord(head);
00217
00218
00219 candrec->SetName("PrimaryCandidateRecord");
00220 candrec->SetTitle("Created by DigitListModule from RawRecord.");
00221 mom->AdoptFragment(candrec);
00222 }
00223
00224 return result;
00225 }
00226
00227
00228 JobCResult DigitListModule::Reco(MomNavigator *mom)
00229 {
00230 JobCResult result(JobCResult::kPassed);
00231
00232 MSG("Digit", Msg::kVerbose) << "DigitListModule::Reco\n";
00233
00234
00235 const char *tmps = 0;
00236 Int_t tmpi = 0;
00237
00238 UInt_t liststomake = 0;
00239 const char *namedatalist = 0;
00240 const char *namemclist = 0;
00241 const char *titledatalist = 0;
00242 const char *titlemclist = 0;
00243 const char *digitlistalgorithm = 0;
00244 const char *digitlistalgconfig = 0;
00245 const char *mcdigitlistalgorithm = 0;
00246 const char *mcdigitlistalgconfig = 0;
00247
00248 Registry &r = GetConfig();
00249 if (r.Get("ListsToMake", tmpi)) liststomake = tmpi;
00250 if (r.Get("NameDataList", tmps)) namedatalist = tmps;
00251 if (r.Get("NameMCList", tmps)) namemclist = tmps;
00252 if (r.Get("TitleDataList", tmps)) titledatalist = tmps;
00253 if (r.Get("TitleMCList", tmps)) titlemclist = tmps;
00254 if (r.Get("DigitListAlgorithm", tmps)) digitlistalgorithm = tmps;
00255 if (r.Get("DigitListAlgConfig", tmps)) digitlistalgconfig = tmps;
00256 if (r.Get("MCDigitListAlgorithm", tmps)) mcdigitlistalgorithm = tmps;
00257 if (r.Get("MCDigitListAlgConfig", tmps)) mcdigitlistalgconfig = tmps;
00258
00259
00260
00261
00262
00263
00264 MSG("Digit", Msg::kDebug)
00265 << "RawRecord *rr = "
00266 << "(RawRecord *) mom->GetFragment(\"RawRecord\",0,\"DaqSnarl\");"
00267 << endl;
00268 RawRecord *rr =
00269 dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00270
00271 if (rr == 0) {
00272 MSG("Digit", Msg::kDebug)
00273 << "No RawRecord in DaqSnarl stream in MOM."
00274 << endl;
00275
00276 MSG("Digit", Msg::kDebug)
00277 << "rr = "
00278 << "(RawRecord *) mom->GetFragment(\"RawRecord\",0,\"LightInjection\");"
00279 << endl;
00280 rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"LightInjection"));
00281
00282 if (rr == 0) {
00283 MSG("Digit", Msg::kDebug)
00284 << "No RawRecord in DaqSnarl or LightInjection streams in MOM."
00285 << endl;
00286 result.SetWarning().SetFailed();
00287 return result;
00288 }
00289 }
00290
00291
00292 if ( ! rr->FindRawBlock("RawDigitDataBlock") ) {
00293 MSG("Digit", Msg::kDebug)
00294 << "No RawDigitDataBlock in RawRecord."
00295 << endl;
00296 result.SetWarning().SetFailed();
00297 return result;
00298 }
00299
00300 MSG("Digit", Msg::kDebug) << "CandContext cx(this);" << endl;
00301 CandContext cx(this, mom);
00302
00303 MSG("Digit", Msg::kDebug) << "cx.SetDataIn(rr);" << endl;
00304 cx.SetDataIn(rr);
00305
00306
00307 CandRecord *candrec = dynamic_cast<CandRecord *>
00308 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00309 if (candrec == 0) {
00310 MSG("Digit", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00311 << endl;
00312 result.SetWarning().SetFailed();
00313 return result;
00314 }
00315 else {
00316 MSG("Digit", Msg::kDebug)
00317 << "Set CandRecord pointer in CandContext." << endl;
00318 cx.SetCandRecord(candrec);
00319 }
00320
00321
00322 MSG("Digit", Msg::kDebug)
00323 << "Get Singleton instance of AlgFactory." << endl
00324 << "AlgFactory &af = AlgFactory::GetInstance();" << endl;
00325 AlgFactory &af = AlgFactory::GetInstance();
00326
00327 if (liststomake & DigitListModule::kDataList) {
00328
00329
00330 MSG("Digit", Msg::kDebug)
00331 << "Ask AlgFactory for Singleton AlgDigitList instance." << endl
00332 << "AlgHandle adlh = af.GetAlgHandle("
00333 << digitlistalgorithm << ", "
00334 << digitlistalgconfig << ");" << endl;
00335 AlgHandle adlh = af.GetAlgHandle(digitlistalgorithm,
00336 digitlistalgconfig);
00337
00338 MSG("Digit", Msg::kDebug)
00339 << "cdlh = CandDigitList::MakeCandidate(adlh, cx);" << endl;
00340 CandDigitListHandle cdlh = CandDigitList::MakeCandidate(adlh, cx);
00341 cdlh.SetName(namedatalist);
00342 cdlh.SetTitle(titledatalist);
00343
00344
00345 MSG("Digit", Msg::kDebug) << "candrec->SecureCandHandle(cdlh);"
00346 << endl;
00347 candrec->SecureCandHandle(cdlh);
00348 }
00349
00350 SimFlag::SimFlag_t simflag = rr->GetVldContext()->GetSimFlag();
00351 bool isMC = (simflag == SimFlag::kReroot ||
00352 simflag == SimFlag::kMC );
00353
00354 static bool dowarn = true;
00355 if ((liststomake & DigitListModule::kMCList) && !isMC && dowarn) {
00356 MSG("Digit",Msg::kInfo)
00357 << "DigitListModule::Reco MCList making enabled for non-MC data: "
00358 << endl
00359 << " " << *(rr->GetVldContext())
00360 << " -- no MC list will be made" << endl;
00361 dowarn = false;
00362 }
00363
00364 if (liststomake & DigitListModule::kMCList && isMC ) {
00365
00366
00367 MSG("Digit", Msg::kDebug)
00368 << "Ask AlgFactory for Singleton AlgDigitMCList instance." << endl
00369 << "AlgHandle amcdlh = af.GetAlgHandle("
00370 << mcdigitlistalgorithm << ", "
00371 << mcdigitlistalgconfig << ");" << endl;
00372 AlgHandle amcdlh = af.GetAlgHandle(mcdigitlistalgorithm,
00373 mcdigitlistalgconfig);
00374
00375 MSG("Digit", Msg::kDebug)
00376 << "cmcdlh = CandDigitList::MakeCandidate(amcdlh, cx);" << endl;
00377 CandDigitListHandle cmcdlh =
00378 CandDigitList::MakeCandidate(amcdlh,cx);
00379 cmcdlh.SetName(namemclist);
00380 cmcdlh.SetTitle(titlemclist);
00381
00382
00383 MSG("Digit", Msg::kDebug) << "candrec->SecureCandHandle(cmcdlh);"
00384 << endl;
00385 candrec->SecureCandHandle(cmcdlh);
00386 }
00387
00388 return result;
00389 }