00001 #include "BeamDataNtuple/Module/NtpBDLiteModule.h"
00002 #include "BeamDataNtuple/NtpBDLiteRecord.h"
00003 #include "BeamDataNtuple/BeamDataLiteHeader.h"
00004
00005 #include <BeamDataUtil/BDSpillAccessor.h>
00006
00007 #include <Record/RecMinos.h>
00008 #include <Record/RecMinosHdr.h>
00009 #include <Record/RecRecord.h>
00010 #include <RawData/RawRecord.h>
00011
00012 #include <MessageService/MsgService.h>
00013 #include <MinosObjectMap/MomNavigator.h>
00014
00015 #include <Validity/VldContext.h>
00016 #include <DataUtil/GetVldContext.h>
00017
00018 #include <SpillTiming/SpillTimeFinder.h>
00019
00020 #include <JobControl/JobCModuleRegistry.h>
00021
00022 #include <vector>
00023
00024 ClassImp(NtpBDLiteModule)
00025
00026 JOBMODULE(NtpBDLiteModule, "NtpBDLite",
00027 "Fill the beam monitoring data ntuple");
00028 CVSID("$Id: NtpBDLiteModule.cxx,v 1.2 2010/01/22 20:38:50 rhatcher Exp $");
00029
00030
00031
00032 NtpBDLiteModule::NtpBDLiteModule()
00033 :fInputRecordsFilter("!ConfigRecord")
00034 {}
00035
00036
00037
00038 NtpBDLiteModule::~NtpBDLiteModule()
00039 {}
00040
00041
00042
00043 const Registry& NtpBDLiteModule::DefaultConfig() const
00044 {
00045 MSG("NtpBDLite",Msg::kDebug) <<
00046 "NtpBDLiteModule::DefaultConfig" << endl;
00047
00048 static Registry r;
00049 std::string name = this->JobCModule::GetName();
00050 name += ".config.default";
00051 r.SetName(name.c_str());
00052
00053 r.UnLockValues();
00054 r.Set("InputRecordsFilter","!ConfigRecord");
00055 r.LockValues();
00056
00057 return r;
00058 }
00059
00060
00061
00062 void NtpBDLiteModule::Config(const Registry& r)
00063 {
00064 MSG("NtpBDLite",Msg::kDebug) << "NtpBDLiteModule::Config" << endl;
00065
00066 const char* tmps;
00067 if ( r.Get("InputRecordsFilter",tmps) ) fInputRecordsFilter = tmps;
00068 }
00069
00070
00071
00072 JobCResult NtpBDLiteModule::Reco(MomNavigator* mom)
00073 {
00074 MSG("NtpBDLite",Msg::kDebug)<<"In NtpBDLite::Reco"<<endl;
00075
00076
00077
00078 VldContext vldc;
00079
00080 RawRecord* daqsnarl =
00081 dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00082 if ( daqsnarl ) {
00083
00084 vldc = daqsnarl->GetHeader()->GetVldContext();
00085 } else {
00086
00087 if (fInputRecordsFilter.empty()) {
00088 MAXMSG("NtpBDLite",Msg::kWarning,5)
00089 << "No input record name set. Might pick up wrong VldContext."
00090 << endl;
00091 }
00092
00093 MSG("NtpBDLite",Msg::kDebug) << "Record filter = "
00094 << fInputRecordsFilter << endl;
00095
00096 vector<VldContext> vldcv =
00097 DataUtil::GetVldContext(mom,fInputRecordsFilter.c_str());
00098 if ( vldcv.empty() ){
00099 MSG("NtpBDLite",Msg::kDebug)
00100 << "In NtpBDLite::Reco: "
00101 << "Nothing interesting found in mom." << endl;
00102 return JobCResult::kFailed;
00103 }
00104
00105 vldc = vldcv[0];
00106
00107 for (UInt_t i=1; i<vldcv.size(); ++i) {
00108 if (vldcv[i].GetTimeStamp()<vldc.GetTimeStamp()) vldc = vldcv[i] ;
00109 }
00110 }
00111
00112 NtpBDLiteRecord* ntpbdr = FillNtpBDLite(vldc);
00113
00114
00115 mom->AdoptFragment(ntpbdr);
00116
00117 return JobCResult::kPassed;
00118
00119 }
00120
00121
00122
00123 NtpBDLiteRecord* NtpBDLiteModule::FillNtpBDLite(const VldContext& vldc)
00124 {
00125
00126 MSG("NtpBDLite",Msg::kDebug)<< "vldc = " << vldc <<endl;
00127 BeamDataLiteHeader bdh(vldc);
00128
00129 const BeamMonSpill* spill = BDSpillAccessor::Get().LoadSpill(vldc.GetTimeStamp());
00130
00131
00132 if (!spill){
00133 MSG("NtpBDLite",Msg::kDebug)<< "No spill found!" <<endl;
00134 NtpBDLiteRecord* ntpbdr = new NtpBDLiteRecord(bdh);
00135 return ntpbdr;
00136 }
00137
00138
00139
00140 VldTimeStamp spill_time = spill->SpillTime();
00141 bdh.SetEarliestTimeStamp(spill_time);
00142 VldTimeStamp vldd = spill_time-vldc.GetTimeStamp();
00143 bdh.SetTimeDiffStreamSpill(vldd.GetSeconds());
00144 bdh.SetFoundBD(1);
00145 bdh.SetStatus(spill->GetStatusInt());
00146
00147 NtpBDLiteRecord* ntpbdr = new NtpBDLiteRecord(bdh);
00148 MSG("NtpBDLite",Msg::kDebug)<< spill->fTor101 <<endl;
00149 ntpbdr->tor101 = spill->fTor101;
00150 ntpbdr->tr101d = spill->fTr101d;
00151 ntpbdr->tortgt = spill->fTortgt;
00152 ntpbdr->trtgtd = spill->fTrtgtd;
00153 ntpbdr->horncur = spill->fHornCur;
00154 for (Int_t i=0;i<6;++i){
00155 ntpbdr->bposx[i]=spill->fTargBpmX[i];
00156 ntpbdr->bposy[i]=spill->fTargBpmY[i];
00157 ntpbdr->bpmint[i]=spill->fBpmInt[i];
00158 }
00159 ntpbdr->bwidx = spill->fProfWidX;
00160 ntpbdr->bwidy = spill->fProfWidY;
00161 ntpbdr->hadint = spill->fHadInt;
00162 ntpbdr->muint1 = spill->fMuInt1;
00163 ntpbdr->muint2 = spill->fMuInt2;
00164 ntpbdr->muint3 = spill->fMuInt3;
00165
00166 SpillTimeFinder &stf = SpillTimeFinder::Instance();
00167 ntpbdr->dt_nearest = stf.GetTimeToNearestSpill(vldc);
00168 VldTimeStamp tons = stf.GetTimeOfNearestSpill(vldc);
00169 ntpbdr->nearest_sec = tons.GetSec();
00170 ntpbdr->nearest_nsec = tons.GetNanoSec();
00171
00172 return ntpbdr;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181