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