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.7 2009/12/02 22:14:08 rhatcher 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
00110 RawRecord * rawrec =
00111 dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord","","DaqSnarl"));
00112 if (!rawrec) rawrec =
00113 dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00114 if (!rawrec) {
00115 MSG("RecSetup", Msg::kWarning) << "No RawRecord in MOM." << endl;
00116 result.SetWarning().SetFailed();
00117 return result;
00118 }
00119
00120 VldContext vldc = rawrec->GetRawHeader()->GetVldContext();
00121 Int_t run = -1;
00122 Int_t snarl = -1;
00123
00124 const RawDaqSnarlHeader* snarlHdr =
00125 dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00126 if (snarlHdr) {
00127 run = snarlHdr->GetRun();
00128 snarl = snarlHdr->GetSnarl();
00129 } else {
00130 const RawDaqHeader* daqHdr =
00131 dynamic_cast<const RawDaqHeader*>(rawrec->GetRawHeader());
00132 if (daqHdr) {
00133 MSG("RecSetup", Msg::kWarning)
00134 << "RawRecord only had a RawDaqHeader"
00135 << " - CandHeader will have bogus Snarl #'s"
00136 << endl;
00137 run = daqHdr->GetRun();
00138 } else {
00139 MSG("RecSetup", Msg::kWarning)
00140 << "RawRecord didn't have RawDaqSnarlHeader"
00141 << " - CandHeader will have bogus Run/Snarl #'s"
00142 << endl;
00143 MSG("RecSetup", Msg::kWarning)
00144 << " List of RawDataBlocks in RawRecord:" << endl;
00145 TIter rbi = rawrec->GetRawBlockIter();
00146 TObject *tobj;
00147 RawDataBlock *rb;
00148 while ( (tobj = rbi()) ) {
00149 rb = dynamic_cast<RawDataBlock *>(tobj);
00150 if (!rb) continue;
00151 MSG("RecSetup", Msg::kWarning)
00152 << " " << rb->ClassName() << " : "
00153 << rb->GetName()
00154 << " 0x" << hex << rb->GetBlockId().GetEncoded() << dec
00155 << endl;
00156 }
00157 }
00158 }
00159
00160
00161 CandRecord *candrec = dynamic_cast<CandRecord *>
00162 (mom->GetFragment("CandRecord", candrecordname));
00163 if (candrec == 0) {
00164 MSG("RecSetup", Msg::kDebug)
00165 << "No " << candrecordname << " in MOM. Create a new one." << endl;
00166
00167
00168 CandHeader *head = new CandHeader(vldc, run, snarl);
00169
00170
00171 candrec = new CandRecord(head);
00172
00173
00174 candrec->SetName(candrecordname);
00175 candrec->SetTitle(candrecordtitle);
00176
00177 RecJobHistory& jobhist
00178 = const_cast<RecJobHistory&>(candrec->GetJobHistory());
00179 jobhist.Append(rawrec->GetJobHistory());
00180 jobhist.CreateJobRecord(RecJobHistory::kCand);
00181
00182 mom->AdoptFragment(candrec);
00183 }
00184
00185 return result;
00186 }
00187
00188
00189 JobCResult RecordSetupModule::Reco(MomNavigator *mom)
00190 {
00191 JobCResult result(JobCResult::kPassed);
00192
00193 MSG("RecSetup", Msg::kDebug) << "RecordSetupModule::Reco\n";
00194
00195
00196 const char *tmps = 0;
00197
00198 const char *candrecordname = 0;
00199 const char *candrecordtitle = 0;
00200 const char *configrecordname = 0;
00201 const char *configrecordtitle = 0;
00202
00203 Registry &r = GetConfig();
00204 if (r.Get("CandRecordName", tmps)) candrecordname = tmps;
00205 if (r.Get("CandRecordTitle", tmps)) candrecordtitle = tmps;
00206 if (r.Get("ConfigRecordName", tmps)) configrecordname = tmps;
00207 if (r.Get("ConfigRecordTitle", tmps)) configrecordtitle = tmps;
00208
00209 CandRecord* candrec =
00210 dynamic_cast<CandRecord*>(mom->GetFragment("CandRecord"));
00211 if (candrec != 0) {
00212 const VldContext* vc = candrec->GetVldContext();
00213 AlgFactory &af = AlgFactory::GetInstance();
00214 ConfigRecord *conrec = af.GetOwnedConfigRecord(vc);
00215 if (conrec) {
00216 if (configrecordname) conrec->SetName(configrecordname);
00217 if (configrecordtitle) conrec->SetTitle(configrecordtitle);
00218 mom->AdoptFragment(conrec);
00219
00220
00221 TIter criter = mom->FragmentIter();
00222 TObject *tob;
00223 MSG("RecSetup", Msg::kDebug) << "Mom Fragment List:" << endl;
00224 while ((tob = criter())) {
00225 MSG("RecSetup", Msg::kDebug)
00226 << "Fragment Class = " << tob->ClassName()
00227 << " Fragment Name = " << tob->GetName()
00228 << " Fragment Title = " << tob->GetTitle() << endl;
00229 }
00230 TIter algiter = conrec->GetConfigIter();
00231 MSG("RecSetup", Msg::kDebug) << "AlgConfig List:" << endl;
00232 while ((tob = algiter())) {
00233 MSG("RecSetup", Msg::kDebug)
00234 << "Config Class = " << tob->ClassName()
00235 << " Config Name = " << tob->GetName() << endl;
00236 }
00237
00238
00239 }
00240 }
00241 return result;
00242 }