Belle II Software  release-08-01-10
StoreWrappedObjPtr.test.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/trackFindingCDC/testFixtures/TrackFindingCDCTestWithTopology.h>
9 
10 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
11 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
12 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13 
14 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
15 
16 #include <tracking/trackFindingCDC/rootification/StoreWrapper.h>
17 #include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
18 
19 #include <framework/datastore/StoreObjPtr.h>
20 #include <framework/datastore/DataStore.h>
21 
22 #include <boost/python.hpp>
23 #include <gtest/gtest.h>
24 
25 using namespace Belle2;
26 using namespace TrackFindingCDC;
27 
28 
29 TEST(TrackFindingCDCTest, cpp_storeWrapper)
30 {
32  // do something so that cppcheck is happy
33  stdVector.isOptional();
34 }
35 
36 TEST(TrackFindingCDCTest, cpp_storeWrappedObjPtr)
37 {
39  // do something so that cppcheck is happy
40  stdVector.isOptional();
41 }
42 
43 template <class T>
45 };
46 
47 using RootifiedTypes =
48  ::testing::Types<std::vector<CDCWireHit>,
49  std::vector<CDCSegment2D>,
50  std::vector<CDCTrack>,
51  std::vector<WeightedRelation<const CDCTrack> > >;
52 
53 TYPED_TEST_SUITE(DISABLED_TrackFindingCDCTestRootification, RootifiedTypes);
54 
55 TYPED_TEST(DISABLED_TrackFindingCDCTestRootification, rootification_UsableAsStoreWrappedObjPtr)
56 {
57  DataStore& datastore = DataStore::Instance();
59 
60  // Initialization phase
61  datastore.setInitializeActive(true);
63  datastore.setInitializeActive(false);
64 
65  // Event processing phase
66  // First module
67  storeObj.create();
68  const std::string& objectName = storeObj.getName();
69 
70  // Second module - a python module
71  // Setting up the Python interpreter
72  Py_Initialize(); // Repeated initialization calls do nothing
73 
74  // Loading basf2
75  ASSERT_NE(-1, PyRun_SimpleString("import basf2"));
76  ASSERT_NE(-1, PyRun_SimpleString("from ROOT import Belle2"));
77 
78  // Make the object name available in the Python interpreter
79  std::string pyCmd_transferName_prototype = "objectName = 'X'";
80  std::string pyCmd_transferName = pyCmd_transferName_prototype.replace(pyCmd_transferName_prototype.find("X"), 1, objectName);
81  ASSERT_NE(-1, PyRun_SimpleString(pyCmd_transferName.c_str()));
82 
83  // Fetch the object from the DataStore and use it
84  ASSERT_NE(-1, PyRun_SimpleString("pyStoreObj = Belle2.PyStoreObj(objectName)"));
85  ASSERT_NE(-1, PyRun_SimpleString("if not pyStoreObj: raise ValueError('PyStoreObj does not point to a "
86  "valid object on the DataStore')"));
87  ASSERT_NE(-1, PyRun_SimpleString("print('pyStoreObj.obj() is', pyStoreObj.obj())"));
88  ASSERT_NE(-1, PyRun_SimpleString("print('pyStoreObj.obj().unwrap() is', pyStoreObj.obj().unwrap())"));
89 
90  // Note: if an error is raised in Python the return value is -1
91  // ASSERT_EQ(-1,PyRun_SimpleString("raise ValueError('This is a test')"));
92 
93  // Root crashes, if you terminate the python interpreter already
94  // Py_Finalize();
95 }
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
Register the object/array in the DataStore.
This class provides the declaration of the common test fixture to all test of the track finding in th...
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.