ATLAS Offline Software
Loading...
Searching...
No Matches
Athena_test Namespace Reference

functions & macros to test the difference between floats More...

Classes

class  DummyRCUSvc
class  InitGaudi
 Generic test fixture to setup Gaudi. More...
class  InitGaudiGoogleTest
struct  Leakcheck
struct  LeakCheckDisable
class  normal_distribution
struct  RNG
 Generator compatible with the STL RandomNumberGenerator. More...
class  TestAlloc
 To test handling of non-standard memory allocators. More...
class  TestedValue
class  uniform_real_distribution
struct  URNG
 Generator compatible with the C++11 STL UniformRandomNumberGenerator. More...

Functions

bool initGaudi (ISvcLocator *&pSvcLoc)
 Minimal Gaudi initialization for unit testing without job options.
bool initGaudi (const std::string &jobOptsFile, ISvcLocator *&pSvcLoc)
 Minimal Gaudi initialization for unit testing.
void referenceGaudiSymbols ()
template<typename T>
bool cmp_eq (T a, T b)
template<>
bool cmp_eq< float > (float a, float b)
template<>
bool cmp_eq< double > (double a, double b)
bool floatEQ (float lhs, float rhs)
bool floatNEQ (float lhs, float rhs)
bool isEqual (double x1, double x2, double thresh=1e-6)
uint32_t rng_seed (uint32_t &seed)
 Generate a random number between 0 and rngmax.
float randf_seed (uint32_t &seed, float rmax, float rmin=0)
 Generate a floating-point random number between rmin and rmax.
int randi_seed (uint32_t &seed, int rmax, int rmin=0)
 Generate an integer random number between rmin and rmax.
uint32_t rng ATLAS_NOT_REENTRANT ()
int randi ATLAS_NOT_REENTRANT (int rmax, int rmin=0)
float randf ATLAS_NOT_REENTRANT (float rmax, float rmin=0)
bool setupStoreGate (std::string progname, std::string options_file="")
 Helper for setting up StoreGate for regression tests.
void testCreate (StoreGateSvc &rSG)
void testRecord (StoreGateSvc &rSG)
void testSymLink (StoreGateSvc &rSG)
void test_symlink2 (StoreGateSvc &rSG)
void test_symlink3 (StoreGateSvc &rSG)
void testContains (StoreGateSvc &rSG)
void testFolders (StoreGateSvc &rSG)
void testRetrieve (StoreGateSvc &rSG)
void testTryRetrieve (StoreGateSvc &rSG)
void testReadPrivateCopy (StoreGateSvc &rSG)
void testRetrievePrivateCopy (StoreGateSvc &rSG)
void testRemove (StoreGateSvc &rSG)
void testClear (StoreGateSvc &rSG)
void testTransientSwap (StoreGateSvc &rSG)
void testVersionedKey (StoreGateSvc &rSG)
void testKeys (StoreGateSvc &rSG)
void testRetrieveAux (StoreGateSvc &rSG)
void testBoundReset (StoreGateSvc &rSG)
void testRecordObject (StoreGateSvc &rSG)
void testWriteAux (StoreGateSvc &rSG)
void varHandleTest (SGTest::TestStore &)
void resetableTest (void)
void refCountTest (void)
bool initMcEventCollection (ISvcLocator *&pSvcLoc, std::vector< HepMC::GenParticlePtr > &genPartVector, const bool initGaudi=true)
void populateGenEvent (HepMC::GenEvent &ge, int pdgid1, int pdgid2, std::vector< HepMC::GenParticlePtr > &genPartVector)
void populateFilteredGenEvent (HepMC::GenEvent &ge, std::vector< HepMC::GenParticlePtr > &genPartVector)
int maximumBarcode (std::vector< HepMC::GenParticlePtr > &genPartList)

Variables

std::unordered_set< void * > * allocs = nullptr
static const uint32_t rngmax = static_cast<uint32_t> (-1)
 Maximum number generated.
static uint32_t seed = 1

Detailed Description

functions & macros to test the difference between floats

Function Documentation

◆ ATLAS_NOT_REENTRANT() [1/3]

uint32_t rng Athena_test::ATLAS_NOT_REENTRANT ( )
inline

Definition at line 90 of file random.h.

90{ return rng_seed(seed); }
static uint32_t seed
Definition random.h:88
uint32_t rng_seed(uint32_t &seed)
Generate a random number between 0 and rngmax.
Definition random.h:44

◆ ATLAS_NOT_REENTRANT() [2/3]

float randf Athena_test::ATLAS_NOT_REENTRANT ( float rmax,
float rmin = 0 )
inline

Definition at line 94 of file random.h.

94{ return randf_seed (seed, rmax, rmin); }
float randf_seed(uint32_t &seed, float rmax, float rmin=0)
Generate a floating-point random number between rmin and rmax.
Definition random.h:53

◆ ATLAS_NOT_REENTRANT() [3/3]

int randi Athena_test::ATLAS_NOT_REENTRANT ( int rmax,
int rmin = 0 )
inline

Definition at line 92 of file random.h.

92{ return randi_seed (seed, rmax, rmin); }
int randi_seed(uint32_t &seed, int rmax, int rmin=0)
Generate an integer random number between rmin and rmax.
Definition random.h:61

◆ cmp_eq()

template<typename T>
bool Athena_test::cmp_eq ( T a,
T b )

Definition at line 18 of file expect.h.

18{ return a == b; }
static Double_t a

◆ cmp_eq< double >()

template<>
bool Athena_test::cmp_eq< double > ( double a,
double b )

Definition at line 22 of file expect.h.

22{ return std::abs(a - b) < 1.e-6; }

◆ cmp_eq< float >()

template<>
bool Athena_test::cmp_eq< float > ( float a,
float b )

Definition at line 20 of file expect.h.

20{ return std::abs(a - b) < 1.e-4; }

◆ floatEQ()

bool Athena_test::floatEQ ( float lhs,
float rhs )
inline

Definition at line 17 of file FLOATassert.h.

17 {
18 return fabs(lhs-rhs)<=FLT_EPSILON;
19 }

◆ floatNEQ()

bool Athena_test::floatNEQ ( float lhs,
float rhs )
inline

Definition at line 21 of file FLOATassert.h.

21 {
22 return fabs(lhs-rhs)>FLT_EPSILON;
23 }

◆ initGaudi() [1/2]

bool Athena_test::initGaudi ( const std::string & jobOptsFile,
ISvcLocator *& pSvcLoc )

Minimal Gaudi initialization for unit testing.

Parameters
jobOptsFilejob options file name
pSvcLocreturns a pointer to the Gaudi ServiceLocator
Returns
true on success, false on failure

Definition at line 29 of file initGaudi.cxx.

29 {
30
31 std::string jobOptsPath;
32 if (!jobOptsFile.empty()) {
33 jobOptsPath = System::PathResolver::find_file(jobOptsFile, "JOBOPTSEARCHPATH");
34 if (jobOptsPath.empty()) {
35 std::cout << "\n\nCannot find job opts " << jobOptsFile << std::endl;
36 }
37 else {
38 std::cout << "\n\nInitializing Gaudi ApplicationMgr using job opts " << jobOptsPath << std::endl;
39 }
40 }
41
42 // Create an instance of ApplicationMgr
43 SmartIF<IAppMgrUI> appMgr = Gaudi::createApplicationMgr();
44 if(!appMgr.isValid()) {
45 std::cout << "Fatal error while creating the ApplicationMgr " << std::endl;
46 return false;
47 }
48
49 SmartIF<IProperty> propMgr(appMgr);
50 SmartIF<ISvcLocator> svcLoc(appMgr);
51 if(!svcLoc.isValid() || !propMgr.isValid()) {
52 std::cout << "Fatal error while retrieving AppMgr interfaces " << std::endl;
53 return false;
54 }
55
56 // Return pointer to ISvcLocator
57 pSvcLoc = svcLoc.get();
58
59 propMgr->setProperty( "EvtSel", "NONE" ).
60 orThrow("Cannnot set EvtSel property", "initGaudi");
61 if (jobOptsFile.empty()) {
62 propMgr->setProperty( "JobOptionsType", "NONE" ).
63 orThrow("Cannnot set JobOptionsType property", "initGaudi");
64 } else {
65 propMgr->setProperty( "JobOptionsType", "FILE" ).
66 orThrow("Cannnot set JobOptionsType property", "initGaudi");
67 propMgr->setProperty( "JobOptionsPath", jobOptsPath ).
68 orThrow("Cannnot set JobOptionsPath property", "initGaudi");
69 }
70
71 if (appMgr->configure().isSuccess() && appMgr->initialize().isSuccess()) {
72 std::cout<<"ApplicationMgr Ready"<<std::endl;
73 return true;
74 } else {
75 std::cout << "Fatal error while initializing the AppMgr" << std::endl;
76 return false;
77 }
78 }

◆ initGaudi() [2/2]

bool Athena_test::initGaudi ( ISvcLocator *& pSvcLoc)

Minimal Gaudi initialization for unit testing without job options.

Parameters
pSvcLocreturns a pointer to the Gaudi ServiceLocator
Returns
true on success, false on failure

Definition at line 24 of file initGaudi.cxx.

24 {
25 return initGaudi({}, pSvcLoc);
26 }
bool initGaudi(ISvcLocator *&pSvcLoc)
Minimal Gaudi initialization for unit testing without job options.
Definition initGaudi.cxx:24

◆ initMcEventCollection()

bool Athena_test::initMcEventCollection ( ISvcLocator *& pSvcLoc,
std::vector< HepMC::GenParticlePtr > & genPartVector,
const bool initGaudi = true )

Definition at line 24 of file initMcEventCollection.cxx.

25 {
26 if (initGaudi && !Athena_test::initGaudi(pSvcLoc)) {
27 std::cerr << "This test can not be run" << std::endl;
28 return false;
29 }
30 // create dummy input McEventCollection with a name that
31 // HepMcParticleLink knows about
32 SG::WriteHandle<McEventCollection> inputTestDataHandle{"TruthEvent"};
33 inputTestDataHandle = std::make_unique<McEventCollection>();
34
35 // create a dummy EventContext
36 EventContext ctx;
37 ctx.setExtension( Atlas::ExtendedEventContext( SG::CurrentEventStore::store() ) );
38 Gaudi::Hive::setCurrentContext( ctx );
39
40 // Add a dummy GenEvent
41 const int process_id1(20);
42 const int event_number1(17);
43 inputTestDataHandle->push_back(HepMC::newGenEvent(process_id1, event_number1));
44 HepMC::GenEvent& ge1 = *(inputTestDataHandle->at(0));
45 populateGenEvent(ge1,-11,11,genPartList);
46 populateGenEvent(ge1,-13,13,genPartList);
47 populateGenEvent(ge1,-11,11,genPartList);
48 populateGenEvent(ge1,-13,13,genPartList);
49 populateGenEvent(ge1,-11,11,genPartList);
50 populateGenEvent(ge1,22,22,genPartList);
51 inputTestDataHandle->push_back(new HepMC::GenEvent(ge1));
52 HepMC::GenEvent& ge2 = *(inputTestDataHandle->at(1));
53 const int event_number2(89);
54 ge2.set_event_number(event_number2);
55 populateFilteredGenEvent(ge2,genPartList);
56 return true;
57 }
void populateGenEvent(HepMC::GenEvent &ge, int pdgid1, int pdgid2, std::vector< HepMC::GenParticlePtr > &genPartVector)
void populateFilteredGenEvent(HepMC::GenEvent &ge, std::vector< HepMC::GenParticlePtr > &genPartVector)
GenEvent * newGenEvent(const int signal_process_id, const int event_number)
Definition GenEvent.h:360
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39

◆ isEqual()

bool Athena_test::isEqual ( double x1,
double x2,
double thresh = 1e-6 )
inline

Definition at line 26 of file FLOATassert.h.

27 {
28 double den = std::abs(x1+x2);
29 if (den < thresh) return true;
30 double diff = std::abs (x1-x2) / den;
31 if (diff < thresh)
32 return true;
33 std::cout << "Match failure: " << x1 << " " << x2 << " (" << diff << ")\n";
34 return false;
35 }
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631

◆ maximumBarcode()

int Athena_test::maximumBarcode ( std::vector< HepMC::GenParticlePtr > & genPartList)

Definition at line 59 of file initMcEventCollection.cxx.

60 {
61 int maxBarcode{0};
62 if (genPartList.empty()) { return maxBarcode; }
63 for (HepMC::GenParticlePtr genPart : genPartList)
64 {
65 maxBarcode = std::max(maxBarcode, HepMC::barcode(genPart));
66 }
67 return maxBarcode;
68 }
int barcode(const T *p)
Definition Barcode.h:15
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19

◆ populateFilteredGenEvent()

void Athena_test::populateFilteredGenEvent ( HepMC::GenEvent & ge,
std::vector< HepMC::GenParticlePtr > & genPartVector )

< set decay status

Definition at line 98 of file initMcEventCollection.cxx.

99 {
100 //.......Create new particle (geantino) to link hits from pileup
102 genPart->set_pdg_id(999); //Geantino
103 genPart->set_status(1);
105
107 genVertex->add_particle_out(genPart);
108 genPartVector.push_back(genPart);
109
110 //to set geantino vertex as a truth primary vertex
112 if (hScatVx!=nullptr) {
113 HepMC::FourVector pmvxpos=hScatVx->position();
114 genVertex->set_position(pmvxpos);
115 //to set geantino kinematic phi=eta=0, E=p=E_hard_scat
116 auto itrp =hScatVx->particles_in().cbegin();
117 if (hScatVx->particles_in().size()==2) {
118 HepMC::FourVector mom1=(*itrp)->momentum();
119 HepMC::FourVector mom2=(*(++itrp))->momentum();
120 HepMC::FourVector vxmom;
121 vxmom.setPx(mom1.e()+mom2.e());
122 vxmom.setPy(0.);
123 vxmom.setPz(0.);
124 vxmom.setE(mom1.e()+mom2.e());
125 genPart->set_momentum(vxmom);
126 }
127 }
128
129 if (!ge.vertices().empty()) {
130 std::vector<HepMC::GenVertexPtr> vtxvec;
131 for (const auto& vtx: ge.vertices()) {
132 vtxvec.push_back(vtx);
133 ge.remove_vertex(vtx);
134 }
135 vtxvec.clear();
136 }
137
138 //.....add new vertex with geantino
139 ge.add_vertex(std::move(genVertex));
141 }
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:403
HepMC3::FourVector FourVector
constexpr int SUPPRESSED_PILEUP_BARCODE(std::numeric_limits< int32_t >::max())
This barcode is used by objects matched to particles from pile-up interactions in standard MC Product...
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:607
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23

◆ populateGenEvent()

void Athena_test::populateGenEvent ( HepMC::GenEvent & ge,
int pdgid1,
int pdgid2,
std::vector< HepMC::GenParticlePtr > & genPartVector )

Definition at line 70 of file initMcEventCollection.cxx.

71 {
72 int maxBarcode = maximumBarcode(genPartList);
73 HepMC::FourVector myPos( 0.0, 0.0, 0.0, 0.0);
74 HepMC::GenVertexPtr myVertex = HepMC::newGenVertexPtr( myPos, -1 );
75 HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
76 HepMC::GenParticlePtr inParticle1 = HepMC::newGenParticlePtr(fourMomentum1, pdgid1, 2);
77 myVertex->add_particle_in(inParticle1);
78 HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
79 HepMC::GenParticlePtr inParticle2 = HepMC::newGenParticlePtr(fourMomentum2, pdgid2, 2);
80 myVertex->add_particle_in(inParticle2);
81 HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
82 HepMC::GenParticlePtr inParticle3 = HepMC::newGenParticlePtr(fourMomentum3, pdgid1, 1);
83 myVertex->add_particle_out(inParticle3);
84 genPartList.push_back(inParticle3);
85 HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
86 HepMC::GenParticlePtr inParticle4 = HepMC::newGenParticlePtr(fourMomentum4, pdgid2, 1);
87 myVertex->add_particle_out(inParticle4);
88 genPartList.push_back(inParticle4);
89 ge.add_vertex( myVertex );
90 HepMC::suggest_barcode(inParticle1,maxBarcode+1);
91 HepMC::suggest_barcode(inParticle2,maxBarcode+2);
92 HepMC::suggest_barcode(inParticle3,maxBarcode+3);
93 HepMC::suggest_barcode(inParticle4,maxBarcode+4);
95 ge.set_beam_particles(std::move(inParticle1),std::move(inParticle2));
96 }
int maximumBarcode(std::vector< HepMC::GenParticlePtr > &genPartList)
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:591

◆ randf_seed()

float Athena_test::randf_seed ( uint32_t & seed,
float rmax,
float rmin = 0 )
inline

Generate a floating-point random number between rmin and rmax.

Definition at line 53 of file random.h.

54{
55 return static_cast<float>(rng_seed(seed)) / static_cast<float>(rngmax) * (rmax-rmin) + rmin;
56}
static const uint32_t rngmax
Maximum number generated.
Definition random.h:39

◆ randi_seed()

int Athena_test::randi_seed ( uint32_t & seed,
int rmax,
int rmin = 0 )
inline

Generate an integer random number between rmin and rmax.

Definition at line 61 of file random.h.

62{
63 return static_cast<int> (randf_seed (seed, rmax, rmin));
64}

◆ refCountTest()

void Athena_test::refCountTest ( void )

◆ referenceGaudiSymbols()

void Athena_test::referenceGaudiSymbols ( )

Definition at line 94 of file initGaudi.cxx.

95 {
96 ModuleLoadedIncident inc2 ("", "");
97 }

◆ resetableTest()

void Athena_test::resetableTest ( void )

◆ rng_seed()

uint32_t Athena_test::rng_seed ( uint32_t & seed)
inline

Generate a random number between 0 and rngmax.

Definition at line 44 of file random.h.

45{
46 seed = (1664525*seed + 1013904223);
47 return seed;
48}

◆ setupStoreGate()

bool Athena_test::setupStoreGate ( std::string progname,
std::string options_file = "" )

Helper for setting up StoreGate for regression tests.

Parameters
prognameProgram name (argv[0]).
options_fileName of the JO text file to read. If defaulted, one will be generated.

Get StoreGateSvc

Definition at line 27 of file setupStoreGate.cxx.

29{
30 // Build job options file if CppUnit_jobOptions.txt is unavailable
31 if (options_file.empty()) {
32 std::string::size_type pos = progname.rfind ("/");
33 if (pos != std::string::npos)
34 progname.erase (0, pos+1);
35 pos = progname.rfind (".");
36 if (pos != std::string::npos)
37 progname.erase (pos, std::string::npos);
38 options_file = "./" + progname + "_generated.txt";
39 (void)remove (options_file.c_str());
40 std::ofstream jobopt(options_file.c_str());
41
42 // Build a default list of options.
43 {
44 std::list<std::string> opts;
45 opts.push_back("#pragma print off");
46 opts.push_back("ApplicationMgr.Dlls += { \"StoreGate\" };");
47 //opts.push_back("ApplicationMgr.Dlls += { \"CLIDSvc\" };");
48 opts.push_back("ApplicationMgr.ExtSvc += { \"ClassIDSvc\" };");
49 opts.push_back("ApplicationMgr.ExtSvc += { \"StoreGateSvc\", \"StoreGateSvc/DetectorStore\", \"StoreGateSvc/ConditionStore\", \"StoreGateSvc/HistoryStore\" };");
50 opts.push_back("ApplicationMgr.ExtSvc += { \"ActiveStoreSvc\" };");
51 opts.push_back("AuditorSvc.Auditors += { \"AlgContextAuditor\"};");
52 opts.push_back("StoreGateSvc.OutputLevel = 2;");
53 opts.push_back("StoreGateSvc.ActivateHistory = false;");
54 //opts.push_back("CLIDSvc.OutputLevel = 2;");
55 opts.push_back("MessageSvc.useColors = false;");
56 opts.push_back("MessageSvc.OutputLevel = 3;");
57 // Build job options file from list.
58 for ( std::list<std::string>::const_iterator iopt=opts.begin();
59 iopt!=opts.end(); ++iopt )
60 {
61 std::println (jobopt, "{}", *iopt);
62 }
63 }
64 jobopt.close();
65 }
66
67 try {
69 ISvcLocator* svcLoc = 0;
70 if (!Athena_test::initGaudi(options_file, svcLoc)) {
71 std::println (std::cerr, "This test can not be run");
72 return false;
73 }
74 assert( 0 != svcLoc);
75
76 SmartIF<StoreGateSvc> storeGate{svcLoc->service( "StoreGateSvc" )};
77 assert( storeGate );
78
79 if ( !storeGate ) {
80 std::string error = "No valid pointer to StoreGateSvc !!";
81 std::println (std::cerr, "{}", error);
82 return false;
83 } else {
84 return true;
85 }
86 } catch ( std::exception& e ) {
87 std::println (std::cerr, "Caught : {}", e.what());
88 return false;
89 }
90}

◆ test_symlink2()

void Athena_test::test_symlink2 ( StoreGateSvc & rSG)

◆ test_symlink3()

void Athena_test::test_symlink3 ( StoreGateSvc & rSG)

◆ testBoundReset()

void Athena_test::testBoundReset ( StoreGateSvc & rSG)

◆ testClear()

void Athena_test::testClear ( StoreGateSvc & rSG)

◆ testContains()

void Athena_test::testContains ( StoreGateSvc & rSG)

◆ testCreate()

void Athena_test::testCreate ( StoreGateSvc & rSG)

◆ testFolders()

void Athena_test::testFolders ( StoreGateSvc & rSG)

◆ testKeys()

void Athena_test::testKeys ( StoreGateSvc & rSG)

◆ testReadPrivateCopy()

void Athena_test::testReadPrivateCopy ( StoreGateSvc & rSG)

◆ testRecord()

void Athena_test::testRecord ( StoreGateSvc & rSG)

◆ testRecordObject()

void Athena_test::testRecordObject ( StoreGateSvc & rSG)

◆ testRemove()

void Athena_test::testRemove ( StoreGateSvc & rSG)

◆ testRetrieve()

void Athena_test::testRetrieve ( StoreGateSvc & rSG)

◆ testRetrieveAux()

void Athena_test::testRetrieveAux ( StoreGateSvc & rSG)

◆ testRetrievePrivateCopy()

void Athena_test::testRetrievePrivateCopy ( StoreGateSvc & rSG)

◆ testSymLink()

void Athena_test::testSymLink ( StoreGateSvc & rSG)

◆ testTransientSwap()

void Athena_test::testTransientSwap ( StoreGateSvc & rSG)

◆ testTryRetrieve()

void Athena_test::testTryRetrieve ( StoreGateSvc & rSG)

◆ testVersionedKey()

void Athena_test::testVersionedKey ( StoreGateSvc & rSG)

◆ testWriteAux()

void Athena_test::testWriteAux ( StoreGateSvc & rSG)

◆ varHandleTest()

void Athena_test::varHandleTest ( SGTest::TestStore & )

Variable Documentation

◆ allocs

std::unordered_set<void*>* Athena_test::allocs = nullptr

Definition at line 51 of file leakcheck.h.

◆ rngmax

const uint32_t Athena_test::rngmax = static_cast<uint32_t> (-1)
static

Maximum number generated.

Definition at line 39 of file random.h.

◆ seed

uint32_t Athena_test::seed = 1
static

Definition at line 88 of file random.h.