| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Classes | Public Member Functions | Protected Attributes

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

## Classes
class | MyContextType
## 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.

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

      : base_class(name, svcloc)
    {
      declareProperty("CnvService",    m_tupleSvcName = "EvtTupleSvc");
      declareProperty("Authentication",m_authentication= "");
      declareProperty("Container",     m_cntName  = "B2PiPi");
      declareProperty("Item",          m_itemName = "Address");
      declareProperty("Criteria",      m_criteria = "");
      declareProperty("DB",            m_database = "");
      declareProperty("DbType",        m_dbType   = "");
      declareProperty("DbService",     m_dbSvc    = "");
      declareProperty("Function",      m_statement= "NTuple::Selector");
    }

EventCollectionSelector::~EventCollectionSelector | ( | ) |

Standard Destructor.

Definition at line 93 of file EventCollectionSelector.cpp.

                                                        {
    }

## Member Function Documentation

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

Connect collection to selector.

Definition at line 232 of file EventCollectionSelector.cpp.

    {
      if ( ctxt )  {
        StatusCode status = connectDataSource(m_database, m_dbType);
        if ( status.isSuccess() )   {
          status = connectTuple(m_cntName, m_itemName, ctxt->tuple, ctxt->item);
          if ( status.isSuccess() )   {
            status = connectStatement(m_statement, m_criteria, ctxt->tuple);
            if ( status.isSuccess() )   {
              *(ctxt->item) = 0;
              return status;
            }
          }
        }
        return status;
      }
      return StatusCode::FAILURE;
    }

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.

                                                                                                      {
      StatusCode status = StatusCode::FAILURE;
      SmartIF<IDataSourceMgr> svc(m_tupleSvc);
      if ( svc.isValid( ) && db.length() > 0 )   {
        std::string ident = name() + ' ';
        ident += "DATAFILE='" + m_database.substr(5,m_database.length()) + "' ";
        if ( !m_dbSvc.empty() )
          ident += "SVC='" + m_dbSvc + "' ";
        else
          ident += "TYP='" + m_dbType + "' ";
        ident += "OPT='READ' ";
        if ( m_authentication.length() > 0 )    {
          ident += "AUTH='" + m_authentication + "' ";
        }
        status = svc->connect(ident);
      }
      return status;
    }

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.

                                                                                                                {
      std::string seltyp = typ;
      if ( seltyp.length() > 0 || crit.length() > 0 )   {
        if ( crit.length() > 0 && seltyp.length() == 0 ) seltyp = "NTuple::Selector";
        SmartIF<ISelectStatement> stmt(ROOT::Reflex::PluginService::Create<IInterface*>(seltyp, (IInterface*)serviceLocator()));
        if ( stmt.isValid( ) )    {
          if ( crit.length() > 0 ) stmt->setCriteria(crit);
          tuple->attachSelector(stmt).ignore();
          return StatusCode::SUCCESS;
        }
        return StatusCode::FAILURE;
      }
      return StatusCode::SUCCESS;
    }

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.

                                                                                                                                                     {
      std::string top = "/NTUPLES/" + name() + '/' + nam;
      StatusCode status = m_tupleSvc->retrieveObject(top, (DataObject*&)tup);
      if ( status.isSuccess() )    {
        item = new NTuple::Item<IOpaqueAddress*>();
        status = tup->item(itName, *item);
        if ( status.isSuccess() )   {
          return status;
        }
        else    {
          MsgStream log(msgSvc(), name());
          log << MSG::ERROR << "Item " << itName << " is not part of the collection:" << top << endmsg;
        }
        delete item;
        item = 0;
      }
      else  {
        MsgStream err(msgSvc(), name());
        err << MSG::ERROR << "Cannot connect to collection:" << top << endmsg;
      }
      tup = 0;
      return status;
    }

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.

    {
      const MyContextType* ctxt = dynamic_cast<const MyContextType*>(&refCtxt);
      if ( ctxt )   {
        IOpaqueAddress* pA = *(ctxt->item);
        if ( pA )  {
          IOpaqueAddress* pAddress = 0;
          StatusCode status = m_pAddrCreator->createAddress(pA->svcType(),
                                                            pA->clID(),
                                                            pA->par(),
                                                            pA->ipar(),
                                                            pAddress);
          if ( status.isSuccess() )   {
            refpAddr = pAddress;
            return StatusCode::SUCCESS;
          }
          else    {
            MsgStream log(msgSvc(), name());
            log << MSG::ERROR << "Failed to access " << pA->par()[0]
                << ":" << pA->par()[1]
                << " SvcTyp:" << long(pA->svcType())
                << " CLID:"   << pA->clID()
                << endmsg;
          }
        }
      }
      return StatusCode::FAILURE;
    }

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.

    {
      refpCtxt = 0;
      std::auto_ptr<MyContextType> ctxt(new MyContextType());
      StatusCode status = connectCollection(ctxt.get());
      if( !status.isSuccess() )  {
        MsgStream log(msgSvc(), name());
        log << MSG::ERROR << "Unable to connect Collection file \"" << m_database << "\"" << endmsg;
        return status;
      }
      refpCtxt = ctxt.release();
      return StatusCode::SUCCESS;
    }

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

Service override: Finalize Service.

Reimplemented from Service.

Definition at line 252 of file EventCollectionSelector.cpp.

                                                    {
      // release services
      m_pAddrCreator = 0;
      m_tupleSvc = 0;
      return Service::finalize();
    }

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

Read next record of the N-tuple.

Definition at line 183 of file EventCollectionSelector.cpp.

                                                                                {
      StatusCode status = StatusCode::FAILURE;
      if ( 0 != tuple )   {
        do {
          status = m_tupleSvc->readRecord(tuple);
          if ( status.isSuccess() )   {
            ISelectStatement* statement = tuple->selector();
            bool use_it = (statement) ? (*statement)(tuple) : true;
            if ( use_it )   {
              return status;
            }
          }
        } while ( status.isSuccess() );
      }
      return status;
    }

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.

                                                                                     {
      StatusCode status = StatusCode::FAILURE;
      if ( tuple )  {
        IRegistry* pReg = tuple->registry();
        if ( pReg )  {
          IOpaqueAddress* pAddr = pReg->address();
          if ( pAddr )  {
            long* ip = (long*)pAddr->ipar();
            do {
              if ( ip[1] > 1 )  {
                ip[1] -= 2;
                status = m_tupleSvc->readRecord(tuple);
                if ( status.isSuccess() )   {
                  ISelectStatement* statement = tuple->selector();
                  bool use_it = (statement) ? (*statement)(tuple) : true;
                  if ( use_it )   {
                    return status;
                  }
                }
              }
              else  {
                return StatusCode::FAILURE;
              }
            } while ( status.isSuccess() );
          }
        }
      }
      return StatusCode::FAILURE;
    }

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

Service override: Initialize service.

Reimplemented from Service.

Definition at line 97 of file EventCollectionSelector.cpp.

                                                      {
      // Initialize base class
      StatusCode status = Service::initialize();
      MsgStream log(msgSvc(), name());
      if ( !status.isSuccess() )    {
        log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
        return status;
      }
      m_pAddrCreator = serviceLocator()->service("EventPersistencySvc");
      if(!m_pAddrCreator.isValid()) {
        log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endmsg;
        return status;
      }
      m_tupleSvc = serviceLocator()->service(m_tupleSvcName);
      if( !m_tupleSvc.isValid() )   {
        log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endmsg;
        return status;
      }
      return status;
    }

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.

    {
      return StatusCode::FAILURE;
    }

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.

    {
      MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
      if ( ctxt )    {
        *(ctxt->item) = ctxt->addressBuffer;
        StatusCode sc = StatusCode::SUCCESS;
        for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
          sc = getNextRecord(ctxt->tuple);
        }
        return sc;
      }
      return StatusCode::FAILURE;
    }

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.

    {
      return next(refCtxt, 1);
    }

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.

    {
      MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
      if ( ctxt )    {
        *(ctxt->item) = ctxt->addressBuffer;
        StatusCode sc = StatusCode::SUCCESS;
        for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
          sc = getPreviousRecord(ctxt->tuple);
        }
        return sc;
      }
      return StatusCode::FAILURE;
    }

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.

    {
      return previous(refCtxt, 1);
    }

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.

    {
      MyContextType *ctxt  = dynamic_cast<MyContextType*>(refCtxt);
      if ( ctxt )   {
        delete ctxt;
        ctxt = 0;
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

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.

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.

    {
      MyContextType *ctxt  = dynamic_cast<MyContextType*>(&refCtxt);
      if ( ctxt )   {
        ctxt->criteria = cr;
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

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.

    {
      return StatusCode::FAILURE;
    }

## Member Data Documentation

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

Database service (exclusive property with db type)

Definition at line 96 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_itemName`[protected]`

Item name.

Definition at line 88 of file EventCollectionSelector.h.

SmartIF<IAddressCreator> EventCollectionSelector::m_pAddrCreator`[mutable, protected]`

Definition at line 80 of file EventCollectionSelector.h.

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

Selector name.

Definition at line 98 of file EventCollectionSelector.h.

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

Reference to Tuple service.

Definition at line 79 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.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines