CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonServiceProxy.cc
Go to the documentation of this file.
1 
14 // Class Header
16 
17 // Framework Headers
23 
24 #include <vector>
25 
26 // Constructor
29  UseEventSetupIn useEventSetupIn)
30  : theTrackingGeometry(nullptr),
31  theMGField(nullptr),
32  theDetLayerGeometry(nullptr),
33  theEventSetup(nullptr),
34  theSchool(nullptr) {
35  theMuonNavigationFlag = par.getUntrackedParameter<bool>("UseMuonNavigation", true);
36 
38  theRPCLayer = par.getParameter<bool>("RPCLayers");
39 
40  if (par.existsAs<bool>("CSCLayers"))
41  theCSCLayer = par.getParameter<bool>("CSCLayers");
42  else
43  theCSCLayer = true;
44 
45  if (par.existsAs<bool>("GEMLayers"))
46  theGEMLayer = par.getParameter<bool>("GEMLayers");
47  else
48  theGEMLayer = false;
49 
50  if (par.existsAs<bool>("ME0Layers"))
51  theME0Layer = par.getParameter<bool>("ME0Layers");
52  else
53  theME0Layer = false;
54 
55  } else {
56  theRPCLayer = true;
57  theCSCLayer = true;
58  theGEMLayer = true;
59  theME0Layer = true;
60  }
61 
62  // load the propagators map
63  std::vector<std::string> noPropagators;
64  std::vector<std::string> propagatorNames =
65  par.getUntrackedParameter<std::vector<std::string>>("Propagators", noPropagators);
66 
67  if (propagatorNames.empty())
68  LogDebug("Muon|RecoMuon|MuonServiceProxy") << "NO propagator(s) selected!";
69 
70  for (auto const& propagatorName : propagatorNames) {
72  }
73  theCacheId_GTG = 0;
74  theCacheId_MG = 0;
75  theCacheId_DG = 0;
76  theCacheId_P = 0;
78 
79  // Declare the products we get from the EventSetup and initialize the tokens used to get them
80  if (useEventSetupIn == UseEventSetupIn::Event || useEventSetupIn == UseEventSetupIn::RunAndEvent) {
84  for (auto& element : thePropagators) {
85  element.second.eventToken_ =
86  iC.esConsumes<Propagator, TrackingComponentsRecord>(edm::ESInputTag("", element.first));
87  }
88  }
89  if (useEventSetupIn == UseEventSetupIn::Run || useEventSetupIn == UseEventSetupIn::RunAndEvent) {
95  for (auto& element : thePropagators) {
96  element.second.runToken_ = iC.esConsumes<Propagator, TrackingComponentsRecord, edm::Transition::BeginRun>(
97  edm::ESInputTag("", element.first));
98  }
99  }
100 }
101 
102 // Destructor
104  if (theSchool)
105  delete theSchool;
106 }
107 
108 // Operations
109 
110 // update the services each event
111 void MuonServiceProxy::update(const edm::EventSetup& setup, bool duringEvent) {
112  const std::string metname = "Muon|RecoMuon|MuonServiceProxy";
113 
114  theEventSetup = &setup;
115 
116  // Global Tracking Geometry
117  unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
118  if (newCacheId_GTG != theCacheId_GTG) {
119  LogTrace(metname) << "GlobalTrackingGeometry changed!";
120  theCacheId_GTG = newCacheId_GTG;
121  if (duringEvent) {
123  } else {
125  }
126  }
127 
128  // Magfield Field
129  unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
130  if (newCacheId_MG != theCacheId_MG) {
131  LogTrace(metname) << "Magnetic Field changed!";
132  theCacheId_MG = newCacheId_MG;
133  if (duringEvent) {
135  } else {
137  }
138  }
139 
140  // DetLayer Geometry
141  unsigned long long newCacheId_DG = setup.get<MuonRecoGeometryRecord>().cacheIdentifier();
142  if (newCacheId_DG != theCacheId_DG) {
143  LogTrace(metname) << "Muon Reco Geometry changed!";
144  theCacheId_DG = newCacheId_DG;
145  if (duringEvent) {
147  } else {
149  }
150  // MuonNavigationSchool should live until its validity expires, and then DELETE
151  // the NavigableLayers (this is implemented in MuonNavigationSchool's dtor)
152  if (theMuonNavigationFlag) {
153  if (theSchool)
154  delete theSchool;
156  }
157  }
158 
159  // Propagators
160  unsigned long long newCacheId_P = setup.get<TrackingComponentsRecord>().cacheIdentifier();
161  if (newCacheId_P != theCacheId_P) {
162  LogTrace(metname) << "Tracking Component changed!";
164  theCacheId_P = newCacheId_P;
165  for (auto& element : thePropagators) {
166  if (duringEvent) {
167  element.second.esHandle_ = setup.getHandle(element.second.eventToken_);
168  } else {
169  element.second.esHandle_ = setup.getHandle(element.second.runToken_);
170  }
171  }
172  } else
174 }
175 
176 // get the propagator
178  PropagatorMap::const_iterator prop = thePropagators.find(propagatorName);
179 
180  if (prop == thePropagators.end()) {
181  edm::LogError("Muon|RecoMuon|MuonServiceProxy") << "MuonServiceProxy: propagator with name: " << propagatorName
182  << " not found! Please load it in the MuonServiceProxy.cff";
183  return edm::ESHandle<Propagator>(nullptr);
184  }
185  return prop->second.esHandle_;
186 }
T getUntrackedParameter(std::string const &, T const &) const
unsigned long long theCacheId_MG
unsigned long long theCacheId_P
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
tuple propagatorName
const std::string metname
PropagatorMap thePropagators
Log< level::Error, false > LogError
virtual ~MuonServiceProxy()
Destructor.
edm::ESHandle< MagneticField > theMGField
#define LogTrace(id)
MuonServiceProxy(const edm::ParameterSet &, edm::ConsumesCollector &&, UseEventSetupIn useEventSetupIn=UseEventSetupIn::Event)
Constructor.
bool theChangeInTrackingComponentsRecord
unsigned long long theCacheId_DG
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
const MuonNavigationSchool * theSchool
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > globalTrackingGeometryEventToken_
const edm::EventSetup * theEventSetup
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldRunToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > globalTrackingGeometryRunToken_
unsigned long long theCacheId_GTG
T get() const
Definition: EventSetup.h:88
void update(const edm::EventSetup &setup, bool duringEvent=true)
update the services each event
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::ESHandle< MuonDetLayerGeometry > theDetLayerGeometry
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldEventToken_
edm::ESGetToken< MuonDetLayerGeometry, MuonRecoGeometryRecord > muonDetLayerGeometryEventToken_
edm::ESGetToken< MuonDetLayerGeometry, MuonRecoGeometryRecord > muonDetLayerGeometryRunToken_
#define LogDebug(id)