Go to the documentation of this file.00001
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
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012
00013
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
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
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
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
00097 std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker) ) );
00098
00099
00100 TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
00101 scenarioBuilder.applyScenario( theScenario );
00102 Alignments* alignments = theAlignableTracker->alignments();
00103 AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00104
00105
00106 GeometryAligner aligner;
00107 aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors,
00108 AlignTransform());
00109
00110
00111 if (theSaveToDB) {
00112
00113
00114 edm::Service<cond::service::PoolDBOutputService> poolDbService;
00115 if( !poolDbService.isAvailable() )
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
00124
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);