00001
00002
00003
00004
00005
00006 #include "EvtStoreQuery.h"
00007 #include "Event/TemporalDataObject.h"
00008 #include "DataUtilities/DybArchiveList.h"
00009
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012
00013 EvtStoreQuery::EvtStoreQuery(const std::string& name,
00014 ISvcLocator* svc) :
00015 Service(name,svc),
00016 m_useAES(true),
00017 m_evtSvc(0),
00018 m_archiveSvc(0)
00019 {
00020 declareProperty("UseAes",m_useAES=true, "Is AES in use?");
00021 declareProperty("TES",m_evtSvcName="EventDataSvc","Name of TES");
00022 declareProperty("AES",m_archiveSvcName="EventDataArchiveSvc","Name of AES");
00023 }
00024
00025 StatusCode EvtStoreQuery::queryInterface(const InterfaceID& id,
00026 void** interface)
00027 {
00028 MsgStream log(msgSvc(), name());
00029
00030 if (IEvtStoreQuery::interfaceID().versionMatch(id)) {
00031
00032 *interface = (IEvtStoreQuery*)this;
00033 addRef();
00034
00035 } else {
00036
00037
00038 return Service::queryInterface(id,interface);
00039 }
00040
00041 return StatusCode::SUCCESS;
00042 }
00043
00044 StatusCode EvtStoreQuery::initialize()
00045 {
00046 MsgStream log(msgSvc(), name());
00047
00048 StatusCode status = service(m_evtSvcName,m_evtSvc);
00049
00050 log<<MSG::DEBUG<<"m_evtSvc "<<m_evtSvc<<endreq;
00051 if (status.isFailure()) {
00052 log<<MSG::ERROR<<"Service [EventDataSvc] not found"<<endreq;
00053 return status;
00054 }
00055
00056
00057 if(m_useAES) {
00058 status = service(m_archiveSvcName,m_archiveSvc);
00059
00060 log<<MSG::DEBUG<<"m_archiveSvc "<<m_archiveSvc<<endreq;
00061 if (status.isFailure() || m_archiveSvc==0) {
00062 log<<MSG::ERROR<<"Service [EventDataArchiveSvc] not found"<<endreq;
00063 return status;
00064 }
00065 }
00066
00067 return Service::initialize();
00068 }
00069
00070 StatusCode EvtStoreQuery::finalize()
00071 {
00072 if(m_archiveSvc!=0) {
00073 m_archiveSvc->release();
00074 }
00075
00076 return Service::finalize();
00077 }
00078
00079 const DataObject* EvtStoreQuery::queryInputAddress(const std::string& location, const unsigned long& entry)
00080 {
00081 MsgStream log(msgSvc(), name());
00082
00083
00084 DataObject* pObj=0;
00085 DayaBay::TemporalDataObject* pTdo=0;
00086 StatusCode sc;
00087
00088 if(!m_useAES)
00089 {
00090 sc=m_evtSvc->findObject(location,pObj);
00091 if(sc.isSuccess())
00092 {
00093 try{
00094 pTdo=dynamic_cast<DayaBay::TemporalDataObject*>(pObj);
00095 } catch(...) {
00096
00097 }
00098 if(pTdo!=0)
00099 {
00100 const GenericAddress* ria=pTdo->inputAddress();
00101
00102 if(ria!=0)
00103 {
00104
00105 if(ria->ipar()[0]==entry)
00106 {
00107 log<<MSG::DEBUG<<"Found: "<<location<<"\t"<<entry<<"\t"<<pObj<<endreq;
00108 return pObj;
00109 }
00110 else
00111 {
00112 log<<MSG::DEBUG<<"Reject: "<<location<<"\t"<<entry<<"!="<<ria->ipar()[0]<<"\t"<<pObj
00113 <<"[" << pTdo->earliest() << " --> " << pTdo->latest() << "]"
00114 <<endreq;
00115 }
00116 }
00117 }
00118 }
00119 }
00120 else
00121 {
00122 log<<MSG::DEBUG<<"AES, searching... "<<m_archiveSvc<<"\t"<<location<<"\t"<<entry<<endreq;
00123 SmartDataPtr<DybArchiveList> data_list(m_archiveSvc,location);
00124 if( data_list!=0 )
00125 {
00126 log<<MSG::DEBUG<<"size of list "<<data_list->size();
00127
00128 DybArchiveList::const_iterator finished = data_list->end();
00129 DybArchiveList::const_iterator iter = data_list->begin();
00130 for(;iter!=finished;++iter)
00131 {
00132 pObj=(*iter);
00133 if(pObj!=0)
00134 {
00135 try{
00136 pTdo=dynamic_cast<DayaBay::TemporalDataObject*>(pObj);
00137 } catch(...) {
00138
00139 }
00140 if(pTdo!=0)
00141 {
00142 const GenericAddress* ria=pTdo->inputAddress();
00143 log<<MSG::DEBUG<<"ria= "<<ria<<endreq;
00144 if(ria!=0)
00145 {
00146 log<<MSG::DEBUG<<"Checking: "<<location<<"\t"<<ria->ipar()[0]<<"\t"<<entry<<"\t"<<pObj<<endreq;
00147 if(ria->ipar()[0]==entry)
00148 {
00149 log<<MSG::DEBUG<<"Found: "<<location<<"\t"<<entry<<"\t"<<pObj<<endreq;
00150 return pObj;
00151 }
00152 }
00153 }
00154 }
00155 }
00156 }
00157 }
00158
00159 return 0;
00160 }
00161