1 |
#include <vector>
|
2 |
#include <string>
|
3 |
|
4 |
#include "cute/cute.h"
|
5 |
#include "cute/cute_suite.h"
|
6 |
|
7 |
#include "TChain.h"
|
8 |
#include "TString.h"
|
9 |
|
10 |
#include "../interface/Readers/VariableReader.h"
|
11 |
|
12 |
|
13 |
|
14 |
using namespace ROOT;
|
15 |
using namespace BAT;
|
16 |
using namespace std;
|
17 |
|
18 |
struct TestVariableReader {
|
19 |
private:
|
20 |
TString invalidEmptyVariableName, invalidNotAvailableVariableName, runNumber, energyForEachElectron;
|
21 |
TChainPointer input;
|
22 |
boost::scoped_ptr<VariableReader<unsigned int> > singleVariableReader;
|
23 |
boost::scoped_ptr<VariableReader<MultiDoublePointer> > multipleVariableReader;
|
24 |
boost::scoped_ptr<VariableReader<int> > invalidEmptyVariableVariableReader, invalidnNotAvailableVariableReader;
|
25 |
|
26 |
public:
|
27 |
TestVariableReader() :
|
28 |
invalidEmptyVariableName(""),
|
29 |
invalidNotAvailableVariableName("thisIsNotInTheFile"),
|
30 |
runNumber("run"),
|
31 |
energyForEachElectron("Electron.Energy"),
|
32 |
input(new TChain(NTupleEventReader::EVENT_CHAIN)),
|
33 |
singleVariableReader(new VariableReader<unsigned int>::VariableReader(input, runNumber)),
|
34 |
multipleVariableReader(new VariableReader<MultiDoublePointer>::VariableReader(input,
|
35 |
energyForEachElectron)),
|
36 |
invalidEmptyVariableVariableReader(new VariableReader<int>::VariableReader(input, invalidEmptyVariableName)),
|
37 |
invalidnNotAvailableVariableReader(new VariableReader<int>::VariableReader(input, invalidNotAvailableVariableName))
|
38 |
{
|
39 |
input->Add(InputFile::ttbar);
|
40 |
input->SetBranchStatus("*", 0);
|
41 |
singleVariableReader->initialise();
|
42 |
multipleVariableReader->initialise();
|
43 |
input->LoadTree(1);
|
44 |
input->GetEntry(1);
|
45 |
}
|
46 |
|
47 |
void testReadSingleVariable() {
|
48 |
ASSERT_EQUAL(1, singleVariableReader->getVariable());
|
49 |
}
|
50 |
|
51 |
void testReadMultipleVariable() {
|
52 |
ASSERT_EQUAL_DELTA(108.714, multipleVariableReader->getVariableAt(0), 0.001);
|
53 |
ASSERT_EQUAL(singleVariableReader->getVariable(), multipleVariableReader->size());
|
54 |
}
|
55 |
|
56 |
void testInvalidVariableThrowsException() {
|
57 |
ASSERT_THROWS(invalidnNotAvailableVariableReader->initialise(), VariableNotFoundException);
|
58 |
}
|
59 |
|
60 |
void testInvalidEmptyVariableThrowsException() {
|
61 |
ASSERT_THROWS(invalidEmptyVariableVariableReader->initialise(), VariableNotFoundException);
|
62 |
}
|
63 |
|
64 |
};
|
65 |
|
66 |
cute::suite make_suite_TestVariableReader() {
|
67 |
cute::suite s;
|
68 |
|
69 |
s.push_back(CUTE_SMEMFUN(TestVariableReader,testReadSingleVariable));
|
70 |
s.push_back(CUTE_SMEMFUN(TestVariableReader,testReadMultipleVariable));
|
71 |
s.push_back(CUTE_SMEMFUN(TestVariableReader,testInvalidVariableThrowsException));
|
72 |
s.push_back(CUTE_SMEMFUN(TestVariableReader,testInvalidEmptyVariableThrowsException));
|
73 |
|
74 |
return s;
|
75 |
}
|
76 |
|