Source

mana-core-testtools / src / initGaudi.cxx

/***************************************************************************
 minimal gaudi initialization for AthenaServices unit testing
 ------------------------------------------------------------
 ATLAS Collaboration
 ***************************************************************************/

// $Id: initGaudi.cxx,v 1.1.1.1 2003-04-02 17:09:42 calaf Exp $

//<<<<<< INCLUDES                                                       >>>>>>

#include "TestTools/initGaudi.h"

#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/ISvcManager.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/SmartIF.h"
using namespace std;

namespace Athena_test {
  bool initGaudi(ISvcLocator*& pSvcLoc) {
    return initGaudi(string(), pSvcLoc); //wily hack
  }
  bool initGaudi(const string& jobOptsFile, ISvcLocator*& pSvcLoc) {
    string jobOptsPath("../share/"+jobOptsFile);
    bool noJobOpts(jobOptsFile.empty());
    if (!noJobOpts) {
      cout << "\n\nInitializing Gaudi ApplicationMgr using job opts " << jobOptsPath << endl;
    }

    // Create an instance of an application manager
    IInterface* iface = Gaudi::createApplicationMgr();
    if( 0 == iface ) {
      cout << "Fatal error while creating the ApplicationMgr " << endl;
      return false;
    }

    SmartIF<ISvcManager> svcMgr(IID_ISvcManager, iface);
    SmartIF<IAppMgrUI> appMgr(IID_IAppMgrUI, iface);
    SmartIF<IProperty> propMgr ( IID_IProperty, iface );
    SmartIF<ISvcLocator> svcLoc ( IID_ISvcLocator, iface );
    if(!svcLoc.isValid() || !appMgr.isValid() || !svcMgr.isValid() || !propMgr.isValid()) {
      cout << "Fatal error while creating the AppMgr smart if " << endl;
      return false;
    }

    pSvcLoc = svcLoc.pRef();

    //    propMgr->setProperty( "DLLs", "['StoreGate']" );
    //    string services("['ActiveStoreSvc']");
    //    cout << "adding services " << services << endl;
    //    propMgr->setProperty( "ExtSvc", services );
    propMgr->setProperty( "EvtSel",         "NONE" );
    if (noJobOpts) {
      propMgr->setProperty( "JobOptionsType", "NONE" );
    } else {
      propMgr->setProperty( "JobOptionsType", "FILE" );
      propMgr->setProperty( "JobOptionsPath", jobOptsPath );
    }

    appMgr->configure();
    if ((appMgr->initialize()).isSuccess()) {
      cout<<"ApplicationMgr Ready"<<endl;
    } else {
      cout << "Fatal error while initializing the AppMgr" << endl;
      return false;
    }
    return true;
  }
}