Skip to content
Snippets Groups Projects
Commit 773fa5c2 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

TestTools: cleanup initGaudi

Code cleanup and simlification:
 - do not import namespaces
 - update documentation
 - use `PathResolver` for finding job options
parent 81430670
No related branches found
No related tags found
1 merge request!74528TestTools: cleanup initGaudi
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TEST_INITGAUDI_H
......@@ -8,7 +8,6 @@
* @brief minimal gaudi initialization for AthenaServices unit testing
*
* @author Paolo Calafiura <pcalafiura@lbl.gov> -ATLAS Collaboration
* $Id: initGaudi.h,v 1.4 2005-11-29 00:51:33 calaf Exp $
**/
#include <string>
......@@ -19,15 +18,20 @@ class ISvcLocator;
namespace Athena_test {
/** @fn bool initGaudi(ISvcLocator*& pSvcLoc)
* @brief minimal gaudi initialization for AthenaServices unit testing
/**
* Minimal Gaudi initialization for unit testing without job options.
*
* @param pSvcLoc returns a pointer to the Gaudi ServiceLocator
* @return true on success, false on failure
*/
bool initGaudi(ISvcLocator*& pSvcLoc);
/** @fn initGaudi(const std::string& jobOptsFile, ISvcLocator*& pSvcLoc);
* @brief minimal gaudi initialization for AthenaServices unit testing
* @param jobOptsFile job opts file name (located at ../share/jobOptFiles)
/**
* Minimal Gaudi initialization for unit testing.
*
* @param jobOptsFile job options file name
* @param pSvcLoc returns a pointer to the Gaudi ServiceLocator
* @return true on success, false on failure
*/
bool initGaudi(const std::string& jobOptsFile, ISvcLocator*& pSvcLoc);
}
......
......@@ -16,58 +16,44 @@
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/ModuleIncident.h"
using std::cout;
using std::endl;
using std::string;
#include "GaudiKernel/PathResolver.h"
namespace Athena_test {
bool initGaudi(ISvcLocator*& pSvcLoc) {
return initGaudi(string(), pSvcLoc); //wily hack
return initGaudi({}, pSvcLoc);
}
bool initGaudi(const std::string& jobOptsFile, ISvcLocator*& pSvcLoc) {
string jobOptsPath = jobOptsFile;
if (access (jobOptsPath.c_str(), R_OK) != 0)
jobOptsPath = "../share/"+jobOptsFile;
if (access (jobOptsPath.c_str(), R_OK) != 0) {
const char* jopath = getenv ("JOBOPTSEARCHPATH");
if (jopath) {
char* savepath = new char[strlen(jopath)+1];
strcpy (savepath, jopath);
char* saveptr = nullptr;
char* str = savepath;
while (char* tok = strtok_r (str, ":", &saveptr)) {
str = nullptr;
jobOptsPath = std::string(tok) + "/" + jobOptsFile;
if (access (jobOptsPath.c_str(), R_OK) == 0) {
break;
}
jobOptsPath.clear();
}
delete [] savepath;
}
}
if (jobOptsPath.empty()) {
cout << "\n\nCannot find job opts " << jobOptsFile << endl;
}
else {
cout << "\n\nInitializing Gaudi ApplicationMgr using job opts " << jobOptsPath << endl;
std::string jobOptsPath;
if (!jobOptsFile.empty()) {
jobOptsPath = System::PathResolver::find_file(jobOptsFile, "JOBOPTSEARCHPATH");
if (jobOptsPath.empty()) {
std::cout << "\n\nCannot find job opts " << jobOptsFile << std::endl;
}
else {
std::cout << "\n\nInitializing Gaudi ApplicationMgr using job opts " << jobOptsPath << std::endl;
}
}
// Create an instance of an application manager
// Create an instance of ApplicationMgr
SmartIF<IAppMgrUI> appMgr = Gaudi::createApplicationMgr();
if(!appMgr.isValid()) {
cout << "Fatal error while creating the ApplicationMgr " << endl;
std::cout << "Fatal error while creating the ApplicationMgr " << std::endl;
return false;
}
SmartIF<IProperty> propMgr(appMgr);
SmartIF<ISvcLocator> svcLoc(appMgr);
if(!svcLoc.isValid() || !propMgr.isValid()) {
cout << "Fatal error while creating the AppMgr smart if " << endl;
std::cout << "Fatal error while retrieving AppMgr interfaces " << std::endl;
return false;
}
// Return pointer to ISvcLocator
pSvcLoc = svcLoc.get();
propMgr->setProperty( "EvtSel", "NONE" ).
......@@ -82,12 +68,11 @@ namespace Athena_test {
orThrow("Cannnot set JobOptionsPath property", "initGaudi");
}
if ((appMgr->configure()).isSuccess() &&
(appMgr->initialize()).isSuccess()) {
cout<<"ApplicationMgr Ready"<<endl;
if (appMgr->configure().isSuccess() && appMgr->initialize().isSuccess()) {
std::cout<<"ApplicationMgr Ready"<<std::endl;
return true;
} else {
cout << "Fatal error while initializing the AppMgr" << endl;
std::cout << "Fatal error while initializing the AppMgr" << std::endl;
return false;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment