CMS 3D CMS Logo

AutoMagneticFieldESProducer.cc
Go to the documentation of this file.
1 
7 
9 
11 
14 
19 
20 #include <string>
21 #include <sstream>
22 #include <iostream>
23 #include <vector>
24 
25 using namespace std;
26 using namespace edm;
27 using namespace magneticfield;
28 
29 
30 AutoMagneticFieldESProducer::AutoMagneticFieldESProducer(const edm::ParameterSet& iConfig) : pset(iConfig) {
32  nominalCurrents = pset.getUntrackedParameter<vector<int> >("nominalCurrents");
33  maps = pset.getUntrackedParameter<vector<string> >("mapLabels");
34 
35  if (maps.size()==0 || (maps.size() != nominalCurrents.size())) {
36  throw cms::Exception("InvalidParameter") << "Invalid values for parameters \"nominalCurrents\" and \"maps\"";
37  }
38 }
39 
40 
42 {
43 }
44 
45 
46 std::unique_ptr<MagneticField>
48 {
49  float current = pset.getParameter<int>("valueOverride");
50 
51  string message;
52 
53  if (current < 0) {
54  ESHandle<RunInfo> rInfo;
55  iRecord.getRecord<RunInfoRcd>().get(rInfo);
56  current = rInfo->m_avg_current;
57  message = " (from RunInfo DB)";
58  } else {
59  message = " (from valueOverride card)";
60  }
61 
62  string model = closerModel(current);
63 
64  edm::LogInfo("MagneticField|AutoMagneticField") << "Current: " << current << message << "; using map with label: " << model;
65 
66 
68 
69  iRecord.get(model,map);
70 
71  MagneticField* result = map.product()->clone();
72 
73  return std::unique_ptr<MagneticField>(result);
74 }
75 
76 
78  int i=0;
79  for(;i<(int)maps.size()-1;i++) {
80  if(2*current < nominalCurrents[i]+nominalCurrents[i+1] )
81  return maps[i];
82  }
83  return maps[i];
84 }
85 
86 
87 
90 
91 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void get(HolderT &iHolder) const
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
float m_avg_current
Definition: RunInfo.h:29
HLT enums.
T const * product() const
Definition: ESHandle.h:86
virtual MagneticField * clone() const
Definition: MagneticField.h:26