RHardwareProfileXMLManager.cc
Go to the documentation of this file.
1 #include <boost/lambda/lambda.hpp>
2 
3 #include <rdet/RHardwareProfileXMLManager.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/TabulatedFunction.h>
6 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
7 #include <rdet/RDetector.h>
8 #include <rdet/RManagerRegister.h>
9 
10 using namespace rdet;
11 using namespace std;
12 using namespace utl;
13 using namespace det;
14 using namespace xercesc;
15 using namespace boost::lambda;
16 
17 REGISTER_R_MANAGER("RHardwareProfileXMLManager", RHardwareProfileXMLManager)
18 
19 
20 void
21 RHardwareProfileXMLManager::Init(const string& configLink)
22 {
23  VManager::Init(configLink);
24 }
25 
26 
27 // Meant for finding GetData("flatDemo", "Response")
29  const string& hardwareProp)
30  const
31 {
32  Branch hardwareB = FindHardwareProfile(hardwareType);
33 
34  // in case FindHardwareProfile could not find the desired branch
35  if (!hardwareB)
36  return hardwareB;
37 
38  Branch hardwarePropB = hardwareB.GetFirstChild();
39  for ( ; hardwarePropB; hardwarePropB = hardwarePropB.GetNextSibling())
40  if (hardwarePropB.GetName() == hardwareProp)
41  return hardwarePropB;
42 
43  if (IsReportingErrors()) {
44  ostringstream err;
45  err << "Cannot find " + hardwareProp + " while parsing for hardwareType "+ hardwareType +" in XML." ;
46  ERROR(err);
47  }
48 
49  return hardwarePropB;
50 }
51 
52 
53 // Find single hardware types ("flatDemo"):
55  const
56 {
57  Branch hardwareB = fBranch.GetFirstChild();
58  for ( ; hardwareB; hardwareB = hardwareB.GetNextSibling())
59  if (hardwareB.GetName() == "RResponse" &&
60  hardwareB.GetAttributes().begin()->second == hardwareType)
61  return hardwareB;
62 
63  if (IsReportingErrors()) {
64  ostringstream err;
65  err << "Cannot find specifications for '" + hardwareType + "' while XML parsing.";
66  ERROR(err);
67  }
68 
69  return hardwareB;
70 }
71 
72 
73 // propIndex not used, but to obey interface
75 RHardwareProfileXMLManager::GetInternalData(TabulatedFunctionComplexLgAmpPhase& returnData,
76  const string& hardwareProp,
77  const string& hardwareType,
78  const IndexMap& /*propIndex*/)
79  const
80 {
81 
82  // Find where requested data resides in DOM
83  Branch dataBranch =
84  FindHardwareProfileProperty(hardwareType, hardwareProp);
85  if (!dataBranch)
86  return eNotFound;
87 
88  // Since this is tabulated data, retrieve the ordinate and abscissa
89  // NOTE: it is assumed that the x, usually the frequency, is labelled "x"
90  // amplification can be given in one of three units: "LgAmp", "LgPow", "dB"
91  // LgAmp means log10 of the amplification with regard to voltage,
92  // LgPow means log10 of the amplification with regard to power,
93  // dB means amplification in dB
94  // the third column is the phase given in either degrees or radians
95  Branch xB = dataBranch.GetChild("x");
96  if (!xB)
97  return eNotFound;
98 
99  vector<double> x;
100  xB.GetData(x);
101 
102  // the branch AmpB has to be filled with vlues in log10(Amplitude); check for the three options and convert accordingly
103  vector<double> lgAmp;
104  Branch AmpB = dataBranch.GetChild("dB");
105  if (AmpB) {
106  AmpB.GetData(lgAmp);
107  for_each(lgAmp.begin(), lgAmp.end(), _1 *= 0.05); // convert dB to LgAmp
108  } else {
109  AmpB = dataBranch.GetChild("LgAmp");
110  if (AmpB) {
111  AmpB.GetData(lgAmp); // no conversion necessary
112  } else {
113  AmpB = dataBranch.GetChild("LgPow");
114  if (AmpB) {
115  AmpB.GetData(lgAmp);
116  for_each(lgAmp.begin(), lgAmp.end(), _1 *= 0.5); // convert LgPow to LgAmp
117  } else
118  return eNotFound; // none of "dB", "LgAmp", "lgPow"
119  }
120  }
121 
122  Branch phaseB = dataBranch.GetChild("Phase");
123  if (!phaseB)
124  return eNotFound;
125 
126  vector<double> phase;
127  phaseB.GetData(phase);
128 
129  const unsigned int n = x.size();
130  returnData = TabulatedFunctionComplexLgAmpPhase();
131  for (unsigned int i = 0; i < n; ++i)
132  returnData.PushBack(x[i], ComplexLgAmpPhase(lgAmp[i],phase[i]));
133 
134  return eFound;
135 }
Manager for RD description in XML &quot;HardwareProfile&quot; files.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
utl::Branch FindHardwareProfileProperty(const std::string &hardwareType, const std::string &hardwareProp) const
Find the Branch corresponding for given hardwareType and hardwarePoperty.
AttributeMap GetAttributes() const
Get a map&lt;string, string&gt; containing all the attributes of this Branch.
Definition: Branch.cc:267
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
#define REGISTER_R_MANAGER(_name_, _Type_)
Class representing a document branch.
Definition: Branch.h:107
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
std::string GetName() const
function to get the Branch name
Definition: Branch.cc:374
A class to store complex numbers which are internally represented by log10(amplitude) and phase (and ...
void PushBack(const double x, const utl::ComplexLgAmpPhase &y)
utl::Branch FindHardwareProfile(const std::string &hardwareType) const
Find Branch for a given hardwareType.
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.