CMS 3D CMS Logo

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 
17  std::vector<std::string> names = pset.getParameterNamesForType<std::vector<std::string> >();
18 
19  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
20  contents_[*it] = pset.getParameter<std::vector<std::string> >(*it);
21 }
22 
24 
26  std::vector<std::string>::const_iterator begin,
27  std::vector<std::string>::const_iterator end,
28  bool special,
29  std::ostream *dump)
30  : collector_(collector), dump_(dump), special_(special) {
31  if (begin != end)
32  iter_.push_back(IterPair(begin, end));
33 
34  next();
35 }
36 
38  if (++iter_.back().first == iter_.back().second)
39  iter_.pop_back();
40 
41  next();
42 }
43 
45  if (iter_.empty()) {
46  cache_.clear();
47  return;
48  }
49 
50  for (;;) {
51  const std::string &line = *iter_.back().first;
52 
53  bool special = special_ && iter_.size() == 1;
54  if ((!line.empty() && line[0] == '+') || special) {
55  if (++iter_.back().first == iter_.back().second) {
56  iter_.pop_back();
57  if (iter_.empty())
58  special_ = false;
59  }
60 
61  std::string block = special ? line : line.substr(1);
62 
63  std::map<std::string, std::vector<std::string> >::const_iterator pos = collector_->contents_.find(block);
64  if (pos == collector_->contents_.end())
65  throw edm::Exception(edm::errors::Configuration) << "ParameterCollector could not find configuration lines "
66  "block \""
67  << block << "\", included via plus sign.";
68 
69  if (dump_)
70  *dump_ << "\n####### " << block << " #######" << std::endl;
71 
72  if (!pos->second.empty())
73  iter_.push_back(IterPair(pos->second.begin(), pos->second.end()));
74  } else {
75  cache_ = collector_->resolve(line);
76  if (dump_)
77  *dump_ << cache_ << std::endl;
78  break;
79  }
80  }
81 }
82 
84  std::map<std::string, std::vector<std::string> >::const_iterator pos = contents_.find("parameterSets");
85  if (pos == contents_.end())
86  throw edm::Exception(edm::errors::Configuration) << "ParameterCollector could not find \"parameterSets\" block.";
87 
88  return const_iterator(this, pos->second.begin(), pos->second.end(), true);
89 }
90 
92  std::map<std::string, std::vector<std::string> >::const_iterator pos = contents_.find("parameterSets");
93  if (pos == contents_.end())
94  throw edm::Exception(edm::errors::Configuration) << "ParameterCollector could not find \"parameterSets\" block.";
95 
96  return const_iterator(this, pos->second.begin(), pos->second.end(), true, &dump);
97 }
98 
100  std::map<std::string, std::vector<std::string> >::const_iterator pos = contents_.find(block);
101  if (pos == contents_.end())
102  throw edm::Exception(edm::errors::Configuration) << "ParameterCollector could not find \"" << block << "\" block.";
103 
104  return const_iterator(this, pos->second.begin(), pos->second.end());
105 }
106 
108  std::map<std::string, std::vector<std::string> >::const_iterator pos = contents_.find(block);
109  if (pos == contents_.end())
110  throw edm::Exception(edm::errors::Configuration) << "ParameterCollector could not find \"" << block << "\" block.";
111 
112  dump << "\n####### " << block << " #######" << std::endl;
113 
114  return const_iterator(this, pos->second.begin(), pos->second.end(), false, &dump);
115 }
116 
119 
120  for (;;) {
121  std::string::size_type pos = result.find("${");
122  if (pos == std::string::npos)
123  break;
124 
125  std::string::size_type endpos = result.find('}', pos);
126  if (endpos == std::string::npos)
127  break;
128  else
129  ++endpos;
130 
131  std::string var = result.substr(pos + 2, endpos - pos - 3);
132  const char *path = std::getenv(var.c_str());
133 
134  result.replace(pos, endpos - pos, path ? path : "");
135  }
136 
137  return result;
138 }
static std::string resolve(const std::string &line)
const_iterator begin() const
const_iterator end() const
uint16_t size_type
const std::string names[nVars_]
std::pair< std::vector< std::string >::const_iterator, std::vector< std::string >::const_iterator > IterPair
std::map< std::string, std::vector< std::string > > contents_