18#ifndef O2_TOF_PARAMCONTAINER_H
19#define O2_TOF_PARAMCONTAINER_H
37 Parameters(std::array<std::string, nPar> parNames, std::string
name) : mName{
name}, mPar{}, mParNames{parNames} {};
55 for (
int i = 0;
i < nPar;
i++) {
71 LOG(info) <<
"Parameters '" << mName <<
"'";
72 for (
int i = 0;
i < nPar;
i++) {
73 LOG(info) <<
"Parameter " <<
i <<
"/" << nPar - 1 <<
" " << mParNames[
i] <<
" is " << mPar[
i];
80 for (
int i = 0;
i < nPar;
i++) {
81 metadata[Form(
"p%i",
i)] = Form(
"%f", mPar[
i]);
90 TFile
f(FileName,
"READ");
92 LOG(fatal) <<
"Could not open file " << FileName;
94 if (!
f.Get(ParamName)) {
96 LOG(fatal) <<
"Did not find parameters " << ParamName <<
" in file " << FileName;
98 LOG(info) <<
"Loading parameters " << ParamName <<
" from TFile " << FileName;
100 f.GetObject(ParamName, p);
102 LOG(fatal) <<
"Could not get parameters " << ParamName <<
" from file";
124 const std::string
getName()
const {
return mName; }
128 static int size() {
return nPar; }
137 std::array<paramvar_t, nPar> mPar;
138 const std::array<std::string, nPar> mParNames;
154 bool hasKey(
const std::string&
key)
const {
return (mParameters.find(
key) != mParameters.end()); }
162 template <
typename ParType>
169 const auto& toGet = mParameters.at(
key);
170 for (
int i = 0;
i < p.size();
i++) {
171 const auto&
name = p.getParameterName(
i);
172 if (toGet.find(
name) == toGet.end()) {
173 LOG(
debug) <<
"Did not find parameter '" <<
name <<
"' in collection, keeping preexisting";
176 LOG(
debug) <<
"Found parameter '" <<
name <<
"' in collection, updating from " << p[
i] <<
" to " << toGet.at(
name);
177 p.setParameter(
i, toGet.at(
name));
188 const bool alreadyPresent =
hasKey(pass);
189 if (alreadyPresent) {
190 LOG(
debug) <<
"Changing parametrization corresponding to key " << pass <<
" from size " << mParameters[pass].size() <<
" to " << parName;
192 mParameters[pass] = std::unordered_map<std::string, paramvar_t>{};
193 LOG(
debug) <<
"Adding new parametrization corresponding to key " << pass <<
": " << parName;
195 mParameters[pass][parName] =
value;
205 return mParameters.at(pass).size();
213 template <
typename ParType>
217 if (alreadyPresent) {
218 LOG(
debug) <<
"Changing parametrization corresponding to key " <<
key <<
" from size " << mParameters[
key].size() <<
" to " << p.getName() <<
" of size " << p.size();
220 mParameters[
key] = std::unordered_map<std::string, paramvar_t>{};
221 LOG(
debug) <<
"Adding new parametrization corresponding to key " <<
key <<
": " << p.getName() <<
" of size " << p.size();
223 for (
int i = 0;
i < p.size();
i++) {
224 mParameters[
key][p.getParameterName(
i)] = p[
i];
226 return alreadyPresent;
230 const auto&
getPars(
const std::string& pass)
const {
return mParameters.at(pass); }
234 void print(
const std::string& pass)
const
238 LOG(info) <<
"empty pass: " << pass;
241 LOG(info) <<
"Pass \"" << pass <<
"\" with size " <<
size;
242 for (
const auto& [par,
value] : mParameters.at(pass)) {
243 LOG(info) <<
"par name = " << par <<
", value = " <<
value;
250 for (
const auto& [pass, pars] : mParameters) {
264 TFile
f(FileName,
"READ");
266 LOG(fatal) <<
"Could not open file " << FileName;
268 if (!
f.Get(ParamName)) {
270 LOG(fatal) <<
"Did not find parameters " << ParamName <<
" in file " << FileName;
272 LOG(info) <<
"Loading parameters " << ParamName <<
" from TFile " << FileName;
274 f.GetObject(ParamName, p);
276 LOG(fatal) <<
"Could not get parameters " << ParamName <<
" from file";
281 for (
const auto& pass : p->mParameters) {
282 for (
const auto& par : pass.second) {
291 std::unordered_map<std::string, std::unordered_map<std::string, paramvar_t>> mParameters;
Class container to hold different parameters meant to be stored on the CCDB.
const auto & getPars(const std::string &pass) const
getter for the parameters stored in the container matching to a pass
const auto & getFullMap()
Getter of the full map of parameters stored in the container.
bool hasKey(const std::string &key) const
Checks if the container has a particular key e.g. a pass.
bool retrieveParameters(ParType &p, const std::string &key) const
Function to load the parameters from the this container into the array based for the asked key,...
void print() const
printing function for the full content of the container
ParameterCollection(TString name="DefaultParameters")
Default constructor.
void print(const std::string &pass) const
printing function for the content of the pass
bool addParameter(const std::string &pass, const std::string &parName, float value)
Function to add a single parameter conatiner based on the asked key, e.g. pass or version.
int getSize(const std::string &pass) const
~ParameterCollection() override=default
Default destructor.
void loadParamFromFile(const TString FileName, const TString ParamName)
bool storeParameters(const ParType &p, const std::string &key)
Function to push the parameters from the sub container into the collection and store it under a given...
void setParameter(const unsigned int iparam, const paramvar_t value)
void loadParamFromFile(const TString FileName, const TString ParamName)
virtual ~Parameters()=default
Default destructor.
const std::string getName() const
const std::string getParameterName(int i) const
void setParameters(const Parameters< nPar > *params)
void setParameters(const Parameters< nPar > params)
void setParameters(const paramvar_t *params)
void addToMetadata(std::map< std::string, std::string > &metadata) const
Adds the parameters to the metadata.
const paramvar_t getParameter(int i) const
const paramvar_t * getParameters() const
void setParameters(const std::array< paramvar_t, nPar > params)
paramvar_t operator[](const unsigned int i) const
void print() const
Printer of the parameter values.
Parameters(std::array< std::string, nPar > parNames, std::string name)
Default constructor.
GLuint const GLchar * name
GLsizei const GLfloat * value
GLenum const GLfloat * params
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"