CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MisalignedTrackerESProducer.cc
Go to the documentation of this file.
1 // Framework
8 
9 // Conditions database
12 
13 // Geometry
18 
19 // Alignment
24 
25 // C++
26 #include <boost/shared_ptr.hpp>
27 #include <memory>
28 #include <algorithm>
29 
36 
38 {
39 public:
40 
43 
46 
48  boost::shared_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
49 
50 private:
51  const bool theSaveToDB;
52  const bool theSaveFakeScenario;
56 
57  boost::shared_ptr<TrackerGeometry> theTracker;
58 };
59 
60 //__________________________________________________________________________________________________
61 //__________________________________________________________________________________________________
62 //__________________________________________________________________________________________________
63 
64 
65 
66 //__________________________________________________________________________________________________
68  theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
69  theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
70  theScenario(p.getParameter<edm::ParameterSet>("scenario")),
71  thePSet(p),
72  theAlignRecordName("TrackerAlignmentRcd"),
73  theErrorRecordName("TrackerAlignmentErrorRcd")
74 {
75  setWhatProduced(this);
76 
77 }
78 
79 
80 //__________________________________________________________________________________________________
82 
83 
84 //__________________________________________________________________________________________________
85 boost::shared_ptr<TrackerGeometry>
87 {
88  //Retrieve tracker topology from geometry
90  iRecord.getRecord<IdealGeometryRecord>().get(tTopoHandle);
91  const TrackerTopology* const tTopo = tTopoHandle.product();
92 
93  edm::LogInfo("MisalignedTracker") << "Producer called";
94 
95  // Create the tracker geometry from ideal geometry
97  iRecord.getRecord<IdealGeometryRecord>().get( gD );
99  theTracker = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*gD), thePSet));
100 
101  // Create the alignable hierarchy
102  std::auto_ptr<AlignableTracker> theAlignableTracker(new AlignableTracker( &(*theTracker), tTopo ) );
103 
104  // Create misalignment scenario, apply to geometry
105  TrackerScenarioBuilder scenarioBuilder( &(*theAlignableTracker) );
106  scenarioBuilder.applyScenario( theScenario );
107  Alignments* alignments = theAlignableTracker->alignments();
108  AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
109 
110  // Store result to EventSetup
111  GeometryAligner aligner;
112  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), alignments, alignmentErrors,
113  AlignTransform()); // dummy global position
114 
115  // Write alignments to DB: have to sort beforhand!
116  if (theSaveToDB) {
117 
118  // Call service
120  if( !poolDbService.isAvailable() ) // Die if not available
121  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
122  if (theSaveFakeScenario) { // make empty!
123  alignments->clear();
124  alignmentErrors->clear();
125  }
126  poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(),
128  poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->currentTime(),
130  } else {
131  // poolDbService::writeOne takes over ownership
132  // we have to delete in the case that containers are not written
133  delete alignments;
134  delete alignmentErrors;
135  }
136 
137 
138  edm::LogInfo("MisalignedTracker") << "Producer done";
139  return theTracker;
140 
141 }
142 
143 
const bool theSaveFakeScenario
whether or not writing to DB
Class to update a given geometry with a set of alignments.
const edm::ParameterSet thePSet
misalignment scenario
TrackerGeometry * build(const GeometricDet *gd, const edm::ParameterSet &pSet)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
MisalignedTrackerESProducer(const edm::ParameterSet &p)
Constructor.
bool isAvailable() const
Definition: Service.h:46
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates)
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void applyScenario(const edm::ParameterSet &scenario)
Apply misalignment scenario to the tracker.
boost::shared_ptr< TrackerGeometry > produce(const TrackerDigiGeometryRecord &iRecord)
Produce the misaligned tracker geometry and store it.
T const * product() const
Definition: ESHandle.h:86
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
boost::shared_ptr< TrackerGeometry > theTracker
const edm::ParameterSet theScenario
if theSaveToDB is true, save a fake scenario (empty alignments), irrespective of the misalignment sce...
Builds a scenario from configuration and applies it to the alignable tracker.
virtual ~MisalignedTrackerESProducer()
Destructor.