ATLAS Offline Software
Loading...
Searching...
No Matches
setupStoreGate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
12
13
16#include "TestTools/initGaudi.h"
17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/Bootstrap.h"
19#include <fstream>
20#include <iostream>
21#include <list>
22#include <cassert>
23
24
25namespace Athena_test {
26
27
28bool setupStoreGate (std::string progname,
29 std::string options_file /*= ""*/)
30{
31 // Build job options file if CppUnit_jobOptions.txt is unavailable
32 if (options_file.empty()) {
33 std::string::size_type pos = progname.rfind ("/");
34 if (pos != std::string::npos)
35 progname.erase (0, pos+1);
36 pos = progname.rfind (".");
37 if (pos != std::string::npos)
38 progname.erase (pos, std::string::npos);
39 options_file = "./" + progname + "_generated.txt";
40 (void)remove (options_file.c_str());
41 std::ofstream jobopt(options_file.c_str());
42
43 // Build a default list of options.
44 {
45 std::list<std::string> opts;
46 opts.push_back("#pragma print off");
47 opts.push_back("ApplicationMgr.Dlls += { \"StoreGate\" };");
48 //opts.push_back("ApplicationMgr.Dlls += { \"CLIDSvc\" };");
49 opts.push_back("ApplicationMgr.ExtSvc += { \"ClassIDSvc\" };");
50 opts.push_back("ApplicationMgr.ExtSvc += { \"StoreGateSvc\", \"StoreGateSvc/DetectorStore\", \"StoreGateSvc/ConditionStore\", \"StoreGateSvc/HistoryStore\" };");
51 opts.push_back("ApplicationMgr.ExtSvc += { \"ActiveStoreSvc\" };");
52 opts.push_back("AuditorSvc.Auditors += { \"AlgContextAuditor\"};");
53 opts.push_back("StoreGateSvc.OutputLevel = 2;");
54 opts.push_back("StoreGateSvc.ActivateHistory = false;");
55 //opts.push_back("CLIDSvc.OutputLevel = 2;");
56 opts.push_back("MessageSvc.useColors = false;");
57 opts.push_back("MessageSvc.OutputLevel = 3;");
58 // Build job options file from list.
59 for ( std::list<std::string>::const_iterator iopt=opts.begin();
60 iopt!=opts.end(); ++iopt )
61 {
62 jobopt << *iopt << std::endl;
63 }
64 }
65 jobopt.close();
66 }
67
68 try {
70 ISvcLocator* svcLoc = 0;
71 if (!Athena_test::initGaudi(options_file, svcLoc)) {
72 std::cerr << "This test can not be run" << std::endl;
73 return false;
74 }
75 assert( 0 != svcLoc);
76
77 SmartIF<StoreGateSvc> storeGate{svcLoc->service( "StoreGateSvc" )};
78 assert( storeGate );
79
80 if ( !storeGate ) {
81 std::string error = "No valid pointer to StoreGateSvc !!";
82 std::cerr << error << std::endl;
83 return false;
84 } else {
85 return true;
86 }
87 } catch ( std::exception& e ) {
88 std::cerr << "Caught : " << e.what() << std::endl;
89 return false;
90 }
91}
92
93
94} // namespace Athena_test
bool setupStoreGate()
Simple function to instantiate and initialize the StoreGateSvc.
minimal gaudi initialization for AthenaServices unit testing
functions & macros to test the difference between floats
bool initGaudi(ISvcLocator *&pSvcLoc)
Minimal Gaudi initialization for unit testing without job options.
Definition initGaudi.cxx:24
Helper for setting up StoreGate for regression tests.