| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# EventSelectorDataStream.cpp

Go to the documentation of this file.

    00001 //====================================================================
    00002 //      EventSelectorDataStream.cpp
    00003 //--------------------------------------------------------------------
    00004 //
    00005 //      Package    : EventSelectorDataStream  (The LHCb Event Selector Package)
    00006 //
    00007 //
    00008 //      Author     : M.Frank
    00009 //      Created    : 4/10/00
    00010 //      Changes    : R. Lambert 2009-09-04
    00011 //
    00012 //====================================================================
    00013 #define GAUDISVC_EVENTSELECTOR_EVENTSELECTORDATASTREAM_CPP 1
    00014 // Include files
    00015 #include "GaudiKernel/Tokenizer.h"
    00016 #include "GaudiKernel/IService.h"
    00017 #include "GaudiKernel/ISvcLocator.h"
    00018 #include "GaudiKernel/IConversionSvc.h"
    00019 #include "GaudiKernel/IDataManagerSvc.h"
    00020 #include "GaudiKernel/IPersistencySvc.h"
    00021 #include "GaudiKernel/PropertyMgr.h"
    00022 #include "GaudiKernel/MsgStream.h"
    00023 #include "GaudiKernel/EventSelectorDataStream.h"
    00024
    00025
    00026 // Output friend
    00027 MsgStream& operator<<(MsgStream& s, const EventSelectorDataStream& obj)    {
    00028   s << "Stream:"   << obj.name() << " Def:" << obj.definition();
    00029   return s;
    00030 }
    00031
    00032 // Output friend
    00033 std::ostream& operator<<(std::ostream& s, const EventSelectorDataStream& obj)    {
    00034   s << "Stream:"   << obj.name() << " Def:" << obj.definition();
    00035   return s;
    00036 }
    00037
    00038 // Standard Constructor
    00039 EventSelectorDataStream::EventSelectorDataStream(const std::string& nam, const std::string& def, ISvcLocator* svcloc)
    00040 : m_pSelector(0),
    00041   m_pSvcLocator(svcloc)
    00042 {
    00043   m_name = nam;
    00044   m_definition = def;
    00045   m_initialized = false;
    00046   m_properties = new Properties();
    00047 }
    00048
    00049 // Standard Constructor
    00050 EventSelectorDataStream::~EventSelectorDataStream()   {
    00051   setSelector(0);
    00052   delete m_properties;
    00053 }
    00054
    00055 // Set selector
    00056 void EventSelectorDataStream::setSelector(IEvtSelector* pSelector)   {
    00057   if ( 0 != pSelector   )  pSelector->addRef();
    00058   if ( 0 != m_pSelector )  m_pSelector->release();
    00059   m_pSelector = pSelector;
    00060 }
    00061
    00062 // Allow access to individual properties by name
    00063 StringProperty* EventSelectorDataStream::property(const std::string& nam)    {
    00064   for ( Properties::iterator i = m_properties->begin(); i != m_properties->end(); i++ )   {
    00065     if ( (*i).name() == nam )    {
    00066       return &(*i);
    00067     }
    00068   }
    00069   return 0;
    00070 }
    00071
    00072 // Allow access to individual properties by name
    00073 const StringProperty* EventSelectorDataStream::property(const std::string& nam)   const  {
    00074   for ( Properties::const_iterator i = m_properties->begin(); i != m_properties->end(); i++ )   {
    00075     if ( (*i).name() == nam )    {
    00076       return &(*i);
    00077     }
    00078   }
    00079   return 0;
    00080 }
    00081
    00082 // Parse input criteria
    00083 StatusCode EventSelectorDataStream::initialize()   {
    00084   bool isData = true;
    00085   std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
    00086   std::string cnt    = "/Event";
    00087   std::string db     = "<Unknown>";
    00088   Tokenizer tok(true);
    00089
    00090   SmartIF<IDataManagerSvc> eds(m_pSvcLocator->service("EventDataSvc"));
    00091   if( !eds.isValid() ) {
    00092     std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
    00093               << std::endl;
    00094     return StatusCode::FAILURE;
    00095   }
    00096   else {
    00097     cnt = eds->rootName();
    00098   }
    00099   m_selectorType = m_criteria = m_dbName= "";
    00100   m_properties->erase(m_properties->begin(), m_properties->end());
    00101
    00102   tok.analyse(m_definition, " ", "", "", "=", "'", "'");
    00103   for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ )   {
    00104     long hash = -1;
    00105     const std::string& tag = (*i).tag();
    00106     const std::string& val = (*i).value();
    00107     switch( ::toupper(tag[0]) )    {
    00108     case 'A':
    00109       auth = val;
    00110       break;
    00111     case 'C':
    00112       svc  = "EvtTupleSvc";
    00113       isData = false;
    00114     case 'E':
    00115       hash = val.find('#');
    00116       if ( hash > 0 )   {
    00117         cnt  = val.substr(0,hash);
    00118         item = val.substr(hash+1, val.length()-hash-1);
    00119       }
    00120       else    {
    00121         cnt  = val;
    00122         item = "Address";
    00123       }
    00124       break;
    00125     case 'D':
    00126       m_criteria     = "FILE " + val;
    00127       m_dbName=val;
    00128       break;
    00129     case 'F':
    00130       switch( ::toupper(tag[1]) )    {
    00131       case 'I':
    00132         m_criteria   = "FILE " + val;
    00133         m_dbName=val;
    00134         break;
    00135       case 'U':
    00136         stmt = val;
    00137         break;
    00138       default:
    00139         break;
    00140       }
    00141       break;
    00142     case 'J':
    00143       m_criteria     = "JOBID " + val;
    00144       m_dbName=val;
    00145       dbtyp          = "SICB";
    00146       break;
    00147     case 'T':
    00148       switch( ::toupper(tag[1]) )    {
    00149       case 'Y':
    00150         dbtyp = val;
    00151         break;
    00152       default:
    00153         break;
    00154       }
    00155       break;
    00156     case 'S':
    00157       switch( ::toupper(tag[1]) )    {
    00158       case 'E':
    00159         sel = val;
    00160         break;
    00161       case 'V':
    00162         svc = val;
    00163         collsvc = val;
    00164         break;
    00165       default:
    00166         break;
    00167       }
    00168       break;
    00169     default:
    00170       m_properties->push_back(StringProperty(tag,val));
    00171       break;
    00172     }
    00173   }
    00174   if ( !isData )    { // Unfortunately options do not come in order...
    00175     m_selectorType = "EventCollectionSelector";
    00176     svc  = "EvtTupleSvc";
    00177   }
    00178   else if ( dbtyp.substr(0,4) == "POOL" )    {
    00179     m_selectorType = "PoolDbEvtSelector";
    00180   }
    00181   else if ( svc.empty() ) {
    00182     m_selectorType = "DbEvtSelector";
    00183   }
    00184   else  {
    00185     m_selectorType = svc;
    00186   }
    00187   StatusCode status = StatusCode::SUCCESS;
    00188   if ( svc.length() == 0 && dbtyp.length() != 0 )    {
    00189     SmartIF<IPersistencySvc> ipers(m_pSvcLocator->service("EventPersistencySvc"));
    00190     if ( ipers.isValid() )   {
    00191       IConversionSvc* icnvSvc = 0;
    00192       status = ipers->getService(dbtyp, icnvSvc);
    00193       if ( status.isSuccess() )   {
    00194         IService* isvc = 0;
    00195         status = icnvSvc->queryInterface(IService::interfaceID(), pp_cast<void>(&isvc));
    00196         if ( status.isSuccess() )   {
    00197           svc = isvc->name();
    00198           isvc->release();
    00199         }
    00200       }
    00201     }
    00202   }
    00203   m_properties->push_back( StringProperty("Function",      stmt));
    00204   m_properties->push_back( StringProperty("CnvService",    svc));
    00205   m_properties->push_back( StringProperty("Authentication",auth));
    00206   m_properties->push_back( StringProperty("Container",     cnt));
    00207   m_properties->push_back( StringProperty("Item",          item));
    00208   m_properties->push_back( StringProperty("Criteria",      sel));
    00209   m_properties->push_back( StringProperty("DbType",        dbtyp));
    00210   m_properties->push_back( StringProperty("DB",            m_criteria));
    00211   if ( !isData && !collsvc.empty() )    {
    00212     m_properties->push_back( StringProperty("DbService",   collsvc));
    00213   }
    00214
    00215   m_initialized = status.isSuccess();
    00216   return status;
    00217 }
    00218
    00219 // Parse input criteria
    00220 StatusCode EventSelectorDataStream::finalize()   {
    00221   setSelector(0);
    00222   if ( m_properties )  {
    00223     m_properties->clear();
    00224   }
    00225   m_initialized = false;
    00226   return StatusCode::SUCCESS;
    00227 }