Gaudi Framework, version v20r3

Generated: 24 Nov 2008

PoolDbEvtSelector Class Reference

#include <PoolDbEvtSelector.h>

Inheritance diagram for PoolDbEvtSelector:

Inheritance graph
[legend]
Collaboration diagram for PoolDbEvtSelector:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 39 of file PoolDbEvtSelector.h.


Public Member Functions

virtual StatusCode initialize ()
 IService implementation: Db event selector override.
virtual StatusCode finalize ()
 IService implementation: Service finalization.
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 Query interfaces of Interface.
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.
 PoolDbEvtSelector (const std::string &name, ISvcLocator *svcloc)
 Service Constructor.
virtual ~PoolDbEvtSelector ()
 Standard destructor.

Protected Attributes

std::string m_cnvSvcName
IPoolDbMgrm_dbMgr
CLID m_rootCLID
std::string m_rootName
std::string m_criteria

Constructor & Destructor Documentation

PoolDbEvtSelector::PoolDbEvtSelector ( const std::string &  name,
ISvcLocator svcloc 
)

Service Constructor.

Definition at line 122 of file PoolDbEvtSelector.cpp.

00124   : Service( name, svcloc),
00125     m_dbMgr(0), m_rootCLID(CLID_NULL)
00126 {
00127   declareProperty("CnvService",  m_cnvSvcName);
00128   pool::DbInstanceCount::increment(this);
00129 }

PoolDbEvtSelector::~PoolDbEvtSelector (  )  [virtual]

Standard destructor.

Definition at line 131 of file PoolDbEvtSelector.cpp.

00131                                       {
00132   pool::DbInstanceCount::decrement(this);
00133 }


Member Function Documentation

StatusCode PoolDbEvtSelector::initialize (  )  [virtual]

IService implementation: Db event selector override.

Reimplemented from Service.

Definition at line 146 of file PoolDbEvtSelector.cpp.

00146                                             {
00147   // Initialize base class
00148   StatusCode status = Service::initialize();
00149   MsgStream log(messageService(), name());
00150   if ( !status.isSuccess() )    {
00151     log << MSG::ERROR << "Error initializing base class Service!" << endreq;
00152     return status;
00153   }
00154   // Retrieve conversion service handling event iteration
00155   status = serviceLocator()->service(m_cnvSvcName, m_dbMgr);
00156   if( !status.isSuccess() ) {
00157     log << MSG::ERROR 
00158         << "Unable to localize interface IID_IPoolDbMgr from service:" 
00159         << m_cnvSvcName << endreq;
00160     return status;
00161   }
00162   // Get DataSvc
00163   IDataManagerSvc* eds = 0;
00164   status = serviceLocator()->service("EventDataSvc", eds);
00165   if( !status.isSuccess() ) {
00166     log << MSG::ERROR 
00167       << "Unable to localize interface IID_IDataManagerSvc "
00168       << "from service EventDataSvc"
00169             << endreq;
00170     return status;
00171   }
00172   m_rootCLID = eds->rootCLID();
00173   m_rootName = eds->rootName();
00174   eds->release();
00175   log << MSG::DEBUG << "Selection root:" << m_rootName 
00176                     << " CLID:" << m_rootCLID << endreq;
00177   return status;
00178 }

StatusCode PoolDbEvtSelector::finalize ( void   )  [virtual]

IService implementation: Service finalization.

Reimplemented from Service.

Definition at line 181 of file PoolDbEvtSelector.cpp.

00181                                           {
00182   // Initialize base class
00183   MsgStream log(messageService(), name());
00184   pool::releasePtr(m_dbMgr);
00185   StatusCode status = Service::finalize();
00186   if ( !status.isSuccess() )    {
00187     log << MSG::ERROR << "Error initializing base class Service!" << endreq;
00188   }
00189   return status;
00190 }

StatusCode PoolDbEvtSelector::queryInterface ( const InterfaceID riid,
void **  ppvUnknown 
) [virtual]

Query interfaces of Interface.

Parameters:
riid ID of Interface to be retrieved
ppvUnknown Pointer to Location for interface pointer

Reimplemented from Service.

Definition at line 136 of file PoolDbEvtSelector.cpp.

00136                                                                                   {
00137   if ( riid == IID_IEvtSelector )  {
00138     *ppvIf = (IEvtSelector*)this;
00139     addRef();
00140     return SUCCESS;
00141   }
00142   return Service::queryInterface( riid, ppvIf );
00143 }

StatusCode PoolDbEvtSelector::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 193 of file PoolDbEvtSelector.cpp.

00194 {
00195   refpCtxt = new PoolDbContext(this);
00196   return StatusCode::SUCCESS;
00197 }

StatusCode PoolDbEvtSelector::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 200 of file PoolDbEvtSelector.cpp.

00200                                                                  {
00201   return StatusCode::FAILURE;
00202 }

StatusCode PoolDbEvtSelector::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 205 of file PoolDbEvtSelector.cpp.

00206 {
00207   PoolDbContext* pCtxt = dynamic_cast<PoolDbContext*>(&ctxt);
00208   if ( pCtxt != 0 ) {
00209     pool::DbSelect* it = pCtxt->iterator();
00210     if ( !it ) {
00211       PoolDbContext::ListName::const_iterator fileit = pCtxt->fileIterator();
00212       if ( pCtxt->currentInput().length() > 0 ) {
00213         pCtxt->setToken(0);
00214         m_dbMgr->disconnect(pCtxt->currentInput());
00215       }
00216       if ( fileit != pCtxt->files().end() ) {
00217         std::string input = *fileit;
00218         pCtxt->setFileIterator(++fileit);
00219         it = pCtxt->selectInput(m_dbMgr, "", input, m_rootName);
00220       }
00221     }
00222     if ( it ) {
00223       pool::Token* token = 0;
00224       if ( it->next(token).isSuccess() )  {
00225         pCtxt->setToken(token);
00226         if( 0 == pCtxt->token() ) {
00227           pCtxt->setIterator(0);
00228           return next(ctxt);
00229         }
00230         return StatusCode::SUCCESS;
00231       }
00232       return StatusCode::FAILURE;
00233     }
00234   }
00235   if ( pCtxt ) {
00236     if ( pCtxt->currentInput().length() > 0 ) {
00237       m_dbMgr->disconnect( pCtxt->currentInput() );
00238     }
00239     pCtxt->setToken(0);
00240     pCtxt->setIterator(0);
00241     pCtxt->setCurrentInput("");
00242     pCtxt->setFileIterator(pCtxt->files().end());
00243   }  
00244   return StatusCode::FAILURE;
00245 }

StatusCode PoolDbEvtSelector::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 248 of file PoolDbEvtSelector.cpp.

00249 {
00250   if ( jump > 0 ) {
00251     for ( int i = 0; i < jump; ++i ) {
00252       StatusCode status = next(ctxt);
00253       if ( !status.isSuccess() ) {
00254         return status;
00255       }
00256     }
00257     return StatusCode::SUCCESS;
00258   }
00259   return StatusCode::FAILURE;
00260 }

StatusCode PoolDbEvtSelector::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 263 of file PoolDbEvtSelector.cpp.

00264 {
00265   MsgStream log(msgSvc(), name());
00266   log << MSG::FATAL 
00267     << " EventSelector Iterator, operator -- not supported " << endreq;
00268   return StatusCode::FAILURE;
00269 }

StatusCode PoolDbEvtSelector::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 272 of file PoolDbEvtSelector.cpp.

00273 {
00274   if ( jump > 0 ) {
00275     for ( int i = 0; i < jump; ++i ) {
00276       StatusCode status = previous(ctxt);
00277       if ( !status.isSuccess() ) {
00278         return status;
00279       }
00280     }
00281     return StatusCode::SUCCESS;
00282   }
00283   return StatusCode::FAILURE;
00284 }

StatusCode PoolDbEvtSelector::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 287 of file PoolDbEvtSelector.cpp.

00288 {
00289   PoolDbContext* pCtxt = dynamic_cast<PoolDbContext*>(&ctxt);
00290   if ( pCtxt ) {
00291     if ( pCtxt->currentInput().length() > 0 ) {
00292       m_dbMgr->disconnect( pCtxt->currentInput() );
00293     }
00294     pCtxt->setToken(0);
00295     pCtxt->setIterator(0);
00296     pCtxt->setCurrentInput("");
00297     pCtxt->setFileIterator(pCtxt->files().begin());
00298     return StatusCode::SUCCESS;
00299   }
00300   return StatusCode::FAILURE;
00301 }

StatusCode PoolDbEvtSelector::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 304 of file PoolDbEvtSelector.cpp.

00305 {
00306   const PoolDbContext* pctxt = dynamic_cast<const PoolDbContext*>(&ctxt);
00307   if ( pctxt ) {
00308     pool::Token* tok = pctxt->token();
00309     if ( 0 != tok )  {
00310       PoolDbAddress* pA = 0;
00311       if ( m_dbMgr->createAddress(tok, &pA).isSuccess() )  {
00312         pAddr = pA;
00313         return StatusCode::SUCCESS;
00314       }
00315       pool::releasePtr(tok);
00316     }
00317   }
00318   pAddr = 0;
00319   return StatusCode::FAILURE;
00320 }

StatusCode PoolDbEvtSelector::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 323 of file PoolDbEvtSelector.cpp.

00324 {
00325   PoolDbContext* pCtxt = dynamic_cast<PoolDbContext*>(ctxt);
00326   if ( pCtxt ) {
00327     pool::deletePtr(pCtxt);
00328     return StatusCode::SUCCESS;
00329   }
00330   return StatusCode::FAILURE;
00331 }

StatusCode PoolDbEvtSelector::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 334 of file PoolDbEvtSelector.cpp.

00336 {
00337   MsgStream log(messageService(), name());
00338   PoolDbContext* ctxt = dynamic_cast<PoolDbContext*>(&context);
00339   std::string db, typ, item, sel, stmt, aut, addr;
00340   if ( ctxt )  {
00341     if ( criteria.substr(0,5) == "FILE " )  {
00342       // The format for the criteria is:
00343       //        FILE  filename1, filename2 ...
00344       db = criteria.substr(5);
00345     }
00346     else  {
00347       Tokenizer tok(true);
00348       tok.analyse(criteria," ","","","=","'","'");
00349       for(Tokenizer::Items::iterator i=tok.items().begin(); i!=tok.items().end();i++) {
00350         std::string tmp = (*i).tag().substr(0,3);
00351         if(tmp=="DAT")  {
00352           db = (*i).value();
00353         }
00354         if(tmp=="OPT")   {
00355           if((*i).value() != "REA")   {
00356             log << MSG::ERROR << "Option:\"" << (*i).value() << "\" not valid" << endreq;
00357             return StatusCode::FAILURE;
00358           }
00359         }
00360         if (tmp=="TYP") {
00361           typ = (*i).value();
00362         }
00363         if(tmp=="ADD")  {
00364           item = (*i).value();
00365         }
00366         if(tmp=="SEL")  {
00367           sel = (*i).value();
00368         }
00369         if(tmp=="FUN")  {
00370           stmt = (*i).value();
00371         }
00372         if(tmp=="AUT")  {
00373           aut = (*i).value();
00374         }
00375         if(tmp=="COL")  {
00376           addr = (*i).value();
00377         }
00378       }
00379     }
00380     // It's now time to parse the criteria for the event selection
00381     // The format for the criteria is:
00382     //        FILE  filename1, filename2 ...
00383     //        JOBID number1-number2, number3, ...
00384     std::string rest = db;
00385     ctxt->files().clear();
00386     while(true)  {
00387       int ipos = rest.find_first_not_of(" ,");
00388       if (ipos == -1 ) break;
00389       rest = rest.substr(ipos, std::string::npos);// remove blanks before
00390       int lpos  = rest.find_first_of(" ,");       // locate next blank
00391       ctxt->files().push_back( rest.substr(0,lpos )); // insert in list
00392       if (lpos == -1 ) break;
00393       rest = rest.substr(lpos, std::string::npos);// get the rest
00394     }
00395     ctxt->setFileIterator(ctxt->files().begin());
00396     ctxt->setCriteria(criteria);
00397     return StatusCode::SUCCESS;
00398   }
00399   log << MSG::ERROR << "Invalid iteration context." << endreq;
00400   return StatusCode::FAILURE;
00401 }


Member Data Documentation

std::string PoolDbEvtSelector::m_cnvSvcName [protected]

Definition at line 132 of file PoolDbEvtSelector.h.

Definition at line 133 of file PoolDbEvtSelector.h.

Definition at line 134 of file PoolDbEvtSelector.h.

std::string PoolDbEvtSelector::m_rootName [protected]

Definition at line 135 of file PoolDbEvtSelector.h.

std::string PoolDbEvtSelector::m_criteria [protected]

Definition at line 136 of file PoolDbEvtSelector.h.


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

Generated at Mon Nov 24 14:46:14 2008 for Gaudi Framework, version v20r3 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004