test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VolumeBasedMagneticFieldESProducerFromDB.cc
Go to the documentation of this file.
1 
9 
12 
17 
19 
23 
27 
36 
37 #include <string>
38 #include <vector>
39 #include <iostream>
40 #include <memory>
41 
42 #include <boost/algorithm/string/split.hpp>
43 #include <boost/algorithm/string/classification.hpp>
44 #include <boost/lexical_cast.hpp>
45 
46 using namespace std;
47 using namespace magneticfield;
48 using namespace edm;
49 
50 namespace magneticfield {
52  public:
54 
55  std::auto_ptr<MagneticField> produce(const IdealMagneticFieldRecord & iRecord);
56 
57  private:
58  // forbid copy ctor and assignment op.
61  std::string closerNominalLabel(float current);
62 
64  std::vector<int> nominalCurrents;
65  std::vector<std::string> nominalLabels;
66 
67  };
68 }
69 
70 
71 VolumeBasedMagneticFieldESProducerFromDB::VolumeBasedMagneticFieldESProducerFromDB(const edm::ParameterSet& iConfig) : pset(iConfig)
72 {
74  nominalCurrents={-1, 0,9558,14416,16819,18268,19262};
75  nominalLabels ={"3.8T","0T","2T", "3T", "3.5T", "3.8T", "4T"};
76 }
77 
78 
79 
80 // ------------ method called to produce the data ------------
82 {
83 
84  bool debug = pset.getUntrackedParameter<bool>("debugBuilder", false);
85 
86  // Get value of the current from condition DB
87  float current = pset.getParameter<int>("valueOverride");
88  string message;
89  if (current < 0) {
90  ESHandle<RunInfo> rInfo;
91  iRecord.getRecord<RunInfoRcd>().get(rInfo);
92  current = rInfo->m_avg_current;
93  message = " (from RunInfo DB)";
94  } else {
95  message = " (from valueOverride card)";
96  }
97  string configLabel = closerNominalLabel(current);
98 
99  // Get configuration
100  ESHandle<MagFieldConfig> confESH;
101  iRecord.getRecord<MagFieldConfigRcd>().get(configLabel, confESH);
102  const MagFieldConfig* conf = &*confESH;
103 
104  edm::LogInfo("MagneticField|AutoMagneticField") << "Current: " << current << message << "; using map configuration with label: " << configLabel << endl
105  << "Version: " << conf->version
106  << " geometryVersion: " << conf->geometryVersion
107  << " slaveFieldVersion: " << conf->slaveFieldVersion;
108 
109  // Get the parametrized field
110  std::auto_ptr<MagneticField> paramField = ParametrizedMagneticFieldFactory::get(conf->slaveFieldVersion, conf->slaveFieldParameters);
111 
112 
113  if (conf->version == "parametrizedMagneticField") {
114  // The map consist of only the parametrization in this case
115  return paramField;
116  } else {
117  // Full VolumeBased map + parametrization
118  MagGeoBuilderFromDDD builder(conf->version,
119  conf->geometryVersion,
120  debug);
121 
122  // Set scaling factors
123  if (conf->keys.size() != 0) {
124  builder.setScaling(conf->keys, conf->values);
125  }
126 
127  // Set specification for the grid tables to be used.
128  if (conf->gridFiles.size()!=0) {
129  builder.setGridFiles(conf->gridFiles);
130  }
131 
132  // Build the geomeytry (DDDCompactView) from the DB blob
133  // (code taken from GeometryReaders/XMLIdealGeometryESSource/src/XMLIdealMagneticFieldGeometryESProducer.cc)
135  iRecord.getRecord<MFGeometryFileRcd>().get( boost::lexical_cast<string>(conf->geometryVersion), gdd );
136 
137  DDName ddName("cmsMagneticField:MAGF");
138  DDLogicalPart rootNode(ddName);
139  DDRootDef::instance().set(rootNode);
140  std::auto_ptr<DDCompactView> cpv(new DDCompactView(rootNode));
141  DDLParser parser(*cpv);
142  parser.getDDLSAX2FileHandler()->setUserNS(true);
143  parser.clearFiles();
144  std::unique_ptr<std::vector<unsigned char> > tb = (*gdd).getUncompressedBlob();
145  parser.parse(*tb, tb->size());
146  cpv->lockdown();
147 
148  builder.build(*cpv);
149 
150  // Build the VB map. Ownership of the parametrization is transferred to it, so and auto_ptr is released
151  std::auto_ptr<MagneticField> s(new VolumeBasedMagneticField(conf->geometryVersion,builder.barrelLayers(), builder.endcapSectors(), builder.barrelVolumes(), builder.endcapVolumes(), builder.maxR(), builder.maxZ(), paramField.release(), true));
152  return s;
153  }
154 }
155 
156 
158 
159  int i=0;
160  for(;i<(int)nominalLabels.size()-1;i++) {
161  if(2*current < nominalCurrents[i]+nominalCurrents[i+1] )
162  return nominalLabels[i];
163  }
164  return nominalLabels[i];
165 }
166 
167 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int parse(const DDLDocumentProvider &dp)
Parse all files. Return is meaningless.
Definition: DDLParser.cc:204
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:14
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::vector< double > values
static std::auto_ptr< MagneticField > get(std::string version, const edm::ParameterSet &parameters)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
magneticfield::TableFileMap gridFiles
Specification of which data table is to be used for each volume.
std::vector< MagVolume6Faces * > barrelVolumes() const
std::string slaveFieldVersion
Label or type of the tracker parametrization.
static value_type & instance()
virtual void build(const DDCompactView &cpv)
virtual void setUserNS(bool userns)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
std::vector< int > keys
Scaling factors for the field in specific volumes.
void clearFiles()
Clear the file list - see Warning!
Definition: DDLParser.cc:373
DDLSAX2FileHandler * getDDLSAX2FileHandler()
To get the parent this class allows access to the handler.
Definition: DDLParser.cc:73
DDLParser is the main class of Detector Description Language Parser.
Definition: DDLParser.h:64
#define debug
Definition: HDRShower.cc:19
std::string version
Version of the data tables to be used.
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setScaling(const std::vector< int > &keys, const std::vector< double > &values)
std::vector< MagVolume6Faces * > endcapVolumes() const
int geometryVersion
Version of the geometry to be used.
std::auto_ptr< MagneticField > produce(const IdealMagneticFieldRecord &iRecord)
void setGridFiles(const magneticfield::TableFileMap &gridFiles)
std::vector< double > slaveFieldParameters