-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathORHardwareDictionary.cc
127 lines (117 loc) · 4.81 KB
/
ORHardwareDictionary.cc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "ORHardwareDictionary.hh"
#include "ORDecoderDictionary.hh"
#include "ORLogger.hh"
#include <sstream>
ORHardwareDictionary::ORHardwareDictionary(std::string name) : ORDictionary(name)
{
/* We always look for crates/cards, but this allows us to look for other
dictionaries that might contain */
fVectorOfBaseDicts.push_back("GPIB");
fVectorOfBaseDicts.push_back("USB");
}
bool ORHardwareDictionary::LoadHardwareDictFromDict(const ORDictionary* dict)
{
if (!dict) {
ORLog(kError) << "Dictionary doesn't exist!" << std::endl;
return false;
}
/* first let us find Crates and crate numbers*/
if (!LoadCratesAndCards(dict)) return false;
return true;
}
bool ORHardwareDictionary::LoadCratesAndCards(const ORDictionary* dict)
{
/* To document, fCrateMap holds a key with a pair that is:
pair< Name of the crate, number of the crate >
and a value which is:
pair< number of offset (0 or 1), vector of cards filled. */
if (!dict) {
ORLog(kError) << "Dictionary is NULL!" << std::endl;
return false;
}
/* First let us grab the crate list. */
const ORDictValueA* crateArray =
dynamic_cast<const ORDictValueA*>(dict->LookUp("ObjectInfo:Crates"));
if (!crateArray) {
ORLog(kError) << "Error finding ObjectInfo:Crates" << std::endl;
return false;
}
/* Now load up fCrateMap*/
for (size_t i=0;i<crateArray->GetNValues();i++) {
const ORDictionary* oneCrate = dynamic_cast<const ORDictionary*>(crateArray->At(i));
if (!oneCrate) {
ORLog(kWarning) << "Crates array includes non-dictionary." << std::endl;
} else {
const ORDictValueI* crateNum = dynamic_cast<const ORDictValueI*>(
oneCrate->LookUp("CrateNumber"));
const ORDictValueS* crateName = dynamic_cast<const ORDictValueS*>(
oneCrate->LookUp("ClassName"));
const ORDictValueI* crateOffset = dynamic_cast<const ORDictValueI*>(
oneCrate->LookUp("FirstSlot"));
if (!crateNum || !crateName || !crateOffset) {
ORLog(kError) << "Error finding Crate information." << std::endl;
return false;
}
/* Now grab the cards from the crate. */
const ORDictValueA* crateCardArray = dynamic_cast<const ORDictValueA*>(
oneCrate->LookUp("Cards"));
if (!crateCardArray) {
ORLog(kError) << "Error finding array Cards" << std::endl;
return false;
}
for (size_t i=0;i<crateCardArray->GetNValues();i++) {
const ORDictionary* cardDict = dynamic_cast<const ORDictionary*>(crateCardArray->At(i));
if (!cardDict) {
ORLog(kWarning) << "Cards array includes non-dictionary." << std::endl;
} else {
/* grab numbers, grab names*/
const ORDictValueS* className = dynamic_cast<const ORDictValueS*>(
cardDict->LookUp("Class Name"));
const ORDictValueI* slotNumber = dynamic_cast<const ORDictValueI*>(
cardDict->LookUp("Card"));
if (!className || !slotNumber) {
ORLog(kError) << "Error getting card." << std::endl;
return false;
}
/* Is there an offset? */
//int slotCrateNum = slotNumber->GetI() + crateOffset->GetI();
int slotCrateNum = slotNumber->GetI();
ORDecoderDictionary* decoderCrateDict = 0;
if ((fDictMap.find(className->GetS())) == fDictMap.end()) {
decoderCrateDict = new ORDecoderDictionary(className->GetS());
fDictMap[className->GetS()] = decoderCrateDict;
} else {
decoderCrateDict =
dynamic_cast<ORDecoderDictionary*>(fDictMap[className->GetS()]);
}
/* OK, now load it up with the card/crate info. */
std::ostringstream os1, os2;
os1 << crateNum->GetI();
decoderCrateDict->LookUp(os1.str());
ORDictionary* crateDictForCard = 0;
/* Insert crate if it doesn't exist. */
if (!(crateDictForCard = dynamic_cast<ORDictionary*>(
decoderCrateDict->LookUp(os1.str())))) {
crateDictForCard = new ORDictionary(os1.str());
decoderCrateDict->LoadEntry(os1.str(), crateDictForCard);
}
/* Finally making new dictionary from a copy and inserting. */
ORDictionary* newCardDict = new ORDictionary(*cardDict);
os2 << slotCrateNum;
newCardDict->SetName(os2.str());
crateDictForCard->LoadEntry(os2.str(), newCardDict);
}
}
}
}
return true;
}
const ORDecoderDictionary* ORHardwareDictionary::GetDecoderDictionary(std::string dictName) const
{
if (dictName.size() == 0) return NULL;
const ORDecoderDictionary* dict = dynamic_cast<const ORDecoderDictionary*>(LookUp(dictName));
if(!dict) {
ORLog(kWarning) << "Decoder Dictionary (" << dictName << ") requested but not found" << std::endl;
}
return dict;
}