CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
bak_RootCnvSvc-04-01-14/src/RootEvtSelector.cxx
Go to the documentation of this file.
1// File and Version Information:
2// $Header: /bes/bes/CgemBossCvs/Event/RootCnvSvc/src/RootEvtSelector.cxx,v 1.1.1.1 2013/11/22 02:06:40 juxd Exp $
3//
4// Description:
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/IDataManagerSvc.h"
9#include "GaudiKernel/IAddressCreator.h"
10#include "GaudiKernel/GenericAddress.h"
11#include "RootCnvSvc/RootEvtSelector.h"
12#include "RootCnvSvc/RootInterface.h"
13#include "RootCnvSvc/RootEventContext.h"
14#include "EventModel/EventModel.h"
15
16extern const CLID& CLID_Event;
17extern const long int ROOT_StorageType;
18
19//static const SvcFactory<RootEvtSelector> s_factory;
20//const ISvcFactory& RootEvtSelectorFactory = s_factory;
21
22// Constructor
23RootEvtSelector::RootEvtSelector( const std::string& name, ISvcLocator* svcloc )
24 : Service( name, svcloc),
25 p_beginContext(0),
26 p_endContext(0) {
27 m_recId = new int;
28 (*m_recId) = -1;
29 declareProperty( "Input", m_jobInput="ROOT");
30 getMaxEvent();
31}
33 delete m_recId;
34}
35// Instantiation of a static factory class used by clients to create
36// instances of this service
38 MsgStream log(msgSvc(), name());
39 StatusCode sc = Service::initialize();
40 log << MSG::DEBUG << "RootEvtSelector::initialize" << endreq; if( sc.isSuccess() ) {
41 setProperties();
42 } else {
43 log << MSG::ERROR << "Unable to initialize service " << endreq;
44 }
45
46 if(m_jobInput.value() != " "){
47 sc = setCriteria(m_jobInput);
48 if(sc.isFailure()){
49 log << MSG::ERROR << "Unable to get input value" << endreq;
50 return sc;
51 }
52 }
53
54 // Retrieve conversion service handling event iteration
55 sc = serviceLocator()->service("EventCnvSvc", m_addrCreator);
56 if( !sc.isSuccess() ) {
57 log << MSG::ERROR <<
58 "Unable to localize interface IID_IAddressCreator from service:"
59 << "RootEventSelector"
60 << endreq;
61 return sc;
62 }
63 // Get DataSvc
64 IDataManagerSvc* eds = 0;
65 sc = serviceLocator()->service("EventDataSvc", eds, true);
66 if( !sc.isSuccess() ) {
67 log << MSG::ERROR
68 << "Unable to localize interface IID_IDataManagerSvc "
69 << "from RootEventSelector"
70 << endreq;
71 return sc;
72 }
73
74 m_rootCLID = eds->rootCLID();
75
76 // provide access to the Root Interface
77 m_rootInterface=RootInterface::Instance(log);
78 if (!m_rootInterface) log << MSG::ERROR << "Unable to start Root service within RootCnvSvc" << endreq;
79
80 // create root event context
81 p_beginContext = new RootEventContext(this);
82
83 return sc;
84}
85
86StatusCode RootEvtSelector::setCriteria( const std::string& criteria ) {
87 // Purpose and Method: set the input criteria
88 MsgStream log(msgSvc(), name());
89 m_criteria = criteria;
90
91 if( criteria == "ROOT" ) {
92 log << MSG::INFO << "RootEvtSelector input has been set to ROOT" << endreq;
93 m_criteriaType = ROOT;
94 }else if( criteria == "NONE"){
95 m_criteriaType = NONE;
96 log << MSG::INFO << "RootEvtSelector input has been set to NONE" << endreq;
97 }
98 else {
99 log << MSG::ERROR << "Invalid Event Selection Criteria: " << criteria << endreq;
100 return StatusCode::FAILURE;
101 }
102 return StatusCode::SUCCESS;
103}
104
105StatusCode
106RootEvtSelector::createContext(IEvtSelector::Context*& it) const
107{
108 it = p_beginContext;
109 return(StatusCode::SUCCESS);
110}
111
112// Implementation of IEvtSelector::next().
113StatusCode RootEvtSelector::next(IEvtSelector::Context& it) const
114{
115 return this->next();
116}
117
118//__________________________________________________________________________
119StatusCode RootEvtSelector::next(IEvtSelector::Context& ctxt, int jump) const {
120 if ( jump > 0 ) {
121 for ( int i = 0; i < jump; ++i ) {
122 StatusCode status = next(ctxt);
123 if ( !status.isSuccess() ) {
124 return status;
125 }
126 }
127 return StatusCode::SUCCESS;
128 }
129 return StatusCode::FAILURE;
130}
131
132StatusCode RootEvtSelector::previous(IEvtSelector::Context& /*it*/) const {
133 MsgStream log(messageService(), name());
134 log << MSG::ERROR << "RootEvtSelector::previous() not implemented" << endreq;
135 return(StatusCode::FAILURE);
136}
137
138StatusCode RootEvtSelector::previous(IEvtSelector::Context& it,int /*jump*/) const {
139 return(previous(it));
140}
141
142StatusCode RootEvtSelector::last(IEvtSelector::Context& it)const {
143 if (it.identifier() == p_endContext->identifier()) {
144 MsgStream log(messageService(), name());
145 log << MSG::DEBUG << "last(): Last event in InputStream." <<endreq;
146 return(StatusCode::SUCCESS);
147 }
148 return (StatusCode::FAILURE);
149}
150
151StatusCode RootEvtSelector::resetCriteria(const std::string& /*criteria*/, IEvtSelector::Context& /*ctxt*/) const {
152 return(StatusCode::SUCCESS);
153}
154
155
156StatusCode RootEvtSelector::rewind(IEvtSelector::Context& /*it*/) const {
157 MsgStream log(messageService(), name());
158 log << MSG::ERROR << "RootEvtSelector::rewind() not implemented" << endreq;
159 return(StatusCode::FAILURE);
160}
161
162StatusCode
163RootEvtSelector::releaseContext(IEvtSelector::Context*& /*it*/)const {
164 return(StatusCode::SUCCESS);
165}
166
167StatusCode RootEvtSelector::createAddress(const IEvtSelector::Context& /*it*/,
168 IOpaqueAddress*& iop) const {
169 iop = new GenericAddress(ROOT_StorageType, CLID_Event, " ", " ", 0);
170 return(StatusCode::SUCCESS);
171}
172
173StatusCode
175 MsgStream log(msgSvc(), name());
176
177 if(m_criteriaType == ROOT)
178 {
179 log<<MSG::INFO<<"m_criteriaType == ROOT"<<endreq;
180 (*m_recId)++;
181
182 //if((*m_recId)>m_evtMax){ // if get the max event number?
183 // return StatusCode::FAILURE;
184 //}else{ //didn't get the max event number
185 static int entry = 0;
186
187 bool endOfFile = m_rootInterface->getEOF();
188 entry++;
189 bool maxEntry = (entry >m_rootInterface->getEntries() && m_rootInterface->getEntries()>=0);
190 if(maxEntry) entry =1;
191 log<<MSG::INFO<<"entry = "<<entry<<" "<<maxEntry<<" "<<endOfFile<<endreq;
192 if(endOfFile || maxEntry){ //the using file is get max event or get the end of file
193 bool endAll = m_rootInterface->checkEndOfTree();
194
195 if(endAll){ //if all is finished ?
196 return StatusCode::FAILURE;
197 }
198 }
199 //} // to make it run if not set event number from jobOption
200 }
201 else if( m_criteriaType == NONE)
202 {
203 log << MSG::DEBUG << "Reading Event " << (*m_recId) << endreq;
204 //If we go over the count set equal to the end
205 if((*m_recId) > m_evtMax) {
206 return StatusCode::FAILURE;
207 }
208 }else {
209 //We are going to blow up if this situation happens
210 log << MSG::FATAL << "Cannot iterate a dead iterator" << endreq;
211 return StatusCode::FAILURE;
212 }
213 log << MSG::DEBUG << "Reading Event " << (*m_recId) << endreq;
214 log << MSG::DEBUG << "Max Event " << m_evtMax << endreq;
215 return StatusCode::SUCCESS;
216}
217
218StatusCode RootEvtSelector::queryInterface(const InterfaceID& riid, void** ppvInterface) {
219 if ( riid == IID_IRootEvtSelector ) {
220 *ppvInterface = (RootEvtSelector*)this;
221 }
222 else if ( riid == IEvtSelector::interfaceID() ) {
223 *ppvInterface = (IEvtSelector*)this;
224 }
225 else if ( riid == IProperty::interfaceID() ) {
226 *ppvInterface = (IProperty*)this;
227 }
228 else {
229 return Service::queryInterface( riid, ppvInterface );
230 }
231 addRef();
232 return SUCCESS;
233}
234
235StatusCode RootEvtSelector::getMaxEvent() {
236 IProperty* appPropMgr=0;
237 StatusCode status =
238 serviceLocator()->getService("ApplicationMgr", IProperty::interfaceID(),
239 reinterpret_cast<IInterface*&>( appPropMgr ));
240 if( status.isFailure() ) return status;
241
242 IntegerProperty evtMax("EvtMax",0);
243 status = appPropMgr->getProperty( &evtMax );
244 if (status.isFailure()) return status;
245
246 m_evtMax = evtMax.value();
247 return status;
248}
249
250
251
252
253
254
255
const long int ROOT_StorageType
const CLID & CLID_Event
Definition: EventModel.cxx:214
const CLID & CLID_Event
Definition: EventModel.cxx:214
const long int ROOT_StorageType
This class provides the Context for RootEventSelector.
virtual void * identifier() const
Inequality operator.
RootEvtSelector performs the function of controlling the ApplicationMgr loop.
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode setCriteria(const std::string &criteria)
virtual StatusCode rewind(Context &it) const
virtual StatusCode resetCriteria(const std::string &criteria, Context &context) const
virtual StatusCode last(Context &it) const
virtual StatusCode releaseContext(Context *&it) const
virtual StatusCode previous(Context &it) const
virtual StatusCode createContext(Context *&it) const
virtual StatusCode createAddress(const Context &it, IOpaqueAddress *&iop) const
RootEvtSelector(const std::string &name, ISvcLocator *svcloc)
virtual bool checkEndOfTree()
check if all the files is over 2005-11-28
static RootInterface * Instance(MsgStream log)
singleton behaviour