00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "JobControl/JobCModuleRegistry.h"
00013 #include "JobControl/JobCommand.h"
00014 #include "PulserCalibration/PulserFromRawCollectorModule.h"
00015 #include "MessageService/MsgService.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "PulserCalibration/PulserFromRawSummaryList.h"
00018 #include "PulserCalibration/PulserSummary.h"
00019 #include "Validity/VldContext.h"
00020 #include "Validity/VldRange.h"
00021 #include "Validity/VldTimeStamp.h"
00022 #include "DatabaseInterface/DbiWriter.h"
00023
00024 ClassImp(PulserFromRawCollectorModule)
00025
00026
00027
00028 CVSID("$Id: PulserFromRawCollectorModule.cxx,v 1.1 2003/02/06 21:38:33 rjn Exp $");
00029 JOBMODULE(PulserFromRawCollectorModule,"PulserFromRawCollectorModule","Collect summaries, write to DB");
00030
00031 PulserFromRawCollectorModule::PulserFromRawCollectorModule()
00032 {
00033 fDoReferencePoint=0;
00034 fIdent = 0;
00035 fGCValid = 3600*24*62;
00036 fDPValid = 3600*24*1;
00037 fLongTime = 3600*24*365*20;
00038 }
00039
00040 PulserFromRawCollectorModule::~PulserFromRawCollectorModule()
00041 {
00042
00043 }
00044
00045 JobCResult PulserFromRawCollectorModule::ReferencePointReco(MomNavigator *mom)
00046 {
00047
00048 PulserFromRawSummaryList *psl = dynamic_cast<PulserFromRawSummaryList *>
00049 (mom->GetFragment("PulserFromRawSummaryList"));
00050 if (psl==0) {
00051 MSG("Pulser",Msg::kVerbose) <<"No pulser summary list here\n";
00052 return JobCResult::kFailed;
00053 }
00054 MSG("Pulser",Msg::kDebug) <<"Got pulser summary "<<psl->GetPointIndex()
00055 <<" of "<<psl->GetExpectedPoints()<<endl;
00056
00057 switch(psl->GetExpectedPoints()) {
00058 case 0:
00059
00060 break;
00061 case 1:
00062
00063 MSG("Pulser",Msg::kDebug) <<"Doug Point"<<endl;
00064 ;
00065 fHighPinRef.New(psl->GetAggregateNo(),
00066 psl->GetHighPin().GetPinDiodeId(),
00067 psl->GetHighPin());
00068 fLowPinRef.New(psl->GetAggregateNo(),
00069 psl->GetLowPin().GetPinDiodeId(),
00070 psl->GetLowPin());
00071
00072 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
00073 it!=psl->GetNearEnd(); it++) {
00074 fNearMapRef[(*it).first].New(psl->GetAggregateNo(),
00075 (*it).second.GetStripEndId().BuildPlnStripEndKey(),
00076 (*it).second);
00077 }
00078 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
00079 it!=psl->GetFarEnd(); it++) {
00080 fFarMapRef[(*it).first].New(psl->GetAggregateNo(),
00081 (*it).second.GetStripEndId().BuildPlnStripEndKey(),
00082 (*it).second);
00083 }
00084 WriteReferenceDriftData(psl);
00085 break;
00086 default:
00087 return JobCResult::kFailed;
00088 }
00089 return JobCResult::kPassed;
00090 }
00091
00092
00093
00094 JobCResult PulserFromRawCollectorModule::Reco(MomNavigator *mom)
00095 {
00096 if(fDoReferencePoint) {
00097 return ReferencePointReco(mom);
00098 }
00099
00100 PulserFromRawSummaryList *psl = dynamic_cast<PulserFromRawSummaryList *>
00101 (mom->GetFragment("PulserFromRawSummaryList"));
00102 if (psl==0) {
00103 MSG("Pulser",Msg::kVerbose) <<"No pulser summary list here\n";
00104 return JobCResult::kFailed;
00105 }
00106 MSG("Pulser",Msg::kDebug) <<"Got pulser summary "<<psl->GetPointIndex()
00107 <<" of "<<psl->GetExpectedPoints()<<endl;
00108 int point = psl->GetPointIndex();
00109 switch(psl->GetExpectedPoints()) {
00110 case 0:
00111
00112 break;
00113 case 1:
00114
00115 MSG("Pulser",Msg::kDebug) <<"Doug Point"<<endl;
00116 fHighPinDrift.New(psl->GetAggregateNo(),
00117 psl->GetHighPin().GetPinDiodeId(),
00118 psl->GetHighPin());
00119 fLowPinDrift.New(psl->GetAggregateNo(),
00120 psl->GetLowPin().GetPinDiodeId(),
00121 psl->GetLowPin());
00122
00123 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
00124 it!=psl->GetNearEnd(); it++) {
00125 fNearMapDrift[(*it).first].New(psl->GetAggregateNo(),
00126 (*it).second.GetStripEndId().BuildPlnStripEndKey(),
00127 (*it).second);
00128 }
00129 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
00130 it!=psl->GetFarEnd(); it++) {
00131 fFarMapDrift[(*it).first].New(psl->GetAggregateNo(),
00132 (*it).second.GetStripEndId().BuildPlnStripEndKey(),
00133 (*it).second);
00134 }
00135 WriteRawDriftData(psl);
00136 break;
00137 default:
00138
00139
00140 if (fIdent!=0 && fIdent!=psl->GetIdent()) {
00141 MSG("Pulser",Msg::kWarning)<< "Conflicting gaincurves in same place!\n";
00142 }
00143 if (fIdent==0) {
00144 fHighPinCurve.New(psl->GetAggregateNo(),psl->GetExpectedPoints(),
00145 psl->GetHighPin().GetPinDiodeId());
00146 fLowPinCurve.New(psl->GetAggregateNo(),psl->GetExpectedPoints(),
00147 psl->GetLowPin().GetPinDiodeId());
00148 fIdent = psl->GetIdent();
00149 }
00150 MSG("Pulser",Msg::kDebug) <<"Gain Curve"<<endl;
00151
00152 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
00153 it!=psl->GetNearEnd(); it++) {
00154 if (!fNearMapCurve.count((*it).first)) {
00155 fNearMapCurve[(*it).first].New(psl->GetAggregateNo(),
00156 psl->GetExpectedPoints(),
00157 (*it).first);
00158 }
00159 fNearMapCurve[(*it).first].AddPoint(point,(*it).second);
00160 }
00161 for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
00162 it!=psl->GetFarEnd(); it++) {
00163 if (!fFarMapCurve.count((*it).first)) {
00164 fFarMapCurve[(*it).first].New(psl->GetAggregateNo(),
00165 psl->GetExpectedPoints(),
00166 (*it).first);
00167 }
00168 fFarMapCurve[(*it).first].AddPoint(point,(*it).second);
00169 }
00170 fHighPinCurve.AddPoint(point,psl->GetHighPin());
00171 fLowPinCurve.AddPoint(point,psl->GetLowPin());
00172 if (point == psl->GetExpectedPoints()||point==37){
00173
00174 WriteRawCurveData(psl);
00175 }
00176
00177 }
00178 return JobCResult::kPassed;
00179
00180 }
00181
00182
00183
00184 void PulserFromRawCollectorModule::WriteRawCurveData(PulserFromRawSummaryList *psl)
00185 {
00186 VldContext vld = psl->GetVldContext();
00187 VldTimeStamp start = vld.GetTimeStamp();
00188 VldTimeStamp end = start;
00189 end.Add(VldTimeStamp(fGCValid,0));
00190 VldRange vr(vld.GetDetector(),vld.GetSimFlag(),start,
00191 end, "PulserFromRawCollectorModule");
00192 VldTimeStamp create;
00193 int aggNo = psl->GetAggregateNo();
00194 DbiWriter<PulserRawGain> writer(vr,aggNo,0,start);
00195 MSG("Pulser",Msg::kDebug)<<"Writing database "<<psl->GetVldContext()<<endl;
00196 for (std::map <Int_t,PulserRawGain>::const_iterator
00197 it = fNearMapCurve.begin(); it!=fNearMapCurve.end(); it++) {
00198 writer << (*it).second;
00199 }
00200 writer.Close();
00201 DbiWriter<PulserRawGainF> fwriter(vr,aggNo,0,start);
00202 for (std::map <Int_t,PulserRawGainF>::const_iterator
00203 it = fFarMapCurve.begin(); it!=fFarMapCurve.end(); it++) {
00204 fwriter << (*it).second;
00205 }
00206 fwriter.Close();
00207 DbiWriter<PulserRawGainPin> w(vr,aggNo,0,start);
00208 w << fHighPinCurve;
00209 w << fLowPinCurve;
00210 w.Close();
00211 fNearMapCurve.clear();
00212 fFarMapCurve.clear();
00213 fIdent=0;
00214 }
00215
00216 void PulserFromRawCollectorModule::WriteReferenceDriftData(PulserFromRawSummaryList *psl)
00217 {
00218 VldContext vld = psl->GetVldContext();
00219
00220
00221
00222
00223 VldTimeStamp start = VldTimeStamp(2002,9,4,15,0,1);
00224 VldTimeStamp end = VldTimeStamp(2002,10,2,0,0,0);
00225
00226 VldRange vr(vld.GetDetector(),vld.GetSimFlag(),start,
00227 end, "PulserFromRawCollectorModule");
00228 VldTimeStamp create;
00229 int aggNo = psl->GetAggregateNo();
00230 DbiWriter<PulserRefDrift> writer(vr,aggNo,0,start);
00231 MSG("Pulser",Msg::kDebug)<<"Writing database "<<psl->GetVldContext()<<endl;
00232 for (std::map <Int_t,PulserRefDrift>::const_iterator
00233 it = fNearMapRef.begin(); it!=fNearMapRef.end(); it++) {
00234
00235 writer << (*it).second;
00236 }
00237 writer.Close();
00238 DbiWriter<PulserRefDriftF> fwriter(vr,aggNo,0,start);
00239 for (std::map <Int_t,PulserRefDriftF>::const_iterator
00240 it = fFarMapRef.begin(); it!=fFarMapRef.end(); it++) {
00241 fwriter << (*it).second;
00242 }
00243 fwriter.Close();
00244 DbiWriter<PulserRefDriftPin> w(vr,aggNo,0,start);
00245 w << fHighPinRef;
00246 w << fLowPinRef;
00247 w.Close();
00248 fNearMapRef.clear();
00249 fFarMapRef.clear();
00250 }
00251
00252
00253 void PulserFromRawCollectorModule::WriteRawDriftData(PulserFromRawSummaryList *psl)
00254 {
00255 VldContext vld = psl->GetVldContext();
00256 VldTimeStamp start = vld.GetTimeStamp();
00257 VldTimeStamp end = start;
00258 end.Add(VldTimeStamp(fDPValid,0));
00259 VldRange vr(vld.GetDetector(),vld.GetSimFlag(),start,
00260 end, "PulserFromRawCollectorModule");
00261 VldTimeStamp create;
00262 int aggNo = psl->GetAggregateNo();
00263 DbiWriter<PulserRawDrift> writer(vr,aggNo,0,start);
00264 MSG("Pulser",Msg::kDebug)<<"Writing database "<<psl->GetVldContext()<<endl;
00265 for (std::map <Int_t,PulserRawDrift>::const_iterator
00266 it = fNearMapDrift.begin(); it!=fNearMapDrift.end(); it++) {
00267 writer << (*it).second;
00268 }
00269 writer.Close();
00270 DbiWriter<PulserRawDriftF> fwriter(vr,aggNo,0,start);
00271 for (std::map <Int_t,PulserRawDriftF>::const_iterator
00272 it = fFarMapDrift.begin(); it!=fFarMapDrift.end(); it++) {
00273 fwriter << (*it).second;
00274 }
00275 fwriter.Close();
00276 DbiWriter<PulserRawDriftPin> w(vr,aggNo,0,start);
00277 w << fHighPinDrift;
00278 w << fLowPinDrift;
00279 w.Close();
00280 fNearMapDrift.clear();
00281 fFarMapDrift.clear();
00282 }
00283
00284
00285 void PulserFromRawCollectorModule::HandleCommand(JobCommand *command)
00286 {
00287
00288
00289 TString cmd = command->PopCmd();
00290
00291 MSG("Pulser", Msg::kDebug)
00292 << "PulserFromRawCollectorModule:HandleCommand: " << cmd << endl;
00293 if (cmd == "Reference") {
00294 fDoReferencePoint=1;
00295 }
00296 else {
00297 MSG("Pulser", Msg::kWarning)
00298 << "Unrecognized Command: " << cmd << endl;
00299 }
00300
00301 }