PandaRoot
PndParameterRegister.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef PNDPARAMETERREGISTER_HH
14 #define PNDPARAMETERREGISTER_HH
15 
16 #include <algorithm>
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 #include "FairLogger.h"
22 #include "FairParGenericSet.h"
23 #include "FairParSet.h"
24 
30 class PndParameterRegister : public TObject {
31  public:
37  void AddRequest(const std::string &t_request)
38  {
39  if (std::find(std::begin(fRequests), std::end(fRequests), t_request) == std::end(fRequests)) {
40  fRequests.push_back(t_request);
41  }
42  }
43 
49  void AddRequestList(const std::vector<std::string> &t_requests)
50  {
51  for (const std::string &request : t_requests) {
52  AddRequest(request);
53  }
54  }
55 
62  FairParSet *GetParameter(const std::string &t_name) const
63  {
64  if (fRegister.find(t_name) != fRegister.end()) {
65  return fRegister.at(t_name);
66  }
67  return nullptr;
68  }
69 
76  void SetParameter(const std::string &t_name, FairParSet *t_parameter)
77  {
78  if (fRegister.find(t_name) != fRegister.end()) {
79  return;
80  } else {
81  fRegister[t_name] = t_parameter;
82  }
83  }
84 
90  const std::vector<std::string> &GetRequestList() const { return fRequests; }
91  virtual ~PndParameterRegister() = default;
92 
93  private:
94  std::vector<std::string> fRequests{};
95  std::map<std::string, FairParSet *> fRegister{};
96 
97  ClassDef(PndParameterRegister, 1);
98 };
99 
100 #endif /*PNDPARAMETERREGISTER_HH*/
FairParSet * GetParameter(const std::string &t_name) const
Access the parameter via the name.
void SetParameter(const std::string &t_name, FairParSet *t_parameter)
Set the parameter pointer t_parameter for the parameter t_name.
virtual ~PndParameterRegister()=default
void AddRequestList(const std::vector< std::string > &t_requests)
Add a list of parameter names to the list of requested parameters.
const std::vector< std::string > & GetRequestList() const
Get the list of requested parameter names.
Helper class to indirect the Parameter fetching via the FairRuntimeDb.
void AddRequest(const std::string &t_request)
Add a parameter name to the list of requested parameters.