00001 #include "DybEvtSelector.h"
00002
00003
00004
00005
00006 #include "DybIO/IDybIODaqSvc.h"
00007 #include "RootIOSvc/IRootIOSvc.h"
00008 #include "RootIOSvc/RootInputStream.h"
00009 #include "Event/RegistrationSequence.h"
00010
00011 #include "GaudiKernel/IDataManagerSvc.h"
00012 #include "GaudiKernel/MsgStream.h"
00013
00014 #include <string>
00015
00016 DybEvtSelector::DybEvtSelector(const std::string& name, ISvcLocator* svcloc)
00017 : Service(name,svcloc)
00018 , RootIOEvtSelector(name,svcloc)
00019 , m_reqSeqName("")
00020 , m_daqSvc(0)
00021 , m_controlStream(0)
00022 {
00023 m_reqSeqName = DayaBay::RegistrationSequenceLocation::Default;
00024 declareProperty("ReqSeq",m_reqSeqName,
00025 "TES/TFile path where to find the RegistrationSequence");
00026
00027 }
00028
00029 DybEvtSelector::~DybEvtSelector()
00030 {
00031 }
00032
00033 StatusCode DybEvtSelector::initialize()
00034 {
00035 StatusCode sc = RootIOEvtSelector::initialize();
00036 if (sc.isFailure()) {
00037 return sc;
00038 }
00039
00040 IService* isvc=0;
00041 sc = serviceLocator()->service("DybIODaqSvc","DybIODaqSvc", isvc);
00042 if (sc.isFailure()) {
00043 m_daqSvc = 0;
00044 } else {
00045 sc = isvc->queryInterface(IDybIODaqSvc::interfaceID(), (void**)&m_daqSvc);
00046 if (sc.isFailure()) {
00047 m_daqSvc = 0;
00048 }
00049 }
00050 return StatusCode::SUCCESS;
00051 }
00052
00053 StatusCode DybEvtSelector::finalize()
00054 {
00055 if (0 != m_daqSvc) {
00056 m_daqSvc->release();
00057 }
00058 return RootIOEvtSelector::finalize();
00059 }
00060
00061 StatusCode DybEvtSelector::setEntry(RootIOEvtSelector::Context& rc, int entry) const
00062 {
00063 MsgStream log(msgSvc(), "DybEvtSelector");
00064
00065 if (!m_controlStream) {
00066 IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
00067 m_controlStream = ism[m_reqSeqName];
00068 if (!m_controlStream) {
00069 log << MSG::WARNING << "failed to get control stream at "
00070 << m_reqSeqName << endreq;
00071 return StatusCode::FAILURE;
00072 }
00073 }
00074
00075 log << MSG::DEBUG << "Loading control stream (RegistrationSequence) entry " << entry << endreq;
00076
00077
00078 if (0 != m_daqSvc) {
00079 StatusCode sc = m_daqSvc->setEventEntry(entry);
00080 if (sc.isFailure()) {
00081 log << MSG::INFO
00082 << "No more DAQ blocks are available"
00083 << endreq;
00084 }
00085 }
00086
00087 bool okay = m_controlStream->setEntry(entry,false);
00088 if (!okay) {
00089 log << MSG::WARNING << "Failed to set entry " <<
00090 entry << " for control input stream " << m_reqSeqName << endreq;
00091 log << MSG::WARNING << "End of the input stream?" << endreq;
00092 return StatusCode::FAILURE;
00093 }
00094
00095
00096
00097 rc.m_entry = entry;
00098 return StatusCode::SUCCESS;
00099 }
00100