CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/MagneticField/GeomBuilder/plugins/AutoMagneticFieldESProducer.cc

Go to the documentation of this file.
00001 
00008 #include "MagneticField/GeomBuilder/plugins/AutoMagneticFieldESProducer.h"
00009 
00010 #include "MagneticField/GeomBuilder/src/MagGeoBuilderFromDDD.h"
00011 
00012 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00013 
00014 #include "CondFormats/RunInfo/interface/RunInfo.h"
00015 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00016 
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/Utilities/interface/Exception.h"
00020 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00021 
00022 #include <string>
00023 #include <sstream>
00024 #include <iostream>
00025 #include <vector>
00026 
00027 using namespace std;
00028 using namespace edm;
00029 using namespace magneticfield;
00030 
00031 
00032 AutoMagneticFieldESProducer::AutoMagneticFieldESProducer(const edm::ParameterSet& iConfig) : pset(iConfig) {
00033   setWhatProduced(this, pset.getUntrackedParameter<std::string>("label",""));
00034   nominalCurrents = pset.getUntrackedParameter<vector<int> >("nominalCurrents"); 
00035   maps = pset.getUntrackedParameter<vector<string> >("mapLabels");
00036 
00037   if (maps.size()==0 || (maps.size() != nominalCurrents.size())) {
00038     throw cms::Exception("InvalidParameter") << "Invalid values for parameters \"nominalCurrents\" and \"maps\"";
00039   }
00040 }
00041 
00042 
00043 AutoMagneticFieldESProducer::~AutoMagneticFieldESProducer()
00044 {
00045 }
00046 
00047 
00048 std::auto_ptr<MagneticField>
00049 AutoMagneticFieldESProducer::produce(const IdealMagneticFieldRecord& iRecord)
00050 {
00051   float current = pset.getParameter<int>("valueOverride");
00052 
00053   string message;
00054 
00055   if (current < 0) {
00056     ESHandle<RunInfo> rInfo;
00057     iRecord.getRecord<RunInfoRcd>().get(rInfo);
00058     current = rInfo->m_avg_current;
00059     message = " (from RunInfo DB)";
00060   } else {
00061     message = " (from valueOverride card)";
00062   }
00063 
00064   string model  = closerModel(current);
00065 
00066   edm::LogInfo("MagneticField|AutoMagneticField") << "Current: " << current << message << "; using map with label: " << model;
00067 
00068 
00069   edm::ESHandle<MagneticField> map;
00070   
00071   iRecord.get(model,map);
00072 
00073   MagneticField* result = map.product()->clone();
00074 
00075   std::auto_ptr<MagneticField> s(result);
00076   
00077   return s;
00078 }
00079 
00080 
00081 std::string AutoMagneticFieldESProducer::closerModel(float current) {
00082   int i=0;
00083   for(;i<(int)maps.size()-1;i++) {
00084     if(2*current < nominalCurrents[i]+nominalCurrents[i+1] )
00085       return maps[i];
00086   }
00087   return  maps[i];
00088 }
00089 
00090 
00091 
00092 #include "FWCore/Framework/interface/ModuleFactory.h"
00093 DEFINE_FWK_EVENTSETUP_MODULE(AutoMagneticFieldESProducer);
00094 
00095