| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# EventCollectionSelector Class Reference

`#include <EventCollectionSelector.h>`

Inheritance diagram for EventCollectionSelector:

[legend]
Collaboration diagram for EventCollectionSelector:

[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 | queryInterface (const InterfaceID &riid, void **ppvInterface)
| Service override: query interfaces.
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
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

## Constructor & Destructor Documentation

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

Standard Constructor.

Definition at line 79 of file EventCollectionSelector.cpp.

    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 | ( |  | ) |

Standard Destructor.

Definition at line 93 of file EventCollectionSelector.cpp.

    00093                                                     {
    00094 }

## Member Function Documentation

StatusCode EventCollectionSelector::initialize | ( |  | ) | `[virtual]`

Service override: Initialize service.

Reimplemented from Service.

Definition at line 97 of file EventCollectionSelector.cpp.

    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 | ( | void |  | ) | `[virtual]`

Service override: Finalize Service.

Reimplemented from Service.

Definition at line 250 of file EventCollectionSelector.cpp.

    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.

    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]`

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

    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]`

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

    00281 {
    00282   return next(refCtxt, 1);
    00283 }

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

    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]`

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

    00304 {
    00305   return previous(refCtxt, 1);
    00306 }

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

    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]`

Rewind the dataset.

Parameters:

  | refCtxt | [IN/OUT] Reference to the context

Returns:
  StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 326 of file EventCollectionSelector.cpp.

    00327 {
    00328   return StatusCode::FAILURE;
    00329 }

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

    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]`

Release existing event iteration context.

Parameters:

  | refCtxt | [IN/OUT] Reference to the context

Returns:
  StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 364 of file EventCollectionSelector.cpp.

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

    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.

Parameters:

  | refCtxt | [IN/OUT] Reference to the Context object.

Returns:
  StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 390 of file EventCollectionSelector.cpp.

    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.

    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.

    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.

    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.

    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.

    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.

Read previous record of the N-tuple.

Definition at line 199 of file EventCollectionSelector.cpp.

    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 }

## Member Data Documentation

INTupleSvc* EventCollectionSelector::m_tupleSvc`[mutable, protected]`

Reference to Tuple service.

Definition at line 79 of file EventCollectionSelector.h.

IAddressCreator* EventCollectionSelector::m_pAddrCreator`[mutable, protected]`

Definition at line 80 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_tupleSvcName`[protected]`

Name of the event collection service name.

Definition at line 82 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_authentication`[protected]`

Authentication string (if needed).

Definition at line 84 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_cntName`[protected]`

Container name.

Definition at line 86 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_itemName`[protected]`

Item name.

Definition at line 88 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_criteria`[protected]`

Criteria.

Definition at line 90 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_database`[protected]`

Datafile name.

Definition at line 92 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_dbType`[protected]`

Database type identifier.

Definition at line 94 of file EventCollectionSelector.h.

std::string EventCollectionSelector::m_statement`[protected]`

Selector name.

Definition at line 96 of file EventCollectionSelector.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiSvc/src/EventSelector/EventCollectionSelector.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiSvc/src/EventSelector/EventCollectionSelector.cpp