00001 #include "RootIOSvc/RootIOEvtSelector.h"
00002
00003 #include "RootIOSvc/RootIOAddress.h"
00004 #include "RootIOSvc/IRootIOSvc.h"
00005
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/DataObject.h"
00008 #include "GaudiKernel/IDataManagerSvc.h"
00009
00010 using namespace std;
00011
00012 RootIOEvtSelector::RootIOEvtSelector(const string& name,
00013 ISvcLocator* svcloc)
00014 : Service(name,svcloc)
00015 , m_rioSvc(0)
00016 {
00017
00018 }
00019 RootIOEvtSelector::~RootIOEvtSelector()
00020 {
00021 MsgStream log(msgSvc(), "RootIOEvtSelector");
00022 log << MSG::DEBUG << "RootIOEvtSelector::~RootIOEvtSelector()" << endreq;
00023 }
00024
00025 StatusCode RootIOEvtSelector::initialize()
00026 {
00027 MsgStream log(msgSvc(), "RootIOEvtSelector");
00028 log << MSG::DEBUG << "initializing @" << (void*)this << endreq;
00029 log << MSG::DEBUG << "called " << this->name() << endreq;
00030
00031 StatusCode sc = this->Service::initialize();
00032 if (sc.isFailure()) return sc;
00033
00034 IService* isvc=0;
00035 sc = serviceLocator()->service("RootIOCnvSvc", isvc, false);
00036
00037 if (sc.isFailure()) {
00038 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00039 << " could not be retrieved" << endreq;
00040 return sc;
00041 }
00042 isvc->addRef();
00043
00044 sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
00045 if (sc.isFailure()) {
00046 log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00047 << " does not implement IRootIOCnvSvc" << endreq;
00048 return sc;
00049 }
00050
00051 log << MSG::DEBUG << "initialized @" << (void*)this
00052 << " got RootIOCnvSvc @" << (void*)m_rioSvc
00053 << endreq;
00054 return sc;
00055 }
00056 StatusCode RootIOEvtSelector::finalize()
00057 {
00058 return this->Service::finalize();
00059 }
00060
00061
00062 StatusCode RootIOEvtSelector::createContext(IEvtSelector::Context*& c) const
00063 {
00064 MsgStream log(msgSvc(), "RootIOEvtSelector");
00065 log << MSG::DEBUG << "createContext" << endreq;
00066
00067 c = new RootIOEvtSelector::Context(this);
00068 return StatusCode::SUCCESS;
00069 }
00070
00071 StatusCode RootIOEvtSelector::next(IEvtSelector::Context& c) const
00072 {
00073 MsgStream log(msgSvc(), "RootIOEvtSelector");
00074 log << MSG::DEBUG << "next" << endreq;
00075 return this->next(c,1);
00076 }
00077
00078 StatusCode RootIOEvtSelector::next(IEvtSelector::Context& c, int jump) const
00079 {
00080 MsgStream log(msgSvc(), "RootIOEvtSelector");
00081 log << MSG::DEBUG << "next(" << jump << ")" << endreq;
00082 RootIOEvtSelector::Context* rc =
00083 dynamic_cast<RootIOEvtSelector::Context*>(&c);
00084 if (!rc) return StatusCode::FAILURE;
00085 return this->setEntry(*rc,rc->m_entry+jump);
00086 }
00087
00088 StatusCode RootIOEvtSelector::previous(IEvtSelector::Context& c) const
00089 {
00090 return this->previous(c,1);
00091 }
00092
00093 StatusCode RootIOEvtSelector::previous(IEvtSelector::Context& c, int jump) const
00094 {
00095 RootIOEvtSelector::Context* rc =
00096 dynamic_cast<RootIOEvtSelector::Context*>(&c);
00097 if (!rc) return StatusCode::FAILURE;
00098 rc->m_entry -= jump;
00099 return this->setEntry(*rc,rc->m_entry-jump);
00100 }
00101
00102 StatusCode RootIOEvtSelector::last(IEvtSelector::Context&) const
00103 {
00104 MsgStream log(msgSvc(), "RootIOEvtSelector");
00105 log << MSG::ERROR << "last() not currently supported" << endreq;
00106 return StatusCode::FAILURE;
00107 }
00108
00109 StatusCode RootIOEvtSelector::rewind(IEvtSelector::Context&) const
00110 {
00111 MsgStream log(msgSvc(), "RootIOEvtSelector");
00112 log << MSG::ERROR << "rewind() not currently supported" << endreq;
00113 return StatusCode::FAILURE;
00114 }
00115
00116 StatusCode RootIOEvtSelector::setEntry(RootIOEvtSelector::Context& rc, int entry) const
00117 {
00118 MsgStream log(msgSvc(), "RootIOEvtSelector");
00119 log << MSG::DEBUG << "setEntry(" << entry << ")" << endreq;
00120
00121 IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
00122 IRootIOSvc::InputStreamMap::iterator it, done = ism.end();
00123 int errors = 0;
00124 for (it = ism.begin(); it != done; ++it) {
00125 RootInputStream* ris = it->second;
00126 bool okay = ris->setEntry(entry);
00127 if (!okay) {
00128 log << MSG::WARNING
00129 << "setEntry("<<entry<<") failed to set entry on input stream for "
00130 << it->first << endreq;
00131 ++errors;
00132 continue;
00133 }
00134 }
00135
00136 if (errors) return StatusCode::FAILURE;
00137 rc.m_entry = entry;
00138 return StatusCode::SUCCESS;
00139 }
00140
00141
00142 StatusCode RootIOEvtSelector::createAddress(const IEvtSelector::Context& c,
00143 IOpaqueAddress*& iop) const
00144 {
00145 MsgStream log(msgSvc(), "RootIOEvtSelector");
00146 log << MSG::DEBUG << "createAddress" << endreq;
00147 const RootIOEvtSelector::Context* rc =
00148 dynamic_cast<const RootIOEvtSelector::Context*>(&c);
00149 if (!rc) {
00150 log << MSG::ERROR << "Failed to get RootIOEvtSelector::Context" << endreq;
00151 return StatusCode::FAILURE;
00152 }
00153
00154 RootInputAddress* ria =
00155 new RootInputAddress(DataObject::classID(),"/Event");
00156 ria->setEntry(rc->m_entry);
00157 iop = ria;
00158 log << MSG::DEBUG << "createAddress for /Event" << endreq;
00159 return StatusCode::SUCCESS;
00160 }
00161
00162 StatusCode RootIOEvtSelector::releaseContext(IEvtSelector::Context*& c) const
00163
00164 {
00165 RootIOEvtSelector::Context* rc =
00166 dynamic_cast<RootIOEvtSelector::Context*>(c);
00167 if (!rc) return StatusCode::FAILURE;
00168
00169 delete rc;
00170 c = 0;
00171 return StatusCode::SUCCESS;
00172 }
00173
00174 StatusCode RootIOEvtSelector::resetCriteria(const string& cr,
00175 IEvtSelector::Context& c) const
00176 {
00177 MsgStream log(msgSvc(), "RootIOEvtSelector");
00178 log << MSG::INFO << "resetCriteria(" << cr << ")" << endreq;
00179
00180 RootIOEvtSelector::Context* rc =
00181 dynamic_cast<RootIOEvtSelector::Context*>(&c);
00182 if (!rc) return StatusCode::FAILURE;
00183
00184
00185
00186 return StatusCode::SUCCESS;
00187 }
00188
00189 StatusCode RootIOEvtSelector::queryInterface(const InterfaceID& riid,
00190 void** ppif)
00191 {
00192 MsgStream log(msgSvc(), "RootIOEvtSelector");
00193
00194 if (riid == IID_IEvtSelector) {
00195 *ppif = (IEvtSelector*)this;
00196 addRef();
00197 log << MSG::DEBUG << "queryInterface(IID_IEvtSelector)" << endreq;
00198 return StatusCode::SUCCESS;
00199 }
00200 log << MSG::DEBUG << "queryInterface(" << riid << ")" << endreq;
00201 return Service::queryInterface(riid,ppif);
00202 }
00203