8#include <nlohmann/json.hpp>
18 const nlohmann::json&
json;
31 auto strip = it->second.getStgcStrip(iclass, strip_id.
istrip);
43 return {
IsValid::VALID, it->second.getPositionAlongStgcStrip(iclass, strip_id.
istrip, sx, sy) };
48 using json = nlohmann::json;
49 json jroot = json::parse(in);
50 for (
const json& jmodule : jroot.at(
"elementarray")) {
53 }
catch (
const std::exception& e) {
54 throw std::runtime_error(e.what());
63 std::unique_ptr<ElementModel> deformation_model;
64 std::string model = j.
json.at(
"model");
65 if (model ==
"nodefo") {
66 deformation_model = std::make_unique<ElementModelRigid>();
68 else if (model ==
"stgc") {
71 const auto& jc = j.
json.at(
"model_constant_pars");
72 jc.at(
"len_x").get_to(lenX);
73 jc.at(
"len_y").get_to(lenY);
74 jc.at(
"defo0_x").get_to(defo0[0]);
75 jc.at(
"defo0_y").get_to(defo0[1]);
76 jc.at(
"defo0_z").get_to(defo0[2]);
77 deformation_model = std::make_unique<ElementModelSTGC>(lenX, lenY, defo0);
80 throw std::runtime_error(
"Unknown model: "+model);
84 std::unique_ptr<Element> el = std::make_unique<Element>(std::move(deformation_model));
87 std::map<std::string, double> correctionPars, nominalPars;
88 j.
json.at(
"pars_corrected").get_to(correctionPars);
89 j.
json.at(
"pars_nominal").get_to(nominalPars);
90 el->setParametersFromMap(ParameterClass::CORRECTION, correctionPars);
91 el->setParametersFromMap(ParameterClass::NOMINAL, nominalPars);
98 std::string stationName;
99 j.
json.at(
"station_name").get_to(stationName);
100 if (stationName ==
"STS") {
102 }
else if (stationName ==
"STL") {
105 throw std::runtime_error(
"StgcStripCalculator: stationName not implemented: "+stationName);
120 auto getPoint = [](
const nlohmann::json& j) {
121 double xpos, ypos, xpitch, ypitch;
122 j.at(
"pos").at(
"x").get_to(xpos);
123 j.at(
"pos").at(
"y").get_to(ypos);
124 j.at(
"pitch").at(
"x").get_to(xpitch);
125 j.at(
"pitch").at(
"y").get_to(ypitch);
143 if (j.
json.contains(
"strip_configuration") && j.
json.contains(
"identifier")) {
151 using json = nlohmann::json;
153 json::const_iterator it;
154 json::const_iterator end;
157 if (!j.
json.contains(
"identifier")) {
165 const std::string KEY =
"zdaughters";
168 std::list<tree_t> jtree;
169 jtree.push_back({j.
json.at(KEY).begin(), j.
json.at(KEY).end()});
170 while (!jtree.empty()) {
171 auto& it = jtree.back().it;
172 if (it != jtree.back().end) {
175 Element* daugref = mom->addDaughter(std::move(daughter));
176 if (it->contains(KEY)) {
177 jtree.push_back({it->at(KEY).begin(), it->at(KEY).end()});
Helper class saving all the needed information to compute strips for a particular cathode board.
Element: a node in a hierarchy of alignment frames.
CathodeBoardElement::stgcStripConfiguration_t getStgcStripConfiguration(json_t j) const
void parseJSON(const std::string &in)
Parses a std::istream with JSON-formatted configuration of the as-built parameters.
void collectStrip(quadrupletIdentifier_t quad_id, Element &element, json_t j)
quadrupletIdentifier_t getQuadrupletIdentifier(json_t j) const
Element::ParameterClass ParameterClass
position_t getPositionAlongStgcStrip(ParameterClass iclass, stripIdentifier_t strip_id, double sx, double sy) const
Returns a the position of a point along the strip, parameterized by s, in the coordinate system of th...
std::unordered_map< pcbIdentifier_t, CathodeBoardElement > m_pcbMap
std::vector< std::unique_ptr< Element > > m_rootElements
pcbIdentifier_t getPcbIdentifier(quadrupletIdentifier_t quad_id, json_t j) const
stgcStrip_t getStgcStrip(ParameterClass iclass, stripIdentifier_t strip_id) const
Computes 3 reference points along a strip identified by strip_id, in coordinate system of quadruplet.
void parseRootElement(json_t j)
std::unique_ptr< Element > buildElement(json_t j) const
Eigen::Matrix< double, 3, 1 > Vector3D
stgcStripPoint_t fCenterPoint
stgcStripPoint_t fLeftPoint
stgcStripPoint_t lCenterPoint
stgcStripPoint_t sCenterPoint
stgcStripPoint_t sLeftPoint
stgcStripPoint_t lRightPoint
stgcStripPoint_t fRightPoint
stgcStripPoint_t sRightPoint
stgcStripPoint_t lLeftPoint
The return object for querying strip positions with the method getPositionAlongStrip: a single point ...
The return object for querying strip positions: three points along the strip are provided,...
quadrupletIdentifier_t quadruplet
Athena indices for a MM quadruplet:
Athena indices of a MM strip.
quadrupletIdentifier_t quadruplet
json_t(const nlohmann::json &j)
const nlohmann::json & json