CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterCollector.cc
Go to the documentation of this file.
1 #include <ostream>
2 #include <cstdlib>
3 #include <vector>
4 #include <string>
5 #include <map>
6 
9 
11 
12 using namespace gen;
13 
15 {
16 }
17 
19 {
20  std::vector<std::string> names =
21  pset.getParameterNamesForType<std::vector<std::string> >();
22 
23  for(std::vector<std::string>::const_iterator it = names.begin();
24  it != names.end(); ++it)
25  contents_[*it] = pset.getParameter<std::vector<std::string> >(*it);
26 }
27 
29 {
30 }
31 
33  const ParameterCollector *collector,
34  std::vector<std::string>::const_iterator begin,
35  std::vector<std::string>::const_iterator end,
36  bool special, std::ostream *dump)
37  : collector_(collector), dump_(dump), special_(special)
38 {
39  if (begin != end)
40  iter_.push_back(IterPair(begin, end));
41 
42  next();
43 }
44 
46 {
47  if (++iter_.back().first == iter_.back().second)
48  iter_.pop_back();
49 
50  next();
51 }
52 
54 {
55  if (iter_.empty()) {
56  cache_.clear();
57  return;
58  }
59 
60  for(;;) {
61  const std::string &line = *iter_.back().first;
62 
63  bool special = special_ && iter_.size() == 1;
64  if ( (!line.empty() && line[0] == '+') || special) {
65  if (++iter_.back().first == iter_.back().second) {
66  iter_.pop_back();
67  if (iter_.empty())
68  special_ = false;
69  }
70 
71  std::string block = special ? line : line.substr(1);
72 
73  std::map<std::string, std::vector<std::string> >::const_iterator
74  pos = collector_->contents_.find(block);
75  if (pos == collector_->contents_.end())
77  << "ParameterCollector could not find configuration lines "
78  "block \"" << block << "\", included via plus sign.";
79 
80  if (dump_)
81  *dump_ << "\n####### " << block << " #######" << std::endl;
82 
83  if (!pos->second.empty())
84  iter_.push_back(IterPair(pos->second.begin(),
85  pos->second.end()));
86  } else {
87  cache_ = collector_->resolve(line);
88  if (dump_)
89  *dump_ << cache_ << std::endl;
90  break;
91  }
92  }
93 }
94 
96 {
97  std::map<std::string, std::vector<std::string> >::const_iterator
98  pos = contents_.find("parameterSets");
99  if (pos == contents_.end())
101  << "ParameterCollector could not find \"parameterSets\" block.";
102 
103  return const_iterator(this, pos->second.begin(), pos->second.end(), true);
104 }
105 
107 {
108  std::map<std::string, std::vector<std::string> >::const_iterator
109  pos = contents_.find("parameterSets");
110  if (pos == contents_.end())
112  << "ParameterCollector could not find \"parameterSets\" block.";
113 
114  return const_iterator(this, pos->second.begin(), pos->second.end(),
115  true, &dump);
116 }
117 
119 {
120  std::map<std::string, std::vector<std::string> >::const_iterator
121  pos = contents_.find(block);
122  if (pos == contents_.end())
124  << "ParameterCollector could not find \"" << block << "\" block.";
125 
126  return const_iterator(this, pos->second.begin(), pos->second.end());
127 }
128 
130 {
131  std::map<std::string, std::vector<std::string> >::const_iterator
132  pos = contents_.find(block);
133  if (pos == contents_.end())
135  << "ParameterCollector could not find \"" << block << "\" block.";
136 
137  dump << "\n####### " << block << " #######" << std::endl;
138 
139  return const_iterator(this, pos->second.begin(), pos->second.end(),
140  false, &dump);
141 }
142 
143 std::string ParameterCollector::resolve(const std::string &line)
144 {
145  std::string result(line);
146 
147  for(;;) {
148  std::string::size_type pos = result.find("${");
149  if (pos == std::string::npos)
150  break;
151 
152  std::string::size_type endpos = result.find('}', pos);
153  if (endpos == std::string::npos)
154  break;
155  else
156  ++endpos;
157 
158  std::string var = result.substr(pos + 2, endpos - pos - 3);
159  const char *path = std::getenv(var.c_str());
160 
161  result.replace(pos, endpos - pos, path ? path : "");
162  }
163 
164  return result;
165 }
T getParameter(std::string const &) const
static std::string resolve(const std::string &line)
uint16_t size_type
int path() const
Definition: HLTadd.h:3
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:189
std::pair< std::vector< std::string >::const_iterator, std::vector< std::string >::const_iterator > IterPair
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:38
std::map< std::string, std::vector< std::string > > contents_
#define begin
Definition: vmac.h:31
const_iterator begin() const
static const HistoName names[]