File indexing completed on 2024-04-06 12:02:25
0001
0002
0003
0004
0005
0006 #include "CondFormats/MFObjects/interface/MagFieldConfig.h"
0007 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0008
0009 #include <iostream>
0010 #include <vector>
0011 #include <memory>
0012
0013 #include <boost/algorithm/string/split.hpp>
0014 #include <boost/algorithm/string/classification.hpp>
0015
0016 using namespace std;
0017 using namespace magneticfield;
0018
0019 MagFieldConfig::MagFieldConfig(const edm::ParameterSet& pset, bool debug) {
0020 version = pset.getParameter<std::string>("version");
0021 geometryVersion = pset.getParameter<int>("geometryVersion");
0022
0023
0024 typedef vector<edm::ParameterSet> VPSet;
0025
0026 VPSet fileSpec = pset.getParameter<VPSet>("gridFiles");
0027 if (!fileSpec.empty()) {
0028 for (VPSet::const_iterator rule = fileSpec.begin(); rule != fileSpec.end(); ++rule) {
0029 string s_volumes = rule->getParameter<string>("volumes");
0030 string s_sectors = rule->getParameter<string>("sectors");
0031 int master = rule->getParameter<int>("master");
0032 string path = rule->getParameter<string>("path");
0033
0034 vector<unsigned> volumes = expandList(s_volumes);
0035 vector<unsigned> sectors = expandList(s_sectors);
0036
0037 if (debug) {
0038 cout << "Volumes: " << s_volumes << " Sectors: " << s_sectors << " Master: " << master << " Path: " << path
0039 << endl;
0040 cout << " Expanded volumes: ";
0041 copy(volumes.begin(), volumes.end(), ostream_iterator<unsigned>(cout, " "));
0042 cout << endl;
0043 cout << " Expanded sectors: ";
0044 copy(sectors.begin(), sectors.end(), ostream_iterator<unsigned>(cout, " "));
0045 cout << endl;
0046 }
0047
0048 for (vector<unsigned>::iterator i = volumes.begin(); i != volumes.end(); ++i) {
0049 for (vector<unsigned>::iterator j = sectors.begin(); j != sectors.end(); ++j) {
0050 unsigned vpacked = (*i) * 100 + (*j);
0051 if (gridFiles.find(vpacked) == gridFiles.end()) {
0052 gridFiles[vpacked] = make_pair(path, master);
0053 } else {
0054 throw cms::Exception("ConfigurationError")
0055 << "VolumeBasedMagneticFieldESProducer: malformed gridFiles config parameter" << endl;
0056 }
0057 }
0058 }
0059 }
0060 }
0061
0062
0063 keys = pset.getParameter<vector<int> >("scalingVolumes");
0064 values = pset.getParameter<vector<double> >("scalingFactors");
0065
0066
0067
0068 slaveFieldVersion = pset.getParameter<string>("paramLabel");
0069
0070 if (pset.existsAs<vector<double> >("paramData")) {
0071 slaveFieldParameters = pset.getParameter<vector<double> >("paramData");
0072 }
0073 }
0074
0075 vector<unsigned> MagFieldConfig::expandList(const string& list) {
0076 typedef vector<string> vstring;
0077 vector<unsigned> values;
0078 vstring v1;
0079 boost::split(v1, list, boost::is_any_of(","));
0080 for (vstring::const_iterator i = v1.begin(); i != v1.end(); ++i) {
0081 vstring v2;
0082 boost::split(v2, *i, boost::is_any_of("-"));
0083 unsigned start = std::stoul(v2.front());
0084 unsigned end = std::stoul(v2.back());
0085 if ((v2.size() > 2) || (start > end)) {
0086 throw cms::Exception("ConfigurationError")
0087 << "VolumeBasedMagneticFieldESProducerFromDB: malformed configuration" << list << endl;
0088 }
0089 for (unsigned k = start; k <= end; ++k) {
0090 values.push_back(k);
0091 }
0092 }
0093 return values;
0094 }