-
Notifications
You must be signed in to change notification settings - Fork 0
/
testHashMap.C
60 lines (54 loc) · 2.6 KB
/
testHashMap.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <map>
#include <iostream>
std::map<uint, std::map<uint, std::vector<unsigned long long> > > eventMap;
ushort findEvent(uint run, uint lumiBlock, unsigned long long event) {
std::map<uint, std::map<uint, std::vector<unsigned long long> > >::iterator runIt = eventMap.find(run);
if (runIt != eventMap.end()) {
std::map<uint, std::vector<unsigned long long> >::iterator lumiIt = eventMap.at(run).find(lumiBlock);
if (lumiIt != eventMap.at(run).end()) {
if (std::find(eventMap.at(run).at(lumiBlock).begin(), eventMap.at(run).at(lumiBlock).end(), event) != eventMap.at(run).at(lumiBlock).end()) {
return 0; // found the event
}
else return 1; // found the run and lumiblock, but the event wasn't there
}
else return 2; // found the run, but lumiblock wasn't there
}
else return 3; // didn't find the run
}
void addEvent(uint run, uint lumiBlock, unsigned long long event) {
ushort searchResult = findEvent(run, lumiBlock, event);
if (searchResult==0) {
std::cout << "Error! Trying to add an event that is already present!" << endl;
}
else if (searchResult == 1) {
eventMap.at(run).at(lumiBlock).push_back(event);
}
else if (searchResult == 2) {
std::vector<unsigned long long> newLumiBlock;
newLumiBlock.push_back(event);
eventMap.at(run).insert(std::pair<uint, std::vector<unsigned long long> >(lumiBlock, newLumiBlock));
}
else if (searchResult == 3) {
std::map<uint, std::vector<unsigned long long> > newRun;
std::vector<unsigned long long> newLumiBlock;
newLumiBlock.push_back(event);
newRun.insert(std::pair<uint, std::vector<unsigned long long> >(lumiBlock, newLumiBlock));
eventMap.insert(std::pair<uint, std::map<uint, std::vector<unsigned long long> > >(run, newRun));
}
}
void testHashMap() {
std::cout << "adding 123456:100:999999999" << std::endl;
addEvent(123456, 100, 999999999);
std::cout << "looking for 123456:100:999999999" << std::endl;
std::cout << findEvent(123456, 100, 999999999) << std::endl;
std::cout << "looking for 654321:200:888888888" << std::endl;
std::cout << findEvent(654321, 200, 888888888) << std::endl;
std::cout << "looking for 123456:200:888888888" << std::endl;
std::cout << findEvent(123456, 200, 888888888) << std::endl;
std::cout << "looking for 123456:100:888888888" << std::endl;
std::cout << findEvent(123456, 100, 888888888) << std::endl;
std::cout << "adding 123456:100:888888888" << std::endl;
addEvent(123456, 100, 888888888);
std::cout << "looking for 123456:100:888888888" << std::endl;
std::cout << findEvent(123456, 100, 888888888) << std::endl;
}