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 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
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
00096 std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker) ) );
00097
00098
00099 TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
00100 scenarioBuilder.applyScenario( theScenario );
00101 Alignments* alignments = theAlignableTracker->alignments();
00102 AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00103
00104
00105 GeometryAligner aligner;
00106 aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors,
00107 AlignTransform());
00108
00109
00110 if (theSaveToDB) {
00111
00112
00113 edm::Service<cond::service::PoolDBOutputService> poolDbService;
00114 if( !poolDbService.isAvailable() )
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
00123
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);