CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_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   const edm::ParameterSet thePSet;
00054   const std::string theAlignRecordName, theErrorRecordName;
00055   
00056   boost::shared_ptr<TrackerGeometry> theTracker;
00057 };
00058 
00059 //__________________________________________________________________________________________________
00060 //__________________________________________________________________________________________________
00061 //__________________________________________________________________________________________________
00062 
00063 
00064 
00065 //__________________________________________________________________________________________________
00066 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p) :
00067   theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
00068   theScenario(p.getParameter<edm::ParameterSet>("scenario")),
00069   thePSet(p),
00070   theAlignRecordName("TrackerAlignmentRcd"),
00071   theErrorRecordName("TrackerAlignmentErrorRcd")
00072 {
00073   setWhatProduced(this);
00074 
00075 }
00076 
00077 
00078 //__________________________________________________________________________________________________
00079 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {}
00080 
00081 
00082 //__________________________________________________________________________________________________
00083 boost::shared_ptr<TrackerGeometry> 
00084 MisalignedTrackerESProducer::produce( const TrackerDigiGeometryRecord& iRecord )
00085 { 
00086 
00087   edm::LogInfo("MisalignedTracker") << "Producer called";
00088 
00089   // Create the tracker geometry from ideal geometry
00090   edm::ESHandle<GeometricDet> gD;
00091   iRecord.getRecord<IdealGeometryRecord>().get( gD );
00092   TrackerGeomBuilderFromGeometricDet trackerBuilder;
00093   theTracker  = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*gD), thePSet));
00094  
00095   // Create the alignable hierarchy
00096   std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker) ) );
00097 
00098   // Create misalignment scenario, apply to geometry
00099   TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
00100   scenarioBuilder.applyScenario( theScenario );
00101   Alignments* alignments =  theAlignableTracker->alignments();
00102   AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00103   
00104   // Store result to EventSetup
00105   GeometryAligner aligner;
00106   aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors, 
00107                                             AlignTransform()); // dummy global position
00108 
00109   // Write alignments to DB: have to sort beforhand!
00110   if (theSaveToDB) {
00111 
00112       // Call service
00113       edm::Service<cond::service::PoolDBOutputService> poolDbService;
00114       if( !poolDbService.isAvailable() ) // Die if not available
00115         throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00116           
00117       poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(),
00118                                           theAlignRecordName);
00119       poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->currentTime(),
00120                                                theErrorRecordName);
00121   } else {
00122     // poolDbService::writeOne takes over ownership
00123     // we have to delete in the case that containers are not written
00124     delete alignments;
00125     delete alignmentErrors;
00126   }
00127   
00128 
00129   edm::LogInfo("MisalignedTracker") << "Producer done";
00130   return theTracker;
00131   
00132 }
00133 
00134 
00135 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);