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