CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMuon/TrackingTools/src/MuonServiceProxy.cc

Go to the documentation of this file.
00001 
00013 // Class Header
00014 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00015 
00016 // Service Records
00017 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00019 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
00020 #include "RecoMuon/Navigation/interface/MuonNavigationSchool.h"
00021 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00022 
00023 // Framework Headers
00024 #include "FWCore/Framework/interface/EventSetup.h"
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 
00028 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00029 
00030 // C++ Headers
00031 #include <map>
00032 
00033 using namespace std;
00034 using namespace edm;
00035 
00036 // Constructor
00037 MuonServiceProxy::MuonServiceProxy(const edm::ParameterSet& par):theTrackingGeometry(0),theMGField(0),theDetLayerGeometry(0),theEventSetup(0),theSchool(0){
00038   
00039   // load the propagators map
00040   vector<string> noPropagators;
00041   vector<string> propagatorNames;
00042 
00043   theMuonNavigationFlag = par.getUntrackedParameter<bool>("UseMuonNavigation",true);
00044   if(theMuonNavigationFlag) theRPCLayer = par.getParameter<bool>("RPCLayers");
00045   else theRPCLayer = true;
00046 
00047   propagatorNames = par.getUntrackedParameter<vector<string> >("Propagators", noPropagators);
00048   
00049   if(propagatorNames.empty())
00050     LogDebug("Muon|RecoMuon|MuonServiceProxy") << "NO propagator(s) selected!";
00051   
00052   for(vector<string>::iterator propagatorName = propagatorNames.begin();
00053       propagatorName != propagatorNames.end(); ++propagatorName)
00054     thePropagators[ *propagatorName ] = ESHandle<Propagator>(0);
00055 
00056   theCacheId_GTG = 0;
00057   theCacheId_MG = 0;  
00058   theCacheId_DG = 0;
00059   theCacheId_P = 0;
00060   theChangeInTrackingComponentsRecord = false;
00061 
00062 }
00063 
00064 
00065 // Destructor
00066 MuonServiceProxy::~MuonServiceProxy(){
00067   
00068   // FIXME: how do that?
00069   // delete theTrackingGeometry;
00070   // delete theMGField;
00071   // delete theDetLayerGeometry;
00072   
00073   // FIXME: is it enough?
00074   thePropagators.clear();
00075   if(theSchool) delete theSchool;
00076 }
00077 
00078 // Operations
00079 
00080 // update the services each event
00081 void MuonServiceProxy::update(const edm::EventSetup& setup){
00082   const std::string metname = "Muon|RecoMuon|MuonServiceProxy";
00083   
00084   theEventSetup = &setup;
00085 
00086   // Global Tracking Geometry
00087   unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
00088   if ( newCacheId_GTG != theCacheId_GTG ) {
00089     LogTrace(metname) << "GlobalTrackingGeometry changed!";
00090     theCacheId_GTG = newCacheId_GTG;
00091     setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry); 
00092   }
00093   
00094   // Magfield Field
00095   unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
00096   if ( newCacheId_MG != theCacheId_MG ) {
00097     LogTrace(metname) << "Magnetic Field changed!";
00098     theCacheId_MG = newCacheId_MG;
00099     setup.get<IdealMagneticFieldRecord>().get(theMGField);
00100   }
00101   
00102   // DetLayer Geometry
00103   unsigned long long newCacheId_DG = setup.get<MuonRecoGeometryRecord>().cacheIdentifier();
00104   if ( newCacheId_DG != theCacheId_DG ) {
00105     LogTrace(metname) << "Muon Reco Geometry changed!";
00106     theCacheId_DG = newCacheId_DG;
00107     setup.get<MuonRecoGeometryRecord>().get(theDetLayerGeometry);
00108     // MuonNavigationSchool should live until its validity expires, and then DELETE
00109     // the NavigableLayers (this is implemented in MuonNavigationSchool's dtor)
00110     if ( theMuonNavigationFlag ) {
00111       if(theSchool) delete theSchool;
00112       theSchool = new MuonNavigationSchool(&*theDetLayerGeometry,theRPCLayer);
00113     }
00114   }
00115   
00116   // Propagators
00117   unsigned long long newCacheId_P = setup.get<TrackingComponentsRecord>().cacheIdentifier();
00118   if ( newCacheId_P != theCacheId_P ) {
00119     LogTrace(metname) << "Tracking Component changed!";
00120     theChangeInTrackingComponentsRecord = true;
00121     theCacheId_P = newCacheId_P;
00122     for(propagators::iterator prop = thePropagators.begin(); prop != thePropagators.end();
00123         ++prop)
00124       setup.get<TrackingComponentsRecord>().get( prop->first , prop->second );
00125   }
00126   else
00127     theChangeInTrackingComponentsRecord = false;
00128 
00129 }
00130 
00131 // get the propagator
00132 ESHandle<Propagator> MuonServiceProxy::propagator(std::string propagatorName) const{
00133   
00134   propagators::const_iterator prop = thePropagators.find(propagatorName);
00135   
00136   if (prop == thePropagators.end()){
00137     LogError("Muon|RecoMuon|MuonServiceProxy") 
00138       << "MuonServiceProxy: propagator with name: "<< propagatorName <<" not found! Please load it in the MuonServiceProxy.cff"; 
00139     return ESHandle<Propagator>(0);
00140   }
00141   
00142   return prop->second;
00143 }
00144 
00145 
00146