00001
00002 #include "DybTrimIO.h"
00003
00004
00005 #include "Event/RegistrationSequence.h"
00006 #include "Event/TemporalDataObject.h"
00007
00008
00009 #include "DybKernel/ISaveB4TrimAesSvc.h"
00010 #include "DybKernel/IDybStorageSvc.h"
00011
00012
00013 #include "GaudiKernel/IDataManagerSvc.h"
00014 #include "DybKernel/IArchiveTrimSvc.h"
00015
00016 #include "GaudiKernel/SmartDataPtr.h"
00017
00019
00020 DybTrimIO::DybTrimIO(const std::string& name, ISvcLocator* pSvcLocator):
00021 GaudiAlgorithm(name, pSvcLocator),
00022 m_pSaveB4TrimAesSvc(0),
00023 m_pDybStorageSvc(0),
00024 m_pArchiveSvc(0),
00025 m_pTrimSvc(0)
00026 {
00027 declareProperty("SaveFlag",m_saveFlag=false,"Save or not");
00028
00029 declareProperty("NowLocation",
00030 m_nowLocation = DayaBay::RegistrationSequenceLocation::Default,
00031 "Location to determine current time, default: RegistrationSequence");
00032
00033 declareProperty("RegSeqLocation",
00034 m_regSeqLocation=DayaBay::RegistrationSequenceLocation::Default,
00035 "Location to RegistrationSequence");
00036
00037 declareProperty("SaveB4TrimAesSvc",
00038 m_pSaveB4TrimAesSvcName="SaveB4TrimAesSvc",
00039 "Name of SaveB4TrimAesSvc");
00040
00041 declareProperty("DybStorageSvc",
00042 m_pDybStorageSvcName="DybStorageSvc",
00043 "Name of an IDybStorageSvc");
00044
00045 declareProperty("ArchiveSvc",
00046 m_pArchiveSvcName="EventDataArchiveSvc",
00047 "Name of AES");
00048
00049 declareProperty("TrimSvc",
00050 m_pTrimSvcName="ArchiveTrimSvc",
00051 "Name of trimming service");
00052
00053 }
00054
00055
00056
00057 StatusCode DybTrimIO::initialize()
00058 {
00059
00060 StatusCode status;
00061 debug() << " DybTrimIO initialize()" << endreq;
00062
00063 if ( m_saveFlag ) {
00064
00065 status = service(m_pSaveB4TrimAesSvcName,
00066 m_pSaveB4TrimAesSvc);
00067
00068 debug()<<"m_pSaveB4TrimAesSvc "<<m_pSaveB4TrimAesSvc<<endreq;
00069 if (status.isFailure()) {
00070 error()<<"Service [SaveB4TrimAesSvc] not found"<<endreq;
00071 return StatusCode::FAILURE;
00072 }
00073
00074
00075 status = service(m_pDybStorageSvcName,
00076 m_pDybStorageSvc);
00077
00078 debug()<<"m_pDybStorageSvc "<<m_pDybStorageSvc<<endreq;
00079 if (status.isFailure()) {
00080 error()<<"Service [DybStorageSvc] not found"<<endreq;
00081 return StatusCode::FAILURE;
00082 }
00083 }
00084
00085
00086 status = service(m_pArchiveSvcName,
00087 m_pArchiveSvc);
00088
00089 debug()<<"m_pArchiveSvc "<<m_pArchiveSvc<<endreq;
00090 if (status.isFailure()) {
00091 error()<<"Service [EventDataArchiveSvc] not found"<<endreq;
00092 return StatusCode::FAILURE;
00093 }
00094
00095
00096 status = service(m_pTrimSvcName,
00097 m_pTrimSvc);
00098
00099 debug()<<"m_pTrimSvc "<<m_pTrimSvc<<endreq;
00100 if (status.isFailure()) {
00101 error()<<"Service [ArchiveTrimSvc] not found"<<endreq;
00102 return StatusCode::FAILURE;
00103 }
00105
00106 return StatusCode::SUCCESS;
00107 }
00108
00109
00110
00111 StatusCode DybTrimIO::execute()
00112 {
00113 StatusCode sc;
00114 debug() << "DybTrimIO execute()" << endreq;
00115
00116
00117 SmartDataPtr<const DayaBay::TemporalDataObject>
00118 pTemoral(eventSvc(),m_nowLocation);
00119
00120 if (0 == pTemoral) {
00121 error()<<"Failed to retrieve TemporalDataObject from Event Store"<<endreq;
00122 return StatusCode::FAILURE;
00123 }
00124 debug()<<"Current time in DybTrimIO: "<<pTemoral->earliest()<<endreq;
00125
00126
00127 if(m_saveFlag) {
00128 sc = m_pSaveB4TrimAesSvc->store(m_regSeqLocation,
00129 m_pDybStorageSvc,
00130 m_pArchiveSvc,
00131 m_pTrimSvc,
00132 pTemoral->earliest());
00133 if(sc.isFailure()) {
00134 debug()<<"Failed to write"<<endreq;
00135 return StatusCode::FAILURE;
00136 }
00137 }
00138
00139
00140 sc = m_pTrimSvc->trim(m_pArchiveSvc,pTemoral->earliest());
00141 if(sc.isFailure()) {
00142 debug()<<"Failed to trim"<<endreq;
00143 return StatusCode::FAILURE;
00144 }
00145
00146 return StatusCode::SUCCESS;
00147 }
00148
00149
00150
00151 StatusCode DybTrimIO::finalize()
00152 {
00153 StatusCode sc;
00154 debug() << "DybTrimIO finalize()" << endreq;
00155
00156
00157
00158
00159
00160
00161 if(m_saveFlag) {
00162 sc = m_pSaveB4TrimAesSvc->store(m_regSeqLocation,
00163 m_pDybStorageSvc,
00164 m_pArchiveSvc,
00165 m_pTrimSvc,
00166 TimeStamp::GetEOT());
00167 if(sc.isFailure()) {
00168 debug()<<"Failed to write"<<endreq;
00169 return StatusCode::FAILURE;
00170 }
00171 }
00172
00173
00174 sc = m_pTrimSvc->trim(m_pArchiveSvc,TimeStamp::GetEOT());
00175 if(sc.isFailure()) {
00176 debug()<<"Failed to trim"<<endreq;
00177 return StatusCode::FAILURE;
00178 }
00179
00180
00181 if (0 != m_pTrimSvc) {
00182 m_pTrimSvc->release();
00183 }
00184
00185 if (0 != m_pArchiveSvc) {
00186 m_pArchiveSvc->release();
00187 }
00188
00189 if(m_saveFlag) {
00190 if (0 != m_pSaveB4TrimAesSvc) {
00191 m_pSaveB4TrimAesSvc->release();
00192 }
00193
00194 if (0 != m_pDybStorageSvc) {
00195 m_pDybStorageSvc->release();
00196 }
00197 }
00198
00199 return StatusCode::SUCCESS;
00200 }