CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Alignment/TrackerAlignment/plugins/MisalignedTrackerESProducer.cc

Go to the documentation of this file.
00001 // Framework
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/ModuleFactory.h"
00005 #include "FWCore/Framework/interface/ESProducer.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 
00009 // Conditions database
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012 
00013 // Geometry
00014 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00015 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00018 
00019 // Alignment
00020 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00021 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00022 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
00023 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00024 
00025 // C++
00026 #include <boost/shared_ptr.hpp>
00027 #include <memory>
00028 #include <algorithm>
00029 
00036 
00037 class MisalignedTrackerESProducer: public edm::ESProducer
00038 {
00039 public:
00040 
00042   MisalignedTrackerESProducer(const edm::ParameterSet & p);
00043   
00045   virtual ~MisalignedTrackerESProducer(); 
00046   
00048   boost::shared_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
00049 
00050 private:
00051   const bool theSaveToDB; 
00052   const edm::ParameterSet theScenario; 
00053 
00054   const std::string theAlignRecordName, theErrorRecordName;
00055   
00056   boost::shared_ptr<TrackerGeometry> theTracker;
00057 
00058 };
00059 
00060 //__________________________________________________________________________________________________
00061 //__________________________________________________________________________________________________
00062 //__________________________________________________________________________________________________
00063 
00064 
00065 
00066 //__________________________________________________________________________________________________
00067 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p) :
00068   theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
00069   theScenario(p.getParameter<edm::ParameterSet>("scenario")),
00070   theAlignRecordName("TrackerAlignmentRcd"),
00071   theErrorRecordName("TrackerAlignmentErrorRcd")
00072 {
00073   
00074   setWhatProduced(this);
00075 
00076 }
00077 
00078 
00079 //__________________________________________________________________________________________________
00080 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {}
00081 
00082 
00083 //__________________________________________________________________________________________________
00084 boost::shared_ptr<TrackerGeometry> 
00085 MisalignedTrackerESProducer::produce( const TrackerDigiGeometryRecord& iRecord )
00086 { 
00087 
00088   edm::LogInfo("MisalignedTracker") << "Producer called";
00089 
00090   // Create the tracker geometry from ideal geometry
00091   edm::ESHandle<GeometricDet> gD;
00092   iRecord.getRecord<IdealGeometryRecord>().get( gD );
00093   TrackerGeomBuilderFromGeometricDet trackerBuilder;
00094   theTracker  = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*gD)) );
00095   
00096   // Create the alignable hierarchy
00097   std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker) ) );
00098 
00099   // Create misalignment scenario, apply to geometry
00100   TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
00101   scenarioBuilder.applyScenario( theScenario );
00102   Alignments* alignments =  theAlignableTracker->alignments();
00103   AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00104   
00105   // Store result to EventSetup
00106   GeometryAligner aligner;
00107   aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors, 
00108                                             AlignTransform()); // dummy global position
00109 
00110   // Write alignments to DB: have to sort beforhand!
00111   if (theSaveToDB) {
00112 
00113       // Call service
00114       edm::Service<cond::service::PoolDBOutputService> poolDbService;
00115       if( !poolDbService.isAvailable() ) // Die if not available
00116         throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00117           
00118       poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(),
00119                                           theAlignRecordName);
00120       poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->currentTime(),
00121                                                theErrorRecordName);
00122   } else {
00123     // poolDbService::writeOne takes over ownership
00124     // we have to delete in the case that containers are not written
00125     delete alignments;
00126     delete alignmentErrors;
00127   }
00128   
00129 
00130   edm::LogInfo("MisalignedTracker") << "Producer done";
00131   return theTracker;
00132   
00133 }
00134 
00135 
00136 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);