CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MagFieldConfig.cc
Go to the documentation of this file.
1 
8 
9 #include <iostream>
10 #include <vector>
11 #include <memory>
12 
13 #include <boost/algorithm/string/split.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 
16 using namespace std;
17 using namespace magneticfield;
18 
20  version = pset.getParameter<std::string>("version");
21  geometryVersion = pset.getParameter<int>("geometryVersion");
22 
23  // Get specification for the grid tables to be used.
24  typedef vector<edm::ParameterSet> VPSet;
25 
26  VPSet fileSpec = pset.getParameter<VPSet>("gridFiles");
27  if (!fileSpec.empty()) {
28  for (VPSet::const_iterator rule = fileSpec.begin(); rule != fileSpec.end(); ++rule) {
29  string s_volumes = rule->getParameter<string>("volumes");
30  string s_sectors = rule->getParameter<string>("sectors"); // 0 means all volumes
31  int master = rule->getParameter<int>("master");
32  string path = rule->getParameter<string>("path");
33 
34  vector<unsigned> volumes = expandList(s_volumes);
35  vector<unsigned> sectors = expandList(s_sectors);
36 
37  if (debug) {
38  cout << "Volumes: " << s_volumes << " Sectors: " << s_sectors << " Master: " << master << " Path: " << path
39  << endl;
40  cout << " Expanded volumes: ";
41  copy(volumes.begin(), volumes.end(), ostream_iterator<unsigned>(cout, " "));
42  cout << endl;
43  cout << " Expanded sectors: ";
44  copy(sectors.begin(), sectors.end(), ostream_iterator<unsigned>(cout, " "));
45  cout << endl;
46  }
47 
48  for (vector<unsigned>::iterator i = volumes.begin(); i != volumes.end(); ++i) {
49  for (vector<unsigned>::iterator j = sectors.begin(); j != sectors.end(); ++j) {
50  unsigned vpacked = (*i) * 100 + (*j);
51  if (gridFiles.find(vpacked) == gridFiles.end()) {
52  gridFiles[vpacked] = make_pair(path, master);
53  } else {
54  throw cms::Exception("ConfigurationError")
55  << "VolumeBasedMagneticFieldESProducer: malformed gridFiles config parameter" << endl;
56  }
57  }
58  }
59  }
60  }
61 
62  // Get scaling factors
63  keys = pset.getParameter<vector<int> >("scalingVolumes");
64  values = pset.getParameter<vector<double> >("scalingFactors");
65 
66  // Slave field label. Either a label of an existing map (legacy support), or the
67  // type of parametrization to be constructed with the "paramData" parameters.
68  slaveFieldVersion = pset.getParameter<string>("paramLabel");
69  // Check for compatibility with older configurations
70  if (pset.existsAs<vector<double> >("paramData")) {
71  slaveFieldParameters = pset.getParameter<vector<double> >("paramData");
72  }
73 }
74 
75 vector<unsigned> MagFieldConfig::expandList(const string& list) {
76  typedef vector<string> vstring;
77  vector<unsigned> values;
78  vstring v1;
79  boost::split(v1, list, boost::is_any_of(","));
80  for (vstring::const_iterator i = v1.begin(); i != v1.end(); ++i) {
81  vstring v2;
82  boost::split(v2, *i, boost::is_any_of("-"));
83  unsigned start = std::stoul(v2.front());
84  unsigned end = std::stoul(v2.back());
85  if ((v2.size() > 2) || (start > end)) {
86  throw cms::Exception("ConfigurationError")
87  << "VolumeBasedMagneticFieldESProducerFromDB: malformed configuration" << list << endl;
88  }
89  for (unsigned k = start; k <= end; ++k) {
90  values.push_back(k);
91  }
92  }
93  return values;
94 }
Master< F > master(const F &f)
Definition: FunctClone.h:63
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
vector< string > vstring
Definition: ExoticaDQM.cc:8
#define debug
Definition: HDRShower.cc:19
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
string end
Definition: dataset.py:937
tuple cout
Definition: gather_cfg.py:144
std::vector< unsigned > expandList(const std::string &list)