1 |
/*
|
2 |
* TestTH1Collection.h
|
3 |
*
|
4 |
* Created on: 9 Aug 2010
|
5 |
* Author: kreczko
|
6 |
*/
|
7 |
|
8 |
#include "cute/cute.h"
|
9 |
#include "cute/cute_suite.h"
|
10 |
#include "../interface/HistHelpers/THCollection.h"
|
11 |
#include "TH1F.h"
|
12 |
#include "TFile.h"
|
13 |
#include <boost/shared_ptr.hpp>
|
14 |
#include <boost/filesystem.hpp>
|
15 |
|
16 |
using namespace BAT;
|
17 |
|
18 |
struct TestTHCollection {
|
19 |
private:
|
20 |
boost::shared_ptr<TFile> histFile;
|
21 |
TH1Collection collection;
|
22 |
TH1Collection collectionWithPath;
|
23 |
TH2Collection collection2D;
|
24 |
|
25 |
public:
|
26 |
TestTHCollection() :
|
27 |
histFile(new TFile("testTHCollection.root", "RECREATE")), collection(), collectionWithPath("mc/ttbar"),
|
28 |
collection2D() {
|
29 |
}
|
30 |
|
31 |
~TestTHCollection() {
|
32 |
if (boost::filesystem::exists("testTHCollection.root")) {
|
33 |
boost::filesystem::remove("testTHCollection.root");
|
34 |
}
|
35 |
}
|
36 |
|
37 |
void testInitialSize() {
|
38 |
ASSERT_EQUAL(0, collection.size());
|
39 |
}
|
40 |
|
41 |
void testSize() {
|
42 |
collection.add("test", "test", 100, 0, 100);
|
43 |
ASSERT_EQUAL(1, collection.size());
|
44 |
}
|
45 |
|
46 |
void test2DSize() {
|
47 |
collection2D.add("test", "test", 100, 0, 100, 50, 0, 50);
|
48 |
ASSERT_EQUAL(1, collection2D.size());
|
49 |
}
|
50 |
|
51 |
void testInterference() {
|
52 |
collection.add("test", "test", 100, 0, 100);
|
53 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
54 |
collection.get("test")->Fill(1);
|
55 |
collectionWithPath.get("test")->Fill(1);
|
56 |
ASSERT_EQUAL(1, collectionWithPath.get("test")->GetEntries());
|
57 |
}
|
58 |
|
59 |
void testWriteInterference() {
|
60 |
collection.add("test", "test", 100, 0, 100);
|
61 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
62 |
collection.get("test")->Fill(1);
|
63 |
collectionWithPath.get("test")->Fill(1);
|
64 |
collection.writeToFile(histFile);
|
65 |
collectionWithPath.writeToFile(histFile);
|
66 |
ASSERT(histFile->Get("test") != 0);
|
67 |
ASSERT(histFile->Get("mc/ttbar/test") != 0);
|
68 |
}
|
69 |
|
70 |
void testWriteFileWithoutFolder() {
|
71 |
collection.add("test", "test", 100, 0, 100);
|
72 |
collection.writeToFile(histFile);
|
73 |
ASSERT(histFile->Get("test") != 0);
|
74 |
}
|
75 |
|
76 |
void testWriteFileWithFolderFirstDirectory() {
|
77 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
78 |
collectionWithPath.writeToFile(histFile);
|
79 |
ASSERT(histFile->Get("mc") != 0);
|
80 |
|
81 |
}
|
82 |
|
83 |
void testWriteFileWithFolderSubDirectory() {
|
84 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
85 |
collectionWithPath.writeToFile(histFile);
|
86 |
ASSERT(histFile->Get("mc/ttbar") != 0);
|
87 |
}
|
88 |
|
89 |
void testWriteFileWithFolder() {
|
90 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
91 |
collectionWithPath.writeToFile(histFile);
|
92 |
ASSERT(histFile->Get("mc/ttbar/test") != 0);
|
93 |
}
|
94 |
|
95 |
void testPrefix() {
|
96 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
97 |
collectionWithPath.setPrefix("first");
|
98 |
collectionWithPath.writeToFile(histFile);
|
99 |
ASSERT(histFile->Get("mc/ttbar/first_test") != 0);
|
100 |
}
|
101 |
|
102 |
void testSuffix() {
|
103 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
104 |
collectionWithPath.setSuffix("old");
|
105 |
collectionWithPath.writeToFile(histFile);
|
106 |
ASSERT(histFile->Get("mc/ttbar/test_old") != 0);
|
107 |
}
|
108 |
|
109 |
void testPrefixAndSuffix() {
|
110 |
collectionWithPath.add("test", "test", 100, 0, 100);
|
111 |
collectionWithPath.setPrefix("first");
|
112 |
collectionWithPath.setSuffix("old");
|
113 |
collectionWithPath.writeToFile(histFile);
|
114 |
ASSERT(histFile->Get("mc/ttbar/first_test_old") != 0);
|
115 |
}
|
116 |
|
117 |
};
|
118 |
|
119 |
extern cute::suite make_suite_TestTHCollection() {
|
120 |
cute::suite s;
|
121 |
|
122 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testInitialSize));
|
123 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testSize));
|
124 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, test2DSize));
|
125 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testInterference));
|
126 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testWriteInterference));
|
127 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testWriteFileWithoutFolder));
|
128 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testWriteFileWithFolderFirstDirectory));
|
129 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testWriteFileWithFolderSubDirectory));
|
130 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testWriteFileWithFolder));
|
131 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testPrefix));
|
132 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testSuffix));
|
133 |
s.push_back(CUTE_SMEMFUN(TestTHCollection, testPrefixAndSuffix));
|
134 |
|
135 |
return s;
|
136 |
}
|
137 |
|