diff --git a/Control/AthenaExamples/ToyConversion/ToyConversion/FooBar.h b/Control/AthenaExamples/ToyConversion/ToyConversion/FooBar.h new file mode 100755 index 0000000000000000000000000000000000000000..f1a6b5b0ac7f9ab0b4c9710d5869359d1100c37b --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/ToyConversion/FooBar.h @@ -0,0 +1,32 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TEST_FOOBAR_H +# define TEST_FOOBAR_H + +#include "CLIDSvc/CLASS_DEF.h" +class Foo{ +private: + double m_a; +public: + Foo(): m_a(0.0) { + // std::cout << "Foo() called @" << this <<std::endl; + } + Foo(double a): m_a(a) { + // std::cout << "Foo() called @" << this << std::endl; + } + ~Foo() { + // std::cout << "~Foo() called @" << this << std::endl; + } + void setA(double a) { m_a=a; } + double a() const { return m_a; } + void doNothing() const {}; +}; +CLASS_DEF( Foo, 8101, 0) +struct Bar{ + void doNothing() const {}; +}; +CLASS_DEF( Bar, 8107, 0) + +#endif // TEST_FOOBAR_H diff --git a/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConversionSvc.h b/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConversionSvc.h new file mode 100755 index 0000000000000000000000000000000000000000..0c0d35fa3ad49a60e47e0cfe6112fee94518c56b --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConversionSvc.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TEST_TOYCONVERSIONSVC_H +# define TEST_TOYCONVERSIONSVC_H + +//<<<<<< INCLUDES >>>>>> +#include "GaudiKernel/ConversionSvc.h" +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< FORWARD DECLARATIONS >>>>>> +//<<<<<< CLASS DECLARATIONS >>>>>> + +/** @class ToyConversionSvc + * @brief a toy that implements IConversionSvc + * @author Paolo Calafiura <pcalafiura@lbl.gov> - ATLAS Collaboration + * $Id: ToyConversionSvc.h,v 1.3 2008-03-18 01:36:59 calaf Exp $ + */ + + +class ToyConversionSvc : public ConversionSvc { +public: + static long int storageType(); + virtual long int repSvcType() const; + + ToyConversionSvc(const std::string &name, ISvcLocator* svc); + virtual ~ToyConversionSvc(); +}; + + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> + +#endif // TEST_TOYCONVERSIONSVC_H diff --git a/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConverter.h b/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConverter.h new file mode 100755 index 0000000000000000000000000000000000000000..d0707efaefa5b8445b139133b0f46ae4412b8f84 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/ToyConversion/ToyConverter.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TEST_TOYCONVERTER_H +# define TEST_TOYCONVERTER_H + +//<<<<<< INCLUDES >>>>>> +#include "GaudiKernel/Converter.h" +#include "GaudiKernel/StatusCode.h" + +#include "CLIDSvc/tools/ClassID_traits.h" +#include "SGTools/StorableConversions.h" + +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< FORWARD DECLARATIONS >>>>>> +template <class Cnv> class CnvFactory; +//<<<<<< CLASS DECLARATIONS >>>>>> +/** @class ToyConverter + * @brief a toy converter template that creates a default instance of DATA + * @param DATA the type to be "converted". Must have a default constructor + * @author Paolo Calafiura <pcalafiura@lbl.gov> - ATLAS Collaboration + *$Id: ToyConverter.h,v 1.3 2006-12-22 23:12:30 calaf Exp $ + */ + +#include "ToyConversion/ToyConversionSvc.h" +template <typename DATA> +class ToyConverter : public Converter { +public: + // tran->per + // StatusCode createRep(DataObject* pO, IOpaqueAddress*& pA); + + // per->tran + StatusCode createObj(IOpaqueAddress*, DataObject *& pO) { + //could alse get DATA (perhaps as boost::any) from the IOA + pO = SG::asStorable(new DATA); + return StatusCode::SUCCESS; + } + + static const CLID& classID() { return ClassID_traits<DATA>::ID(); } + + virtual long int repSvcType() const; + static long int storageType(); + +protected: + friend class CnvFactory< ToyConverter<DATA> >; + ToyConverter(ISvcLocator* svcloc) : + Converter(storageType(), classID(), svcloc) {} +}; + + +template <typename DATA> +long int ToyConverter<DATA>::storageType() { + return ToyConversionSvc::storageType(); +} +template <typename DATA> +long int ToyConverter<DATA>::repSvcType() const { + return storageType(); +} + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> +#endif // TEST_TOYCONVERTER_H diff --git a/Control/AthenaExamples/ToyConversion/cmt/requirements b/Control/AthenaExamples/ToyConversion/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..5967e4f035f892009b657c3b643f815ea7cfaf98 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/cmt/requirements @@ -0,0 +1,16 @@ +package ToyConversion +author Paolo Calafiura <Paolo.Calafiura@cern.ch> + +use AtlasPolicy AtlasPolicy-* +use GaudiInterface GaudiInterface-* External + +#need CLASS_DEF.h and ClassID_traits.h +use CLIDSvc CLIDSvc-* Control +#need StorableConversions.h +use SGTools SGTools-* Control +apply_pattern dual_use_library files=*.cxx + +apply_pattern declare_joboptions files="\ + ToyConversionOpts.txt \ + ToyConversionOpts.py" + diff --git a/Control/AthenaExamples/ToyConversion/doc/MainPage.h b/Control/AthenaExamples/ToyConversion/doc/MainPage.h new file mode 100755 index 0000000000000000000000000000000000000000..df825d7670f211ff84389b902e42d5af2f093df0 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/doc/MainPage.h @@ -0,0 +1,89 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + + \mainpage + +This package contains a few tools to help writing unit tests. + +\section UnitTest_run The UnitTest_run cmt pattern + +TestTools requirements file defines the cmt pattern UnitTest_run. UnitTest_run +will compile, link and run a standalone C++ program when a "gmake check" +command is issued. It will then run the share/post.sh script to compare the +program output with a reference one, if available. + The pattern takes one parameter <unit_test> which is used to identify a number of files: + -# $PKGROOT/test/<unit_test>_test.cxx C++ program to be run + -# $PKGROOT/share/<unit_test>_test.ref optional reference output + -# $PKGROOT/run/<unit_test>_test.log program output (stdout & stderr) + -# $PKGROOT/$CMTCONFIG/<unit_test>_test.exe executable + +So for example +<PRE> + apply_pattern UnitTest_run unit_test=DataPool +will compile and link + ../test/DataPool_test.cxx +into + ../$CMTCONFIG/DataPool_test.exe +which will be run and produce + ../run/DataPool_test.log +If you have created the reference output + ../share/DataPool_test.ref +this will be compared to the log file at the end of the job. +</PRE> + +Notice that the comparison tries to ignore a certain +number of differences that are usually harmless (e.g. the execution time +reported by ChronoStatSvc or the package versions and even in certain cases +pointer addresses). This is currently done in a very naive fashion (using +diff -I option) but a more sophisticated "diff" script is in the plans + +\section initGaudi The initGaudi functions +TestTools/initGaudi.h defines two functions in the namespace Athena_test +to initialize Gaudi ApplicationMgr +and be able to run using core Gaudi services. An optional string argument +<jobOptsFile> instructs initGaudi to read in the job options file + $PKGROOT/share/<jobOptsFile> +to configure your job + +\section scripts Scripts + - share/runUnitTests.sh is a sh script that cmt broadcasts gmake check + and filter its output. It is +installed in the run area. It accepts one or more arguments that it passes +to cmt broadcast, for example +<PRE> + ../run/%runUnitTests.sh -select=StoreGate +</PRE> + - share/post.sh is a script used by the UnitTest_run pattern to +analize a job output + +\section toys Toys + +The TestTools component library provides toy implementations of a number of +typical Gaudi classes, namely ToyConverter, ToyConversionSvc (and soon +ToyAlgorithm). These are made available via the job opts file + $TESTTOOLSROOT/share/ToyConversionOpts.txt + + + +\section Examples Examples + +The package AthenaTests/ControlTests contains several examples that use +the initGaudi function. +Control/StoreGate has a couple of non-Gaudi-based, +very simple unit tests (e.g. KeyConcept) as well as more sophisticated ones +that show + - how to link the test program with an extra library (e.g. Clear_Store) + - how to use the ToyConversionSvc provided by TestTools (ProxyProviderSvc) + +\section links More info +The package can be browsed using LXR +(http://atlassw1.phy.bnl.gov/lxr/source/atlas/AtlasTest/TestTools/) + +To generate doxygen doc, run (from the cmt dir) gmake doxygen and point +your browser to .../doc/Doxygen/html/index.html + +\author Paolo Calafiura <Paolo.Calafiura@cern.ch> +*/ diff --git a/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.py b/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.py new file mode 100755 index 0000000000000000000000000000000000000000..7510d7dddc6a8afc24417d969fe4f8a6906040f6 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.py @@ -0,0 +1,3 @@ +# add ToyConversionSvc and its converters +EventPersistencySvc = Service( "EventPersistencySvc" ) +EventPersistencySvc.CnvServices += [ "ToyConversionSvc" ] diff --git a/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.txt b/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.txt new file mode 100755 index 0000000000000000000000000000000000000000..9af229f442061451cd91131ce63a05633890dd97 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/share/ToyConversionOpts.txt @@ -0,0 +1,5 @@ +// add ToyConversionSvc and its converters + +// $Id: ToyConversionOpts.txt,v 1.2 2006-12-20 22:33:36 calaf Exp $ + +EventPersistencySvc.CnvServices += { "ToyConversionSvc" }; diff --git a/Control/AthenaExamples/ToyConversion/src/ToyConversionSvc.cxx b/Control/AthenaExamples/ToyConversion/src/ToyConversionSvc.cxx new file mode 100755 index 0000000000000000000000000000000000000000..5b062241b878ea88716ccd1068876df9171e4e56 --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/src/ToyConversionSvc.cxx @@ -0,0 +1,25 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ToyConversion/ToyConversionSvc.h" +long int +ToyConversionSvc::storageType() { + static long _type(0xFF); + return _type; +} + +long int ToyConversionSvc::repSvcType() const { + return storageType(); +} + +ToyConversionSvc::~ToyConversionSvc() { + std::cout << "deleting toy " << this << std::endl; +} + +ToyConversionSvc::ToyConversionSvc(const std::string &name, ISvcLocator* svc) : + ConversionSvc(name,svc,storageType()) +{ + std::cout << "building toy " << this << std::endl; +} + diff --git a/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_entries.cxx b/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_entries.cxx new file mode 100755 index 0000000000000000000000000000000000000000..c2bd905bdfcd9f30521fd99006d821747f284e8c --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_entries.cxx @@ -0,0 +1,16 @@ +#include "ToyConversion/FooBar.h" +#include "ToyConversion/ToyConversionSvc.h" +#include "ToyConversion/ToyConverter.h" + +typedef ToyConverter<Foo> ToyCnvFoo; +typedef ToyConverter<Bar> ToyCnvBar; + +#include "GaudiKernel/DeclareFactoryEntries.h" +DECLARE_FACTORY_ENTRIES( ToyConversion ) { + DECLARE_SERVICE( ToyConversionSvc ) + DECLARE_CONVERTER( ToyCnvFoo ) + DECLARE_CONVERTER( ToyCnvBar ) +} +DECLARE_SERVICE_FACTORY( ToyConversionSvc ) +DECLARE_CONVERTER_FACTORY( ToyCnvFoo ) +DECLARE_CONVERTER_FACTORY( ToyCnvBar ) diff --git a/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_load.cxx b/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_load.cxx new file mode 100755 index 0000000000000000000000000000000000000000..a456dcfdfb93093775ac0bd1cfbe2528bec754ca --- /dev/null +++ b/Control/AthenaExamples/ToyConversion/src/components/ToyConversion_load.cxx @@ -0,0 +1,2 @@ +#include "GaudiKernel/LoadFactoryEntries.h" +LOAD_FACTORY_ENTRIES( ToyConversion )