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  else
93  value_ = value;
94 }
95 
96 
97 l1t::LUT Setting::getLUT(size_t addrWidth, size_t dataWidth, int padding, std::string delim)
98 {
99  if ( type_.find("vector:uint") == std::string::npos )
100  throw std::runtime_error("Cannot build LUT from type: " + type_ + ". Only vector:unsigned int is allowed.");
101 
102  if ( delim.empty() )
103  delim = ",";
104 
105  std::vector<unsigned int> vec = getVector<unsigned int>();
106 
107  // if the addrWidth parameter is 0 calculate the address width from the LUT length
108  if (addrWidth == 0) {
109  size_t nEntries = vec.size();
110  while (nEntries >>= 1) {
111  ++addrWidth;
112  }
113  }
114 
115  // write the stream to fill the LUT
116  std::stringstream ss;
117  ss << "#<header> V1 " << addrWidth << " " << dataWidth << " </header>" << std::endl;
118  size_t i = 0;
119  for (; i < vec.size() && i < (size_t)(1<<addrWidth); ++i) {
120  ss << i << " " << vec[i] << std::endl;
121  }
122  // add padding to 2^addrWidth rows
123  if (padding >= 0 && i < (size_t)(1<<addrWidth)) {
124  for (; i < (size_t)(1<<addrWidth); ++i) {
125  ss << i << " " << padding << std::endl;
126  }
127  }
128 
129  l1t::LUT lut;
130  lut.read(ss);
131 
132  return lut;
133 }
134 
136 {
137  value_ = aSet.value_;
138  id_ = aSet.id_;
139  type_ = aSet.type_;
140  procRole_ = aSet.procRole_;
141  return *this;
142 }
143 
144 void Setting::addTableRow(const std::string& row, const std::vector<std::string>& types, const std::vector<std::string>& columns)
145 {
146  if (type_.find("table") == std::string::npos)
147  throw std::runtime_error("You cannot add a table row in type: " + type_ + ". Type is not table.");
148 
149  std::vector<std::string> vals;
150  str2VecStr_(row, delim_, vals);
151 
152  // TableRow tempRow(vals);
153  // tempRow.setRowTypes(tableTypes_);
154  // tempRow.setRowColumns(tableColumns_);
155  TableRows_.push_back(TableRow(vals, logText_));
156  TableRows_.back().setRowTypes(types);
157  TableRows_.back().setRowColumns(columns);
158 
159 }
160 
161 // void Setting::setTableTypes(const std::string& types)
162 // {
163 // if (type_.find("table") == std::string::npos)
164 // throw std::runtime_error("You cannot set table types in type: " + type_ + ". Type is not table.");
165 
166 
167 // str2VecStr_(types, delim_, tableTypes_);
168 // }
169 
170 // void Setting::setTableColumns(const std::string& cols)
171 // {
172 // if (type_.find("table") == std::string::npos)
173 // throw std::runtime_error("You cannot set table columns in type: " + type_ + ". Type is not table.");
174 
175 
176 // str2VecStr_(cols, delim_, tableColumns_);
177 
178 // }
179 
180 TableRow::TableRow(const std::vector<std::string>& row, std::string *lt)
181 {
182  row_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(row));
183  logText_ = lt;
184 }
185 
186 void TableRow::setRowColumns(const std::vector<std::string>& columns)
187 {
188  if( columns_.get() == 0 )
189  columns_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(columns));
190  else
191  *columns_ = columns;
192 
193  if( colDict_.get() == 0 )
194  colDict_ = std::shared_ptr< std::map<std::string,int> >(new std::map<std::string,int>());
195 
196  colDict_->clear();
197 
198  for(unsigned int i=0; i<columns.size(); i++)
199  (*colDict_)[ columns[i] ] = i;
200 }
201 
202 void TableRow::setRowTypes(const std::vector<std::string>& types)
203 {
204  if( types_.get() == 0 )
205  types_ = std::shared_ptr< std::vector<std::string> >(new std::vector<std::string>(types));
206  else
207  *types_ = types;
208 }
209 
211 {
212  std::ostringstream str;
213  for (auto it=row_->begin(); it!=row_->end(); ++it)
214  str << *it << " ";
215 
216  return str.str();
217 }
218 
219 }
220 
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:144
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:202
std::string * logText_
Definition: Setting.h:38
Setting & operator=(const Setting &aSet)
Definition: Setting.cc:135
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:97
tuple lut
Definition: lumiPlot.py:244
std::string getRowAsStr()
Definition: Setting.cc:210
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:186
std::string type_
Definition: Setting.h:72