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/MessageLogger/interface/MessageLogger.h" 00006 00007 // Conditions database 00008 #include "FWCore/ServiceRegistry/interface/Service.h" 00009 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h" 00010 00011 // Geometry 00012 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h" 00013 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h" 00014 00015 // Alignment 00016 #include "CondFormats/Alignment/interface/AlignmentErrors.h" 00017 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h" 00018 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h" 00019 #include "Alignment/CommonAlignment/interface/Alignable.h" 00020 00021 00022 #include "Alignment/TrackerAlignment/plugins/MisalignedTrackerESProducer.h" 00023 00029 00030 #include <memory> 00031 #include <algorithm> 00032 00033 //__________________________________________________________________________________________________ 00034 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p) : 00035 theParameterSet( p ), 00036 theAlignRecordName( "TrackerAlignmentRcd" ), 00037 theErrorRecordName( "TrackerAlignmentErrorRcd" ) 00038 { 00039 00040 setWhatProduced(this); 00041 00042 } 00043 00044 00045 //__________________________________________________________________________________________________ 00046 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {} 00047 00048 00049 //__________________________________________________________________________________________________ 00050 boost::shared_ptr<TrackerGeometry> 00051 MisalignedTrackerESProducer::produce( const TrackerDigiGeometryRecord& iRecord ) 00052 { 00053 00054 edm::LogInfo("MisalignedTracker") << "Producer called"; 00055 00056 // Create the tracker geometry from ideal geometry 00057 edm::ESHandle<GeometricDet> gD; 00058 iRecord.getRecord<IdealGeometryRecord>().get( gD ); 00059 TrackerGeomBuilderFromGeometricDet trackerBuilder; 00060 theTracker = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*gD)) ); 00061 00062 // Create the alignable hierarchy 00063 std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker) ) ); 00064 00065 // Create misalignment scenario, apply to geometry 00066 TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) ); 00067 scenarioBuilder.applyScenario( theParameterSet ); 00068 Alignments* alignments = theAlignableTracker->alignments(); 00069 AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors(); 00070 00071 // Store result to EventSetup 00072 GeometryAligner aligner; 00073 aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors, 00074 AlignTransform()); // dummy global position 00075 00076 // Write alignments to DB: have to sort beforhand! 00077 if (theParameterSet.getUntrackedParameter<bool>("saveToDbase")) { 00078 00079 // Call service 00080 edm::Service<cond::service::PoolDBOutputService> poolDbService; 00081 if( !poolDbService.isAvailable() ) // Die if not available 00082 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available"; 00083 00084 // Store 00085 // if ( poolDbService->isNewTagRequest(theAlignRecordName) ) 00086 // poolDbService->createNewIOV<Alignments>( alignments, poolDbService->endOfTime(), 00087 // theAlignRecordName ); 00088 // else 00089 // poolDbService->appendSinceTime<Alignments>( alignments, poolDbService->currentTime(), 00090 // theAlignRecordName ); 00091 poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(), 00092 theAlignRecordName); 00093 // if ( poolDbService->isNewTagRequest(theErrorRecordName) ) 00094 // poolDbService->createNewIOV<AlignmentErrors>( alignmentErrors, 00095 // poolDbService->endOfTime(), 00096 // theErrorRecordName ); 00097 // else 00098 // poolDbService->appendSinceTime<AlignmentErrors>( alignmentErrors, 00099 // poolDbService->currentTime(), 00100 // theErrorRecordName ); 00101 poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->currentTime(), 00102 theErrorRecordName); 00103 } 00104 00105 00106 edm::LogInfo("MisalignedTracker") << "Producer done"; 00107 return theTracker; 00108 00109 } 00110 00111 00112 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);