Belle II Software  release-05-01-25
dbRepresentationOfSoftwareTriggerCut.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <mdst/dbobjects/DBRepresentationOfSoftwareTriggerCut.h>
12 #include <hlt/softwaretrigger/core/SoftwareTriggerCut.h>
13 #include <hlt/softwaretrigger/core/SoftwareTriggerDBHandler.h>
14 #include <boost/filesystem.hpp>
15 
16 #include <framework/utilities/TestHelpers.h>
17 #include <gtest/gtest.h>
18 
19 using namespace std;
20 
21 namespace Belle2 {
26  namespace SoftwareTrigger {
27 
29  class DBRepresentationOfSoftwareTriggerCutTest : public ::testing::Test {
30 
33 
35  void SetUp()
36  {
38  DataStore::Instance().setInitializeActive(true);
39  evtPtr.registerInDataStore();
40  DataStore::Instance().setInitializeActive(false);
41  evtPtr.construct(0, 0, 0);
42  }
43 
45  void TearDown()
46  {
47  boost::filesystem::remove_all("testPayloads");
48  DataStore::Instance().reset();
49  }
50  };
51 
53  TEST_F(DBRepresentationOfSoftwareTriggerCutTest, basic)
54  {
55  auto cut = SoftwareTriggerCut::compile("1 == 2", 10, true);
56  DBRepresentationOfSoftwareTriggerCut representation(cut->getPreScaleFactor(), cut->isRejectCut(), cut->decompile());
57  auto returnedCut = SoftwareTriggerDBHandler::createCutFromDB(representation);
58 
59  EXPECT_EQ(cut->decompile(), returnedCut->decompile());
60  EXPECT_EQ(cut->getPreScaleFactor(), returnedCut->getPreScaleFactor());
61  EXPECT_EQ(cut->isRejectCut(), returnedCut->isRejectCut());
62 
63  auto cut2 = SoftwareTriggerCut::compile("1 == 2", 10, false);
64  DBRepresentationOfSoftwareTriggerCut representation2(cut2->getPreScaleFactor(), cut2->isRejectCut(), cut2->decompile());
65  auto returnedCut2 = SoftwareTriggerDBHandler::createCutFromDB(representation2);
66 
67  EXPECT_EQ(cut2->decompile(), returnedCut2->decompile());
68  EXPECT_EQ(cut2->getPreScaleFactor(), returnedCut2->getPreScaleFactor());
69  EXPECT_EQ(cut2->isRejectCut(), returnedCut2->isRejectCut());
70  }
71  }
73 }
Belle2::SoftwareTrigger::DBRepresentationOfSoftwareTriggerCutTest::SetUp
void SetUp()
Setup the local DB and the datastore with the event meta data.
Definition: dbRepresentationOfSoftwareTriggerCut.cc:35
Belle2::SoftwareTrigger::DBRepresentationOfSoftwareTriggerCutTest
Class to test the db representation of the cuts.
Definition: dbRepresentationOfSoftwareTriggerCut.cc:29
Belle2::TestHelpers::TempDirCreator
changes working directory into a newly created directory, and removes it (and contents) on destructio...
Definition: TestHelpers.h:57
Belle2::SoftwareTrigger::DBRepresentationOfSoftwareTriggerCutTest::TearDown
void TearDown()
Destroy the DB and the DataStore.
Definition: dbRepresentationOfSoftwareTriggerCut.cc:45
Belle2::StoreObjPtr::construct
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:128
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_F
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:65
Belle2::DBRepresentationOfSoftwareTriggerCut
Class to handle storing SoftwareTriggerCuts in the database.
Definition: DBRepresentationOfSoftwareTriggerCut.h:36
Belle2::SoftwareTrigger::DBRepresentationOfSoftwareTriggerCutTest::tmp_dir
TestHelpers::TempDirCreator tmp_dir
Do everything in a temporary dir.
Definition: dbRepresentationOfSoftwareTriggerCut.cc:32