CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Geometry/DTGeometryBuilder/plugins/DTGeometryESModule.cc

Go to the documentation of this file.
00001 
00008 #include "DTGeometryESModule.h"
00009 #include <Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h>
00010 #include <Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromCondDB.h>
00011 
00012 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00013 #include <Geometry/Records/interface/MuonNumberingRecord.h>
00014 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
00015 #include "Geometry/Records/interface/DTRecoGeometryRcd.h"
00016 
00017 // Alignments
00018 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00019 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00020 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00021 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00022 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00023 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00024 
00025 #include <FWCore/Framework/interface/ESHandle.h>
00026 #include <FWCore/Framework/interface/ESTransientHandle.h>
00027 #include <FWCore/Framework/interface/ModuleFactory.h>
00028 
00029 #include <memory>
00030 #include <iostream>
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 DTGeometryESModule::DTGeometryESModule(const edm::ParameterSet & p)
00036   : alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
00037     myLabel_(p.getParameter<std::string>("appendToDataLabel")),
00038     fromDDD_(p.getParameter<bool>("fromDDD"))
00039 {
00040 
00041   applyAlignment_ = p.getParameter<bool>("applyAlignment");
00042 
00043   setWhatProduced(this, dependsOn(&DTGeometryESModule::geometryCallback_) );
00044 
00045   edm::LogInfo("Geometry") << "@SUB=DTGeometryESModule"
00046     << "Label '" << myLabel_ << "' "
00047     << (applyAlignment_ ? "looking for" : "IGNORING")
00048     << " alignment labels '" << alignmentsLabel_ << "'.";
00049 }
00050 
00051 DTGeometryESModule::~DTGeometryESModule(){}
00052 
00053 boost::shared_ptr<DTGeometry> 
00054 DTGeometryESModule::produce(const MuonGeometryRecord & record) {
00055 
00056   //
00057   // Called whenever the alignments or alignment errors change
00058   //  
00059   if ( applyAlignment_ ) {
00060     // applyAlignment_ is scheduled for removal. 
00061     // Ideal geometry obtained by using 'fake alignment' (with applyAlignment_ = true)
00062     edm::ESHandle<Alignments> globalPosition;
00063     record.getRecord<GlobalPositionRcd>().get(alignmentsLabel_, globalPosition);
00064     edm::ESHandle<Alignments> alignments;
00065     record.getRecord<DTAlignmentRcd>().get(alignmentsLabel_, alignments);
00066     edm::ESHandle<AlignmentErrors> alignmentErrors;
00067     record.getRecord<DTAlignmentErrorRcd>().get(alignmentsLabel_, alignmentErrors);
00068     // Only apply alignment if values exist
00069     if (alignments->empty() && alignmentErrors->empty() && globalPosition->empty()) {
00070       edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
00071         << "Alignment(Error)s and global position (label '"
00072         << alignmentsLabel_ << "') empty: Geometry producer (label "
00073         << "'" << myLabel_ << "') assumes fake and does not apply.";
00074     } else {
00075       GeometryAligner aligner;
00076       aligner.applyAlignments<DTGeometry>( &(*_dtGeometry),
00077                                            &(*alignments), &(*alignmentErrors),
00078                                            align::DetectorGlobalPosition(*globalPosition, DetId(DetId::Muon)));
00079     }
00080   }
00081 
00082   return _dtGeometry;
00083 
00084 }
00085 
00086 void DTGeometryESModule::geometryCallback_( const MuonNumberingRecord& record ) {
00087   //
00088   // Called whenever the muon numbering (or ideal geometry) changes
00089   //
00090 
00091   _dtGeometry = boost::shared_ptr<DTGeometry>(new DTGeometry );
00092   if ( fromDDD_ ) {
00093     edm::ESHandle<MuonDDDConstants> mdc;
00094     record.get( mdc );
00095 
00096     edm::ESTransientHandle<DDCompactView> cpv;
00097     record.getRecord<IdealGeometryRecord>().get(cpv);
00098 
00099     DTGeometryBuilderFromDDD builder;
00100     builder.build(_dtGeometry, &(*cpv), *mdc);
00101   } else {
00102     edm::ESHandle<RecoIdealGeometry> rig;
00103     record.getRecord<DTRecoGeometryRcd>().get(rig);
00104 
00105     DTGeometryBuilderFromCondDB builder;
00106     builder.build(_dtGeometry, *rig);
00107   }
00108 
00109 }
00110 
00111 
00112 DEFINE_FWK_EVENTSETUP_MODULE(DTGeometryESModule);