![]() |
|
|
Generated: 18 Jul 2008 |
#include <EventCollectionSelector.h>
Inheritance diagram for EventCollectionSelector:


Basic event selector service. The event selector service itself is able to connect other services to attached streams.
History: +---------+----------------------------------------------+---------+ | Date | Comment | Who | +---------+----------------------------------------------+---------+ | 3/10/00 | Initial version | M.Frank | +---------+----------------------------------------------+---------+
Definition at line 41 of file EventCollectionSelector.h.
Public Member Functions | ||||
| virtual StatusCode | initialize () | |||
| Service override: Initialize service. | ||||
| virtual StatusCode | finalize () | |||
| Service override: Finalize Service. | ||||
| virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvInterface) | |||
| Service override: query interfaces. | ||||
| virtual StatusCode | createContext (Context *&refpCtxt) const | |||
| ||||
| virtual StatusCode | next (Context &refCtxt) const | |||
| ||||
| virtual StatusCode | next (Context &refCtxt, int jump) const | |||
| ||||
| virtual StatusCode | previous (Context &refCtxt) const | |||
| ||||
| virtual StatusCode | previous (Context &refCtxt, int jump) const | |||
| ||||
| virtual StatusCode | rewind (Context &refCtxt) const | |||
| ||||
| virtual StatusCode | createAddress (const Context &refCtxt, IOpaqueAddress *&refpAddr) const | |||
| ||||
| virtual StatusCode | releaseContext (Context *&refCtxt) const | |||
| ||||
| virtual StatusCode | resetCriteria (const std::string &cr, Context &c) const | |||
| Will set a new criteria for the selection of the next list of events and will change the state of the context in a way to point to the new list. | ||||
| virtual StatusCode | last (Context &refCtxt) const | |||
| Access last item in the iteration. | ||||
| virtual StatusCode | connectCollection (MyContextType *ctxt) const | |||
| Connect collection to selector. | ||||
| virtual StatusCode | connectDataSource (const std::string &db, const std::string &typ) const | |||
| Connect collection's data source to selector. | ||||
| virtual StatusCode | connectTuple (const std::string &nam, const std::string &itName, NTuple::Tuple *&tup, NTuple::Item< IOpaqueAddress * > *&item) const | |||
| Connect to existing N-tuple. | ||||
| virtual StatusCode | connectStatement (const std::string &typ, const std::string &crit, INTuple *tuple) const | |||
| Connect selection statement to refine data access. | ||||
| virtual StatusCode | getNextRecord (NTuple::Tuple *tuple) const | |||
| Read next record of the N-tuple. | ||||
| virtual StatusCode | getPreviousRecord (NTuple::Tuple *tuple) const | |||
| Read next record of the N-tuple. | ||||
| EventCollectionSelector (const std::string &name, ISvcLocator *svcloc) | ||||
| Standard Constructor. | ||||
| ~EventCollectionSelector () | ||||
| Standard Destructor. | ||||
Protected Attributes | ||||
| INTupleSvc * | m_tupleSvc | |||
| Reference to Tuple service. | ||||
| IAddressCreator * | m_pAddrCreator | |||
| std::string | m_tupleSvcName | |||
| Name of the event collection service name. | ||||
| std::string | m_authentication | |||
| Authentication string (if needed). | ||||
| std::string | m_cntName | |||
| Container name. | ||||
| std::string | m_itemName | |||
| Item name. | ||||
| std::string | m_criteria | |||
| Criteria. | ||||
| std::string | m_database | |||
| Datafile name. | ||||
| std::string | m_dbType | |||
| Database type identifier. | ||||
| std::string | m_statement | |||
| Selector name. | ||||
Classes | ||||
| class | MyContextType | |||
| EventCollectionSelector::EventCollectionSelector | ( | const std::string & | name, | |
| ISvcLocator * | svcloc | |||
| ) |
Standard Constructor.
Definition at line 79 of file EventCollectionSelector.cpp.
References Service::declareProperty(), m_authentication, m_cntName, m_criteria, m_database, m_dbType, m_itemName, m_pAddrCreator, m_statement, and m_tupleSvcName.
00080 : Service( name, svcloc), m_tupleSvc(0) 00081 { 00082 m_pAddrCreator = 0; 00083 declareProperty("CnvService", m_tupleSvcName = "EvtTupleSvc"); 00084 declareProperty("Authentication",m_authentication= ""); 00085 declareProperty("Container", m_cntName = "B2PiPi"); 00086 declareProperty("Item", m_itemName = "Address"); 00087 declareProperty("Criteria", m_criteria = ""); 00088 declareProperty("DB", m_database = ""); 00089 declareProperty("DbType", m_dbType = ""); 00090 declareProperty("Function", m_statement= "NTuple::Selector"); 00091 }
| EventCollectionSelector::~EventCollectionSelector | ( | ) |
| StatusCode EventCollectionSelector::initialize | ( | ) | [virtual] |
Service override: Initialize service.
Reimplemented from Service.
Definition at line 97 of file EventCollectionSelector.cpp.
References endreq(), MSG::ERROR, Service::initialize(), StatusCode::isSuccess(), m_pAddrCreator, m_tupleSvc, m_tupleSvcName, Service::messageService(), Service::name(), ISvcLocator::service(), and Service::serviceLocator().
00097 { 00098 // Initialize base class 00099 StatusCode status = Service::initialize(); 00100 MsgStream log(messageService(), name()); 00101 if ( !status.isSuccess() ) { 00102 log << MSG::ERROR << "Error initializing base class Service!" << endreq; 00103 return status; 00104 } 00105 status = serviceLocator()->service("EventPersistencySvc", m_pAddrCreator, true ); 00106 if( !status.isSuccess() ) { 00107 log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endreq; 00108 return status; 00109 } 00110 status = serviceLocator()->service(m_tupleSvcName, m_tupleSvc, true ); 00111 if( !status.isSuccess() ) { 00112 log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endreq; 00113 return status; 00114 } 00115 return status; 00116 }
| StatusCode EventCollectionSelector::finalize | ( | ) | [virtual] |
Service override: Finalize Service.
Reimplemented from Service.
Definition at line 250 of file EventCollectionSelector.cpp.
References Service::finalize(), m_pAddrCreator, m_tupleSvc, and IInterface::release().
00250 { 00251 if ( m_pAddrCreator ) { 00252 m_pAddrCreator->release(); 00253 m_pAddrCreator = 0; 00254 } 00255 if ( m_tupleSvc ) { 00256 m_tupleSvc->release(); 00257 m_tupleSvc = 0; 00258 } 00259 return Service::finalize(); 00260 }
| StatusCode EventCollectionSelector::queryInterface | ( | const InterfaceID & | riid, | |
| void ** | ppvInterface | |||
| ) | [virtual] |
Service override: query interfaces.
Reimplemented from Service.
Definition at line 396 of file EventCollectionSelector.cpp.
References Service::addRef(), IID_IEvtSelector, Service::queryInterface(), and IInterface::SUCCESS.
00396 { 00397 if ( riid == IID_IEvtSelector ) { 00398 *ppvInterface = (IEvtSelector*)this; 00399 addRef(); 00400 return SUCCESS; 00401 } 00402 return Service::queryInterface( riid, ppvInterface ); 00403 }
| StatusCode EventCollectionSelector::createContext | ( | Context *& | refpCtxt | ) | const [virtual] |
| refpCtxt | [IN/OUT] Reference to pointer to store the context |
Definition at line 264 of file EventCollectionSelector.cpp.
References connectCollection(), endreq(), MSG::ERROR, std::auto_ptr< _Tp >::get(), StatusCode::isSuccess(), m_database, Service::msgSvc(), Service::name(), std::auto_ptr< _Tp >::release(), and StatusCode::SUCCESS.
00265 { 00266 refpCtxt = 0; 00267 std::auto_ptr<MyContextType> ctxt(new MyContextType()); 00268 StatusCode status = connectCollection(ctxt.get()); 00269 if( !status.isSuccess() ) { 00270 MsgStream log(msgSvc(), name()); 00271 log << MSG::ERROR << "Unable to connect Collection file \"" << m_database << "\"" << endreq; 00272 return status; 00273 } 00274 refpCtxt = ctxt.release(); 00275 return StatusCode::SUCCESS; 00276 }
| StatusCode EventCollectionSelector::next | ( | Context & | refCtxt | ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
Definition at line 280 of file EventCollectionSelector.cpp.
00281 { 00282 return next(refCtxt, 1); 00283 }
| StatusCode EventCollectionSelector::next | ( | Context & | refCtxt, | |
| int | jump | |||
| ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
Definition at line 287 of file EventCollectionSelector.cpp.
References EventCollectionSelector::MyContextType::addressBuffer, StatusCode::FAILURE, getNextRecord(), EventCollectionSelector::MyContextType::item, StatusCode::SUCCESS, and EventCollectionSelector::MyContextType::tuple.
00288 { 00289 MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt); 00290 if ( ctxt ) { 00291 *(ctxt->item) = ctxt->addressBuffer; 00292 StatusCode sc = StatusCode::SUCCESS; 00293 for ( int i=0; i<jump && sc.isSuccess(); ++i ) { 00294 sc = getNextRecord(ctxt->tuple); 00295 } 00296 return sc; 00297 } 00298 return StatusCode::FAILURE; 00299 }
| StatusCode EventCollectionSelector::previous | ( | Context & | refCtxt | ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
| jump | [IN] Number of events to be skipped |
Definition at line 303 of file EventCollectionSelector.cpp.
00304 { 00305 return previous(refCtxt, 1); 00306 }
| StatusCode EventCollectionSelector::previous | ( | Context & | refCtxt, | |
| int | jump | |||
| ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
| jump | [IN] Number of events to be skipped |
Definition at line 310 of file EventCollectionSelector.cpp.
References EventCollectionSelector::MyContextType::addressBuffer, StatusCode::FAILURE, getPreviousRecord(), EventCollectionSelector::MyContextType::item, StatusCode::SUCCESS, and EventCollectionSelector::MyContextType::tuple.
00311 { 00312 MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt); 00313 if ( ctxt ) { 00314 *(ctxt->item) = ctxt->addressBuffer; 00315 StatusCode sc = StatusCode::SUCCESS; 00316 for ( int i=0; i<jump && sc.isSuccess(); ++i ) { 00317 sc = getPreviousRecord(ctxt->tuple); 00318 } 00319 return sc; 00320 } 00321 return StatusCode::FAILURE; 00322 }
| StatusCode EventCollectionSelector::rewind | ( | Context & | refCtxt | ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
Definition at line 326 of file EventCollectionSelector.cpp.
References StatusCode::FAILURE.
00327 { 00328 return StatusCode::FAILURE; 00329 }
| StatusCode EventCollectionSelector::createAddress | ( | const Context & | refCtxt, | |
| IOpaqueAddress *& | refpAddr | |||
| ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
| refpAddr | [OUT] Reference to address pointer |
Definition at line 333 of file EventCollectionSelector.cpp.
References IOpaqueAddress::clID(), IAddressCreator::createAddress(), endreq(), MSG::ERROR, StatusCode::FAILURE, IOpaqueAddress::ipar(), StatusCode::isSuccess(), EventCollectionSelector::MyContextType::item, m_pAddrCreator, Service::msgSvc(), Service::name(), IOpaqueAddress::par(), StatusCode::SUCCESS, and IOpaqueAddress::svcType().
00334 { 00335 const MyContextType* ctxt = dynamic_cast<const MyContextType*>(&refCtxt); 00336 if ( ctxt ) { 00337 IOpaqueAddress* pA = *(ctxt->item); 00338 if ( pA ) { 00339 IOpaqueAddress* pAddress = 0; 00340 StatusCode status = m_pAddrCreator->createAddress(pA->svcType(), 00341 pA->clID(), 00342 pA->par(), 00343 pA->ipar(), 00344 pAddress); 00345 if ( status.isSuccess() ) { 00346 refpAddr = pAddress; 00347 return StatusCode::SUCCESS; 00348 } 00349 else { 00350 MsgStream log(msgSvc(), name()); 00351 log << MSG::ERROR << "Failed to access " << pA->par()[0] 00352 << ":" << pA->par()[1] 00353 << " SvcTyp:" << long(pA->svcType()) 00354 << " CLID:" << pA->clID() 00355 << endreq; 00356 } 00357 } 00358 } 00359 return StatusCode::FAILURE; 00360 }
| StatusCode EventCollectionSelector::releaseContext | ( | Context *& | refCtxt | ) | const [virtual] |
| refCtxt | [IN/OUT] Reference to the context |
Definition at line 364 of file EventCollectionSelector.cpp.
References StatusCode::FAILURE, and StatusCode::SUCCESS.
00365 { 00366 MyContextType *ctxt = dynamic_cast<MyContextType*>(refCtxt); 00367 if ( ctxt ) { 00368 delete ctxt; 00369 ctxt = 0; 00370 return StatusCode::SUCCESS; 00371 } 00372 return StatusCode::FAILURE; 00373 }
| StatusCode EventCollectionSelector::resetCriteria | ( | const std::string & | cr, | |
| Context & | c | |||
| ) | const [virtual] |
Will set a new criteria for the selection of the next list of events and will change the state of the context in a way to point to the new list.
| cr | The new criteria string. | |
| c | Reference pointer to the Context object. |
Definition at line 378 of file EventCollectionSelector.cpp.
References EventCollectionSelector::MyContextType::criteria, StatusCode::FAILURE, and StatusCode::SUCCESS.
00379 { 00380 MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt); 00381 if ( ctxt ) { 00382 ctxt->criteria = cr; 00383 return StatusCode::SUCCESS; 00384 } 00385 return StatusCode::FAILURE; 00386 }
| StatusCode EventCollectionSelector::last | ( | Context & | refCtxt | ) | const [virtual] |
Access last item in the iteration.
| refCtxt | [IN/OUT] Reference to the Context object. |
Definition at line 390 of file EventCollectionSelector.cpp.
References StatusCode::FAILURE.
00391 { 00392 return StatusCode::FAILURE; 00393 }
| StatusCode EventCollectionSelector::connectCollection | ( | MyContextType * | ctxt | ) | const [virtual] |
Connect collection to selector.
Definition at line 230 of file EventCollectionSelector.cpp.
References connectDataSource(), connectStatement(), connectTuple(), StatusCode::FAILURE, StatusCode::isSuccess(), EventCollectionSelector::MyContextType::item, m_cntName, m_criteria, m_database, m_dbType, m_itemName, m_statement, and EventCollectionSelector::MyContextType::tuple.
Referenced by createContext().
00231 { 00232 if ( ctxt ) { 00233 StatusCode status = connectDataSource(m_database, m_dbType); 00234 if ( status.isSuccess() ) { 00235 status = connectTuple(m_cntName, m_itemName, ctxt->tuple, ctxt->item); 00236 if ( status.isSuccess() ) { 00237 status = connectStatement(m_statement, m_criteria, ctxt->tuple); 00238 if ( status.isSuccess() ) { 00239 *(ctxt->item) = 0; 00240 return status; 00241 } 00242 } 00243 } 00244 return status; 00245 } 00246 return StatusCode::FAILURE; 00247 }
| StatusCode EventCollectionSelector::connectDataSource | ( | const std::string & | db, | |
| const std::string & | typ | |||
| ) | const [virtual] |
Connect collection's data source to selector.
Definition at line 120 of file EventCollectionSelector.cpp.
References StatusCode::FAILURE, IID_IDataSourceMgr, SmartIFBase< TYPE >::isValid(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_authentication, m_database, m_dbType, m_tupleSvc, Service::name(), and std::basic_string< _CharT, _Traits, _Alloc >::substr().
Referenced by connectCollection().
00120 { 00121 StatusCode status = StatusCode::FAILURE; 00122 SmartIF<IDataSourceMgr> svc(IID_IDataSourceMgr, m_tupleSvc); 00123 if ( svc.isValid( ) && db.length() > 0 ) { 00124 std::string ident = name() + ' '; 00125 ident += "DATAFILE='" + m_database.substr(5,m_database.length()) + "' "; 00126 ident += "TYP='" + m_dbType + "' "; 00127 ident += "OPT='READ' "; 00128 if ( m_authentication.length() > 0 ) { 00129 ident += "AUTH='" + m_authentication + "' "; 00130 } 00131 status = svc->connect(ident); 00132 } 00133 return status; 00134 }
| StatusCode EventCollectionSelector::connectTuple | ( | const std::string & | nam, | |
| const std::string & | itName, | |||
| NTuple::Tuple *& | tup, | |||
| NTuple::Item< IOpaqueAddress * > *& | item | |||
| ) | const [virtual] |
Connect to existing N-tuple.
Definition at line 138 of file EventCollectionSelector.cpp.
References endreq(), MSG::ERROR, StatusCode::isSuccess(), m_tupleSvc, Service::msgSvc(), Service::name(), and IDataProviderSvc::retrieveObject().
Referenced by connectCollection().
00138 { 00139 std::string top = "/NTUPLES/" + name() + '/' + nam; 00140 StatusCode status = m_tupleSvc->retrieveObject(top, (DataObject*&)tup); 00141 if ( status.isSuccess() ) { 00142 item = new NTuple::Item<IOpaqueAddress*>(); 00143 status = tup->item(itName, *item); 00144 if ( status.isSuccess() ) { 00145 return status; 00146 } 00147 else { 00148 MsgStream log(msgSvc(), name()); 00149 log << MSG::ERROR << "Item " << itName << " is not part of the collection:" << top << endreq; 00150 } 00151 delete item; 00152 item = 0; 00153 } 00154 else { 00155 MsgStream err(msgSvc(), name()); 00156 err << MSG::ERROR << "Cannot connect to collection:" << top << endreq; 00157 } 00158 tup = 0; 00159 return status; 00160 }
| StatusCode EventCollectionSelector::connectStatement | ( | const std::string & | typ, | |
| const std::string & | crit, | |||
| INTuple * | tuple | |||
| ) | const [virtual] |
Connect selection statement to refine data access.
Definition at line 164 of file EventCollectionSelector.cpp.
References INTuple::attachSelector(), StatusCode::FAILURE, StatusCode::ignore(), IID_ISelectStatement, SmartIFBase< TYPE >::isValid(), std::basic_string< _CharT, _Traits, _Alloc >::length(), Service::serviceLocator(), and StatusCode::SUCCESS.
Referenced by connectCollection().
00164 { 00165 std::string seltyp = typ; 00166 if ( seltyp.length() > 0 || crit.length() > 0 ) { 00167 if ( crit.length() > 0 && seltyp.length() == 0 ) seltyp = "NTuple::Selector"; 00168 SmartIF<ISelectStatement> stmt(IID_ISelectStatement, 00169 ROOT::Reflex::PluginService::Create<IInterface*>(seltyp, (IInterface*)serviceLocator())); 00170 if ( stmt.isValid( ) ) { 00171 if ( crit.length() > 0 ) stmt->setCriteria(crit); 00172 tuple->attachSelector(stmt).ignore(); 00173 return StatusCode::SUCCESS; 00174 } 00175 return StatusCode::FAILURE; 00176 } 00177 return StatusCode::SUCCESS; 00178 }
| StatusCode EventCollectionSelector::getNextRecord | ( | NTuple::Tuple * | tuple | ) | const [virtual] |
Read next record of the N-tuple.
Definition at line 181 of file EventCollectionSelector.cpp.
References StatusCode::FAILURE, StatusCode::isSuccess(), m_tupleSvc, INTupleSvc::readRecord(), and INTuple::selector().
Referenced by next().
00181 { 00182 StatusCode status = StatusCode::FAILURE; 00183 if ( 0 != tuple ) { 00184 do { 00185 status = m_tupleSvc->readRecord(tuple); 00186 if ( status.isSuccess() ) { 00187 ISelectStatement* statement = tuple->selector(); 00188 bool use_it = (statement) ? (*statement)(tuple) : true; 00189 if ( use_it ) { 00190 return status; 00191 } 00192 } 00193 } while ( status.isSuccess() ); 00194 } 00195 return status; 00196 }
| StatusCode EventCollectionSelector::getPreviousRecord | ( | NTuple::Tuple * | tuple | ) | const [virtual] |
Read next record of the N-tuple.
Definition at line 199 of file EventCollectionSelector.cpp.
References IRegistry::address(), StatusCode::FAILURE, IOpaqueAddress::ipar(), StatusCode::isSuccess(), m_tupleSvc, INTupleSvc::readRecord(), DataObject::registry(), and INTuple::selector().
Referenced by previous().
00199 { 00200 StatusCode status = StatusCode::FAILURE; 00201 if ( tuple ) { 00202 IRegistry* pReg = tuple->registry(); 00203 if ( pReg ) { 00204 IOpaqueAddress* pAddr = pReg->address(); 00205 if ( pAddr ) { 00206 long* ip = (long*)pAddr->ipar(); 00207 do { 00208 if ( ip[1] > 1 ) { 00209 ip[1] -= 2; 00210 status = m_tupleSvc->readRecord(tuple); 00211 if ( status.isSuccess() ) { 00212 ISelectStatement* statement = tuple->selector(); 00213 bool use_it = (statement) ? (*statement)(tuple) : true; 00214 if ( use_it ) { 00215 return status; 00216 } 00217 } 00218 } 00219 else { 00220 return StatusCode::FAILURE; 00221 } 00222 } while ( status.isSuccess() ); 00223 } 00224 } 00225 } 00226 return StatusCode::FAILURE; 00227 }
INTupleSvc* EventCollectionSelector::m_tupleSvc [mutable, protected] |
Reference to Tuple service.
Definition at line 79 of file EventCollectionSelector.h.
Referenced by connectDataSource(), connectTuple(), finalize(), getNextRecord(), getPreviousRecord(), and initialize().
IAddressCreator* EventCollectionSelector::m_pAddrCreator [mutable, protected] |
Definition at line 80 of file EventCollectionSelector.h.
Referenced by createAddress(), EventCollectionSelector(), finalize(), and initialize().
std::string EventCollectionSelector::m_tupleSvcName [protected] |
Name of the event collection service name.
Definition at line 82 of file EventCollectionSelector.h.
Referenced by EventCollectionSelector(), and initialize().
std::string EventCollectionSelector::m_authentication [protected] |
Authentication string (if needed).
Definition at line 84 of file EventCollectionSelector.h.
Referenced by connectDataSource(), and EventCollectionSelector().
std::string EventCollectionSelector::m_cntName [protected] |
Container name.
Definition at line 86 of file EventCollectionSelector.h.
Referenced by connectCollection(), and EventCollectionSelector().
std::string EventCollectionSelector::m_itemName [protected] |
Item name.
Definition at line 88 of file EventCollectionSelector.h.
Referenced by connectCollection(), and EventCollectionSelector().
std::string EventCollectionSelector::m_criteria [protected] |
Criteria.
Definition at line 90 of file EventCollectionSelector.h.
Referenced by connectCollection(), and EventCollectionSelector().
std::string EventCollectionSelector::m_database [protected] |
Datafile name.
Definition at line 92 of file EventCollectionSelector.h.
Referenced by connectCollection(), connectDataSource(), createContext(), and EventCollectionSelector().
std::string EventCollectionSelector::m_dbType [protected] |
Database type identifier.
Definition at line 94 of file EventCollectionSelector.h.
Referenced by connectCollection(), connectDataSource(), and EventCollectionSelector().
std::string EventCollectionSelector::m_statement [protected] |
Selector name.
Definition at line 96 of file EventCollectionSelector.h.
Referenced by connectCollection(), and EventCollectionSelector().