Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

EventCollectionSelector Class Reference

#include <EventCollectionSelector.h>

Inheritance diagram for EventCollectionSelector:

Inheritance graph
[legend]
Collaboration diagram for EventCollectionSelector:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition of class 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 | +---------+----------------------------------------------+---------+

Author:
Markus Frank
Version:
1.0

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 createContext (Context *&refpCtxt) const
 Create a new event loop context.
virtual StatusCode next (Context &refCtxt) const
 Get next iteration item from the event loop context.
virtual StatusCode next (Context &refCtxt, int jump) const
 Get next iteration item from the event loop context, but skip jump elements.
virtual StatusCode previous (Context &refCtxt) const
 Get previous iteration item from the event loop context.
virtual StatusCode previous (Context &refCtxt, int jump) const
 Get previous iteration item from the event loop context, but skip jump elements.
virtual StatusCode rewind (Context &refCtxt) const
 Rewind the dataset.
virtual StatusCode createAddress (const Context &refCtxt, IOpaqueAddress *&refpAddr) const
 Create new Opaque address corresponding to the current record.
virtual StatusCode releaseContext (Context *&refCtxt) const
 Release existing event iteration context.
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

SmartIF< INTupleSvcm_tupleSvc
 Reference to Tuple service.
SmartIF< IAddressCreatorm_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

Constructor & Destructor Documentation

EventCollectionSelector::EventCollectionSelector ( const std::string name,
ISvcLocator svcloc 
)

Standard Constructor.

Definition at line 79 of file EventCollectionSelector.cpp.

00080   : base_class(name, svcloc)
00081 {
00082   declareProperty("CnvService",    m_tupleSvcName = "EvtTupleSvc");
00083   declareProperty("Authentication",m_authentication= "");
00084   declareProperty("Container",     m_cntName  = "B2PiPi");
00085   declareProperty("Item",          m_itemName = "Address");
00086   declareProperty("Criteria",      m_criteria = "");
00087   declareProperty("DB",            m_database = "");
00088   declareProperty("DbType",        m_dbType   = "");
00089   declareProperty("Function",      m_statement= "NTuple::Selector");
00090 }

EventCollectionSelector::~EventCollectionSelector (  ) 

Standard Destructor.

Definition at line 92 of file EventCollectionSelector.cpp.

00092                                                     {
00093 }


Member Function Documentation

StatusCode EventCollectionSelector::initialize (  )  [virtual]

Service override: Initialize service.

Reimplemented from Service.

Definition at line 96 of file EventCollectionSelector.cpp.

00096                                                   {
00097   // Initialize base class
00098   StatusCode status = Service::initialize();
00099   MsgStream log(msgSvc(), name());
00100   if ( !status.isSuccess() )    {
00101     log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
00102     return status;
00103   }
00104   m_pAddrCreator = serviceLocator()->service("EventPersistencySvc");
00105   if(!m_pAddrCreator.isValid()) {
00106     log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endmsg;
00107     return status;
00108   }
00109   m_tupleSvc = serviceLocator()->service(m_tupleSvcName);
00110   if( !m_tupleSvc.isValid() )   {
00111     log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endmsg;
00112     return status;
00113   }
00114   return status;
00115 }

StatusCode EventCollectionSelector::finalize ( void   )  [virtual]

Service override: Finalize Service.

Reimplemented from Service.

Definition at line 248 of file EventCollectionSelector.cpp.

00248                                                 {
00249   // release services
00250   m_pAddrCreator = 0;
00251   m_tupleSvc = 0;
00252   return Service::finalize();
00253 }

StatusCode EventCollectionSelector::createContext ( Context *&  refpCtxt  )  const [virtual]

Create a new event loop context.

Parameters:
refpCtxt [IN/OUT] Reference to pointer to store the context
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 257 of file EventCollectionSelector.cpp.

00258 {
00259   refpCtxt = 0;
00260   std::auto_ptr<MyContextType> ctxt(new MyContextType());
00261   StatusCode status = connectCollection(ctxt.get());
00262   if( !status.isSuccess() )  {
00263     MsgStream log(msgSvc(), name());
00264     log << MSG::ERROR << "Unable to connect Collection file \"" << m_database << "\"" << endmsg;
00265     return status;
00266   }
00267   refpCtxt = ctxt.release();
00268   return StatusCode::SUCCESS;
00269 }

StatusCode EventCollectionSelector::next ( Context refCtxt  )  const [virtual]

Get next iteration item from the event loop context.

Parameters:
refCtxt [IN/OUT] Reference to the context
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 273 of file EventCollectionSelector.cpp.

00274 {
00275   return next(refCtxt, 1);
00276 }

StatusCode EventCollectionSelector::next ( Context refCtxt,
int  jump 
) const [virtual]

Get next iteration item from the event loop context, but skip jump elements.

Parameters:
refCtxt [IN/OUT] Reference to the context
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 280 of file EventCollectionSelector.cpp.

00281 {
00282   MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
00283   if ( ctxt )    {
00284     *(ctxt->item) = ctxt->addressBuffer;
00285     StatusCode sc = StatusCode::SUCCESS;
00286     for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
00287       sc = getNextRecord(ctxt->tuple);
00288     }
00289     return sc;
00290   }
00291   return StatusCode::FAILURE;
00292 }

StatusCode EventCollectionSelector::previous ( Context refCtxt  )  const [virtual]

Get previous iteration item from the event loop context.

Parameters:
refCtxt [IN/OUT] Reference to the context
jump [IN] Number of events to be skipped
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 296 of file EventCollectionSelector.cpp.

00297 {
00298   return previous(refCtxt, 1);
00299 }

StatusCode EventCollectionSelector::previous ( Context refCtxt,
int  jump 
) const [virtual]

Get previous iteration item from the event loop context, but skip jump elements.

Parameters:
refCtxt [IN/OUT] Reference to the context
jump [IN] Number of events to be skipped
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 303 of file EventCollectionSelector.cpp.

00304 {
00305   MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
00306   if ( ctxt )    {
00307     *(ctxt->item) = ctxt->addressBuffer;
00308     StatusCode sc = StatusCode::SUCCESS;
00309     for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
00310       sc = getPreviousRecord(ctxt->tuple);
00311     }
00312     return sc;
00313   }
00314   return StatusCode::FAILURE;
00315 }

StatusCode EventCollectionSelector::rewind ( Context refCtxt  )  const [virtual]

Rewind the dataset.

Parameters:
refCtxt [IN/OUT] Reference to the context
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 319 of file EventCollectionSelector.cpp.

00320 {
00321   return StatusCode::FAILURE;
00322 }

StatusCode EventCollectionSelector::createAddress ( const Context refCtxt,
IOpaqueAddress *&  refpAddr 
) const [virtual]

Create new Opaque address corresponding to the current record.

Parameters:
refCtxt [IN/OUT] Reference to the context
refpAddr [OUT] Reference to address pointer
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 326 of file EventCollectionSelector.cpp.

00327 {
00328   const MyContextType* ctxt = dynamic_cast<const MyContextType*>(&refCtxt);
00329   if ( ctxt )   {
00330     IOpaqueAddress* pA = *(ctxt->item);
00331     if ( pA )  {
00332       IOpaqueAddress* pAddress = 0;
00333       StatusCode status = m_pAddrCreator->createAddress(pA->svcType(),
00334                                                         pA->clID(),
00335                                                         pA->par(),
00336                                                         pA->ipar(),
00337                                                         pAddress);
00338       if ( status.isSuccess() )   {
00339         refpAddr = pAddress;
00340         return StatusCode::SUCCESS;
00341       }
00342       else    {
00343         MsgStream log(msgSvc(), name());
00344         log << MSG::ERROR << "Failed to access " << pA->par()[0]
00345             << ":" << pA->par()[1]
00346             << " SvcTyp:" << long(pA->svcType())
00347             << " CLID:"   << pA->clID()
00348             << endmsg;
00349       }
00350     }
00351   }
00352   return StatusCode::FAILURE;
00353 }

StatusCode EventCollectionSelector::releaseContext ( Context *&  refCtxt  )  const [virtual]

Release existing event iteration context.

Parameters:
refCtxt [IN/OUT] Reference to the context
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 357 of file EventCollectionSelector.cpp.

00358 {
00359   MyContextType *ctxt  = dynamic_cast<MyContextType*>(refCtxt);
00360   if ( ctxt )   {
00361     delete ctxt;
00362     ctxt = 0;
00363     return StatusCode::SUCCESS;
00364   }
00365   return StatusCode::FAILURE;
00366 }

StatusCode EventCollectionSelector::resetCriteria ( const std::string cr,
Context refCtxt 
) 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.

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.

Parameters:
cr The new criteria string.
c Reference pointer to the Context object.
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 371 of file EventCollectionSelector.cpp.

00372 {
00373   MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
00374   if ( ctxt )   {
00375     ctxt->criteria = cr;
00376     return StatusCode::SUCCESS;
00377   }
00378   return StatusCode::FAILURE;
00379 }

StatusCode EventCollectionSelector::last ( Context refCtxt  )  const [virtual]

Access last item in the iteration.

Parameters:
refCtxt [IN/OUT] Reference to the Context object.
Returns:
StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 383 of file EventCollectionSelector.cpp.

00384 {
00385   return StatusCode::FAILURE;
00386 }

StatusCode EventCollectionSelector::connectCollection ( MyContextType ctxt  )  const [virtual]

Connect collection to selector.

Definition at line 228 of file EventCollectionSelector.cpp.

00229 {
00230   if ( ctxt )  {
00231     StatusCode status = connectDataSource(m_database, m_dbType);
00232     if ( status.isSuccess() )   {
00233       status = connectTuple(m_cntName, m_itemName, ctxt->tuple, ctxt->item);
00234       if ( status.isSuccess() )   {
00235         status = connectStatement(m_statement, m_criteria, ctxt->tuple);
00236         if ( status.isSuccess() )   {
00237           *(ctxt->item) = 0;
00238           return status;
00239         }
00240       }
00241     }
00242     return status;
00243   }
00244   return StatusCode::FAILURE;
00245 }

StatusCode EventCollectionSelector::connectDataSource ( const std::string db,
const std::string typ 
) const [virtual]

Connect collection's data source to selector.

Definition at line 119 of file EventCollectionSelector.cpp.

00119                                                                                                   {
00120   StatusCode status = StatusCode::FAILURE;
00121   SmartIF<IDataSourceMgr> svc(m_tupleSvc);
00122   if ( svc.isValid( ) && db.length() > 0 )   {
00123     std::string ident = name() + ' ';
00124     ident += "DATAFILE='" + m_database.substr(5,m_database.length()) + "' ";
00125     ident += "TYP='" + m_dbType + "' ";
00126     ident += "OPT='READ' ";
00127     if ( m_authentication.length() > 0 )    {
00128       ident += "AUTH='" + m_authentication + "' ";
00129     }
00130     status = svc->connect(ident);
00131   }
00132   return status;
00133 }

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 137 of file EventCollectionSelector.cpp.

00137                                                                                                                                                  {
00138   std::string top = "/NTUPLES/" + name() + '/' + nam;
00139   StatusCode status = m_tupleSvc->retrieveObject(top, (DataObject*&)tup);
00140   if ( status.isSuccess() )    {
00141     item = new NTuple::Item<IOpaqueAddress*>();
00142     status = tup->item(itName, *item);
00143     if ( status.isSuccess() )   {
00144       return status;
00145     }
00146     else    {
00147       MsgStream log(msgSvc(), name());
00148       log << MSG::ERROR << "Item " << itName << " is not part of the collection:" << top << endmsg;
00149     }
00150     delete item;
00151     item = 0;
00152   }
00153   else  {
00154     MsgStream err(msgSvc(), name());
00155     err << MSG::ERROR << "Cannot connect to collection:" << top << endmsg;
00156   }
00157   tup = 0;
00158   return status;
00159 }

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 163 of file EventCollectionSelector.cpp.

00163                                                                                                             {
00164   std::string seltyp = typ;
00165   if ( seltyp.length() > 0 || crit.length() > 0 )   {
00166     if ( crit.length() > 0 && seltyp.length() == 0 ) seltyp = "NTuple::Selector";
00167     SmartIF<ISelectStatement> stmt(ROOT::Reflex::PluginService::Create<IInterface*>(seltyp, (IInterface*)serviceLocator()));
00168     if ( stmt.isValid( ) )    {
00169       if ( crit.length() > 0 ) stmt->setCriteria(crit);
00170       tuple->attachSelector(stmt).ignore();
00171       return StatusCode::SUCCESS;
00172     }
00173     return StatusCode::FAILURE;
00174   }
00175   return StatusCode::SUCCESS;
00176 }

StatusCode EventCollectionSelector::getNextRecord ( NTuple::Tuple tuple  )  const [virtual]

Read next record of the N-tuple.

Definition at line 179 of file EventCollectionSelector.cpp.

00179                                                                             {
00180   StatusCode status = StatusCode::FAILURE;
00181   if ( 0 != tuple )   {
00182     do {
00183       status = m_tupleSvc->readRecord(tuple);
00184       if ( status.isSuccess() )   {
00185         ISelectStatement* statement = tuple->selector();
00186         bool use_it = (statement) ? (*statement)(tuple) : true;
00187         if ( use_it )   {
00188           return status;
00189         }
00190       }
00191     } while ( status.isSuccess() );
00192   }
00193   return status;
00194 }

StatusCode EventCollectionSelector::getPreviousRecord ( NTuple::Tuple tuple  )  const [virtual]

Read next record of the N-tuple.

Read previous record of the N-tuple.

Definition at line 197 of file EventCollectionSelector.cpp.

00197                                                                                  {
00198   StatusCode status = StatusCode::FAILURE;
00199   if ( tuple )  {
00200     IRegistry* pReg = tuple->registry();
00201     if ( pReg )  {
00202       IOpaqueAddress* pAddr = pReg->address();
00203       if ( pAddr )  {
00204         long* ip = (long*)pAddr->ipar();
00205         do {
00206           if ( ip[1] > 1 )  {
00207             ip[1] -= 2;
00208             status = m_tupleSvc->readRecord(tuple);
00209             if ( status.isSuccess() )   {
00210               ISelectStatement* statement = tuple->selector();
00211               bool use_it = (statement) ? (*statement)(tuple) : true;
00212               if ( use_it )   {
00213                 return status;
00214               }
00215             }
00216           }
00217           else  {
00218             return StatusCode::FAILURE;
00219           }
00220         } while ( status.isSuccess() );
00221       }
00222     }
00223   }
00224   return StatusCode::FAILURE;
00225 }


Member Data Documentation

Reference to Tuple service.

Definition at line 79 of file EventCollectionSelector.h.

Definition at line 80 of file EventCollectionSelector.h.

Name of the event collection service name.

Definition at line 82 of file EventCollectionSelector.h.

Authentication string (if needed).

Definition at line 84 of file EventCollectionSelector.h.

Container name.

Definition at line 86 of file EventCollectionSelector.h.

Item name.

Definition at line 88 of file EventCollectionSelector.h.

Criteria.

Definition at line 90 of file EventCollectionSelector.h.

Datafile name.

Definition at line 92 of file EventCollectionSelector.h.

Database type identifier.

Definition at line 94 of file EventCollectionSelector.h.

Selector name.

Definition at line 96 of file EventCollectionSelector.h.


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

Generated at Mon Sep 7 18:17:33 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004