Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PulserCollectorModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserCollectorModule.cxx,v 1.7 2003/02/06 20:02:58 rjn Exp $
00003 //
00004 // PulserCollectorModule.cxx
00005 //
00006 // Collects summaries, writes to database
00007 //
00008 // Author: Phil Adamson 5/2002
00009 //
00010 // $Log: PulserCollectorModule.cxx,v $
00011 // Revision 1.7  2003/02/06 20:02:58  rjn
00012 // Modified PulserSummary.h and added classes to make PulserSummary objects from Raw Data.
00013 //
00014 // Revision 1.6  2002/10/17 05:51:47  rhatcher
00015 // comment out unused variables
00016 //
00017 // Revision 1.5  2002/10/07 10:07:43  phil.adamson
00018 // Try to fix the occasional nan...
00019 //
00020 // Revision 1.4  2002/09/25 08:54:07  phil.adamson
00021 // Add Ryan's bits to make PulserSummary objects from Raw Data
00022 //
00023 // Revision 1.3  2002/08/27 15:16:16  phil.adamson
00024 // Change the PIN diode DB to use the component parts rather than the PIN Id.
00025 //
00026 // Revision 1.2  2002/08/07 16:16:51  phil.adamson
00027 // Minor cosmetic details, plus provide ZeroCorr() methods in PulserSummary.
00028 // Phil.
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; // 2 months validity for Gaincurve
00057   fDPValid = 3600*24*1;  // Driftpoint valid up to a day?
00058   fLongTime = 3600*24*365*20; // 20 yrs
00059 }
00060 
00061 PulserCollectorModule::~PulserCollectorModule()
00062 {
00063 
00064 }
00065 
00066 JobCResult PulserCollectorModule::ReferencePointReco(MomNavigator *mom) 
00067 {
00068    //Get PulserSummary...
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    //unused: int point = psl->GetPointIndex();
00078    switch(psl->GetExpectedPoints()) {
00079    case 0:
00080       // Noise - no pulsing
00081       break;
00082   case 1:
00083      // Doug Point
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      // Loop over near end data
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    //Get PulserSummary...
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       // Noise - no pulsing
00133       break;
00134    case 1:
00135       // Doug Point
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       // Loop over near end data
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       // Gain Curve
00160       // Check we're on the right curve...
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       // Loop over near end data
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          // Got curve - now write DB
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; // now!
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    //   VldTimeStamp start = vld.GetTimeStamp();
00242    //VldTimeStamp start = vld.GetTimeStamp();
00243    //VldTimeStamp end = start;
00244    //end.Add(VldTimeStamp(fDPValid,0));
00245    VldTimeStamp start = VldTimeStamp(2002,9,4,15,0,1); //Valid For all time
00246    VldTimeStamp end = VldTimeStamp(2002,10,2,0,0,0);
00247    //end.Add(VldTimeStamp(fLongTime,0));
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       //MSG("Pulser",Msg::kWarning)<<"RefDrift: " << (*it).first << endl;
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 // Process configuration commands
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 }

Generated on Mon Feb 15 11:07:26 2010 for loon by  doxygen 1.3.9.1