00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012
00013
00014
00015
00017
00018 #include <cassert>
00019
00020 #include "Algorithm/AlgConfig.h"
00021 #include "Algorithm/AlgFactory.h"
00022 #include "Algorithm/ConfigRecord.h"
00023 #include "CandData/CandHeader.h"
00024 #include "CandData/CandRecord.h"
00025 #include "CandData/RecordSetupModule.h"
00026 #include "JobControl/JobCModuleRegistry.h"
00027 #include "JobControl/JobCommand.h"
00028 #include "MessageService/MsgService.h"
00029 #include "MinosObjectMap/MomNavigator.h"
00030 #include "RawData/RawDaqSnarlHeader.h"
00031 #include "RawData/RawRecord.h"
00032 #include "Validity/VldContext.h"
00033
00034 ClassImp(RecordSetupModule)
00035
00036
00037 CVSID("$Id: RecordSetupModule.cxx,v 1.5 2007/11/10 16:24:52 schubert Exp $");
00038 JOBMODULE(RecordSetupModule, "RecordSetupModule",
00039 "Module for Data Record Setup Housekeeping");
00040
00041
00042 RecordSetupModule::RecordSetupModule()
00043 {
00044 MSG("RecSetup", Msg::kVerbose) << "RecordSetupModule::Constructor\n";
00045 }
00046
00047
00048 RecordSetupModule::~RecordSetupModule()
00049 {
00050 MSG("RecSetup", Msg::kVerbose) << "RecordSetupModule::Destructor\n";
00051 }
00052
00053
00054 void RecordSetupModule::BeginJob()
00055 {
00056 MSG("RecSetup", Msg::kVerbose) << "RecordSetupModule::BeginJob\n";
00057 }
00058
00059
00060 void RecordSetupModule::Config(const Registry& )
00061 {
00062 MSG("RecSetup", Msg::kDebug) << "RecordSetupModule::Config" << endl;
00063 }
00064
00065
00066 const Registry& RecordSetupModule::DefaultConfig() const
00067 {
00068 MSG("RecSetup", Msg::kDebug)
00069 << "RecordSetupModule::DefaultConfig" << endl;
00070
00071 static Registry r;
00072
00073 std::string name = this->JobCModule::GetName();
00074 name += ".config.default";
00075 r.SetName(name.c_str());
00076
00077 r.UnLockValues();
00078 r.Set("CandRecordName", "PrimaryCandidateRecord");
00079 r.Set("CandRecordTitle", "Created by RecordSetupModule");
00080 r.Set("ConfigRecordName", "AlgConfigRecord");
00081 r.Set("ConfigRecordTitle", "Created by AlgFactory");
00082 r.LockValues();
00083
00084 return r;
00085 }
00086
00087
00088 JobCResult RecordSetupModule::Get(MomNavigator *mom)
00089 {
00090 JobCResult result(JobCResult::kPassed);
00091
00092 MSG("RecSetup", Msg::kDebug) << "RecordSetupModule::Get\n";
00093
00094
00095 const char *tmps = 0;
00096
00097 const char *candrecordname = 0;
00098 const char *candrecordtitle = 0;
00099 const char *configrecordname = 0;
00100 const char *configrecordtitle = 0;
00101
00102 Registry &r = GetConfig();
00103 if (r.Get("CandRecordName", tmps)) candrecordname = tmps;
00104 if (r.Get("CandRecordTitle", tmps)) candrecordtitle = tmps;
00105 if (r.Get("ConfigRecordName", tmps)) configrecordname = tmps;
00106 if (r.Get("ConfigRecordTitle", tmps)) configrecordtitle = tmps;
00107
00108
00109 RawRecord *rawrec = dynamic_cast<RawRecord *>
00110 (mom->GetFragment("RawRecord"));
00111 if (!rawrec) {
00112 MSG("RecSetup", Msg::kWarning) << "No RawRecord in MOM." << endl;
00113 result.SetWarning().SetFailed();
00114 return result;
00115 }
00116
00117 VldContext vldc = rawrec->GetRawHeader()->GetVldContext();
00118 Int_t run = -1;
00119 Int_t snarl = -1;
00120
00121 const RawDaqSnarlHeader* snarlHdr =
00122 dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00123 if (snarlHdr) {
00124 run = snarlHdr->GetRun();
00125 snarl = snarlHdr->GetSnarl();
00126 } else {
00127 const RawDaqHeader* daqHdr =
00128 dynamic_cast<const RawDaqHeader*>(rawrec->GetRawHeader());
00129 if (daqHdr) {
00130 MSG("RecSetup", Msg::kWarning)
00131 << "RawRecord only had a RawDaqHeader"
00132 << " - CandHeader will have bogus Snarl #'s"
00133 << endl;
00134 run = daqHdr->GetRun();
00135 } else {
00136 MSG("RecSetup", Msg::kWarning)
00137 << "RawRecord didn't have RawDaqSnarlHeader"
00138 << " - CandHeader will have bogus Run/Snarl #'s"
00139 << endl;
00140 MSG("RecSetup", Msg::kWarning)
00141 << " List of RawDataBlocks in RawRecord:" << endl;
00142 TIter rbi = rawrec->GetRawBlockIter();
00143 TObject *tobj;
00144 RawDataBlock *rb;
00145 while ( (tobj = rbi()) ) {
00146 rb = dynamic_cast<RawDataBlock *>(tobj);
00147 if (!rb) continue;
00148 MSG("RecSetup", Msg::kWarning)
00149 << " " << rb->ClassName() << " : "
00150 << rb->GetName()
00151 << " 0x" << hex << rb->GetBlockId().GetEncoded() << dec
00152 << endl;
00153 }
00154 }
00155 }
00156
00157
00158 CandRecord *candrec = dynamic_cast<CandRecord *>
00159 (mom->GetFragment("CandRecord", candrecordname));
00160 if (candrec == 0) {
00161 MSG("RecSetup", Msg::kDebug)
00162 << "No " << candrecordname << " in MOM. Create a new one." << endl;
00163
00164
00165 CandHeader *head = new CandHeader(vldc, run, snarl);
00166
00167
00168 candrec = new CandRecord(head);
00169
00170
00171 candrec->SetName(candrecordname);
00172 candrec->SetTitle(candrecordtitle);
00173
00174 RecJobHistory& jobhist
00175 = const_cast<RecJobHistory&>(candrec->GetJobHistory());
00176 jobhist.Append(rawrec->GetJobHistory());
00177 jobhist.CreateJobRecord(RecJobHistory::kCand);
00178
00179 mom->AdoptFragment(candrec);
00180 }
00181
00182 return result;
00183 }
00184
00185
00186 JobCResult RecordSetupModule::Reco(MomNavigator *mom)
00187 {
00188 JobCResult result(JobCResult::kPassed);
00189
00190 MSG("RecSetup", Msg::kDebug) << "RecordSetupModule::Reco\n";
00191
00192
00193 const char *tmps = 0;
00194
00195 const char *candrecordname = 0;
00196 const char *candrecordtitle = 0;
00197 const char *configrecordname = 0;
00198 const char *configrecordtitle = 0;
00199
00200 Registry &r = GetConfig();
00201 if (r.Get("CandRecordName", tmps)) candrecordname = tmps;
00202 if (r.Get("CandRecordTitle", tmps)) candrecordtitle = tmps;
00203 if (r.Get("ConfigRecordName", tmps)) configrecordname = tmps;
00204 if (r.Get("ConfigRecordTitle", tmps)) configrecordtitle = tmps;
00205
00206 CandRecord* candrec =
00207 dynamic_cast<CandRecord*>(mom->GetFragment("CandRecord"));
00208 if (candrec != 0) {
00209 const VldContext* vc = candrec->GetVldContext();
00210 AlgFactory &af = AlgFactory::GetInstance();
00211 ConfigRecord *conrec = af.GetOwnedConfigRecord(vc);
00212 if (conrec) {
00213 if (configrecordname) conrec->SetName(configrecordname);
00214 if (configrecordtitle) conrec->SetTitle(configrecordtitle);
00215 mom->AdoptFragment(conrec);
00216
00217
00218 TIter criter = mom->FragmentIter();
00219 TObject *tob;
00220 MSG("RecSetup", Msg::kDebug) << "Mom Fragment List:" << endl;
00221 while ((tob = criter())) {
00222 MSG("RecSetup", Msg::kDebug)
00223 << "Fragment Class = " << tob->ClassName()
00224 << " Fragment Name = " << tob->GetName()
00225 << " Fragment Title = " << tob->GetTitle() << endl;
00226 }
00227 TIter algiter = conrec->GetConfigIter();
00228 MSG("RecSetup", Msg::kDebug) << "AlgConfig List:" << endl;
00229 while ((tob = algiter())) {
00230 MSG("RecSetup", Msg::kDebug)
00231 << "Config Class = " << tob->ClassName()
00232 << " Config Name = " << tob->GetName() << endl;
00233 }
00234
00235
00236 }
00237 }
00238 return result;
00239 }