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