BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RootEvtSelector Class Reference

RootEvtSelector performs the function of controlling the ApplicationMgr loop. More...

#include <RootEvtSelector.h>

+ Inheritance diagram for RootEvtSelector:

Public Member Functions

 RootEvtSelector (const std::string &name, ISvcLocator *svcloc)
 
 ~RootEvtSelector ()
 
virtual StatusCode initialize ()
 
virtual StatusCode createContext (Context *&it) const
 
StatusCode next () const
 
virtual StatusCode next (Context &it) const
 
virtual StatusCode next (Context &it, int jump) const
 
virtual StatusCode previous (Context &it) const
 
virtual StatusCode previous (Context &it, int jump) const
 
virtual StatusCode last (Context &it) const
 
virtual StatusCode rewind (Context &it) const
 
virtual StatusCode createAddress (const Context &it, IOpaqueAddress *&iop) const
 
virtual StatusCode releaseContext (Context *&it) const
 
virtual StatusCode resetCriteria (const std::string &criteria, Context &context) const
 
virtual StatusCode setCriteria (const std::string &criteria)
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 
int getRecId () const
 
void getEntryFromTag () const
 

Detailed Description

RootEvtSelector performs the function of controlling the ApplicationMgr loop.

Adapted to RootCnvSvc from GlastSvc/EventSelector. The input property can now be set either to NONE or to ROOT. If it is NONE, the loop will run until it hits EvtMax. A new class variable was added :m_evtMax which is a local copy of the AppMgrs property.

Header
/bes/bes/BossCvs/Event/RootCnvSvc/RootCnvSvc/RootEvtSelector.h,v 1.17 2022/01/24 04:07:17 maqm Exp

Definition at line 29 of file RootEvtSelector.h.

Constructor & Destructor Documentation

◆ RootEvtSelector()

RootEvtSelector::RootEvtSelector ( const std::string & name,
ISvcLocator * svcloc )

Definition at line 39 of file RootEvtSelector.cxx.

40 : base_class( name, svcloc),
41 p_beginContext(0),
42 p_endContext(0) {
43 m_recId = new int;
44 (*m_recId) = -1;
45 declareProperty( "Input", m_jobInput="ROOT");
46 getMaxEvent();
47}

◆ ~RootEvtSelector()

RootEvtSelector::~RootEvtSelector ( )

Definition at line 48 of file RootEvtSelector.cxx.

48 {
49 delete m_recId;
50}

Member Function Documentation

◆ createAddress()

StatusCode RootEvtSelector::createAddress ( const Context & it,
IOpaqueAddress *& iop ) const
virtual

Definition at line 208 of file RootEvtSelector.cxx.

209 {
210 iop = new GenericAddress(ROOT_StorageType, CLID_Event, " ", " ", 0);
211 return(StatusCode::SUCCESS);
212}
const CLID & CLID_Event
const long int ROOT_StorageType

◆ createContext()

StatusCode RootEvtSelector::createContext ( Context *& it) const
virtual

Definition at line 147 of file RootEvtSelector.cxx.

148{
149 it = p_beginContext;
150 return(StatusCode::SUCCESS);
151}

◆ getEntryFromTag()

void RootEvtSelector::getEntryFromTag ( ) const

Definition at line 214 of file RootEvtSelector.cxx.

214 {
215 bool flag=true;;
216 MsgStream log(messageService(), name());
217 static std::string tempFile = "";
218 log << MSG::DEBUG <<"current file: "<<m_rootInterface->getCurrentFileName()<<endreq;
219 std::ifstream fin;
220 static std::string tagFile;
221 static int i=-1;
222 static std::vector<int> ventry;
223 int num1 = m_rootInterface->getCurrentFileNum();
224 int num2 = m_rootInterface->getTotalFileNum();
225
226
227 if(tempFile != m_rootInterface->getCurrentFileName())
228 {
229 tempFile = m_rootInterface->getCurrentFileName();
230 log << MSG::DEBUG<<"temp file: "<<tempFile<<endreq;
231 i=-1;
232 ventry.clear();
233 log << MSG::DEBUG<<"num1: "<<num1<<" num2: "<<num2<<endreq;
234 tagFile = (m_rootInterface->getTagInputFile())[num1];
235 log << MSG::DEBUG <<"tag file: "<<tagFile<<endreq;
236 m_tagFilterSvc->getVEntry(tagFile, ventry);
237 } //end of read a tag file
238
239 i++;
240 log << MSG::DEBUG<<"ventry i: "<<i<<endreq;
241 log << MSG::DEBUG<<"ventry size: "<<ventry.size()<<endreq;
242 if(i<ventry.size())
243 {
244 (*m_recId)=ventry[i];
245 log << MSG::DEBUG<<"ventry[i]: "<<ventry[i]<<endreq;
246 }
247 else
248 (*m_recId)= -1;
249
250 log << MSG::DEBUG<<"(*m_recId): "<<(*m_recId)<<endreq;
251
252 int vs = ventry.size();
253
254 if( (i>(vs-1)) && (num1<(num2-1)))
255 {
256 bool endAll = m_rootInterface->checkEndOfTree();
258 }
259 if( (i>(vs-1)) && (num1==(num2-1)))
260 (*m_recId)= -1;
261}
const int num1
void getEntryFromTag() const
virtual int getTotalFileNum()
virtual bool checkEndOfTree()
check if all the files is over 2005-11-28
virtual std::vector< std::string > getTagInputFile()
virtual int getCurrentFileNum()
virtual std::string getCurrentFileName()
StatusCode getVEntry(string, vector< int > &)

Referenced by getEntryFromTag(), and next().

◆ getRecId()

int RootEvtSelector::getRecId ( ) const
inline

◆ initialize()

StatusCode RootEvtSelector::initialize ( )
virtual

Definition at line 53 of file RootEvtSelector.cxx.

53 {
54 MsgStream log(msgSvc(), name());
55 StatusCode sc = Service::initialize();
56 log << MSG::DEBUG << "RootEvtSelector::initialize" << endreq; if( sc.isSuccess() ) {
57 setProperties();
58 } else {
59 log << MSG::ERROR << "Unable to initialize service " << endreq;
60 }
61
62 if(m_jobInput.value() != " "){
63 sc = setCriteria(m_jobInput);
64 if(sc.isFailure()){
65 log << MSG::ERROR << "Unable to get input value" << endreq;
66 return sc;
67 }
68 }
69
70 // Retrieve conversion service handling event iteration
71 sc = serviceLocator()->service("EventCnvSvc", m_addrCreator);
72 if( !sc.isSuccess() ) {
73 log << MSG::ERROR <<
74 "Unable to localize interface IID_IAddressCreator from service:"
75 << "RootEventSelector"
76 << endreq;
77 return sc;
78 }
79
80 // Get DataSvc
81 IDataManagerSvc* eds = 0;
82 sc = serviceLocator()->service("EventDataSvc", eds, true);
83 if( !sc.isSuccess() ) {
84 log << MSG::ERROR
85 << "Unable to localize interface IID_IDataManagerSvc "
86 << "from RootEventSelector"
87 << endreq;
88 return sc;
89 }
90
91 m_rootCLID = eds->rootCLID();
92
93 // provide access to the Root Interface
94 m_rootInterface=RootInterface::Instance(log);
95 log << MSG::INFO << "currentFile in RootEvtSelector::initialize "<<m_rootInterface->getCurrentFileName()<<endreq;
96 if (!m_rootInterface) log << MSG::ERROR << "Unable to start Root service within RootCnvSvc" << endreq;
97
98 // create root event context
99 p_beginContext = new RootEventContext(this);
100
101
102 ITagFilterSvc *tmpSvc;
103
104 ISvcLocator* svcLocator = Gaudi::svcLocator();
105 StatusCode status = svcLocator->service("TagFilterSvc",tmpSvc);
106 if (status.isSuccess()) {
107 log << MSG::INFO << "get the TagFilterSvc" << endreq;
108 m_tagFilterSvc=dynamic_cast<TagFilterSvc *>(tmpSvc);
109 }else {
110 log << MSG::WARNING << "could not get the TagFilterSvc. Ignore it." << endreq;
111 }
112
113 m_rootInterface->setTagInputFile(m_tagFilterSvc->getTagFiles());
114
115 vector<string> dstFiles = m_tagFilterSvc->getDstFiles();
116 int size = dstFiles.size();
117 std::string treeName="Event";
118
119 for(int i=0;i<size;i++)
120 {
121 std::cout<<"RootEvtSelector, dstFile: "<<dstFiles[i]<<std::endl;
122 m_rootInterface->addInput(treeName, dstFiles[i].c_str());
123 }
124 return sc;
125}
IMessageSvc * msgSvc()
This class provides the Context for RootEventSelector.
virtual StatusCode setCriteria(const std::string &criteria)
virtual void setTagInputFile(std::vector< std::string > input)
virtual StatusCode addInput(const std::string &treename, const std::string &file)
add input tree to the list
static RootInterface * Instance(MsgStream log)
singleton behaviour
vector< string > getTagFiles()
vector< string > getDstFiles()
char * c_str(Index i)

◆ last()

StatusCode RootEvtSelector::last ( Context & it) const
virtual

Definition at line 183 of file RootEvtSelector.cxx.

183 {
184 if (it.identifier() == p_endContext->identifier()) {
185 MsgStream log(messageService(), name());
186 log << MSG::DEBUG << "last(): Last event in InputStream." <<endreq;
187 return(StatusCode::SUCCESS);
188 }
189 return (StatusCode::FAILURE);
190}
virtual void * identifier() const
Inequality operator.

◆ next() [1/3]

StatusCode RootEvtSelector::next ( ) const

Definition at line 264 of file RootEvtSelector.cxx.

264 {
265 MsgStream log(msgSvc(), name());
266 if(m_criteriaType == ROOT)
267 {
268 log<<MSG::INFO<<"m_criteriaType == ROOT"<<endreq;
269 if(m_rootInterface->getSelectFromTag()!=0)
270 {
272 if((*m_recId)<0)
273 return StatusCode::FAILURE;
274 }
275
276 else
277 {
278 (*m_recId)++;
279
280 //if((*m_recId)>m_evtMax){ // if get the max event number?
281 // return StatusCode::FAILURE;
282 //}else{ //didn't get the max event number
283
284 static int entry = 0;
285
286 bool endOfFile = m_rootInterface->getEOF();
287 entry++;
288 bool maxEntry = (entry >m_rootInterface->getEntries() && m_rootInterface->getEntries()>=0);
289 if(maxEntry) entry =1;
290 log<<MSG::INFO<<"entry = "<<entry<<" "<<maxEntry<<" "<<endOfFile<<endreq;
291 if(endOfFile || maxEntry){ //the using file is get max event or get the end of file
292 bool endAll = m_rootInterface->checkEndOfTree();
293
294 if(endAll){ //if all is finished ?
295 return StatusCode::FAILURE;
296 }
297 }
298 }
299 //} // to make it run if not set event number from jobOption
300 }// end if(m_criteriaType == ROOT)
301 else if( m_criteriaType == NONE)
302 {
303 log << MSG::DEBUG << "Reading Event " << (*m_recId) << endreq;
304 //If we go over the count set equal to the end
305 if((*m_recId) > m_evtMax) {
306 return StatusCode::FAILURE;
307 }
308 }else {
309 //We are going to blow up if this situation happens
310 log << MSG::FATAL << "Cannot iterate a dead iterator" << endreq;
311 return StatusCode::FAILURE;
312 }
313
314 log << MSG::DEBUG << "Reading Event " << (*m_recId) << endreq;
315 log << MSG::DEBUG << "Max Event " << m_evtMax << endreq;
316 return StatusCode::SUCCESS;
317}
virtual bool getSelectFromTag()
virtual Int_t getEntries()
get nr of entries
virtual bool getEOF()
get EOF flag

◆ next() [2/3]

virtual StatusCode RootEvtSelector::next ( Context & it) const
virtual

◆ next() [3/3]

virtual StatusCode RootEvtSelector::next ( Context & it,
int jump ) const
virtual

◆ previous() [1/2]

virtual StatusCode RootEvtSelector::previous ( Context & it) const
virtual

◆ previous() [2/2]

virtual StatusCode RootEvtSelector::previous ( Context & it,
int jump ) const
virtual

◆ queryInterface()

StatusCode RootEvtSelector::queryInterface ( const InterfaceID & riid,
void ** ppvInterface )
virtual

Definition at line 319 of file RootEvtSelector.cxx.

319 {
320 if ( riid == IID_IRootEvtSelector ) {
321 *ppvInterface = (RootEvtSelector*)this;
322 }
323 else if ( riid == IEvtSelector::interfaceID() ) {
324 *ppvInterface = (IEvtSelector*)this;
325 }
326 else if ( riid == IProperty::interfaceID() ) {
327 *ppvInterface = (IProperty*)this;
328 }
329 else {
330 return Service::queryInterface( riid, ppvInterface );
331 }
332 addRef();
333 return SUCCESS;
334}
RootEvtSelector performs the function of controlling the ApplicationMgr loop.

◆ releaseContext()

StatusCode RootEvtSelector::releaseContext ( Context *& it) const
virtual

Definition at line 204 of file RootEvtSelector.cxx.

204 {
205 return(StatusCode::SUCCESS);
206}

◆ resetCriteria()

StatusCode RootEvtSelector::resetCriteria ( const std::string & criteria,
Context & context ) const
virtual

Definition at line 192 of file RootEvtSelector.cxx.

192 {
193 return(StatusCode::SUCCESS);
194}

◆ rewind()

StatusCode RootEvtSelector::rewind ( Context & it) const
virtual

Definition at line 197 of file RootEvtSelector.cxx.

197 {
198 MsgStream log(messageService(), name());
199 log << MSG::ERROR << "RootEvtSelector::rewind() not implemented" << endreq;
200 return(StatusCode::FAILURE);
201}

◆ setCriteria()

StatusCode RootEvtSelector::setCriteria ( const std::string & criteria)
virtual

Definition at line 127 of file RootEvtSelector.cxx.

127 {
128 // Purpose and Method: set the input criteria
129 MsgStream log(msgSvc(), name());
130 m_criteria = criteria;
131
132 if( criteria == "ROOT" ) {
133 log << MSG::INFO << "RootEvtSelector input has been set to ROOT" << endreq;
134 m_criteriaType = ROOT;
135 }else if( criteria == "NONE"){
136 m_criteriaType = NONE;
137 log << MSG::INFO << "RootEvtSelector input has been set to NONE" << endreq;
138 }
139 else {
140 log << MSG::ERROR << "Invalid Event Selection Criteria: " << criteria << endreq;
141 return StatusCode::FAILURE;
142 }
143 return StatusCode::SUCCESS;
144}

Referenced by initialize().


The documentation for this class was generated from the following files: