| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

Public Member Functions | Protected Attributes | Private Member Functions

# Gaudi::RootEvtSelector Class Reference

Concrete event selector implementation to access ROOT files. More...

`#include <GAUDIROOT/RootEvtSelector.h>`

Inheritance diagram for Gaudi::RootEvtSelector:
[legend]
Collaboration diagram for Gaudi::RootEvtSelector:
[legend]

List of all members.

## Public Member Functions
| RootEvtSelector (const std::string &name, ISvcLocator *svcloc)
| Service Constructor.
virtual | ~RootEvtSelector ()
| Standard destructor.
virtual StatusCode | initialize ()
| IService implementation: Db event selector override.
virtual StatusCode | finalize ()
| IService implementation: Service finalization.
virtual StatusCode | createContext (Context *&refpCtxt) const
| Create a new event loop context.
virtual StatusCode | last (Context &refContext) const
| Access last item in the iteration.
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 *&) 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.
## Protected Attributes
RootCnvSvc * | m_dbMgr
| Reference to the corresponding conversion service.
CLID | m_rootCLID
| Class id of root node to create opaque address.
std::string | m_persName
| Property; Name of the persistency service to search for conversion service.
std::string | m_cnvSvcName
| Property; Name of the concversion service used to create opaque addresses.
std::string | m_rootName
| Property: Name of the ROOT entry name.
std::string | m_criteria
| Property: File criteria to define item iteration.
std::string | m_dummy
| Property: dummy to fake backwards compatibility.
## Private Member Functions
StatusCode | error (const std::string &msg) const
| Helper method to issue error messages.

## Detailed Description

Concrete event selector implementation to access ROOT files.

Author:
  M.Frank

Version:
  1.0

Date:
  20/12/2009

Definition at line 41 of file RootEvtSelector.h.

## Constructor & Destructor Documentation

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

Service Constructor.

Definition at line 100 of file RootEvtSelector.cpp.

    : base_class(name, svcloc), m_rootCLID(CLID_NULL)
    {
      m_cnvSvcName = "Gaudi::RootCnvSvc/RootCnvSvc";
      m_persName   = "EventPersistencySvc";
      declareProperty("EvtPersistencySvc",m_persName="EventPersistencySvc");
      declareProperty("DbType",m_dummy);
    }

virtual Gaudi::RootEvtSelector::~RootEvtSelector | ( | ) | `[inline, virtual]`

Standard destructor.

Definition at line 51 of file RootEvtSelector.h.

    {}

## Member Function Documentation

StatusCode RootEvtSelector::createAddress | ( | const Context & | refCtxt,
|  | IOpaqueAddress *& | pAddr
| ) |  | const`[virtual]`

Create new Opaque address corresponding to the current record.

Parameters:

  refCtxt | [IN/OUT] Reference to the context

Returns:
  StatusCode indicating success or failure

Implements IEvtSelector.

Definition at line 272 of file RootEvtSelector.cpp.

                                                                                     {
      const RootEvtSelectorContext* pctxt = dynamic_cast<const RootEvtSelectorContext*>(&ctxt);
      if ( pctxt ) {
        long ent = pctxt->entry();
        if ( ent >= 0 )  {
          RootEvtSelectorContext::Files::const_iterator fileit = pctxt->fileIterator();
          if ( fileit != pctxt->files().end() ) {
            const string par[2] = {pctxt->fid(), m_rootName};
            const unsigned long ipar[2] = {0,ent};
            return m_dbMgr->createAddress(m_dbMgr->repSvcType(),m_rootCLID,&par[0],&ipar[0],pAddr);
          }
        }
      }
      pAddr = 0;
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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 165 of file RootEvtSelector.cpp.

                                                                       {
      refpCtxt = new RootEvtSelectorContext(this);
      return StatusCode::SUCCESS;
    }

StatusCode RootEvtSelector::error | ( | const std::string & | msg ) | const`[private]`

Helper method to issue error messages.

Definition at line 110 of file RootEvtSelector.cpp.

                                                               {
      MsgStream log(msgSvc(), name());
      log << MSG::ERROR << msg << endmsg;
      return StatusCode::FAILURE;
    }

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

IService implementation: Service finalization.

Reimplemented from Service.

Definition at line 157 of file RootEvtSelector.cpp.

                                            {
      // Initialize base class
      if ( m_dbMgr ) m_dbMgr->release();
      m_dbMgr = 0; // release
      return Service::finalize();
    }

StatusCode RootEvtSelector::initialize | ( | void | ) | `[virtual]`

IService implementation: Db event selector override.

Reimplemented from Service.

Definition at line 117 of file RootEvtSelector.cpp.

                                              {
      // Initialize base class
      StatusCode status = Service::initialize();
      if ( !status.isSuccess() ) {
        return error("Error initializing base class Service!");
      }

      SmartIF<IPersistencySvc> ipers(serviceLocator()->service(m_persName));
      if( !ipers.isValid() )   {
        return error("Unable to locate IPersistencySvc interface of "+m_persName);
      }
      IConversionSvc *cnvSvc = 0;
      Gaudi::Utils::TypeNameString itm(m_cnvSvcName);
      status = ipers->getService(itm.name(),cnvSvc);
      if( !status.isSuccess() )   {
        status = ipers->getService(itm.type(),cnvSvc);
        if( !status.isSuccess() )   {
          return error("Unable to locate IConversionSvc interface of database type "+m_cnvSvcName);
        }
      }
      m_dbMgr = dynamic_cast<RootCnvSvc*>(cnvSvc);
      if( !m_dbMgr ) {
        cnvSvc->release();
        return error("Unable to localize service:"+m_cnvSvcName);
      }
      m_dbMgr->addRef();

      // Get DataSvc
      SmartIF<IDataManagerSvc> eds(serviceLocator()->service("EventDataSvc"));
      if( !eds.isValid() ) {
        return error("Unable to localize service EventDataSvc");
      }
      m_rootCLID = eds->rootCLID();
      m_rootName = eds->rootName();
      MsgStream log(msgSvc(), name());
      log << MSG::DEBUG << "Selection root:" << m_rootName << " CLID:" << m_rootCLID << endmsg;
      return status;
    }

StatusCode RootEvtSelector::last | ( | Context & | refContext ) | const`[virtual]`

Access last item in the iteration.

Parameters:

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

Implements IEvtSelector.

Definition at line 171 of file RootEvtSelector.cpp.

                                                                   {
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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 176 of file RootEvtSelector.cpp.

                                                         {
      RootEvtSelectorContext* pCtxt = dynamic_cast<RootEvtSelectorContext*>(&ctxt);
      if ( pCtxt ) {
        TBranch* b = pCtxt->branch();
        if ( !b ) {
          RootEvtSelectorContext::Files::const_iterator fileit = pCtxt->fileIterator();
          pCtxt->setBranch(0);
          pCtxt->setEntry(-1);
          if ( fileit != pCtxt->files().end() ) {
            RootDataConnection* con=0;
            string     in = *fileit;
            StatusCode sc = m_dbMgr->connectDatabase(in,IDataConnection::READ,&con);
            if ( sc.isSuccess() ) {
              string section = m_rootName[0] == '/' ? m_rootName.substr(1) : m_rootName;
              b = con->getBranch(section,m_rootName);
              if ( b ) {
                pCtxt->setFID(con->fid());
                pCtxt->setBranch(b);
                return next(ctxt);
              }
            }
            m_dbMgr->disconnect(in).ignore();
            pCtxt->setFileIterator(++fileit);
            return next(ctxt);
          }
          return StatusCode::FAILURE;
        }
        long ent = pCtxt->entry();
        Long64_t nent = b->GetEntries();
        if ( nent > (ent+1) ) {
          pCtxt->setEntry(++ent);
          return StatusCode::SUCCESS;
        }
        RootEvtSelectorContext::Files::const_iterator fit = pCtxt->fileIterator();
        pCtxt->setFileIterator(++fit);
        pCtxt->setEntry(-1);
        pCtxt->setBranch(0);
        pCtxt->setFID("");
        return next(ctxt);
      }
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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 220 of file RootEvtSelector.cpp.

                                                                  {
      if ( jump > 0 ) {
        for ( int i = 0; i < jump; ++i ) {
          StatusCode status = next(ctxt);
          if ( !status.isSuccess() ) {
            return status;
          }
        }
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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 239 of file RootEvtSelector.cpp.

                                                                       {
      if ( jump > 0 ) {
        for ( int i = 0; i < jump; ++i ) {
          StatusCode status = previous(ctxt);
          if ( !status.isSuccess() ) {
            return status;
          }
        }
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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 234 of file RootEvtSelector.cpp.

                                                                    {
      return error("EventSelector Iterator, operator -- not supported ");
    }

StatusCode RootEvtSelector::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 290 of file RootEvtSelector.cpp.

                                                                     {
      RootEvtSelectorContext* pCtxt = dynamic_cast<RootEvtSelectorContext*>(ctxt);
      if ( pCtxt ) {
        delete pCtxt;
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

StatusCode RootEvtSelector::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.

Parameters:

  cr | The new criteria string.
  c | Reference pointer to the Context object.

Implements IEvtSelector.

Definition at line 302 of file RootEvtSelector.cpp.

    {
      MsgStream log(msgSvc(), name());
      RootEvtSelectorContext* ctxt = dynamic_cast<RootEvtSelectorContext*>(&context);
      string db, typ, item, sel, stmt, aut, addr;
      if ( ctxt )  {
        if ( criteria.substr(0,5) == "FILE " )  {
          // The format for the criteria is:
          //        FILE  filename1, filename2 ...
          db = criteria.substr(5);
        }
        else  {
          Tokenizer tok(true);
          tok.analyse(criteria," ","","","=","'","'");
          for(Tokenizer::Items::iterator i=tok.items().begin(); i!=tok.items().end();i++) {
            string tmp = (*i).tag().substr(0,3);
            if(tmp=="DAT")  {
              db = (*i).value();
            }
            if(tmp=="OPT")   {
              if((*i).value() != "REA")   {
                log << MSG::ERROR << "Option:\"" << (*i).value() << "\" not valid" << endmsg;
                return StatusCode::FAILURE;
              }
            }
            if (tmp=="TYP") {
              typ = (*i).value();
            }
            if(tmp=="ADD")  {
              item = (*i).value();
            }
            if(tmp=="SEL")  {
              sel = (*i).value();
            }
            if(tmp=="FUN")  {
              stmt = (*i).value();
            }
            if(tmp=="AUT")  {
              aut = (*i).value();
            }
            if(tmp=="COL")  {
              addr = (*i).value();
            }
          }
        }
        // It's now time to parse the criteria for the event selection
        // The format for the criteria is:
        //        FILE  filename1, filename2 ...
        //        JOBID number1-number2, number3, ...
        RootEvtSelectorContext::Files files;
        string rest = db;
        files.clear();
        while(true)  {
          int ipos = rest.find_first_not_of(" ,");
          if (ipos == -1 ) break;
          rest = rest.substr(ipos,string::npos);// remove blanks before
          int lpos  = rest.find_first_of(" ,");       // locate next blank
          files.push_back(rest.substr(0,lpos )); // insert in list
          if (lpos == -1 ) break;
          rest = rest.substr(lpos,string::npos);// get the rest
        }
        ctxt->setFiles(files);
        ctxt->setFileIterator(ctxt->files().begin());
        return StatusCode::SUCCESS;
      }
      return error("Invalid iteration context.");
    }

StatusCode RootEvtSelector::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 253 of file RootEvtSelector.cpp.

                                                            {
      RootEvtSelectorContext* pCtxt = dynamic_cast<RootEvtSelectorContext*>(&ctxt);
      if ( pCtxt ) {
        RootEvtSelectorContext::Files::const_iterator fileit = pCtxt->fileIterator();
        if ( fileit != pCtxt->files().end() ) {
          string input = *fileit;
          m_dbMgr->disconnect(input).ignore();
        }
        pCtxt->setFID("");
        pCtxt->setEntry(-1);
        pCtxt->setBranch(0);
        pCtxt->setFileIterator(pCtxt->files().begin());
        return StatusCode::SUCCESS;
      }
      return StatusCode::FAILURE;
    }

## Member Data Documentation

std::string Gaudi::RootEvtSelector::m_cnvSvcName`[protected]`

Property; Name of the concversion service used to create opaque addresses.

Definition at line 138 of file RootEvtSelector.h.

std::string Gaudi::RootEvtSelector::m_criteria`[protected]`

Property: File criteria to define item iteration.

Definition at line 142 of file RootEvtSelector.h.

RootCnvSvc* Gaudi::RootEvtSelector::m_dbMgr`[mutable, protected]`

Reference to the corresponding conversion service.

Definition at line 132 of file RootEvtSelector.h.

std::string Gaudi::RootEvtSelector::m_dummy`[protected]`

Property: dummy to fake backwards compatibility.

Definition at line 144 of file RootEvtSelector.h.

std::string Gaudi::RootEvtSelector::m_persName`[protected]`

Property; Name of the persistency service to search for conversion service.

Definition at line 136 of file RootEvtSelector.h.

CLID Gaudi::RootEvtSelector::m_rootCLID`[protected]`

Class id of root node to create opaque address.

Definition at line 134 of file RootEvtSelector.h.

std::string Gaudi::RootEvtSelector::m_rootName`[protected]`

Property: Name of the ROOT entry name.

Definition at line 140 of file RootEvtSelector.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/RootCnv/RootCnv/RootEvtSelector.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/RootCnv/src/RootEvtSelector.cpp

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