From 41c90ef9360775d95854c2cef19d8655381e3922 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 21 Dec 2022 07:49:57 +0100 Subject: [PATCH] define tag energy_vec with attributes start, stop, step to define rge energy vector in a compact way in startup.xml files. --- src/classes/PRgeHandler.cpp | 77 ++++++++++++++++++- .../{ => test}/depth_profile_startup.xml | 0 2 files changed, 76 insertions(+), 1 deletion(-) rename src/external/DepthProfile/{ => test}/depth_profile_startup.xml (100%) diff --git a/src/classes/PRgeHandler.cpp b/src/classes/PRgeHandler.cpp index db1ad595..baa42177 100644 --- a/src/classes/PRgeHandler.cpp +++ b/src/classes/PRgeHandler.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "PRgeHandler.h" ClassImpQ(PXmlRgeHandler) @@ -87,7 +88,7 @@ void PXmlRgeHandler::OnEndDocument() * and sets a proper key. * * \param str XML element name - * \param attributes not used + * \param attributes used only for energy_vect */ void PXmlRgeHandler::OnStartElement(const Char_t *str, const TList *attributes) { @@ -99,6 +100,80 @@ void PXmlRgeHandler::OnStartElement(const Char_t *str, const TList *attributes) fKey = eFlnPre; } else if (!strcmp(str, "energy") && isTrimSp) { fKey = eEnergy; + } else if (!strcmp(str, "energy_vect") && isTrimSp) { + std::string msg(""); + if (attributes == nullptr) { + fIsValid = false; + msg = "Found energy_list without attributes"; + OnError(msg.c_str()); + return; + } + if (attributes->GetEntries() != 3) { + fIsValid = false; + msg = "energy_list: expect 3 attributes (start, stop, step), found " + std::to_string(attributes->GetEntries()); + OnError(msg.c_str()); + return; + } + + TXMLAttr *attr; + + int start=-1, stop=-1, step=-1, ival; + TIter next(attributes); + while ((attr = (TXMLAttr*) next())) { + char sval[256]; + strncpy(sval, attr->GetValue(), sizeof(sval)); + try { + ival = std::stoi(sval); + } catch(std::invalid_argument& e) { + fIsValid = false; + msg = "The found energy_list attribute '" + std::string(sval) + "' which is not a number"; + OnError(msg.c_str()); + return; + } catch(std::out_of_range& e) { + fIsValid = false; + msg = "The found energy_list attribute '" + std::string(sval) + "' which is out-of-range."; + OnError(msg.c_str()); + return; + } catch(...) { + fIsValid = false; + msg = "The found energy_list attribute '" + std::string(sval) + "' which generates an error."; + OnError(msg.c_str()); + return; + } + if (!strcmp(attr->GetName(), "start")) { + start = ival; + } else if (!strcmp(attr->GetName(), "stop")) { + stop = ival; + } else if (!strcmp(attr->GetName(), "step")) { + step = ival; + } + } + // make sure I do have start, stop, and step values set + if ((start == -1) || (stop == -1) || (step == -1)) { + fIsValid = false; + msg = "Found energy_list with missing attributes. Needed start, stop and step."; + OnError(msg.c_str()); + return; + } + // more checks: start < stop, and step > 0. + if ((start > stop)) { + fIsValid = false; + msg = "Found energy_list with start > stop. Not allowed in the context."; + OnError(msg.c_str()); + return; + } + if (step < 0) { + fIsValid = false; + msg = "Found energy_list with step < 0. Not allowed in the context."; + OnError(msg.c_str()); + return; + } + // generate the fTrimSpDataEnergyList vector + ival = start; + do { + fTrimSpDataEnergyList.push_back(ival); + ival += step; + } while (ival <= stop); } } diff --git a/src/external/DepthProfile/depth_profile_startup.xml b/src/external/DepthProfile/test/depth_profile_startup.xml similarity index 100% rename from src/external/DepthProfile/depth_profile_startup.xml rename to src/external/DepthProfile/test/depth_profile_startup.xml