CMS 3D CMS Logo

Setting.h
Go to the documentation of this file.
1 #ifndef L1Trigger_L1TCommon_Setting_h
2 #define L1Trigger_L1TCommon_Setting_h
3 
4 #include <vector>
5 #include <string>
6 #include <memory>
7 
13 
14 //boost libraries
15 #include <boost/shared_ptr.hpp>
16 #include <boost/lexical_cast.hpp>
17 #include <boost/spirit/include/classic.hpp>
18 #include <boost/spirit/include/classic_push_back_actor.hpp>
19 
20 namespace l1t{
21 
22 class TableRow
23 {
24  public:
25  TableRow() {};
26  TableRow(const std::vector<std::string>& row, std::string *lt);
27  void setTableId(const std::string& id) { tableId_ = id; };
28  void setRowTypes(const std::vector<std::string>& types);
29  void setRowColumns(const std::vector<std::string>& columns);
30  void setLogStringVar(std::string* strVar) {logText_ = strVar;};
31  ~TableRow() {};
32  std::vector<std::string> getRow () { return *row_; };
34  std::vector<std::string> getColumnNames() {return *columns_;};
35  template <class varType> varType getRowValue(const std::string& col);
36  private:
39  //here we use the shared just because it reduces significantly the time
40  std::shared_ptr< std::vector<std::string> > row_;
41  std::shared_ptr< std::vector<std::string> > types_;
42  std::shared_ptr< std::vector<std::string> > columns_;
43  std::shared_ptr< std::map<std::string,int> > colDict_;
44 
45 };
46 
47 
48 class Setting
49 {
50  public:
51  Setting() {};
52  Setting(const std::string& type, const std::string& id, const std::string& value, const std::string& procRole, std::string *lt, const std::string& delim = "");
53  Setting(const std::string& id, const std::string& columns, const std::string& types, const std::vector<std::string>& rows, const std::string& procRole, std::string *lt, const std::string& delim);
54  void setProcRole(const std::string& procRole) { procRole_ = procRole; };
55  void setValue(const std::string& value);
56  void setId(const std::string& id) { id_ = id; } ;
57  void setLogStringVar(std::string* strVar) {logText_ = strVar;};
58  void addTableRow(const std::string& row, const std::vector<std::string>& types, const std::vector<std::string>& columns);
59  void resetTableRows() { TableRows_.clear();};
60  std::string getProcRole() { return procRole_; };
61  std::string getValueAsStr() { return value_; };
62  std::string getType() { return type_; };
63  std::string getId() { return id_; } ;
64  template <class varType> varType getValue();
65  template <class varType> std::vector<varType> getVector();
66  std::vector<TableRow> getTableRows() { return TableRows_; };
67  l1t::LUT getLUT(size_t addrWidth = 0, size_t dataWidth = 31, int padding = -1, std::string delim = ","); // if the addrWidth parameter is 0 calculate the address width from the LUT length. 31 is the maximal supported number of bits for the output width of l1t::LUT
68  ~Setting();
69 
70  Setting& operator=(const Setting& aSet);
71  private:
72  std::string type_, id_, value_, procRole_, delim_;
73  std::vector<TableRow> TableRows_;
75 };
76 
77 
78 template <typename varType> std::vector<varType> Setting::getVector()
79 {
80 
81  if ( type_.find("vector") == std::string::npos )
82  throw std::runtime_error("The registered type: " + type_ + " is not vector so you need to call the getValue method");
83 
84  std::vector<std::string> vals;
85  str2VecStr_(value_, delim_, vals);
86 
87  std::vector<varType> newVals;
88  for(auto it=vals.begin(); it!=vals.end(); it++)
89  newVals.push_back(convertVariable<varType>(*it));
90 
91  if ( logText_ )
92  {
93  std::ostringstream tempStr;
94  tempStr << "l1t::Setting::getVector\tReturning vector with values " << this->getValueAsStr() << " from parameter with id: " << this->getId() << std::endl;
95  logText_->append(tempStr.str());
96  }
97  return newVals;
98 }
99 
100 template <class varType> varType Setting::getValue()
101 {
102 
103  if ( type_.find("vector") != std::string::npos )
104  throw std::runtime_error("The registered type: " + type_ + " is vector so you need to call the getVector method");
105 
106  if ( logText_ )
107  {
108  std::ostringstream tempStr;
109  tempStr << "l1t::Setting::getValue\tReturning value " << this->getValueAsStr() << " from parameter with id: " << this->getId() << std::endl;
110  logText_->append(tempStr.str());
111  }
112  return convertVariable<varType>(value_);
113 }
114 
115 template <class varType> varType TableRow::getRowValue(const std::string& col)
116 {
117  std::map<std::string,int>::const_iterator it = colDict_->find(col);
118  if( it == colDict_->end() )
119  throw std::runtime_error ("Column " + col + "not found in table " + tableId_);
120 
121  if ( logText_ )
122  {
123  std::ostringstream tempStr;
124  tempStr << "l1t::Setting::getRowValue\tReturning value " << convertVariable<varType>(row_->at(it->second)) << " from table " << tableId_ << " and row " << this->getRowAsStr() << std::endl;
125  logText_->append(tempStr.str());
126  }
127  return convertVariable<varType>(row_->at(it->second));
128 }
129 
130 }
131 #endif
132 
type
Definition: HCALResponse.h:21
std::shared_ptr< std::map< std::string, int > > colDict_
Definition: Setting.h:43
void resetTableRows()
Definition: Setting.h:59
std::string * logText_
Definition: Setting.h:74
std::shared_ptr< std::vector< std::string > > types_
Definition: Setting.h:41
std::string value_
Definition: Setting.h:72
static unsigned int getId(void)
std::shared_ptr< std::vector< std::string > > row_
Definition: Setting.h:40
void setId(const std::string &id)
Definition: Setting.h:56
void setLogStringVar(std::string *strVar)
Definition: Setting.h:30
delete x;
Definition: CaloConfig.h:22
void setRowTypes(const std::vector< std::string > &types)
Definition: Setting.cc:202
std::string * logText_
Definition: Setting.h:38
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
std::vector< TableRow > getTableRows()
Definition: Setting.h:66
std::string tableId_
Definition: Setting.h:37
varType getRowValue(const std::string &col)
Definition: Setting.h:115
std::vector< std::string > str2VecStr_(const std::string &aStr, const std::string &delim)
Definition: Tools.cc:23
varType getValue()
Definition: Setting.h:100
void setProcRole(const std::string &procRole)
Definition: Setting.h:54
Definition: value.py:1
std::string getRowAsStr()
Definition: Setting.cc:210
Definition: LUT.h:29
std::string getId()
Definition: Setting.h:63
std::string getValueAsStr()
Definition: Setting.h:61
std::vector< std::string > getRow()
Definition: Setting.h:32
std::vector< varType > getVector()
Definition: Setting.h:78
std::string getProcRole()
Definition: Setting.h:60
std::shared_ptr< std::vector< std::string > > columns_
Definition: Setting.h:42
std::vector< TableRow > TableRows_
Definition: Setting.h:73
col
Definition: cuy.py:1008
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
void setRowColumns(const std::vector< std::string > &columns)
Definition: Setting.cc:186
std::string getType()
Definition: Setting.h:62
void setLogStringVar(std::string *strVar)
Definition: Setting.h:57
std::vector< std::string > getColumnNames()
Definition: Setting.h:34
void setTableId(const std::string &id)
Definition: Setting.h:27