test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Setting.cc
Go to the documentation of this file.
1 #include <strstream>
2 
4 
5 namespace l1t{
6 
7 Setting::Setting(const std::string& type, const std::string& id, const std::string& value, const std::string& procRole, std::string *lt, const std::string& delim) :
8 type_(type),
9 id_(id),
10 value_(value),
11 procRole_(procRole),
12 delim_(delim)
13 {
14  if ( delim.empty() )
15  delim_ = ",";
16 
17  logText_ = lt;
18 
19  setValue(value);
20 }
21 
22 Setting::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) :
23 type_("table"),
24 id_(id),
25 procRole_(procRole),
26 delim_(delim)
27 {
28  if ( delim.empty() )
29  delim_ = ",";
30 
31  logText_ = lt;
32  // str2VecStr_(columns, delim_, tableColumns_);
33 
34  // str2VecStr_(types, delim_, tableTypes_);
35 
36  for (auto it=rows.begin(); it!=rows.end(); ++it)
37  {
38  // std::vector<std::string> aRow;
39  // str2VecStr_(*it, delim_, aRow);
40 
41  //TableRow temp(aRow);
42  //temp.setTableId(id);
43  //temp.setRowTypes(tableTypes_);
44  //temp.setRowColumns(tableColumns_);
45  TableRows_.push_back(TableRow(str2VecStr_(*it, delim_),logText_));
46  TableRows_.back().setTableId(id);
47  // TableRows_.back().setRowTypes(tableTypes_);
48  // TableRows_.back().setRowColumns(tableColumns_);
49  TableRows_.back().setRowTypes(str2VecStr_(types, delim_));
50  TableRows_.back().setRowColumns(str2VecStr_(columns, delim_));
51 
52  }
53 }
54 
56 {
57  ;
58 }
59 
61 {
62  if ( type_.find("bool") != std::string::npos )
63  {
64  std::ostringstream convString;
65 
66  if ( type_.find("vector") != std::string::npos )
67  {
68  if (delim_.empty())
69  delim_ = ",";
70 
71  std::vector<std::string> vals;
72  str2VecStr_(value_,delim_, vals);
73 
74  for(std::vector<std::string>::iterator it=vals.begin(); it!=vals.end(); ++it)
75  {
76  if ( it->find("true") != std::string::npos )
77  convString << "1, ";
78  else
79  convString << "0, ";
80  }
81  }
82  else
83  {
84  if ( value.find("true") != std::string::npos )
85  convString << "1";
86  else
87  convString << "0";
88  }
89 
90  value_ = convString.str();
91  }
92 }
93 
94 
95 l1t::LUT Setting::getLUT(size_t addrWidth, size_t dataWidth, int padding, std::string delim)
96 {
97  if ( type_.find("vector:uint") == std::string::npos )
98  throw std::runtime_error("Cannot build LUT from type: " + type_ + ". Only vector:uint is allowed.");
99 
100  if ( delim.empty() )
101  delim = ",";
102 
103  std::vector<unsigned int> vec = getVector<unsigned int>();
104 
105  // if the addrWidth parameter is 0 calculate the address width from the LUT length
106  if (addrWidth == 0) {
107  size_t nEntries = vec.size();
108  while (nEntries >>= 1) {
109  ++addrWidth;
110  }
111  }
112 
113  // write the stream to fill the LUT
114  std::stringstream ss;
115  ss << "#<header> V1 " << addrWidth << " " << dataWidth << " </header>" << std::endl;
116  size_t i = 0;
117  for (; i < vec.size() && i < (size_t)(1<<addrWidth); ++i) {
118  ss << i << " " << vec[i] << std::endl;
119  }
120  // add padding to 2^addrWidth rows
121  if (padding >= 0 && i < (size_t)(1<<addrWidth)) {
122  for (; i < (size_t)(1<<addrWidth); ++i) {
123  ss << i << " " << padding << std::endl;
124  }
125  }
126 
127  l1t::LUT lut;
128  lut.read(ss);
129 
130  return lut;
131 }
132 
134 {
135  value_ = aSet.value_;
136  id_ = aSet.id_;
137  type_ = aSet.type_;
138  procRole_ = aSet.procRole_;
139  return *this;
140 }
141 
142 void Setting::addTableRow(const std::string& row, const std::vector<std::string>& types, const std::vector<std::string>& columns)
143 {
144  if (type_.find("table") == std::string::npos)
145  throw std::runtime_error("You cannot add a table row in type: " + type_ + ". Type is not table.");
146 
147  std::vector<std::string> vals;
148  str2VecStr_(row, delim_, vals);
149 
150  // TableRow tempRow(vals);
151  // tempRow.setRowTypes(tableTypes_);
152  // tempRow.setRowColumns(tableColumns_);
153  TableRows_.push_back(TableRow(vals, logText_));
154  TableRows_.back().setRowTypes(types);
155  TableRows_.back().setRowColumns(columns);
156 
157 }
158 
159 // void Setting::setTableTypes(const std::string& types)
160 // {
161 // if (type_.find("table") == std::string::npos)
162 // throw std::runtime_error("You cannot set table types in type: " + type_ + ". Type is not table.");
163 
164 
165 // str2VecStr_(types, delim_, tableTypes_);
166 // }
167 
168 // void Setting::setTableColumns(const std::string& cols)
169 // {
170 // if (type_.find("table") == std::string::npos)
171 // throw std::runtime_error("You cannot set table columns in type: " + type_ + ". Type is not table.");
172 
173 
174 // str2VecStr_(cols, delim_, tableColumns_);
175 
176 // }
177 
178 TableRow::TableRow(const std::vector<std::string>& row, std::string *lt)
179 {
180  row_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(row));
181  logText_ = lt;
182 }
183 
184 void TableRow::setRowColumns(const std::vector<std::string>& columns)
185 {
186  if( columns_.get() == 0 )
187  columns_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(columns));
188  else
189  *columns_ = columns;
190 
191  if( colDict_.get() == 0 )
192  colDict_ = std::shared_ptr< std::map<std::string,int> >(new std::map<std::string,int>());
193 
194  colDict_->clear();
195 
196  for(unsigned int i=0; i<columns.size(); i++)
197  (*colDict_)[ columns[i] ] = i;
198 }
199 
200 void TableRow::setRowTypes(const std::vector<std::string>& types)
201 {
202  if( types_.get() == 0 )
203  types_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(types));
204  else
205  *types_ = types;
206 }
207 
209 {
210  std::ostringstream str;
211  for (auto it=row_->begin(); it!=row_->end(); ++it)
212  str << *it << " ";
213 
214  return str.str();
215 }
216 
217 }
218 
type
Definition: HCALResponse.h:21
std::shared_ptr< std::map< std::string, int > > colDict_
Definition: Setting.h:43
int i
Definition: DBlmapReader.cc:9
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
std::shared_ptr< std::vector< std::string > > row_
Definition: Setting.h:40
void addTableRow(const std::string &row, const std::vector< std::string > &types, const std::vector< std::string > &columns)
Definition: Setting.cc:142
std::string procRole_
Definition: Setting.h:72
void setValue(const std::string &value)
Definition: Setting.cc:60
void setRowTypes(const std::vector< std::string > &types)
Definition: Setting.cc:200
std::string * logText_
Definition: Setting.h:38
Setting & operator=(const Setting &aSet)
Definition: Setting.cc:133
int read(std::istream &stream)
Definition: LUT.cc:35
std::vector< std::string > str2VecStr_(const std::string &aStr, const std::string &delim)
Definition: Tools.cc:23
l1t::LUT getLUT(size_t addrWidth=0, size_t dataWidth=31, int padding=-1, std::string delim=",")
Definition: Setting.cc:95
tuple lut
Definition: lumiPlot.py:244
std::string getRowAsStr()
Definition: Setting.cc:208
Definition: LUT.h:29
std::string id_
Definition: Setting.h:72
std::shared_ptr< std::vector< std::string > > columns_
Definition: Setting.h:42
std::vector< TableRow > TableRows_
Definition: Setting.h:73
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
tuple columns
Definition: mps_check.py:210
std::string delim_
Definition: Setting.h:72
void setRowColumns(const std::vector< std::string > &columns)
Definition: Setting.cc:184
std::string type_
Definition: Setting.h:72