CMS 3D CMS Logo

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