From b9d81668a73d243d21ad37a36812d515baaeda5b Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 9 Nov 2022 13:09:31 +0100 Subject: [PATCH] add energy_vect tag which allows a more compact startup xml-file if the rge-files are equally spaced in energy. --- src/classes/PRgeHandler.cpp | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/classes/PRgeHandler.cpp b/src/classes/PRgeHandler.cpp index 224746f3..9e11bfda 100644 --- a/src/classes/PRgeHandler.cpp +++ b/src/classes/PRgeHandler.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "PRgeHandler.h" ClassImpQ(PXmlRgeHandler) @@ -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); } }