PulserDBModule Class Reference

#include <PulserDBModule.h>

Inheritance diagram for PulserDBModule:
JobCModule

List of all members.

Public Member Functions

 PulserDBModule ()
 ~PulserDBModule ()
JobCResult Reco (MomNavigator *mom)
void EndRun ()
void BeginRun ()
void EndFile ()
void BeginFile ()
void EndJob ()

Private Member Functions

void DriftPoint (PulserSummaryList *psl)
void GainCurve (PulserSummaryList *psl)
bool AddToGC (PulserSummaryList *psl)
void DropGC ()
bool MergeBack ()
bool MergeForward ()
bool WriteGC ()
bool WriteTempGC ()
bool DoWriteGC (int temp)
template<class T >
bool DeleteGC (DbiResultPtr< T > *p)
template<class T >
bool GetCurrentFromDB (DbiResultPtr< T > &rp, VldContext &vld, int task)

Private Attributes

int fGCValid
int fDPValid
int fLongTime
bool fRunStart
bool fFileStart
std::map< Int_t, PulserGainfGainMapNear
std::map< Int_t, PulserGainfGainMapFar
PulserGainPinfGainPin [2]
PulserGainLogfGainLog
VldContext fCurrentContext

Static Private Attributes

static const int fCodeVersion = 0

Detailed Description

Definition at line 37 of file PulserDBModule.h.


Constructor & Destructor Documentation

PulserDBModule::PulserDBModule (  ) 

Definition at line 101 of file PulserDBModule.cxx.

00101                               : fGainLog(0)
00102 {
00103   fGCValid = 3600*24*62; // 2 months validity for Gaincurve
00104   fDPValid = 3600*24*1;  // Driftpoint valid up to a day?
00105   fLongTime = 3600*24*365*20; // 20 yrs
00106   fRunStart = false;
00107   fFileStart = false;
00108   fGainPin[0] = fGainPin[1] = 0;
00109 }

PulserDBModule::~PulserDBModule (  ) 

Definition at line 111 of file PulserDBModule.cxx.

00112 {
00113 
00114 }


Member Function Documentation

bool PulserDBModule::AddToGC ( PulserSummaryList psl  )  [private]

Definition at line 596 of file PulserDBModule.cxx.

References PulserGainLog::Add(), PulserGainPin::AddPoint(), fCodeVersion, fGainLog, fGainMapFar, fGainMapNear, fGainPin, PulserSummaryList::GetAggregateNo(), PulserGainLog::GetAggregateNo(), PulserSummaryList::GetExpectedPoints(), PulserSummaryList::GetFarBegin(), PulserSummaryList::GetFarEnd(), PulserSummaryList::GetHighPin(), PulserSummaryList::GetLowPin(), PulserSummaryList::GetNearBegin(), PulserSummaryList::GetNearEnd(), PulserSummaryList::GetPointIndex(), it, Msg::kDebug, Msg::kFatal, and MSG.

Referenced by GainCurve().

00597 {
00598   // Test to see whether we can add the pulse point in the PulserSummaryList
00599   // to the current gaincurve
00600 
00601   // If we can, make the addition and return true, else return false.
00602   if (!fGainLog) {
00603     // We don't have a gaincurve object currently, either because we just started
00604     // running, or we just dropped a gaincurve
00605     // With a new gainlog, Add(psl) will always succeed
00606     fGainLog = new PulserGainLog(fCodeVersion);
00607     fGainPin[0] = new PulserGainPin();
00608     fGainPin[1] = new PulserGainPin();
00609   }
00610   if (fGainLog->Add(psl)) {
00611     //    MSG("Pulser",Msg::kDebug)<<"In AddToGC (1).  GetAggNo: " <<  ", " << fGainLog->GetAggNo() << endl; 
00612     MSG("Pulser",Msg::kDebug)<<"In AddToGC (1).  GetAggregateNo: " <<  ", " << fGainLog->GetAggregateNo() << endl; 
00613 
00614     // If we successfully add to the GainLog, we must be able to add the data
00615     // too, by construction. If we can't, something's gone horribly wrong.
00616     bool result=true;
00617     result &= fGainPin[0]->AddPoint(psl->GetPointIndex(),psl->GetHighPin(),psl->GetAggregateNo(),psl->GetExpectedPoints());
00618     result &= fGainPin[1]->AddPoint(psl->GetPointIndex(),psl->GetLowPin(),psl->GetAggregateNo(),psl->GetExpectedPoints());
00619     for (std::map<Int_t,PulserSummary>::const_iterator it = psl->GetNearBegin(); it!=psl->GetNearEnd() ; it++) {
00620 
00621       result &= fGainMapNear[(*it).first].AddPoint(psl->GetPointIndex(),(*it).second,psl->GetAggregateNo(),psl->GetExpectedPoints());
00622     }
00623     for (std::map<Int_t,PulserSummary>::const_iterator it = psl->GetFarBegin();
00624          it!=psl->GetFarEnd() ; it++) {
00625 
00626       result &= fGainMapFar[(*it).first].AddPoint(psl->GetPointIndex(),(*it).second,psl->GetAggregateNo(),psl->GetExpectedPoints());
00627     }
00628     if (!result) {
00629       MSG("Pulser",Msg::kFatal)<<"Internal inconsistency. This can't happen.\n"; 
00630       assert(0);
00631     }
00632     
00633     MSG("Pulser",Msg::kDebug)<<"In AddToGC. Aggregate Number(psl): " << psl->GetAggregateNo() << endl; 
00634     //    MSG("Pulser",Msg::kDebug)<<"In AddToGC. Aggregate Number(log): " << fGainLog->GetAggNo() << endl; 
00635     MSG("Pulser",Msg::kDebug)<<"In AddToGC. Aggregate Number(log): " << fGainLog->GetAggregateNo() << endl; 
00636     
00637     return result;
00638   }
00639   return false;
00640 }

void PulserDBModule::BeginFile (  )  [virtual]

Implement for notification of begin of file. See GetCurrentFile().

Reimplemented from JobCModule.

Definition at line 257 of file PulserDBModule.cxx.

References fFileStart, Msg::kDebug, and MSG.

00258 {
00259   fFileStart = true;
00260   MSG("Pulser",Msg::kDebug) << "PulserDBModule::BeginFile()\n";
00261 }

void PulserDBModule::BeginRun (  )  [virtual]

Implement for notification of begin of run (meaningful for Daq data only). See GetCurrentRun().

Reimplemented from JobCModule.

Definition at line 192 of file PulserDBModule.cxx.

References fRunStart, Msg::kDebug, and MSG.

00193 {
00194   fRunStart = true;
00195   MSG("Pulser",Msg::kDebug) << "PulserDBModule::BeginRun()\n";
00196 }

template<class T >
bool PulserDBModule::DeleteGC ( DbiResultPtr< T > *  p  )  [inline, private]

Definition at line 643 of file PulserDBModule.cxx.

References DbiTableProxy::GetCache(), DbiValidityRec::GetDbNo(), DbiTableProxy::GetDBProxy(), DbiValidityRec::GetSeqNo(), DbiResultPtr< T >::GetValidityRec(), DbiDBProxy::RemoveSeqNo(), DbiCache::SetStale(), and DbiResultPtr< T >::TableProxy().

Referenced by MergeBack(), and WriteTempGC().

00644 {
00645   const DbiValidityRec *vrec = p->GetValidityRec();
00646   int seqno = vrec->GetSeqNo();
00647   int dbno = vrec->GetDbNo();
00648 
00649   DbiTableProxy &t = p->TableProxy();
00650   const DbiDBProxy &dbproxy = t.GetDBProxy();
00651 
00652   
00653   bool result = dbproxy.RemoveSeqNo(seqno,dbno);
00654   t.GetCache()->SetStale();
00655   return result;
00656 }

bool PulserDBModule::DoWriteGC ( int  temp  )  [private]

Definition at line 534 of file PulserDBModule.cxx.

References VldTimeStamp::Add(), DbiWriter< T >::Close(), fCodeVersion, fCurrentContext, fGainLog, fGainMapFar, fGainMapNear, fGainPin, fGCValid, PulserGainLog::GetAggregateNo(), DbiTableProxy::GetCache(), VldContext::GetDetector(), VldContext::GetSimFlag(), PulserGainLog::GetTimeStart(), it, Msg::kDebug, Pulser::kFarEnd, Pulser::kNearEnd, Pulser::kTempData, MSG, DbiWriter< T >::SetDbName(), DbiCache::SetStale(), and DbiWriter< T >::TableProxy().

Referenced by WriteGC(), and WriteTempGC().

00535 {
00536   VldTimeStamp start = fGainLog->GetTimeStart();
00537   VldTimeStamp end = start;
00538   end.Add(VldTimeStamp(fGCValid,0));
00539   VldRange vr(fCurrentContext.GetDetector(),fCurrentContext.GetSimFlag(),start,
00540               end, "PulserDBModule");
00541   VldTimeStamp create = start; 
00542   create.Add(VldTimeStamp(fCodeVersion,0));
00543   //  int aggNo = fGainLog->GetAggNo();
00544   int aggNo = fGainLog->GetAggregateNo();
00545   MSG("Pulser",Msg::kDebug)<<"In DoWriteGC. Aggregate Number: "<<aggNo<<endl;
00546   
00547   //  DbiWriter<PulserGainLog> logwriter(vr,-1,temp, create);
00548   // Use Overlay Creation date and write aggregateno 
00549   DbiWriter<PulserGainLog> logwriter(vr,aggNo,temp);
00550   if (temp & Pulser::kTempData) logwriter.SetDbName("litemp");
00551   MSG("Pulser",Msg::kDebug)<<"Writing database "<<fCurrentContext
00552                            <<" gaincurve starts at "<<start<<endl;
00553   logwriter << *fGainLog;
00554   //  DbiWriter<PulserGain> writer(vr,aggNo,Pulser::kNearEnd | temp, create);
00555   // Use Overlay Creation date
00556   DbiWriter<PulserGain> writer(vr,aggNo,Pulser::kNearEnd | temp);
00557   if (temp & Pulser::kTempData) writer.SetDbName("litemp");
00558   for (std::map<Int_t,PulserGain>::iterator it = fGainMapNear.begin();
00559        it !=fGainMapNear.end(); it++) {
00560     PulserGain &pg = (*it).second;
00561     writer << pg;
00562   }
00563 
00564   //  DbiWriter<PulserGain> fwriter(vr,aggNo,Pulser::kFarEnd | temp, create);
00565   //  Use Overlay Creation date
00566   DbiWriter<PulserGain> fwriter(vr,aggNo,Pulser::kFarEnd | temp);
00567   if (temp & Pulser::kTempData) fwriter.SetDbName("litemp");
00568    for (std::map<Int_t,PulserGain>::iterator it = fGainMapFar.begin();
00569        it !=fGainMapFar.end(); it++) {
00570     PulserGain &pg = (*it).second;
00571     fwriter << pg;
00572   }
00573 
00574    //  DbiWriter<PulserGainPin> pwriter(vr,aggNo,Pulser::kNearEnd | temp, create);
00575    //  Use Overlay Creation date
00576   DbiWriter<PulserGainPin> pwriter(vr,aggNo,Pulser::kNearEnd | temp);
00577   if (temp & Pulser::kTempData) pwriter.SetDbName("litemp");
00578   pwriter << *(fGainPin[0]) << *(fGainPin[1]);
00579 
00580   bool result=true;
00581   logwriter.TableProxy().GetCache()->SetStale();
00582   pwriter.TableProxy().GetCache()->SetStale();
00583   fwriter.TableProxy().GetCache()->SetStale();
00584   writer.TableProxy().GetCache()->SetStale();
00585 
00586   result &=logwriter.Close();
00587   result &=pwriter.Close();
00588   result &=fwriter.Close();
00589   result &=writer.Close();
00590   return result;
00591   
00592 
00593 
00594 }

void PulserDBModule::DriftPoint ( PulserSummaryList psl  )  [private]

Definition at line 268 of file PulserDBModule.cxx.

References VldTimeStamp::Add(), DbiWriter< T >::Close(), fCodeVersion, fCurrentContext, fDPValid, PulserSummaryList::GetAggregateNo(), VldContext::GetDetector(), PulserSummaryList::GetFarBegin(), PulserSummaryList::GetFarEnd(), PulserSummaryList::GetHighPin(), PulserSummaryList::GetLowPin(), PulserSummaryList::GetNearBegin(), PulserSummaryList::GetNearEnd(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), PulserSummaryList::GetVldContext(), it, Msg::kDebug, Pulser::kFarEnd, Pulser::kNearEnd, and MSG.

00269 {
00270   fCurrentContext = psl->GetVldContext();
00271   VldTimeStamp start = fCurrentContext.GetTimeStamp();
00272   VldTimeStamp end = start;
00273   end.Add(VldTimeStamp(fDPValid,0));
00274   VldRange vr(fCurrentContext.GetDetector(),fCurrentContext.GetSimFlag(),start,
00275               end, "PulserDBModule");
00276   VldTimeStamp create = start; 
00277   create.Add(VldTimeStamp(fCodeVersion,0));
00278   int aggNo = psl->GetAggregateNo();
00279   //  DbiWriter<PulserDrift> writer(vr,aggNo,Pulser::kNearEnd,create); // Task==1: near end
00280   // Use Overlay Creation date
00281   DbiWriter<PulserDrift> writer(vr,aggNo,Pulser::kNearEnd); // Task==1: near end
00282   MSG("Pulser",Msg::kDebug)<<"Writing database "<<fCurrentContext<<endl;
00283   for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
00284        it!=psl->GetNearEnd(); it++) {
00285     const PulserSummary &ps = (*it).second;
00286     PulserDrift pd(psl->GetAggregateNo(),ps);
00287     writer<<pd;
00288   }
00289   //  DbiWriter<PulserDrift> fwriter(vr,aggNo,Pulser::kFarEnd,create); // Task==2: far end
00290   // Use Overlay Creation date
00291   DbiWriter<PulserDrift> fwriter(vr,aggNo,Pulser::kFarEnd); // Task==2: far end
00292   for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
00293        it!=psl->GetFarEnd(); it++) {
00294     const PulserSummary &ps = (*it).second;
00295     PulserDrift pd(psl->GetAggregateNo(),ps);
00296     fwriter<<pd;
00297   }
00298   //  DbiWriter<PulserDriftPin> pwriter(vr,aggNo,Pulser::kNearEnd,create);
00299   // Use Overlay Creation date
00300   DbiWriter<PulserDriftPin> pwriter(vr,aggNo,Pulser::kNearEnd);
00301   PulserDriftPin pdp(psl->GetAggregateNo(),psl->GetHighPin());
00302   PulserDriftPin pdpl(psl->GetAggregateNo(),psl->GetLowPin());
00303   pwriter << pdp << pdpl;
00304   
00305   pwriter.Close();
00306   fwriter.Close();
00307   writer.Close();
00308 }

void PulserDBModule::DropGC (  )  [private]

Definition at line 486 of file PulserDBModule.cxx.

References fGainLog, fGainMapFar, fGainMapNear, and fGainPin.

Referenced by EndRun(), and GainCurve().

00487 {
00488   // Silently drop current gaincurve from memory
00489   fGainMapNear.clear();
00490   fGainMapFar.clear();
00491   delete fGainPin[0];
00492   delete fGainPin[1];
00493   delete fGainLog;
00494   fGainPin[0]=0;
00495   fGainPin[1]=0;
00496   fGainLog=0;
00497 }

void PulserDBModule::EndFile (  )  [virtual]

Implement for notification of end of file. See GetLastFile().

Reimplemented from JobCModule.

Definition at line 263 of file PulserDBModule.cxx.

References Msg::kInfo, and MSG.

Referenced by Reco().

00264 {
00265   MSG("Pulser",Msg::kInfo) << "PulserDBModule::EndFile()\n";
00266 }

void PulserDBModule::EndJob (  )  [virtual]

Implement for notification of end of job

Reimplemented from JobCModule.

Definition at line 251 of file PulserDBModule.cxx.

References EndRun(), Msg::kDebug, and MSG.

00252 {
00253   MSG("Pulser",Msg::kDebug) << "PulserDBModule::EndJob()\n";
00254   EndRun();
00255 }

void PulserDBModule::EndRun (  )  [virtual]

Implement for notification of end of run (meaningful for Daq data only). See GetLastRun().

Reimplemented from JobCModule.

Definition at line 198 of file PulserDBModule.cxx.

References DropGC(), fGainLog, GainCurve(), PulserSummaryList::GetExpectedPoints(), PulserSummaryList::GetTriggers(), PulserGainLog::IsComplete(), Msg::kDebug, Msg::kInfo, MergeBack(), MergeForward(), MSG, WriteGC(), and WriteTempGC().

Referenced by EndJob(), and Reco().

00199 {
00200   MSG("Pulser",Msg::kDebug) << "PulserDBModule::EndRun()\n";
00201 
00202   if (fGainLog) {
00203     MergeBack(); 
00204     MergeForward(); 
00205     if (fGainLog->IsComplete()) {
00206       WriteGC();
00207       DropGC();
00208     }
00209   WriteTempGC();
00210   }
00211 
00212   PulserSummaryList *psl = dynamic_cast<PulserSummaryList *>(gROOT->GetRootFolder()->FindObject("Loon/Pulser/PulserSummaryList"));
00213   
00214   if (psl){
00215     MSG("Pulser",Msg::kDebug) << "PulserDBModule::EndRun(): rescue the last point"<<endl;
00216 
00217     switch(psl->GetExpectedPoints()) {
00218     case 0:
00219       // noise - no pulsing
00220       MSG("Pulser",Msg::kInfo) <<"Dropping LI summary with "<<
00221         psl->GetTriggers()<<" pulses: Pulser is off!"<<endl;
00222       break;
00223     case 1: 
00224       // Drift Point
00225       // No longer write drift points. CPW 23/1/06
00226       MSG("Pulser",Msg::kInfo) <<"Doug Point: not written"<<endl;
00227       //      DriftPoint(psl);
00228       break;
00229     default:
00230       // Anything bigger than 1 is a gaincurve
00231       MSG("Pulser",Msg::kInfo) <<"GainCurve"<<endl;
00232       GainCurve(psl);
00233       break;
00234     };
00235     delete psl;
00236   }
00237 
00238   TFolder *lf = dynamic_cast<TFolder *>
00239     (gROOT->GetRootFolder()->FindObject("Loon"));
00240   if (lf) {
00241     TObject *obj = lf->FindObject("Pulser");
00242     if (obj){
00243       lf->Remove(obj);
00244       MSG("Pulser",Msg::kDebug) << "PulserDBModule::EndRun(): directory Pulser removed"<<endl;
00245     }
00246   }
00247 
00248 
00249 }

void PulserDBModule::GainCurve ( PulserSummaryList psl  )  [private]

Definition at line 312 of file PulserDBModule.cxx.

References AddToGC(), DropGC(), fCurrentContext, fFileStart, fGainLog, fRunStart, PulserSummaryList::GetVldContext(), PulserGainLog::IsComplete(), Msg::kDebug, Msg::kError, MergeBack(), MSG, and WriteGC().

Referenced by EndRun(), and Reco().

00313 {
00314   fCurrentContext = psl->GetVldContext();
00315   if (AddToGC(psl)) {
00316     // This point is OK to add to current GainCurve
00317     // Nothing special to do here
00318     MSG("Pulser",Msg::kDebug)<<"Added point to GC\n";
00319   } 
00320   else {
00321     if (!fFileStart) {
00322       // If we can't add the current point to our GainCurve, 
00323       // and we're not at the start of a file, then something
00324       // has gone pear-shaped.
00325 
00326       // The best we can do is to raise an Error, and then throw away the 
00327       // existing part-gaincurve and start from scratch. The only sensible
00328       // way of getting to this condition is if someone kills liMaster and 
00329       // restarts it in the middle of a run.
00330       MSG("Pulser",Msg::kError) <<"New point does not match existing gaincurve\n";
00331       MSG("Pulser",Msg::kError) <<"Dropping existing GC and trying to carry on\n";
00332       MSG("Pulser",Msg::kError) <<"Please report this error to the experts now\n";
00333       DropGC();
00334       AddToGC(psl);
00335     }
00336     if (fFileStart) {
00337       // This is probably OK, and just means that we're processing files 
00338       // out of order, or are missing a file. The current GC will have
00339       // been written to the temp table at the end of the previous file, 
00340       // so we can just drop it and run the new one.
00341       DropGC();
00342       AddToGC(psl);
00343     }
00344   }
00345   fFileStart = false;
00346   fRunStart = false;
00347   // Test GainCurve for completeness
00348   // If Gaincurve is complete, wite to DB (and then delete temp GCs)
00349 
00350   // I think we need a GainCurve info object, that can have all the 
00351   // pulse heights and so on in it.
00352 
00353   // Then I can do
00354   MergeBack(); 
00355   if (fGainLog->IsComplete()) {
00356     WriteGC();
00357     DropGC();
00358   }
00359 
00360 }

template<class T >
bool PulserDBModule::GetCurrentFromDB ( DbiResultPtr< T > &  rp,
VldContext vld,
int  task 
) [inline, private]

Definition at line 660 of file PulserDBModule.cxx.

References fGainLog, PulserGainLog::GetFirstPoint(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), and DbiResultPtr< T >::NewQuery().

Referenced by WriteTempGC().

00661 {
00662   rp.NewQuery(vld,task);
00663   if (rp.GetNumRows()==0) return false;
00664 
00665   const T* obj = rp.GetRow(0);
00666   if (obj->GetFirstPoint()!=fGainLog->GetFirstPoint()) return false;
00667 
00668   return true;
00669 
00670 }

bool PulserDBModule::MergeBack (  )  [private]

Definition at line 363 of file PulserDBModule.cxx.

References PulserGain::Add(), VldTimeStamp::Add(), PulserGainLog::Add(), DeleteGC(), fCurrentContext, fGainLog, fGainMapFar, fGainMapNear, fGainPin, VldContext::GetDetector(), PulserGainLog::GetFirstPoint(), PulserGainPin::GetIndex(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRowByIndex(), VldContext::GetSimFlag(), PulserGain::GetStripEnd(), PulserGainLog::GetTimeStart(), it, Msg::kError, Detector::kFar, Pulser::kFarEnd, Msg::kFatal, Pulser::kNearEnd, Pulser::kTempData, MSG, and WriteTempGC().

Referenced by EndRun(), and GainCurve().

00364 {
00365   if (fGainLog->GetFirstPoint()==1) return false;
00366   
00367   // Try to merge here
00368   VldTimeStamp ts = fGainLog->GetTimeStart();
00369   ts.Add(VldTimeStamp(-2,0));
00370   VldContext vld(fCurrentContext.GetDetector(),
00371                  fCurrentContext.GetSimFlag(),ts);
00372   DbiResultPtr<PulserGainLog> pglrp(vld,Pulser::kTempData);
00373   // need to check that I haven't got a gap, and that it's the right piece
00374   if (pglrp.GetNumRows()==0) return false; // No valid data available
00375   
00376   const PulserGainLog *pgl = pglrp.GetRow(0);
00377   if (fGainLog->Add(*pgl)) {
00378     // Can add gain log, so let's go and add the data too
00379     DbiResultPtr<PulserGain> nearend(vld,Pulser::kNearEnd | Pulser::kTempData);
00380     if (nearend.GetNumRows()==0) {
00381       MSG("Pulser",Msg::kFatal)<< "Database Integrity Error."<<endl;
00382       MSG("Pulser",Msg::kFatal)<< "Near End Gain doesn't match GainLog"<<endl;
00383       return false;
00384     }
00385     for (std::map<Int_t,PulserGain>::iterator it = fGainMapNear.begin();
00386        it !=fGainMapNear.end(); it++) {
00387       PulserGain &pg = (*it).second;
00388       const PulserGain * otherpg = nearend.GetRowByIndex(pg.GetStripEnd());
00389       if (!pg.Add(*otherpg)) {
00390         // Inconsistency - fatal error!
00391         MSG("Pulser",Msg::kFatal)<<"Could add GainLog but not Gain for stripend with key "<<pg.GetStripEnd()<<endl;
00392         assert(0);
00393       }
00394     }
00395 
00396     DbiResultPtr<PulserGain> farend(vld,Pulser::kFarEnd | Pulser::kTempData);
00397     if (vld.GetDetector()==Detector::kFar){
00398       if (farend.GetNumRows()==0) {
00399         MSG("Pulser",Msg::kFatal)<< "Database Integrity Error."<<endl;
00400         MSG("Pulser",Msg::kFatal)<< "Far End Gain doesn't match GainLog"<<endl;
00401         return false;
00402       }
00403       for (std::map<Int_t,PulserGain>::iterator it = fGainMapFar.begin();
00404            it !=fGainMapFar.end(); it++) {
00405         PulserGain &pg = (*it).second;
00406         const PulserGain * otherpg = farend.GetRowByIndex(pg.GetStripEnd());
00407         if (!pg.Add(*otherpg)) {
00408           // Inconsistency - fatal error!
00409           MSG("Pulser",Msg::kFatal)<<"Could add GainLog but not Gain for Far stripend with key "<<pg.GetStripEnd()<<endl;
00410           assert(0);
00411         }
00412       }
00413     }
00414 
00415     DbiResultPtr<PulserGainPin> pins(vld,Pulser::kNearEnd | Pulser::kTempData);
00416     if (pins.GetNumRows()==0) {
00417       MSG("Pulser",Msg::kFatal)<< "Database Integrity Error."<<endl;
00418       MSG("Pulser",Msg::kFatal)<< "Pin Gain doesn't match GainLog"<<endl;
00419       return false;
00420     }
00421     const PulserGainPin * otherpin[2];
00422     for (int k=0;k<2;k++) {
00423       otherpin[k] = pins.GetRowByIndex(fGainPin[k]->GetIndex(0));
00424       if (!(fGainPin[k]->Add(*otherpin[k]))) {
00425         MSG("Pulser",Msg::kFatal)<<"Could add GainLog but not Gain for Pin "<<fGainPin[k]->GetIndex(0)<<endl;
00426         assert(0);
00427       }
00428     }
00429 
00430     // We have now successfully merged the other gain curve into our current
00431     // one. We should now write a new gain curve fragment and delete both old 
00432     // fragments from the temp DB.
00433     // If this merge has completed a gaincurve, write it to the real database 
00434     // instead.
00435 
00436     // Get DbiResultPtrs for an earlier version of the current objects, if they
00437     // exist. This is now done in WriteTempGC()
00438 
00439    // Now write new tables
00440    if (WriteTempGC()) {
00441      DeleteGC(&nearend);
00442      if (vld.GetDetector()==Detector::kFar) DeleteGC(&farend);
00443      DeleteGC(&pins);
00444      DeleteGC(&pglrp);
00445    }
00446    else {
00447      MSG("Pulser",Msg::kError)<< "Failed to delete old bits of gaincurve from temp DB.\n";
00448      return false;
00449    }
00450 
00451 
00452   } 
00453   else return false;
00454 
00455   return MergeBack();
00456 }

bool PulserDBModule::MergeForward (  )  [private]

Definition at line 458 of file PulserDBModule.cxx.

References PulserGainLog::Add(), fCurrentContext, fGainLog, VldContext::GetDetector(), PulserGainLog::GetLastPoint(), PulserGainLog::GetNumPoints(), VldContext::GetSimFlag(), PulserGainLog::GetTimeEnd(), and Pulser::kTempData.

Referenced by EndRun().

00459 {
00460   if (fGainLog->GetLastPoint()==fGainLog->GetNumPoints()) return false;
00461 
00462   // Try to merge here
00463   VldTimeStamp ts = fGainLog->GetTimeEnd();
00464   VldContext vld(fCurrentContext.GetDetector(),
00465                  fCurrentContext.GetSimFlag(),ts);
00466   DbiResultPtr<PulserGainLog> pglrp(vld,Pulser::kTempData);
00467   // This will either be the current curve fragment, if it's in the database,
00468   // or it'll be the previous one, if it's not.
00469   pglrp.NextQuery();
00470   // This should now be the next fragment. Remember, there might not be one, 
00471   // so we might have a gap now,
00472   if (pglrp.GetNumRows()==0) return false;
00473 
00474   const PulserGainLog *pgl = pglrp.GetRow(0);
00475   if (fGainLog->Add(*pgl)) {
00476     // Can add gain log, so lets go and add the data too
00477   } 
00478   else return false;
00479 
00480   return MergeForward();
00481 }

JobCResult PulserDBModule::Reco ( MomNavigator mom  )  [virtual]

Implement this for read-write access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 118 of file PulserDBModule.cxx.

References EndFile(), EndRun(), MomNavigator::FragmentIter(), fRunStart, GainCurve(), PulserSummaryList::GetExpectedPoints(), MomNavigator::GetFragment(), PulserSummaryList::GetPointIndex(), RawRecord::GetRawHeader(), RawDaqHeader::GetRun(), RawDaqHeader::GetSubRun(), PulserSummaryList::GetTriggers(), Msg::kDebug, JobCResult::kFailed, Msg::kInfo, JobCResult::kPassed, Msg::kVerbose, and MSG.

00119 {
00120   //SM: Check if run and subrun are the same. If not, it means we are reading new file:
00121   static int runnew, subrunnew;
00122   static int runold=0;
00123   static int subrunold=0;
00124       //SM: Get run and subrun:
00125 
00126   TIter iter = mom->FragmentIter();
00127   while (TObject *obj = iter.Next()) {
00128     RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00129     if (rawrec) {
00130 
00131       const RawDaqHeader* daqHead =
00132         dynamic_cast<const RawDaqHeader*>(rawrec->GetRawHeader());
00133       
00134       if (daqHead){
00135         runnew = daqHead->GetRun();
00136         subrunnew = daqHead->GetSubRun();
00137         MSG("Pulser",Msg::kDebug) << 
00138           "run, subrun: " << runnew << "' " << subrunnew <<endl;
00139       }
00140   
00141     if ((runold!=0) &&(runnew!=runold || subrunnew!=subrunold)){
00142       MSG("Pulser",Msg::kInfo) <<"Calling Endfile() with runold="<<runold<<endl;
00143       EndFile();
00144     }
00145 
00146     if ((runold!=0) && runnew!=runold){
00147       MSG("Pulser",Msg::kInfo) <<"Calling EndRun() with runold="<<runold<<endl;
00148       MSG("Pulser",Msg::kInfo) <<"Starting new run: "<<runnew<<endl;
00149       EndRun();
00150     }
00151 
00152     runold=runnew;
00153     subrunold=subrunnew;
00154     }
00155   }
00156 
00157   //Get PulserSummary...
00158    PulserSummaryList *psl = dynamic_cast<PulserSummaryList *>
00159       (mom->GetFragment("PulserSummaryList"));
00160    if (psl==0) {
00161       MSG("Pulser",Msg::kVerbose) <<"No pulser summary list here\n";
00162       return JobCResult::kFailed;
00163    }
00164    MSG("Pulser",Msg::kDebug) <<"Got pulser summary "<<psl->GetPointIndex()
00165                              <<" of "<<psl->GetExpectedPoints()<<endl;
00166    //   int point = psl->GetPointIndex();
00167    if (fRunStart) {
00168      
00169    }
00170    switch(psl->GetExpectedPoints()) {
00171    case 0:
00172      // noise - no pulsing
00173      MSG("Pulser",Msg::kInfo) <<"Dropping LI summary with "<<
00174        psl->GetTriggers()<<" pulses: Pulser is off!"<<endl;
00175      break;
00176    case 1: 
00177      // Drift Point
00178      // No longer write drift points. CPW 23/1/06
00179      MSG("Pulser",Msg::kInfo) <<"Doug Point: not written"<<endl;
00180      //     DriftPoint(psl);
00181      break;
00182    default:
00183      // Anything bigger than 1 is a gaincurve
00184      MSG("Pulser",Msg::kInfo) <<"GainCurve"<<endl;
00185      GainCurve(psl);
00186      break;
00187    };
00188    return JobCResult::kPassed;
00189    
00190 }

bool PulserDBModule::WriteGC (  )  [private]

Definition at line 499 of file PulserDBModule.cxx.

References DoWriteGC(), and Pulser::kRealData.

Referenced by EndRun(), and GainCurve().

00500 {
00501   return DoWriteGC(Pulser::kRealData);
00502 }

bool PulserDBModule::WriteTempGC (  )  [private]

Definition at line 505 of file PulserDBModule.cxx.

References DeleteGC(), DoWriteGC(), fCurrentContext, fGainLog, GetCurrentFromDB(), VldContext::GetDetector(), VldContext::GetSimFlag(), PulserGainLog::GetTimeStart(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Pulser::kFarEnd, Pulser::kNearEnd, and Pulser::kTempData.

Referenced by EndRun(), and MergeBack().

00506 {
00507  VldTimeStamp ts = fGainLog->GetTimeStart();
00508    VldContext vld(fCurrentContext.GetDetector(),
00509                  fCurrentContext.GetSimFlag(),ts);
00510    DbiResultPtr<PulserGain> near;
00511    DbiResultPtr<PulserGain> far;
00512    DbiResultPtr<PulserGainPin> pins;
00513    DbiResultPtr<PulserGainLog> gainlog;
00514 
00515    bool del_n = GetCurrentFromDB(near,vld,Pulser::kNearEnd | Pulser::kTempData);
00516    bool del_f = GetCurrentFromDB(far,vld,Pulser::kFarEnd | Pulser::kTempData);
00517    bool del_p = GetCurrentFromDB(pins,vld,Pulser::kNearEnd | Pulser::kTempData);
00518    bool del_g = GetCurrentFromDB(gainlog,vld,Pulser::kNearEnd | Pulser::kTempData);
00519 
00520 bool result = DoWriteGC(Pulser::kTempData);
00521   // We should delete any older versions of the current fragment here, too
00522 
00523  if (result && gainlog.GetValidityRec()->GetVldRange().GetTimeStart()==fGainLog->GetTimeStart()) {
00524    // start time of current gc and fragment in db match, so can delete from db.
00525 
00526   if (del_n) result &=DeleteGC(&near);
00527   if (del_f) result &=DeleteGC(&far);
00528   if (del_p) result &=DeleteGC(&pins);
00529   if (del_g) result &=DeleteGC(&gainlog);
00530  }
00531  return result;
00532 }


Member Data Documentation

const int PulserDBModule::fCodeVersion = 0 [static, private]

Definition at line 68 of file PulserDBModule.h.

Referenced by AddToGC(), DoWriteGC(), and DriftPoint().

Definition at line 82 of file PulserDBModule.h.

Referenced by DoWriteGC(), DriftPoint(), GainCurve(), MergeBack(), MergeForward(), and WriteTempGC().

int PulserDBModule::fDPValid [private]

Definition at line 72 of file PulserDBModule.h.

Referenced by DriftPoint().

Definition at line 75 of file PulserDBModule.h.

Referenced by BeginFile(), and GainCurve().

std::map<Int_t,PulserGain> PulserDBModule::fGainMapFar [private]

Definition at line 78 of file PulserDBModule.h.

Referenced by AddToGC(), DoWriteGC(), DropGC(), and MergeBack().

std::map<Int_t,PulserGain> PulserDBModule::fGainMapNear [private]

Definition at line 77 of file PulserDBModule.h.

Referenced by AddToGC(), DoWriteGC(), DropGC(), and MergeBack().

Definition at line 79 of file PulserDBModule.h.

Referenced by AddToGC(), DoWriteGC(), DropGC(), and MergeBack().

int PulserDBModule::fGCValid [private]

Definition at line 71 of file PulserDBModule.h.

Referenced by DoWriteGC().

Definition at line 73 of file PulserDBModule.h.

bool PulserDBModule::fRunStart [private]

Definition at line 74 of file PulserDBModule.h.

Referenced by BeginRun(), GainCurve(), and Reco().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1