| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# EventCollectionSelector Class Reference

Definition of class EventCollectionSelector. More...

`#include <EventCollectionSelector.h>`

Inheritance diagram for EventCollectionSelector:
[legend]
Collaboration diagram for EventCollectionSelector:
[legend]

List of all members.

## 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< INTupleSvc > | m_tupleSvc
| Reference to Tuple service.
SmartIF< 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_dbSvc
| Database service (exclusive property with db type).
std::string | m_statement
| Selector name.
## Classes
class | MyContextType

## 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.

## 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("DbService",     m_dbSvc    = "");
    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(msgSvc(), name());
    00101   if ( !status.isSuccess() )    {
    00102     log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
    00103     return status;
    00104   }
    00105   m_pAddrCreator = serviceLocator()->service("EventPersistencySvc");
    00106   if(!m_pAddrCreator.isValid()) {
    00107     log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endmsg;
    00108     return status;
    00109   }
    00110   m_tupleSvc = serviceLocator()->service(m_tupleSvcName);
    00111   if( !m_tupleSvc.isValid() )   {
    00112     log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endmsg;
    00113     return status;
    00114   }
    00115   return status;
    00116 }

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

Service override: Finalize Service.

Reimplemented from Service.

Definition at line 252 of file EventCollectionSelector.cpp.

    00252                                                 {
    00253   // release services
    00254   m_pAddrCreator = 0;
    00255   m_tupleSvc = 0;
    00256   return Service::finalize();
    00257 }

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

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

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

    00278 {
    00279   return next(refCtxt, 1);
    00280 }

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

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

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

    00301 {
    00302   return previous(refCtxt, 1);
    00303 }

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

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

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

    00324 {
    00325   return StatusCode::FAILURE;
    00326 }

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

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

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

    00362 {
    00363   MyContextType *ctxt  = dynamic_cast<MyContextType*>(refCtxt);
    00364   if ( ctxt )   {
    00365     delete ctxt;
    00366     ctxt = 0;
    00367     return StatusCode::SUCCESS;
    00368   }
    00369   return StatusCode::FAILURE;
    00370 }

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

    00376 {
    00377   MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
    00378   if ( ctxt )   {
    00379     ctxt->criteria = cr;
    00380     return StatusCode::SUCCESS;
    00381   }
    00382   return StatusCode::FAILURE;
    00383 }

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

    00388 {
    00389   return StatusCode::FAILURE;
    00390 }

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

Connect collection to selector.

Definition at line 232 of file EventCollectionSelector.cpp.

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

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(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     if ( !m_dbSvc.empty() )
    00127       ident += "SVC='" + m_dbSvc + "' ";
    00128     else
    00129       ident += "TYP='" + m_dbType + "' ";
    00130     ident += "OPT='READ' ";
    00131     if ( m_authentication.length() > 0 )    {
    00132       ident += "AUTH='" + m_authentication + "' ";
    00133     }
    00134     status = svc->connect(ident);
    00135   }
    00136   return status;
    00137 }

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

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

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

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

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

Read next record of the N-tuple.

Definition at line 183 of file EventCollectionSelector.cpp.

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

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

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

## Member Data Documentation

SmartIF<INTupleSvc> EventCollectionSelector::m_tupleSvc`[mutable, protected]`

Reference to Tuple service.

Definition at line 79 of file EventCollectionSelector.h.

SmartIF<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_dbSvc`[protected]`

Database service (exclusive property with db type).

Definition at line 96 of file EventCollectionSelector.h.

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

Selector name.

Definition at line 98 of file EventCollectionSelector.h.

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

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