Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:20:24

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/ConditionAny.h>
0016 #include <DD4hep/Factories.h>
0017 #include <iostream>
0018 
0019 using namespace std;
0020 using namespace dd4hep;
0021 
0022 namespace  {
0023   class base_0   {
0024   public:
0025     int data_0 {0};
0026     base_0() = default;
0027     base_0(base_0&& copy) = default;
0028     base_0(const base_0& copy) = default;
0029     virtual ~base_0() = default;
0030     base_0& operator=(base_0&& copy) = default;
0031     base_0& operator=(const base_0& copy) = default;
0032   };
0033   
0034   template <typename T> class base_1   {
0035   public:
0036     T data_1;
0037     base_1() = default;
0038     base_1(base_1&& copy) = default;
0039     base_1(const base_1& copy) = default;
0040     virtual ~base_1() = default;
0041     base_1& operator=(base_1&& copy) = default;
0042     base_1& operator=(const base_1& copy) = default;
0043   };
0044   template <typename T> class base_2: virtual public base_0   {
0045   public:
0046     T data_2;
0047     base_2() = default;
0048     base_2(base_2&& copy) = default;
0049     base_2(const base_2& copy) = default;
0050     virtual ~base_2() = default;
0051     base_2& operator=(base_2&& copy) = default;
0052     base_2& operator=(const base_2& copy) = default;
0053   };
0054   
0055   class payload : public base_1<int>, public base_2<double>  {
0056   public:
0057     payload() = default;
0058     payload(payload&& copy) = default;
0059     payload(const payload& copy) = default;
0060     virtual ~payload()  { cout << "payload destroyed..." << endl; }
0061     payload& operator=(payload&& copy) = default;
0062     payload& operator=(const payload& copy) = default;
0063   };
0064 }
0065 
0066 /// Plugin function: Condition program example
0067 /**
0068  *  Factory: DD4hep_Conditions_dynamic
0069  *
0070  *  \author  M.Frank
0071  *  \version 1.0
0072  *  \date    01/12/2016
0073  */
0074 static int condition_any_basic (Detector& /* description */, int /* argc */, char** /* argv */)  {
0075   ConditionAny c1("any_cond","payload");
0076   Condition    c2("vector_cond","std::vector<int>");
0077 
0078   cout << endl << endl;
0079   cout << "Size std::any:      " << sizeof(std::any) << endl;
0080   cout << "Size std::vector:   " << sizeof(std::vector<int>) << endl;
0081   if ( sizeof(std::any) > OpaqueDataBlock::BUFFER_SIZE )  {
0082     cout << endl << "Test FAILED" << endl << endl;
0083     return EINVAL;
0084   }
0085   if ( sizeof(std::vector<void*>) > OpaqueDataBlock::BUFFER_SIZE )  {
0086     cout << endl << "Test FAILED" << endl << endl;
0087     return EINVAL;
0088   }
0089   cout << "Payload test PASSED" << endl << endl;
0090 
0091   c1.get() = std::make_any<payload>();
0092   auto& v2 = c2.bind<std::vector<int> >();
0093   v2.push_back(1);
0094   v2.push_back(2);
0095 
0096   cout << "c1 : " << c1.any_type().name() << endl;
0097 
0098   // Assign incompatible exception to any condition:
0099   try  {
0100     c1 = c2;
0101     cout << "Assigned:  ConditionAny = Condition(vector) . " << endl;
0102     cout << "Test FAILED" << endl;
0103   }
0104   catch(const std::exception& e)   {
0105     cout << "Expected exception: ConditionAny = Condition(vector) : " << e.what() << endl;
0106   }
0107 
0108   // Assign any to condition:
0109   Condition cc(c2);
0110   c2 = c1;
0111   cout << "Assigned: Condition(vector) = ConditionAny ." << endl;
0112   c2 = cc; // Restore value!
0113 
0114   Condition c3(c1);
0115   cout << "Construct c3: Condition( Condition(any) )   Pointer: "
0116        << (void*)c3.ptr() << endl;
0117 
0118   ConditionAny c4(c3);
0119   cout << "Construct c4: Condition(any)( ConditionAny ) Pointer: "
0120        << (void*)c4.ptr() << " type:" << c4.any_type().name() << endl;
0121 
0122   try  {
0123     ConditionAny c5(c2);
0124     cout << "Construct c5: ConditionAny( Condition(vector) ) Pointer: " 
0125      << (void*)c5.ptr() << " type:" << c5.any_type().name() << endl;
0126     cout << "Test FAILED" << endl;
0127   }
0128   catch(const std::exception& e)   {
0129     cout << "Expected exception: Construct c5: ConditionAny( Condition(vector) ) : " << e.what() << endl;
0130   }
0131 
0132   c1.destroy();
0133   c2.destroy();
0134 
0135   cout << endl << "Test PASSED" << endl << endl;
0136   // All done.
0137   return 1;
0138 }
0139 
0140 // first argument is the type from the xml file
0141 DECLARE_APPLY(DD4hep_Conditions_any_basic,condition_any_basic)