Ejemplo n.º 1
0
StatusCode DataSvcFileEntriesTool::initialize(){
  StatusCode sc = AlgTool::initialize();
  if (sc.isFailure()) return sc;

  // Retrieve the pointer to the needed services.

  m_incidentSvc = serviceLocator()->service("IncidentSvc");
  if ( ! m_incidentSvc ) {
    MsgStream log(msgSvc(), name());
    log << MSG::ERROR << "Cannot get IncidentSvc" << endmsg;
    return StatusCode::FAILURE;
  }

  m_dataMgrSvc = m_dataSvc = serviceLocator()->service(m_dataSvcName);
  if ( ! m_dataSvc || ! m_dataMgrSvc ) {
    MsgStream log(msgSvc(), name());
    log << MSG::ERROR << "Cannot get IDataProviderSvc+IDataManagerSvc " << m_dataSvcName << endmsg;
    return StatusCode::FAILURE;
  }

  // Register ourself to the incident service as listener for BeginEvent
  m_incidentSvc->addListener(this, IncidentType::BeginEvent);

  // If the Root node is not specified, take the name from the data service itself.
  if (m_rootNode.empty()) {
    m_rootNode = m_dataMgrSvc->rootName();
  }

  // Clear the cache (in case the instance is re-initilized).
  m_leaves.clear();
  return StatusCode::SUCCESS;
}
Ejemplo n.º 2
0
SmartIF<IService> ServiceLocatorHelper::service(const std::string &name, const bool quiet, const bool createIf) const {
  SmartIF<IService> theSvc;
  if (isInThread()) {
    //first we look for  a thread-specific version of the service
    theSvc = serviceLocator()->service(name + threadName(), createIf);
  }
  // if not, try to find the common, single-threaded version of the service
  if (!theSvc.isValid()){
    theSvc = serviceLocator()->service(name, createIf);
  }

  if (theSvc.isValid()) {
    if (!quiet) {
      if (UNLIKELY(log().level() <= MSG::VERBOSE))
        log() << MSG::VERBOSE
              << "ServiceLocatorHelper::service: found service " << name <<endmsg;
    }
  } else {
    // if not return an error
    if (!quiet) {
      log() << MSG::ERROR
            << "ServiceLocatorHelper::service: can not locate service "
            << name;
      if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
      log() << MSG::ERROR << endmsg;
    }
  }
  return theSvc;
}
Ejemplo n.º 3
0
// IService implementation: initialize the service
StatusCode AppMgrRunable::initialize()   {
  StatusCode sc = Service::initialize();
  if ( sc.isSuccess() )     {
    sc = serviceLocator()->queryInterface(IAppMgrUI::interfaceID(), pp_cast<void>(&m_appMgrUI));
    // get property from application manager
    if ( m_evtMax == (int)0xFEEDBABE )   {
      SmartIF<IProperty> props(serviceLocator());
      setProperty(props->getProperty("EvtMax")).ignore();
    }
  }
  return sc;
}
Ejemplo n.º 4
0
/// IService implementation: Db event selector override
StatusCode EventSelector::initialize()    {
  // Initialize base class
  StatusCode status = Service::initialize();
  MsgStream logger(msgSvc(), name());
  if ( !status.isSuccess() )    {
    logger << MSG::ERROR << "Error initializing base class Service!" << endmsg;
    return status;
  }
  // Get the references to the services that are needed by the ApplicationMgr itself
  m_incidentSvc = serviceLocator()->service("IncidentSvc");
  if( !m_incidentSvc.isValid() )  {
    logger << MSG::FATAL << "Error retrieving IncidentSvc." << endmsg;
    return StatusCode::FAILURE;
  }
  if ( m_evtMax != INT_MAX )   {
    logger << MSG::ERROR << "EvtMax is an obsolete property of the event selector." << endmsg;
    logger << MSG::ERROR << "Please set \"ApplicationMgr.EvtMax = " << m_evtMax
           << ";\" to process the requested number of events." << endmsg;
    return StatusCode::FAILURE;
  }

  m_toolSvc = serviceLocator()->service("ToolSvc");
  if ( !m_toolSvc.isValid() ) {
    logger << MSG::ERROR << " Could not locate the Tool Service! " << endmsg;
    return StatusCode::FAILURE;
  }

  status = m_toolSvc->retrieveTool(m_streamManager.c_str(), m_streamtool, this);

  if( status.isFailure() ) {
    logger << MSG::ERROR << "Error initializing "
           << m_streamManager << endmsg;
    return status;
  }

  status = m_streamtool->clear();
  if( status.isFailure() ) {
    // Message already printed by the tool
    return status;
  }

  status = m_streamtool->addStreams(m_streamSpecs);

  m_streamSpecsLast = m_streamSpecs;

  m_streamID          = 0;

  return status;
}
Ejemplo n.º 5
0
// ============================================================================
// setup service
// ============================================================================
StatusCode DataOnDemandSvc::setup()
{
  if ( !(m_algMgr = serviceLocator()) ) // assignment meant
  {
    error() << "Failed to retrieve the IAlgManager interface." << endmsg;
    return StatusCode::FAILURE;
  }

  if ( !(m_incSvc = serviceLocator()->service("IncidentSvc")) ) // assignment meant
  {
    error() << "Failed to retrieve Incident service." << endmsg;
    return StatusCode::FAILURE;
  }
  m_incSvc->addListener(this, m_trapType);

  if ( !(m_dataSvc = serviceLocator()->service(m_dataSvcName)) ) // assignment meant
  {
    error()
      << "Failed to retrieve the data provider interface of "
      << m_dataSvcName << endmsg;
    return StatusCode::FAILURE;
  }

  // No need to get the ToolSvc if we are not using tools
  if (!(m_nodeMapTools.empty() && m_algMapTools.empty())) {
    if ( !(m_toolSvc = serviceLocator()->service("ToolSvc")) ) // assignment meant
    {
      error() << "Failed to retrieve ToolSvc" << endmsg;
      return StatusCode::FAILURE;
    }

    // load the node mapping tools
    std::vector<std::string>::iterator i;
    IDODNodeMapper *nodetool = 0;
    for(i = m_nodeMapTools.begin(); i != m_nodeMapTools.end(); ++i) {
      const StatusCode sc = m_toolSvc->retrieveTool(*i, nodetool);
      if (sc.isFailure()) return sc;
      m_nodeMappers.push_back(nodetool);
    }
    IDODAlgMapper *algtool = 0;
    for(i = m_algMapTools.begin(); i != m_algMapTools.end(); ++i) {
      const StatusCode sc = m_toolSvc->retrieveTool(*i, algtool);
      if (sc.isFailure()) return sc;
      m_algMappers.push_back(algtool);
    }
  }
  return update();
}
Ejemplo n.º 6
0
 /// Create a partition object. The name identifies the partition uniquely
 virtual STATUS create(CSTR& nam, CSTR& typ, IInterface*& pPartition)  {
   STATUS sc = get(nam, pPartition);
   if ( !sc.isSuccess() )  {
     Gaudi::Utils::TypeNameString item(typ);
     /// @FIXME: In the old implementation the services were "unmanaged" (non-active)
     SmartIF<IService>& isvc = serviceLocator()->service(typ);
     if (isvc.isValid())  {
       SmartIF<IDataManagerSvc> dataMgr(isvc);
       SmartIF<IDataProviderSvc> dataProv(isvc);
       if ( dataMgr.isValid() && dataProv.isValid() )  {
         Partition p;
         p.name         = nam;
         p.dataManager  = dataMgr;
         p.dataProvider = dataProv;
         p.dataManager->addRef();
         p.dataProvider->addRef();
         m_partitions.insert(std::make_pair(nam, p));
         return STATUS::SUCCESS;
       }
       else  {
         // Error
         return NO_INTERFACE;
       }
     }
     else {
       // Error
       return NO_INTERFACE;
     }
   }
   return PARTITION_EXISTS;
 }
Ejemplo n.º 7
0
StatusCode ChronoAuditor::initialize() {
  StatusCode sc = CommonAuditor::initialize();
  if (UNLIKELY(sc.isFailure())) return sc;

  m_chronoSvc = serviceLocator()->service("ChronoStatSvc");
  if (UNLIKELY(!m_chronoSvc.get())) {
    MsgStream log(msgSvc(), name());
    log << MSG::ERROR << "Cannot get ChronoStatSvc" << endmsg;
    return StatusCode::FAILURE;
  }
  return StatusCode::SUCCESS;
}
Ejemplo n.º 8
0
// initialize data writer
StatusCode EvtCollectionStream::initialize() {
  MsgStream log(msgSvc(), name());
  // Use the Job options service to set the Algorithm's parameters
  setProperties();
  // Get access to the DataManagerSvc
  m_pTupleSvc = serviceLocator()->service(m_storeName);
  if( !m_pTupleSvc.isValid() ) {
    log << MSG::FATAL << "Unable to locate IDataManagerSvc interface" << endmsg;
    return StatusCode::FAILURE;
  }
  // Clear the item list
  clearItems();
  // Take the new item list from the properties.
  for(ItemNames::iterator i = m_itemNames.begin(); i != m_itemNames.end(); i++)   {
    addItem( *i );
  }
  log << MSG::INFO << "Data source:             " << m_storeName  << endmsg;
  return StatusCode::SUCCESS;
}
Ejemplo n.º 9
0
 StatusCode execute(){
   if (m_eventCount <= 0) {
     info() << "Stopping loop with " << m_mode << endmsg;
     if (m_mode == "exception") {
       Exception("Stopping loop");
     } else if (m_mode == "stopRun") {
       SmartIF<IEventProcessor> ep(serviceLocator());
       if (ep) ep->stopRun();
       else {
         error() << "Cannot get IEventProcessor" << endmsg;
         return StatusCode::FAILURE;
       }
     } else { // "failure"
       return StatusCode::FAILURE;
     }
   } else {
     info() << m_eventCount << " events to go" << endmsg;
   }
   --m_eventCount;
   return StatusCode::SUCCESS;
 }
Ejemplo n.º 10
0
//- private helpers ---
IAuditor* AuditorSvc::newAuditor_( MsgStream& log, const std::string& name ) {
  // locate the auditor factory, instantiate a new auditor, initialize it
  IAuditor* aud = 0;
  StatusCode sc;
  Gaudi::Utils::TypeNameString item(name) ;
  aud = Auditor::Factory::create( item.type(), item.name(), serviceLocator().get() );
  if ( aud ) {
    aud->addRef();
    if ( m_targetState >= Gaudi::StateMachine::INITIALIZED ) {
      sc = aud->sysInitialize();
      if ( sc.isFailure() ) {
        log << MSG::WARNING << "Failed to initialize Auditor " << name << endmsg;
        aud->release();
        aud = 0;
      }
    }
  }
  else {
    log << MSG::WARNING << "Unable to retrieve factory for Auditor " << name << endmsg;
  }

  return aud;
}
Ejemplo n.º 11
0
//=============================================================================
StatusCode IncidentListenerTestAlg::initialize() {
  StatusCode sc = GaudiAlgorithm::initialize();
  if (sc.isFailure()) return sc;

  // get a the incident service
  m_incSvc = svc<IIncidentSvc>("IncidentSvc",true);

  // instantiate listeners
  m_listener[0] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("Listener 0",serviceLocator()));
  m_listener[1] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("Listener 1",serviceLocator(),3));
  m_listener[2] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("Listener 2",serviceLocator()));
  m_listener[3] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("Listener 3",serviceLocator()));
  m_listener[4] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("EventBoundary",serviceLocator()));
  m_listener[5] =
    std::auto_ptr<IncidentListenerTest>(new IncidentListenerTest("Generic Listener",serviceLocator()));

  info() << "Registering incident listeners" << endmsg;

  const bool rethrow = false;
  const bool singleShot = true;
  const long priority = -10;
  m_incSvc->addListener(m_listener[3].get(),incident(),priority,rethrow,singleShot);

  m_incSvc->addListener(m_listener[0].get(),incident());
  m_incSvc->addListener(m_listener[1].get(),incident());
  m_incSvc->addListener(m_listener[2].get(),incident());

  m_incSvc->addListener(m_listener[4].get(),IncidentType::BeginEvent);
  m_incSvc->addListener(m_listener[4].get(),IncidentType::EndEvent);

  m_incSvc->addListener(m_listener[5].get());

  return StatusCode::SUCCESS;
}
Ejemplo n.º 12
0
// ============================================================================
void IncidentSvc::i_fireIncident
( const Incident&    incident     ,
  const std::string& listenerType )
{

  boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);

  // Special case: FailInputFile incident must set the application return code
  if (incident.type() == IncidentType::FailInputFile
      || incident.type() == IncidentType::CorruptedInputFile) {
    SmartIF<IProperty> appmgr(serviceLocator());
    if (incident.type() == IncidentType::FailInputFile)
      // Set the return code to Gaudi::ReturnCode::FailInput (2)
      Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::FailInput).ignore();
    else
      Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::CorruptedInput).ignore();
  }

  ListenerMap::iterator itmap = m_listenerMap.find( listenerType );
  if ( m_listenerMap.end() == itmap ) return;

  // setting this pointer will avoid that a call to removeListener() during
  // the loop triggers a segfault
  m_currentIncidentType = &(incident.type());

  ListenerList* llist = (*itmap).second;
  ListenerList::iterator itlist;
  bool weHaveToCleanUp = false;
  // loop over all registered Listeners

    for( itlist = llist->begin(); itlist != llist->end(); itlist++ )
  {

    VERMSG << "Calling '" << getListenerName((*itlist).iListener)
           << "' for incident [" << incident.type() << "]" << endmsg;

    // handle exceptions if they occur
    try {
      (*itlist).iListener->handle(incident);
    }
    catch( const GaudiException& exc ) {
      error() << "Exception with tag=" << exc.tag() << " is caught"
                 " handling incident" << m_currentIncidentType << endmsg;
      error() <<  exc  << endmsg;
      if ( (*itlist).rethrow ) { throw (exc); }
    }
    catch( const std::exception& exc ) {
     error() << "Standard std::exception is caught"
          " handling incident" << m_currentIncidentType << endmsg;
      error() << exc.what()  << endmsg;
      if ( (*itlist).rethrow ) { throw (exc); }
    }
    catch(...) {
      error() << "UNKNOWN Exception is caught"
          " handling incident" << m_currentIncidentType << endmsg;
      if ( (*itlist).rethrow ) { throw; }
    }
    // check if at least one of the listeners is a one-shot
    weHaveToCleanUp |= itlist->singleShot;
  }
  if (weHaveToCleanUp) {
    // remove all the listeners that need to be removed from the list
    llist->remove_if( listenerToBeRemoved() );
    // if the list is empty, we can remove it
    if( llist->size() == 0) {
      delete llist;
      m_listenerMap.erase(itmap);
    }
  }

  m_currentIncidentType = 0;
}
Ejemplo n.º 13
0
//--------------------------------------------------------------------------------------------
// implementation of IAppMgrUI::initalize
//--------------------------------------------------------------------------------------------
StatusCode MTEventLoopMgr::initialize()    {
  MsgStream log(msgSvc(), name());
  log << MSG::DEBUG << " ---> MTEventLoopMgr = " << name() << " initializing " << endmsg;
  // initilaize the base class
  StatusCode sc = MinimalEventLoopMgr::initialize();

  if( sc.isFailure() ) {
    log << MSG::DEBUG << "Error Initializing base class MinimalEventLoopMgr." << endmsg;
    return sc;
  }

  // Setup access to event data services
  sc = service("EventDataSvc", m_evtDataMgrSvc, true);
  if( !sc.isSuccess() )  {
    log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataManagerSvc."
        << endmsg;
    return sc;
  }
  sc = service("EventDataSvc", m_evtDataSvc, false);
  if( !sc.isSuccess() )  {
    log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc."
        << endmsg;
    return sc;
  }

  // Get the references to the services that are needed by the ApplicationMgr itself
  sc = service("IncidentSvc", m_incidentSvc, true);
  if( !sc.isSuccess() )  {
    log << MSG::FATAL << "Error retrieving IncidentSvc" << endmsg;
    return sc;
  }

  // Obtain the IProperty of the ApplicationMgr
  SmartIF<IProperty> prpMgr(serviceLocator());
  if ( ! prpMgr.isValid() )   {
    log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endmsg;
    return StatusCode::FAILURE;
  }
  else {
    m_appMgrProperty = prpMgr;
  }

  // We do not expect a Event Selector necessarily being declared
  setProperty(m_appMgrProperty->getProperty("EvtSel"));

  if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
    sc = service( "EventSelector", m_evtSelector, true );
    if( sc.isSuccess() )     {
      // Setup Event Selector
      sc = m_evtSelector->createContext(m_evtCtxt);
      if ( !sc.isSuccess() )  {
        log << MSG::FATAL << "Failed to create EventSelector context." << endmsg;
        return sc;
      }
    }
    else {
      log << MSG::FATAL << "EventSelector not found." << endmsg;
      return StatusCode::FAILURE;
    }
  }
  else {
    m_evtSelector = 0;
    m_evtCtxt = 0;
    log << MSG::WARNING << "Unable to locate service \"EventSelector\" " << endmsg;
    log << MSG::WARNING << "No events will be processed from external input." << endmsg;
  }

  // Setup access to histogramming services
  sc = service("HistogramDataSvc", m_histoDataMgrSvc, true);
  if( !sc.isSuccess() )  {
    log << MSG::FATAL << "Error retrieving HistogramDataSvc" << endmsg;
    return sc;
  }
  // Setup histogram persistency
  sc = service("HistogramPersistencySvc", m_histoPersSvc, true);
  if( !sc.isSuccess() ) {
    log << MSG::WARNING << "Histograms cannot not be saved - though required." << endmsg;
    return sc;
  }
  return StatusCode::SUCCESS;
}