CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/Alignment/MuonAlignment/plugins/MuonGeometryDBConverter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonGeometryDBConverter
00004 // Class:      MuonGeometryDBConverter
00005 //
00013 //
00014 // Original Author:  Jim Pivarski
00015 //         Created:  Sat Feb 16 00:04:55 CST 2008
00016 // $Id: MuonGeometryDBConverter.cc,v 1.16 2011/09/15 09:15:51 mussgill Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/EDAnalyzer.h"
00024 #include "FWCore/Framework/interface/EventSetup.h"
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 
00031 // user include files
00032 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
00033 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputMethod.h"
00034 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputDB.h"
00035 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputSurveyDB.h"
00036 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputXML.h"
00037 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00038 
00039 //
00040 // class decleration
00041 //
00042 
00043 class MuonGeometryDBConverter : public edm::EDAnalyzer {
00044    public:
00045       explicit MuonGeometryDBConverter(const edm::ParameterSet&);
00046       ~MuonGeometryDBConverter();
00047 
00048 
00049    private:
00050       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00051 
00052       bool m_done;
00053       std::string m_input, m_output;
00054       
00055       std::string m_dtLabel, m_cscLabel;
00056       double m_shiftErr, m_angleErr;
00057       std::string m_fileName;
00058       bool m_getAPEs;
00059 
00060       edm::ParameterSet m_misalignmentScenario;
00061       edm::ParameterSet m_outputXML;
00062 };
00063 
00064 //
00065 // constants, enums and typedefs
00066 //
00067 
00068 //
00069 // static data member definitions
00070 //
00071 
00072 //
00073 // constructors and destructor
00074 //
00075 MuonGeometryDBConverter::MuonGeometryDBConverter(const edm::ParameterSet &iConfig)
00076    : m_done(false)
00077    , m_input(iConfig.getParameter<std::string>("input"))
00078    , m_output(iConfig.getParameter<std::string>("output"))
00079    , m_shiftErr(0.)
00080    , m_angleErr(0.)
00081    , m_getAPEs(false)
00082 {
00084    // Version V02-03-02 and earlier of this module had support for   //
00085    // "cfg" as an input/output format.  It turns out that reading    //
00086    // thousands of parameters from a configuration file takes a very //
00087    // long time, so "cfg" wasn't very practical.  When I reorganized //
00088    // the code, I didn't bother to port it.                          //
00090 
00091    if (m_input == std::string("ideal")) {}
00092 
00093    else if (m_input == std::string("db")) {
00094       m_dtLabel = iConfig.getParameter<std::string>("dtLabel");
00095       m_cscLabel = iConfig.getParameter<std::string>("cscLabel");
00096       m_shiftErr = iConfig.getParameter<double>("shiftErr");
00097       m_angleErr = iConfig.getParameter<double>("angleErr");
00098       m_getAPEs = iConfig.getParameter<bool>("getAPEs");
00099    }
00100 
00101    else if (m_input == std::string("surveydb")) {
00102       m_dtLabel = iConfig.getParameter<std::string>("dtLabel");
00103       m_cscLabel = iConfig.getParameter<std::string>("cscLabel");
00104    }
00105 
00106    else if (m_input == std::string("scenario")) {
00107       m_misalignmentScenario = iConfig.getParameter<edm::ParameterSet>("MisalignmentScenario");
00108       m_shiftErr = iConfig.getParameter<double>("shiftErr");
00109       m_angleErr = iConfig.getParameter<double>("angleErr");
00110    }
00111 
00112    else if (m_input == std::string("xml")) {
00113       m_fileName = iConfig.getParameter<std::string>("fileName");
00114       m_shiftErr = iConfig.getParameter<double>("shiftErr");
00115       m_angleErr = iConfig.getParameter<double>("angleErr");
00116    }
00117 
00118    else {
00119       throw cms::Exception("BadConfig") << "input must be \"ideal\", \"db\", \"surveydb\", or \"xml\"." << std::endl;
00120    }
00121 
00122    if (m_output == std::string("none")) {}
00123 
00124    else if (m_output == std::string("db")) {}
00125 
00126    else if (m_output == std::string("surveydb")) {}
00127 
00128    else if (m_output == std::string("xml")) {
00129       m_outputXML = iConfig.getParameter<edm::ParameterSet>("outputXML");
00130    }
00131 
00132    else {
00133       throw cms::Exception("BadConfig") << "output must be \"none\", \"db\", or \"surveydb\"." << std::endl;
00134    }
00135 }
00136 
00137 MuonGeometryDBConverter::~MuonGeometryDBConverter() { }
00138 
00139 // ------------ method called to for each event  ------------
00140 void
00141 MuonGeometryDBConverter::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
00142    if (!m_done) {
00143       MuonAlignment *muonAlignment = NULL;
00144 
00145       if (m_input == std::string("ideal")) {
00146          MuonAlignmentInputMethod inputMethod;
00147          muonAlignment = new MuonAlignment(iSetup, inputMethod);
00148          muonAlignment->fillGapsInSurvey(0., 0.);
00149       }
00150 
00151       else if (m_input == std::string("db")) {
00152          MuonAlignmentInputDB inputMethod(m_dtLabel, m_cscLabel, m_getAPEs);
00153          muonAlignment = new MuonAlignment(iSetup, inputMethod);
00154          if (m_getAPEs) {
00155             muonAlignment->copyAlignmentToSurvey(m_shiftErr, m_angleErr);
00156          }
00157       }
00158 
00159       else if (m_input == std::string("surveydb")) {
00160          MuonAlignmentInputSurveyDB inputMethod(m_dtLabel, m_cscLabel);
00161          muonAlignment = new MuonAlignment(iSetup, inputMethod);
00162          muonAlignment->copySurveyToAlignment();
00163       }
00164    
00165       else if (m_input == std::string("scenario")) {
00166          MuonAlignmentInputMethod inputMethod;
00167          muonAlignment = new MuonAlignment(iSetup, inputMethod);
00168 
00169          MuonScenarioBuilder muonScenarioBuilder(muonAlignment->getAlignableMuon());
00170          muonScenarioBuilder.applyScenario(m_misalignmentScenario);
00171          muonAlignment->copyAlignmentToSurvey(m_shiftErr, m_angleErr);
00172       }
00173 
00174       else if (m_input == std::string("xml")) {
00175          MuonAlignmentInputXML inputMethod(m_fileName);
00176          muonAlignment = new MuonAlignment(iSetup, inputMethod);
00177          muonAlignment->fillGapsInSurvey(m_shiftErr, m_angleErr);
00178       }
00179 
00181 
00182       if (muonAlignment) {
00183 
00184         if (m_output == std::string("none")) {}
00185 
00186         else if (m_output == std::string("db")) {
00187           muonAlignment->saveToDB();
00188         }
00189 
00190         else if (m_output == std::string("surveydb")) {
00191           muonAlignment->saveSurveyToDB();
00192         }
00193 
00194         else if (m_output == std::string("xml")) {
00195           muonAlignment->writeXML(m_outputXML, iSetup);
00196         }
00197 
00198         delete muonAlignment;
00199 
00200       }
00201 
00202       m_done = true;
00203    } // end if not done
00204    else {
00205       throw cms::Exception("BadConfig") << "Set maxEvents.input to 1.  (Your output is okay.)" << std::endl;
00206    }
00207 }
00208 
00209 //define this as a plug-in
00210 DEFINE_FWK_MODULE(MuonGeometryDBConverter);