BAT  0.9.4
The Bayesian analysis toolkit
 All Classes Namespaces Functions Variables Enumerations
BCParameterSet.cxx
1 /*
2  * Copyright (C) 2007-2014, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 // ---------------------------------------------------------
10 
11 #include "BCParameterSet.h"
12 
13 #include "BCLog.h"
14 #include "BCParameter.h"
15 
16 #include <TString.h>
17 
18 // ---------------------------------------------------------
20 {
21  if ( !parameter)
22  return false;
23  // check if parameter with same name exists
24  for (unsigned int i = 0; i < fPars.size() ; ++i)
25  if ( parameter->GetName() == fPars[i]->GetName() ) {
26  BCLog::OutError(TString::Format("BCParameterSet::Add : Parameter with name %s exists already. ",
27  parameter->GetName().data()));
28  return false;
29  }
30 
31  // add parameter to parameter container
32  fPars.push_back(parameter);
33  return true;
34 }
35 
36 // ---------------------------------------------------------
37 void BCParameterSet::Clear(bool hard)
38 {
39  if (hard) {
40  for (unsigned int i = 0; i < fPars.size() ; ++i)
41  delete fPars[i];
42  }
43 
44  fPars.clear();
45 }
46 
47 // ---------------------------------------------------------
48 bool BCParameterSet::ValidIndex(unsigned index, const std::string caller) const
49 {
50  if (index >= fPars.size()) {
51  BCLog::OutError(TString::Format("BCParameterSet::%s : Parameter index %u out of range", caller.c_str(), index));
52  return false;
53  }
54  else
55  return true;
56 }
57 
58 // ---------------------------------------------------------
59 unsigned BCParameterSet::Index(const std::string & name) const
60 {
61  for (unsigned int i=0; i < fPars.size() ; ++i)
62  if (name == fPars[i]->GetName())
63  return i;
64 
65  BCLog::OutWarning(TString::Format("BCParameterSet::Index: no parameter named '%s'", name.c_str()));
66  return fPars.size();
67 }
bool Add(BCParameter *par)
bool ValidIndex(unsigned index, const std::string caller="CheckIndex") const
A class representing a parameter of a model.
Definition: BCParameter.h:28
unsigned Index(const std::string &name) const
const std::string & GetName() const
Definition: BCParameter.h:54