00001 #include "GaudiKernel/MsgStream.h"
00002 #include "GaudiKernel/DataObject.h"
00003 #include "Event/RegistrationSequence.h"
00004 #include "RootIOSvc/IRootIOSvc.h"
00005 #include "RootIOSvc/RootIOAddress.h"
00006 #include "Mixing/IMixingSvc.h"
00007 #include "RootIOSvc/RootInputStream.h"
00008 #include "Event/ReadoutHeader.h"
00009 #include "Mixing/MixRootEvtSelector.h"
00010
00011 using namespace std;
00012
00013 MixRootEvtSelector::MixRootEvtSelector(const std::string& name, ISvcLocator* svcloc)
00014 :Service(name,svcloc)
00015 ,RootIOEvtSelector(name,svcloc)
00016 ,m_reqSeqName(""), m_controlStream(0)
00017 {
00018 m_reqSeqName = DayaBay::RegistrationSequenceLocation::Default;
00019 declareProperty("ReqSeq",m_reqSeqName,
00020 "TES/TFile path where to find the RegistrationSequence");
00021 }
00022
00023 MixRootEvtSelector::~MixRootEvtSelector()
00024 {
00025 MsgStream log(msgSvc(), "MixRootEvtSelector");
00026 log << MSG::INFO << "MixRootEvtSelector::~MixIOEvtSelector()" << endreq;
00027 }
00028
00029 StatusCode MixRootEvtSelector::initialize()
00030 {
00031 MsgStream log(msgSvc(), "MixRootEvtSelector");
00032 log << MSG::INFO << "initializing @" << (void*)this << endreq;
00033 log << MSG::DEBUG << "called " << this->name() << endreq;
00034 StatusCode sc = this->Service::initialize();
00035 if(sc.isFailure()) return sc;
00036
00037 IService* isvc=0;
00038 sc = serviceLocator()->service("MixRootIOCnvSvc", "RootIOCnvSvc", isvc, false);
00039 if(sc.isFailure())
00040 {
00041 log << MSG::ERROR << "Conversion service MixRootIOCnvSvc"
00042 << " could not be retrieved" << endreq;
00043 return sc;
00044 }
00045 isvc->addRef();
00046
00047 sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
00048 if(sc.isFailure())
00049 {
00050 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00051 << " does not implement IRootIOCnvSvc" << endreq;
00052 return sc;
00053 }
00054
00055 log << MSG::INFO << "initialized @" << (void*)this
00056 << " got RootIOCnvSvc @" << (void*)m_rioSvc
00057 << endreq;
00058
00059 sc = isvc->queryInterface(IMixingSvc::interfaceID(), (void**)&m_mixSvc);
00060 if(sc.isFailure())
00061 {
00062 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00063 << " does not implement IMixingSvc" << endreq;
00064 return sc;
00065 }
00066
00067 log << MSG::INFO << "initialized @" << (void*)this
00068 << " got RootIOCnvSvc @" << (void*)m_mixSvc
00069 << endreq;
00070
00071 return StatusCode::SUCCESS;
00072 }
00073
00074 StatusCode MixRootEvtSelector::setEntry(MixRootEvtSelector::Context& rc, int entry) const
00075 {
00076 MsgStream log(msgSvc(), "MixRootEvtSelector");
00077 log << MSG::DEBUG << "SetEntry(" << entry << ")" << endreq;
00078 log << MSG::DEBUG << "Mix Context: "<< rc.m_entry << endreq;
00079
00080 long entries = m_mixSvc->entries();
00081 StatusCode sc = m_mixSvc->buildStream();
00082 if(entry > entries || sc.isFailure())
00083 {
00084 log<< MSG::DEBUG<< "Now the entry is: "<< entries<< endreq;
00085 return StatusCode::FAILURE;
00086 }
00087
00088 log << MSG::DEBUG << "Now ,read in other headers" << endreq;
00089 IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
00090 m_controlStream = ism[m_reqSeqName];
00091 if(!m_controlStream)
00092 {
00093 log << MSG::ERROR << "failed to get control stream at " << m_reqSeqName << endreq;
00094 return StatusCode::FAILURE;
00095 }
00096 rc.m_entry = entry;
00097 return StatusCode::SUCCESS;
00098 }
00099
00100 StatusCode MixRootEvtSelector::createAddress(const IEvtSelector::Context& c, IOpaqueAddress*& iop) const
00101 {
00102 MsgStream log(msgSvc(), "MixRootEvtSelector");
00103 log << MSG::DEBUG << "createAddress" << endreq;
00104 const MixRootEvtSelector::Context* rc = dynamic_cast<const MixRootEvtSelector::Context*>(&c);
00105 if(!rc)
00106 {
00107 log << MSG::ERROR << "Failed to get MixRootIOEvtSelector::Context" << endreq;
00108 return StatusCode::FAILURE;
00109 }
00110
00111 RootInputAddress* ria = new RootInputAddress(DataObject::classID(),"/Event");
00112 MixHeader mh = m_mixSvc->fetchMixHeader();
00113 ria->setEntry(mh.entry);
00114 iop = ria;
00115 log << MSG::DEBUG << "createAddress for /Event" << endreq;
00116 return StatusCode::SUCCESS;
00117 }