00001
00002 #include "SaveB4TrimAesSvc.h"
00003 #include "GaudiKernel/MsgStream.h"
00004 #include "GaudiKernel/IDataManagerSvc.h"
00005 #include "GaudiKernel/DataSvc.h"
00006 #include "DataUtilities/DybArchiveList.h"
00007 #include "Event/RegistrationSequence.h"
00008
00009 SaveB4TrimAesSvc::SaveB4TrimAesSvc(const std::string& name,
00010 ISvcLocator* svc) :
00011 Service(name,svc)
00012 {
00013 }
00014
00015 StatusCode SaveB4TrimAesSvc::queryInterface(const InterfaceID& id,
00016 void** interface)
00017 {
00018 MsgStream log(msgSvc(), name());
00019
00020 if (ISaveB4TrimAesSvc::interfaceID().versionMatch(id)) {
00021
00022 *interface = (ISaveB4TrimAesSvc*)this;
00023 addRef();
00024
00025 } else {
00026
00027
00028 return Service::queryInterface(id,interface);
00029 }
00030
00031 return StatusCode::SUCCESS;
00032 }
00033
00034 StatusCode SaveB4TrimAesSvc::initialize()
00035 {
00036 return Service::initialize();
00037 }
00038
00039 StatusCode SaveB4TrimAesSvc::finalize()
00040 {
00041 return Service::finalize();
00042 }
00043
00044 StatusCode SaveB4TrimAesSvc::store(const std::string& regSeqLocation,
00045 IDybStorageSvc* dybStorageSvc,
00046 IDataManagerSvc* aes,
00047 IArchiveTrimSvc* archiveTrimSvc,
00048 const TimeStamp& now)
00049 {
00050 MsgStream log(msgSvc(), name());
00051
00052 log<<MSG::DEBUG<<"SaveB4TrimAes::store()"<<endreq;
00053
00054
00055 double window = archiveTrimSvc->window(regSeqLocation);
00056
00057
00058 TimeStamp thres = now;
00059 thres.Add(-1.0 * window);
00060 log << MSG::DEBUG
00061 << " store() now @ t=\"" << now << "\" threshold @ t=\"" << thres << "\""
00062 << " window=" << window
00063 << endreq;
00064
00065
00066 DataObject* pObj=0;
00067
00068
00069
00070
00071 DataSvc* pAes=0;
00072 try{
00073 pAes=dynamic_cast<DataSvc*>(aes);
00074 }
00075 catch(...) {
00076 log<<MSG::ERROR<<"Failed to AES"<<endreq;
00077 return StatusCode::FAILURE;
00078 }
00079
00080 log<<MSG::DEBUG<<aes<<endreq;
00081 StatusCode sc = pAes->retrieveObject(regSeqLocation,pObj);
00082 if(sc.isFailure()) {
00083 log<<MSG::ERROR<<"Failed to get data object"<<endreq;
00084 return StatusCode::FAILURE;
00085 }
00086
00087 DybArchiveList* pRegSeqList=0;
00088 try{
00089 pRegSeqList=dynamic_cast<DybArchiveList*>(pObj);
00090 }
00091 catch (...) {
00092 log<<MSG::ERROR<<"Failed to get DybArchiveList"<<endreq;
00093 return StatusCode::FAILURE;
00094 }
00095
00096
00097
00098 DybArchiveList::reverse_iterator iter;
00099 DayaBay::RegistrationSequence* pRS=0;
00100
00101 for(iter=pRegSeqList->rbegin();iter!=pRegSeqList->rend();++iter) {
00102
00103 pObj=*iter;
00104 try{
00105 pRS=dynamic_cast<DayaBay::RegistrationSequence*>(pObj);
00106 }
00107 catch (...) {
00108 log<<MSG::ERROR<<"Failed to get RegistrationSequence"<<endreq;
00109 return StatusCode::FAILURE;
00110 }
00111
00112 log << MSG::DEBUG
00113 << "Checking RegSeq @ t=\"" << pRS->earliest() << "\"... ";
00114
00115
00116
00117 if(pRS->earliest()<=thres) {
00118
00119 sc = dybStorageSvc->store(*pRS);
00120 log << "stored." << endreq;
00121 }
00122 else {
00123 log << "not yet." << endreq;
00124 }
00125 }
00126
00127 return StatusCode::SUCCESS;
00128 }
00129