emcOMTimeStamp.C

Go to the documentation of this file.
00001 #include "emcOMTimeStamp.h"
00002 #include "RunToTime.hh"
00003 #include "emcTimeStamp.h"
00004 #include <memory>
00005 
00006 emcOMTimeStamp gemcOMTimeStamp("PostgreSQL:emcOMTimeStamp","Wrap reading of RunToTimePg");
00007 
00008 //_____________________________________________________________________________
00009 emcOMTimeStamp::emcOMTimeStamp(const char* name, const char* title)
00010   : emcObjectManager(name,title)
00011 {
00012 }
00013 
00014 //_____________________________________________________________________________
00015 emcOMTimeStamp::~emcOMTimeStamp()
00016 {
00017   Reset();
00018 }
00019 
00020 //_____________________________________________________________________________
00021 bool
00022 emcOMTimeStamp::CanRead(const emcManageable& object) const
00023 {
00024   const emcManageable* pobject = &object;
00025   const emcTimeStamp* test = dynamic_cast<const emcTimeStamp*>(pobject);
00026 
00027   if ( test && object.GetSource() == emcManageable::kDB_Pg ) 
00028     {
00029       return true;
00030     }
00031   else
00032     {
00033       return false;
00034     }
00035 }
00036 
00037 //_____________________________________________________________________________
00038 bool
00039 emcOMTimeStamp::Read(emcManageable& object, int runnumber)
00040 {
00041   emcTimeStamp& ts = static_cast<emcTimeStamp&>(object);
00042 
00043   std::map<int,PHTimeStamp*>::const_iterator it = fTSMap.find(runnumber);
00044 
00045   if ( it != fTSMap.end() )
00046     {
00047       ts.setTimeStamp(*(it->second));
00048       return true;
00049     }
00050   else
00051     {
00052       RunToTime *runTime = RunToTime::instance();
00053       PHTimeStamp* rts = runTime->getBeginTime(runnumber);
00054       
00055       if ( rts != 0 )
00056         {
00057           ts.setTimeStamp(*rts);
00058           fTSMap[runnumber]=rts;
00059           return true;
00060         }
00061       else
00062         {
00063           return false;
00064         }
00065     }
00066 }
00067 
00068 //_____________________________________________________________________________
00069 void
00070 emcOMTimeStamp::Reset()
00071 {
00072   std::map<int,PHTimeStamp*>::iterator it;
00073   for ( it = fTSMap.begin(); it != fTSMap.end(); ++it ) 
00074     {
00075       delete it->second;
00076     }
00077   fTSMap.clear();
00078 }