CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Alignment/CommonAlignmentProducer/plugins/AlignmentProducer.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "AlignmentProducer.h"
00009 #include "FWCore/Framework/interface/LooperFactory.h" 
00010 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterBuilder.h" 
00011 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h" 
00012 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00013 
00014 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00015 
00016 // System include files
00017 #include <memory>
00018 #include <sstream>
00019 
00020 // Framework
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/EventSetup.h"
00024 #include "FWCore/Framework/interface/ESTransientHandle.h"
00025 #include "FWCore/Framework/interface/Run.h"
00026 
00027 #include "FWCore/Utilities/interface/Parse.h"
00028 
00029 // Conditions database
00030 #include "FWCore/ServiceRegistry/interface/Service.h"
00031 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00032 
00033 // Geometry
00034 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00035 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00036 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00037 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00038 #include "Geometry/Records/interface/MuonNumberingRecord.h"
00039 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00040 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00041 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00042 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00043 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00044 #include "CondFormats/AlignmentRecord/interface/TrackerSurfaceDeformationRcd.h"
00045 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00046 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00047 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
00048 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorRcd.h"
00049 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyRcd.h"
00050 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyErrorRcd.h"
00051 #include "CondFormats/AlignmentRecord/interface/DTSurveyRcd.h"
00052 #include "CondFormats/AlignmentRecord/interface/DTSurveyErrorRcd.h"
00053 #include "CondFormats/AlignmentRecord/interface/CSCSurveyRcd.h"
00054 #include "CondFormats/AlignmentRecord/interface/CSCSurveyErrorRcd.h"
00055 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00056 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00057 
00058 // Tracking, LAS and cluster flag map (fwd is enough!) 
00059 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00060 #include "DataFormats/Alignment/interface/AliClusterValueMapFwd.h"
00061 #include "DataFormats/Alignment/interface/TkFittedLasBeamCollectionFwd.h"
00062 #include "Alignment/LaserAlignment/interface/TsosVectorCollection.h"
00063 
00064 // Alignment
00065 #include "CondFormats/Alignment/interface/SurveyErrors.h"
00066 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
00067 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00068 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00069 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
00070 #include "Alignment/CommonAlignmentParametrization/interface/BeamSpotAlignmentParameters.h"
00071 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmPluginFactory.h"
00072 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
00073 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterSelector.h"
00074 
00075 //_____________________________________________________________________________
00076 AlignmentProducer::AlignmentProducer(const edm::ParameterSet& iConfig) :
00077   theAlignmentAlgo(0), theAlignmentParameterStore(0),
00078   theAlignableExtras(0), theAlignableTracker(0), theAlignableMuon(0), 
00079   globalPositions_(0),
00080   nevent_(0), theParameterSet(iConfig),
00081   theMaxLoops( iConfig.getUntrackedParameter<unsigned int>("maxLoops") ),
00082   stNFixAlignables_(iConfig.getParameter<int>("nFixAlignables") ),
00083   stRandomShift_(iConfig.getParameter<double>("randomShift")),
00084   stRandomRotation_(iConfig.getParameter<double>("randomRotation")),
00085   applyDbAlignment_( iConfig.getUntrackedParameter<bool>("applyDbAlignment")),
00086   checkDbAlignmentValidity_( iConfig.getUntrackedParameter<bool>("checkDbAlignmentValidity")),
00087   doMisalignmentScenario_(iConfig.getParameter<bool>("doMisalignmentScenario")),
00088   saveToDB_(iConfig.getParameter<bool>("saveToDB")),
00089   saveApeToDB_(iConfig.getParameter<bool>("saveApeToDB")),
00090   saveDeformationsToDB_(iConfig.getParameter<bool>("saveDeformationsToDB")),
00091   doTracker_( iConfig.getUntrackedParameter<bool>("doTracker") ),
00092   doMuon_( iConfig.getUntrackedParameter<bool>("doMuon") ),
00093   useExtras_( iConfig.getUntrackedParameter<bool>("useExtras") ),
00094   useSurvey_( iConfig.getParameter<bool>("useSurvey") ),
00095   tjTkAssociationMapTag_(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
00096   beamSpotTag_(iConfig.getParameter<edm::InputTag>("beamSpotTag")),
00097   tkLasBeamTag_(iConfig.getParameter<edm::InputTag>("tkLasBeamTag")),
00098   clusterValueMapTag_(iConfig.getParameter<edm::InputTag>("hitPrescaleMapTag"))
00099 {
00100   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::AlignmentProducer";
00101 
00102   // Tell the framework what data is being produced
00103   if (doTracker_) {
00104      setWhatProduced(this, &AlignmentProducer::produceTracker);
00105   }
00106   if (doMuon_) {
00107      setWhatProduced(this, &AlignmentProducer::produceDT);
00108      setWhatProduced(this, &AlignmentProducer::produceCSC);
00109   }
00110 
00111   // Create the alignment algorithm
00112   edm::ParameterSet algoConfig = iConfig.getParameter<edm::ParameterSet>( "algoConfig" );
00113   edm::VParameterSet iovSelection = iConfig.getParameter<edm::VParameterSet>( "RunRangeSelection" );
00114   algoConfig.addUntrackedParameter<edm::VParameterSet>( "RunRangeSelection", iovSelection );
00115   std::string algoName = algoConfig.getParameter<std::string>( "algoName" );
00116   theAlignmentAlgo = AlignmentAlgorithmPluginFactory::get( )->create( algoName, algoConfig  );
00117 
00118   // Check if found
00119   if ( !theAlignmentAlgo )
00120         throw cms::Exception("BadConfig") << "Couldn't find algorithm called " << algoName;
00121 
00122   edm::ParameterSet monitorConfig = iConfig.getParameter<edm::ParameterSet>( "monitorConfig" );
00123   std::vector<std::string> monitors = monitorConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
00124 
00125   for (std::vector<std::string>::const_iterator miter = monitors.begin();  miter != monitors.end();  ++miter) {
00126     AlignmentMonitorBase* newMonitor = AlignmentMonitorPluginFactory::get()->create(*miter, monitorConfig.getUntrackedParameter<edm::ParameterSet>(*miter));
00127 
00128     if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
00129 
00130     theMonitors.push_back(newMonitor);
00131   }
00132 }
00133 
00134 
00135 //_____________________________________________________________________________
00136 // Delete new objects
00137 AlignmentProducer::~AlignmentProducer()
00138 {
00139   delete theAlignmentAlgo;
00140 
00141   delete theAlignmentParameterStore;
00142   delete theAlignableExtras;
00143   delete theAlignableTracker;
00144   delete theAlignableMuon;
00145 
00146   delete globalPositions_;
00147 }
00148 
00149 
00150 //_____________________________________________________________________________
00151 // Produce tracker geometry
00152 boost::shared_ptr<TrackerGeometry>
00153 AlignmentProducer::produceTracker( const TrackerDigiGeometryRecord& iRecord )
00154 {
00155   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceTracker";
00156   return theTracker;
00157 }
00158 
00159 //_____________________________________________________________________________
00160 // Produce muonDT geometry
00161 boost::shared_ptr<DTGeometry>
00162 AlignmentProducer::produceDT( const MuonGeometryRecord& iRecord )
00163 {
00164   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceDT";
00165   return theMuonDT;
00166 }
00167 
00168 //_____________________________________________________________________________
00169 // Produce muonCSC geometry
00170 boost::shared_ptr<CSCGeometry>
00171 AlignmentProducer::produceCSC( const MuonGeometryRecord& iRecord )
00172 {
00173   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::produceCSC";
00174   return theMuonCSC;  
00175 }
00176 
00177 
00178 //_____________________________________________________________________________
00179 // Initialize algorithm
00180 void AlignmentProducer::beginOfJob( const edm::EventSetup& iSetup )
00181 {
00182   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob";
00183 
00184   // Create the geometries from the ideal geometries (first time only)
00185   this->createGeometries_( iSetup );
00186   
00187   // Retrieve and apply alignments, if requested (requires DB setup)
00188   if ( applyDbAlignment_ ) {
00189     // we need GlobalPositionRcd - and have to keep track for later removal
00190     // before writing again to DB...
00191     edm::ESHandle<Alignments> globalPositionRcd;
00192     iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
00193     globalPositions_ = new Alignments(*globalPositionRcd);
00194 
00195     if ( doTracker_ ) {     // apply to tracker
00196       this->applyDB<TrackerGeometry,TrackerAlignmentRcd,TrackerAlignmentErrorRcd>
00197         (&(*theTracker), iSetup,  
00198          align::DetectorGlobalPosition(*globalPositions_, DetId(DetId::Tracker)));
00199       this->applyDB<TrackerGeometry,TrackerSurfaceDeformationRcd>(&(*theTracker), iSetup);
00200     }
00201     
00202     if ( doMuon_ ) { // apply to tracker
00203       this->applyDB<DTGeometry,DTAlignmentRcd,DTAlignmentErrorRcd>
00204         (&(*theMuonDT), iSetup,
00205          align::DetectorGlobalPosition(*globalPositions_, DetId(DetId::Muon)));
00206       this->applyDB<CSCGeometry,CSCAlignmentRcd,CSCAlignmentErrorRcd>
00207         (&(*theMuonCSC), iSetup,
00208          align::DetectorGlobalPosition(*globalPositions_, DetId(DetId::Muon)));
00209     }
00210   }
00211 
00212   // Create alignable tracker and muon 
00213   if (doTracker_) {
00214     theAlignableTracker = new AlignableTracker( &(*theTracker) );
00215   }
00216 
00217   if (doMuon_) {
00218      theAlignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
00219   }
00220 
00221   if (useExtras_) {
00222     theAlignableExtras = new AlignableExtras();
00223   }
00224 
00225   // Create alignment parameter builder
00226   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob" 
00227                             << "Creating AlignmentParameterBuilder";
00228   edm::ParameterSet aliParamBuildCfg = 
00229     theParameterSet.getParameter<edm::ParameterSet>("ParameterBuilder");
00230   AlignmentParameterBuilder alignmentParameterBuilder(theAlignableTracker,
00231                                                       theAlignableMuon,
00232                                                       theAlignableExtras,
00233                                                       aliParamBuildCfg );
00234   // Fix alignables if requested
00235   if (stNFixAlignables_>0) alignmentParameterBuilder.fixAlignables(stNFixAlignables_);
00236 
00237   // Get list of alignables
00238   Alignables theAlignables = alignmentParameterBuilder.alignables();
00239   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob" 
00240                             << "got " << theAlignables.size() << " alignables";
00241 
00242   // Create AlignmentParameterStore 
00243   edm::ParameterSet aliParamStoreCfg = 
00244     theParameterSet.getParameter<edm::ParameterSet>("ParameterStore");
00245   theAlignmentParameterStore = new AlignmentParameterStore(theAlignables, aliParamStoreCfg);
00246   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob" 
00247                             << "AlignmentParameterStore created!";
00248 
00249   // Apply misalignment scenario to alignable tracker and muon if requested
00250   // WARNING: this assumes scenarioConfig can be passed to both muon and tracker
00251   if (doMisalignmentScenario_ && (doTracker_ || doMuon_)) {
00252     edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob" 
00253                               << "Applying misalignment scenario to "
00254                               << (doTracker_ ? "tracker" : "")
00255                               << (doMuon_    ? (doTracker_ ? " and muon" : "muon") : ".");
00256     edm::ParameterSet scenarioConfig 
00257       = theParameterSet.getParameter<edm::ParameterSet>( "MisalignmentScenario" );
00258     if (doTracker_) {
00259       TrackerScenarioBuilder scenarioBuilder( theAlignableTracker );
00260       scenarioBuilder.applyScenario( scenarioConfig );
00261     }
00262     if (doMuon_) {
00263       MuonScenarioBuilder muonScenarioBuilder( theAlignableMuon );
00264       muonScenarioBuilder.applyScenario( scenarioConfig );
00265     }
00266   } else {
00267     edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::beginOfJob" 
00268                               << "NOT applying misalignment scenario!";
00269   }
00270 
00271   // Apply simple misalignment
00272   const std::string sParSel(theParameterSet.getParameter<std::string>("parameterSelectorSimple"));
00273   this->simpleMisalignment_(theAlignables, sParSel, stRandomShift_, stRandomRotation_, true);
00274 
00275   // Initialize alignment algorithm
00276   theAlignmentAlgo->initialize( iSetup, 
00277                                 theAlignableTracker, theAlignableMuon, theAlignableExtras,
00278                                 theAlignmentParameterStore );
00279 
00280   for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();
00281        monitor != theMonitors.end();  ++monitor) {
00282      (*monitor)->beginOfJob(theAlignableTracker, theAlignableMuon, theAlignmentParameterStore);
00283   }
00284 }
00285 
00286 //_____________________________________________________________________________
00287 // Terminate algorithm
00288 void AlignmentProducer::endOfJob()
00289 {
00290   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfJob";
00291 
00292   for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();  monitor != theMonitors.end();  ++monitor) {
00293      (*monitor)->endOfJob();
00294   }
00295 
00296   if (0 == nevent_) {
00297     edm::LogError("Alignment") << "@SUB=AlignmentProducer::endOfJob" << "Did not process any "
00298                                << "events in last loop, do not dare to store to DB.";
00299   } else {
00300     
00301     // Expand run ranges and make them unique
00302     edm::VParameterSet runRangeSelectionVPSet(theParameterSet.getParameter<edm::VParameterSet>("RunRangeSelection"));
00303     RunRanges uniqueRunRanges(this->makeNonOverlappingRunRanges(runRangeSelectionVPSet));
00304     if (uniqueRunRanges.empty()) { // create dummy IOV
00305       const RunRange runRange(cond::timeTypeSpecs[cond::runnumber].beginValue,
00306                               cond::timeTypeSpecs[cond::runnumber].endValue);
00307       uniqueRunRanges.push_back(runRange);
00308     }
00309 
00310     std::vector<AlgebraicVector> beamSpotParameters;
00311 
00312     for (RunRanges::const_iterator iRunRange = uniqueRunRanges.begin();
00313          iRunRange != uniqueRunRanges.end();
00314          ++iRunRange) {
00315 
00316       theAlignmentAlgo->setParametersForRunRange(*iRunRange);
00317 
00318       // Save alignments to database
00319       if (saveToDB_ || saveApeToDB_ || saveDeformationsToDB_)
00320         this->writeForRunRange((*iRunRange).first);
00321       
00322       // Deal with extra alignables, e.g. beam spot
00323       if (theAlignableExtras) {
00324         Alignables &alis = theAlignableExtras->beamSpot();
00325         if (!alis.empty()) {
00326           BeamSpotAlignmentParameters *beamSpotAliPars = dynamic_cast<BeamSpotAlignmentParameters*>(alis[0]->alignmentParameters());
00327           beamSpotParameters.push_back(beamSpotAliPars->parameters());
00328         }
00329       }
00330     }
00331     
00332     if (theAlignableExtras) {
00333       std::ostringstream bsOutput;
00334       
00335       std::vector<AlgebraicVector>::const_iterator itPar = beamSpotParameters.begin();
00336       for (RunRanges::const_iterator iRunRange = uniqueRunRanges.begin();
00337            iRunRange != uniqueRunRanges.end();
00338            ++iRunRange, ++itPar) {
00339         bsOutput << "Run range: " << (*iRunRange).first << " - " << (*iRunRange).second << "\n";
00340         bsOutput << "  Displacement: x=" << (*itPar)[0] << ", y=" << (*itPar)[1] << "\n"; 
00341         bsOutput << "  Slope: dx/dz=" << (*itPar)[2] << ", dy/dz=" << (*itPar)[3] << "\n"; 
00342       }
00343       
00344       edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfJob"
00345                                 << "Parameters for alignable beamspot:\n"
00346                                 << bsOutput.str();
00347     }
00348 
00349   }
00350 }
00351 
00352 //_____________________________________________________________________________
00353 // Called at beginning of loop
00354 void AlignmentProducer::startingNewLoop(unsigned int iLoop )
00355 {
00356   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop" 
00357                             << "Starting loop number " << iLoop;
00358 
00359   nevent_ = 0;
00360 
00361   theAlignmentAlgo->startNewLoop();
00362 
00363   for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();  monitor != theMonitors.end();  ++monitor) {
00364      (*monitor)->startingNewLoop();
00365   }
00366 
00367   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::startingNewLoop" 
00368                             << "Now physically apply alignments to  geometry...";
00369 
00370 
00371   // Propagate changes to reconstruction geometry (from initialisation or iteration)
00372   GeometryAligner aligner;
00373   if ( doTracker_ ) {
00374     std::auto_ptr<Alignments> alignments(theAlignableTracker->alignments());
00375     std::auto_ptr<AlignmentErrors> alignmentErrors(theAlignableTracker->alignmentErrors());
00376     aligner.applyAlignments<TrackerGeometry>( &(*theTracker),&(*alignments),&(*alignmentErrors), AlignTransform() ); // don't apply global a second time!
00377     std::auto_ptr<AlignmentSurfaceDeformations> aliDeforms(theAlignableTracker->surfaceDeformations());
00378     aligner.attachSurfaceDeformations<TrackerGeometry>(&(*theTracker), &(*aliDeforms));
00379 
00380   }
00381   if ( doMuon_ ) {
00382     std::auto_ptr<Alignments>      dtAlignments(       theAlignableMuon->dtAlignments());
00383     std::auto_ptr<AlignmentErrors> dtAlignmentErrors(  theAlignableMuon->dtAlignmentErrors());
00384     std::auto_ptr<Alignments>      cscAlignments(      theAlignableMuon->cscAlignments());
00385     std::auto_ptr<AlignmentErrors> cscAlignmentErrors( theAlignableMuon->cscAlignmentErrors());
00386 
00387     aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors), AlignTransform() ); // don't apply global a second time!
00388     aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors), AlignTransform() ); // nope!
00389   }
00390 }
00391 
00392 
00393 //_____________________________________________________________________________
00394 // Called at end of loop
00395 edm::EDLooper::Status 
00396 AlignmentProducer::endOfLoop(const edm::EventSetup& iSetup, unsigned int iLoop)
00397 {
00398 
00399   if (0 == nevent_) {
00400     // beginOfJob is usually called by the framework in the first event of the first loop
00401     // (a hack: beginOfJob needs the EventSetup that is not well defined without an event)
00402     // and the algorithms rely on the initialisations done in beginOfJob. We cannot call 
00403     // this->beginOfJob(iSetup); here either since that will access the EventSetup to get
00404     // some geometry information that is not defined either without having seen an event.
00405     edm::LogError("Alignment") << "@SUB=AlignmentProducer::endOfLoop" 
00406                                << "Did not process any events in loop " << iLoop
00407                                << ", stop processing without terminating algorithm.";
00408     return kStop;
00409   }
00410 
00411   edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endOfLoop" 
00412                             << "Ending loop " << iLoop << ", terminating algorithm.";
00413 
00414   theAlignmentAlgo->terminate();
00415 
00416   for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();  monitor != theMonitors.end();  ++monitor) {
00417      (*monitor)->endOfLoop(iSetup);
00418   }
00419 
00420   if ( iLoop == theMaxLoops-1 || iLoop >= theMaxLoops ) return kStop;
00421   else return kContinue;
00422 }
00423 
00424 //_____________________________________________________________________________
00425 // Called at each event
00426 edm::EDLooper::Status 
00427 AlignmentProducer::duringLoop( const edm::Event& event, 
00428                                const edm::EventSetup& setup )
00429 {
00430   ++nevent_;
00431 
00432   // reading in survey records
00433   this->readInSurveyRcds(setup);
00434         
00435   // Printout event number
00436   for ( int i=10; i<10000000; i*=10 )
00437     if ( nevent_<10*i && (nevent_%i)==0 )
00438       edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop" 
00439                                 << "Events processed: " << nevent_;
00440   
00441   // Retrieve trajectories and tracks from the event
00442   // -> merely skip if collection is empty
00443   edm::Handle<TrajTrackAssociationCollection> m_TrajTracksMap;
00444   if (event.getByLabel(tjTkAssociationMapTag_, m_TrajTracksMap)) {
00445     
00446     // Form pairs of trajectories and tracks
00447     ConstTrajTrackPairCollection trajTracks;
00448     for ( TrajTrackAssociationCollection::const_iterator iPair = m_TrajTracksMap->begin();
00449           iPair != m_TrajTracksMap->end(); ++iPair) {
00450       trajTracks.push_back( ConstTrajTrackPair( &(*(*iPair).key), &(*(*iPair).val) ) );
00451     }
00452     edm::Handle<reco::BeamSpot> beamSpot;
00453     event.getByLabel(beamSpotTag_, beamSpot);
00454 
00455     if (nevent_==1 && theAlignableExtras) {
00456       edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::duringLoop"
00457                                 << "initializing AlignableBeamSpot" << std::endl;
00458       theAlignableExtras->initializeBeamSpot(beamSpot->x0(), beamSpot->y0(), beamSpot->z0(),
00459                                              beamSpot->dxdz(), beamSpot->dydz());
00460     }
00461 
00462     // Run the alignment algorithm with its input
00463     const AliClusterValueMap *clusterValueMapPtr = 0;
00464     if(clusterValueMapTag_.encode().size()){//check that the input tag is not empty
00465       edm::Handle<AliClusterValueMap> clusterValueMap;
00466       event.getByLabel(clusterValueMapTag_, clusterValueMap);
00467       clusterValueMapPtr = &(*clusterValueMap);
00468     }
00469 
00470     const AlignmentAlgorithmBase::EventInfo eventInfo(event.id(), trajTracks, *beamSpot,
00471                                                       clusterValueMapPtr);
00472     theAlignmentAlgo->run(setup, eventInfo);
00473 
00474 
00475     for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = theMonitors.begin();
00476          monitor != theMonitors.end();  ++monitor) {
00477       (*monitor)->duringLoop(event, setup, trajTracks); // forward eventInfo?
00478     }
00479   } else {
00480     edm::LogError("Alignment") << "@SUB=AlignmentProducer::duringLoop" 
00481                                << "No track collection found: skipping event";
00482   }
00483   
00484 
00485   return kContinue;
00486 }
00487 
00488 // ----------------------------------------------------------------------------
00489 void AlignmentProducer::beginRun(const edm::Run &run, const edm::EventSetup &setup)
00490 {
00491   theAlignmentAlgo->beginRun(setup); // do not forward edm::Run...
00492 }
00493 
00494 // ----------------------------------------------------------------------------
00495 void AlignmentProducer::endRun(const edm::Run &run, const edm::EventSetup &setup)
00496 {
00497   // call with or without las beam info...
00498   typedef AlignmentAlgorithmBase::EndRunInfo EndRunInfo;
00499   if (tkLasBeamTag_.encode().size()) { // non-empty InputTag
00500     edm::Handle<TkFittedLasBeamCollection> lasBeams;
00501     edm::Handle<TsosVectorCollection> tsoses;
00502     run.getByLabel(tkLasBeamTag_, lasBeams);
00503     run.getByLabel(tkLasBeamTag_, tsoses);
00504     
00505     theAlignmentAlgo->endRun(EndRunInfo(run.id(), &(*lasBeams), &(*tsoses)), setup);
00506   } else {
00507     edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::endRun"
00508                               << "No Tk LAS beams to forward to algorithm.";
00509     theAlignmentAlgo->endRun(EndRunInfo(run.id(), 0, 0), setup);
00510   }
00511 }
00512 
00513 // ----------------------------------------------------------------------------
00514 void AlignmentProducer::beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock,
00515                                     const edm::EventSetup &setup)
00516 {
00517   theAlignmentAlgo->beginLuminosityBlock(setup); // do not forward edm::LuminosityBlock
00518 }
00519 
00520 // ----------------------------------------------------------------------------
00521 void AlignmentProducer::endLuminosityBlock(const edm::LuminosityBlock &lumiBlock,
00522                                   const edm::EventSetup &setup)
00523 {
00524   theAlignmentAlgo->endLuminosityBlock(setup); // do not forward edm::LuminosityBlock
00525 }
00526 
00527 // ----------------------------------------------------------------------------
00528 
00529 void AlignmentProducer::simpleMisalignment_(const Alignables &alivec, const std::string &selection, 
00530                                             float shift, float rot, bool local)
00531 {
00532 
00533   std::ostringstream output; // collecting output
00534 
00535   if (shift > 0. || rot > 0.) {
00536     output << "Adding random flat shift of max size " << shift
00537            << " and adding random flat rotation of max size " << rot <<" to ";
00538 
00539     std::vector<bool> commSel(0);
00540     if (selection != "-1") {
00541       AlignmentParameterSelector aSelector(0,0); // no alignable needed here...
00542       const std::vector<char> cSel(aSelector.convertParamSel(selection));
00543       if (cSel.size() < RigidBodyAlignmentParameters::N_PARAM) {
00544         throw cms::Exception("BadConfig") 
00545           << "[AlignmentProducer::simpleMisalignment_]\n"
00546           << "Expect selection string '" << selection << "' to be at least of length " 
00547           << RigidBodyAlignmentParameters::N_PARAM << " or to be '-1'.\n"
00548           << "(Most probably you have to adjust the parameter 'parameterSelectorSimple'.)";
00549       }
00550       for (std::vector<char>::const_iterator cIter = cSel.begin(); cIter != cSel.end(); ++cIter) {
00551         commSel.push_back(*cIter == '0' ? false : true);
00552       }
00553       output << "parameters defined by (" << selection 
00554              << "), representing (x,y,z,alpha,beta,gamma),";
00555     } else {
00556       output << "the active parameters of each alignable,";
00557     }
00558     output << " in " << (local ? "local" : "global") << " frame.";
00559 
00560     for (std::vector<Alignable*>::const_iterator it = alivec.begin(); it != alivec.end(); ++it) {
00561       Alignable* ali=(*it);
00562       std::vector<bool> mysel(commSel.empty() ? ali->alignmentParameters()->selector() : commSel);
00563       
00564       if (std::abs(shift)>0.00001) {
00565         double s0 = 0., s1 = 0., s2 = 0.;
00566         if (mysel[RigidBodyAlignmentParameters::dx]) s0 = shift * double(random()%1000-500)/500.;
00567         if (mysel[RigidBodyAlignmentParameters::dy]) s1 = shift * double(random()%1000-500)/500.;
00568         if (mysel[RigidBodyAlignmentParameters::dz]) s2 = shift * double(random()%1000-500)/500.;
00569         
00570         if (local) ali->move( ali->surface().toGlobal(align::LocalVector(s0,s1,s2)) );
00571         else       ali->move( align::GlobalVector(s0,s1,s2) );
00572 
00573       //AlignmentPositionError ape(dx,dy,dz);
00574       //ali->addAlignmentPositionError(ape);
00575       }
00576 
00577       if (std::abs(rot)>0.00001) {
00578         align::EulerAngles r(3);
00579         if (mysel[RigidBodyAlignmentParameters::dalpha]) r(1)=rot*double(random()%1000-500)/500.;
00580         if (mysel[RigidBodyAlignmentParameters::dbeta])  r(2)=rot*double(random()%1000-500)/500.;
00581         if (mysel[RigidBodyAlignmentParameters::dgamma]) r(3)=rot*double(random()%1000-500)/500.;
00582 
00583         const align::RotationType mrot = align::toMatrix(r);
00584         if (local) ali->rotateInLocalFrame(mrot);
00585         else       ali->rotateInGlobalFrame(mrot);
00586         
00587       //ali->addAlignmentPositionErrorFromRotation(mrot);
00588       }
00589     } // end loop on alignables
00590   } else {
00591     output << "No simple misalignment added!";
00592   }
00593   edm::LogInfo("Alignment")  << "@SUB=AlignmentProducer::simpleMisalignment_" << output.str();
00594 }
00595 
00596 
00597 //__________________________________________________________________________________________________
00598 void AlignmentProducer::createGeometries_( const edm::EventSetup& iSetup )
00599 {
00600    edm::ESTransientHandle<DDCompactView> cpv;
00601    iSetup.get<IdealGeometryRecord>().get( cpv );
00602 
00603    if (doTracker_) {
00604      edm::ESHandle<GeometricDet> geometricDet;
00605      iSetup.get<IdealGeometryRecord>().get( geometricDet );
00606      TrackerGeomBuilderFromGeometricDet trackerBuilder;
00607      theTracker = boost::shared_ptr<TrackerGeometry>( trackerBuilder.build(&(*geometricDet)) );
00608    }
00609 
00610    if (doMuon_) {
00611      edm::ESHandle<MuonDDDConstants> mdc;
00612      iSetup.get<MuonNumberingRecord>().get(mdc);
00613      DTGeometryBuilderFromDDD DTGeometryBuilder;
00614      CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00615      theMuonDT = boost::shared_ptr<DTGeometry>(new DTGeometry );
00616      DTGeometryBuilder.build( theMuonDT, &(*cpv), *mdc);
00617      theMuonCSC = boost::shared_ptr<CSCGeometry>( new CSCGeometry );
00618      CSCGeometryBuilder.build( theMuonCSC, &(*cpv), *mdc );
00619    }
00620 }
00621 
00622 void AlignmentProducer::addSurveyInfo_(Alignable* ali)
00623 {
00624   const std::vector<Alignable*>& comp = ali->components();
00625 
00626   unsigned int nComp = comp.size();
00627 
00628   for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo_(comp[i]);
00629 
00630   const SurveyError& error = theSurveyErrors->m_surveyErrors[theSurveyIndex];
00631 
00632   if ( ali->id() != error.rawId() ||
00633        ali->alignableObjectId() != error.structureType() )
00634   {
00635     throw cms::Exception("DatabaseError")
00636       << "Error reading survey info from DB. Mismatched id!";
00637   }
00638 
00639   const CLHEP::Hep3Vector&  pos = theSurveyValues->m_align[theSurveyIndex].translation();
00640   const CLHEP::HepRotation& rot = theSurveyValues->m_align[theSurveyIndex].rotation();
00641 
00642   AlignableSurface surf( align::PositionType( pos.x(), pos.y(), pos.z() ),
00643                          align::RotationType( rot.xx(), rot.xy(), rot.xz(),
00644                                               rot.yx(), rot.yy(), rot.yz(),
00645                                               rot.zx(), rot.zy(), rot.zz() ) );
00646 
00647   surf.setWidth( ali->surface().width() );
00648   surf.setLength( ali->surface().length() );
00649 
00650   ali->setSurvey( new SurveyDet( surf, error.matrix() ) );
00651 
00652   ++theSurveyIndex;
00653 }
00654 
00655 void AlignmentProducer::readInSurveyRcds( const edm::EventSetup& iSetup ){
00656         
00657   // Get Survey Rcds and add Survey Info
00658   if ( doTracker_ && useSurvey_ ){
00659     bool tkSurveyBool = watchTkSurveyRcd_.check(iSetup);
00660     bool tkSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
00661     edm::LogInfo("Alignment") << "watcher tksurveyrcd: " << tkSurveyBool;
00662     edm::LogInfo("Alignment") << "watcher tksurveyerrrcd: " << tkSurveyErrBool;
00663     if ( tkSurveyBool || tkSurveyErrBool){
00664       
00665       edm::LogInfo("Alignment") << "ADDING THE SURVEY INFORMATION";
00666       edm::ESHandle<Alignments> surveys;
00667       edm::ESHandle<SurveyErrors> surveyErrors;
00668       
00669       iSetup.get<TrackerSurveyRcd>().get(surveys);
00670       iSetup.get<TrackerSurveyErrorRcd>().get(surveyErrors);
00671       
00672       theSurveyIndex  = 0;
00673       theSurveyValues = &*surveys;
00674       theSurveyErrors = &*surveyErrors;
00675       addSurveyInfo_(theAlignableTracker);
00676     }
00677   }
00678   
00679   if ( doMuon_ && useSurvey_) {
00680     bool DTSurveyBool = watchTkSurveyRcd_.check(iSetup);
00681     bool DTSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
00682     bool CSCSurveyBool = watchTkSurveyRcd_.check(iSetup);
00683     bool CSCSurveyErrBool = watchTkSurveyErrRcd_.check(iSetup);
00684     
00685     if ( DTSurveyBool || DTSurveyErrBool || CSCSurveyBool || CSCSurveyErrBool ){
00686       edm::ESHandle<Alignments> dtSurveys;
00687       edm::ESHandle<SurveyErrors> dtSurveyErrors;
00688       edm::ESHandle<Alignments> cscSurveys;
00689       edm::ESHandle<SurveyErrors> cscSurveyErrors;
00690       
00691       iSetup.get<DTSurveyRcd>().get(dtSurveys);
00692       iSetup.get<DTSurveyErrorRcd>().get(dtSurveyErrors);
00693       iSetup.get<CSCSurveyRcd>().get(cscSurveys);
00694       iSetup.get<CSCSurveyErrorRcd>().get(cscSurveyErrors);
00695       
00696       theSurveyIndex  = 0;
00697       theSurveyValues = &*dtSurveys;
00698       theSurveyErrors = &*dtSurveyErrors;
00699       std::vector<Alignable*> barrels = theAlignableMuon->DTBarrel();
00700       for (std::vector<Alignable*>::const_iterator iter = barrels.begin();  iter != barrels.end();  ++iter) {
00701         addSurveyInfo_(*iter);
00702       }
00703       
00704       theSurveyIndex  = 0;
00705       theSurveyValues = &*cscSurveys;
00706       theSurveyErrors = &*cscSurveyErrors;
00707       std::vector<Alignable*> endcaps = theAlignableMuon->CSCEndcaps();
00708       for (std::vector<Alignable*>::const_iterator iter = endcaps.begin();  iter != endcaps.end();  ++iter) {
00709         addSurveyInfo_(*iter);
00710       }
00711     }
00712   }
00713 
00714 }
00715 
00716 
00718 // a templated method - but private, so not accessible from outside
00719 // ==> does not have to be in header file
00720 template<class G, class Rcd, class ErrRcd>
00721 void AlignmentProducer::applyDB(G* geometry, const edm::EventSetup &iSetup,
00722                                 const AlignTransform &globalCoordinates) const
00723 {
00724   // 'G' is the geometry class for that DB should be applied,
00725   // 'Rcd' is the record class for its Alignments 
00726   // 'ErrRcd' is the record class for its AlignmentErrors
00727   // 'globalCoordinates' are global transformation for this geometry
00728 
00729   const Rcd & record = iSetup.get<Rcd>();
00730   if (checkDbAlignmentValidity_) {
00731     const edm::ValidityInterval & validity = record.validityInterval();
00732     const edm::IOVSyncValue first = validity.first();
00733     const edm::IOVSyncValue last = validity.last();
00734     if (first!=edm::IOVSyncValue::beginOfTime() ||
00735         last!=edm::IOVSyncValue::endOfTime()) {
00736       throw cms::Exception("DatabaseError")
00737         << "@SUB=AlignmentProducer::applyDB"
00738         << "\nTrying to apply "
00739         << record.key().name()
00740         << " with multiple IOVs in tag.\n"
00741         << "Validity range is "
00742         << first.eventID().run() << " - " << last.eventID().run();
00743     }
00744   }
00745 
00746   edm::ESHandle<Alignments> alignments;
00747   record.get(alignments);
00748 
00749   edm::ESHandle<AlignmentErrors> alignmentErrors;
00750   iSetup.get<ErrRcd>().get(alignmentErrors);
00751 
00752   GeometryAligner aligner;
00753   aligner.applyAlignments<G>(geometry, &(*alignments), &(*alignmentErrors),
00754                              globalCoordinates);
00755 }
00756 
00757 
00759 // a templated method - but private, so not accessible from outside
00760 // ==> does not have to be in header file
00761 template<class G, class DeformationRcd>
00762 void AlignmentProducer::applyDB(G* geometry, const edm::EventSetup &iSetup) const
00763 {
00764   // 'G' is the geometry class for that DB should be applied,
00765   // 'DeformationRcd' is the record class for its surface deformations 
00766 
00767   const DeformationRcd & record = iSetup.get<DeformationRcd>();
00768   if (checkDbAlignmentValidity_) {
00769     const edm::ValidityInterval & validity = record.validityInterval();
00770     const edm::IOVSyncValue first = validity.first();
00771     const edm::IOVSyncValue last = validity.last();
00772     if (first!=edm::IOVSyncValue::beginOfTime() ||
00773         last!=edm::IOVSyncValue::endOfTime()) {
00774       throw cms::Exception("DatabaseError")
00775         << "@SUB=AlignmentProducer::applyDB"
00776         << "\nTrying to apply "
00777         << record.key().name()
00778         << " with multiple IOVs in tag.\n"
00779         << "Validity range is "
00780         << first.eventID().run() << " - " << last.eventID().run();
00781     }
00782   }
00783   edm::ESHandle<AlignmentSurfaceDeformations> surfaceDeformations;
00784   record.get(surfaceDeformations);
00785 
00786   GeometryAligner aligner;
00787   aligner.attachSurfaceDeformations<G>(geometry, &(*surfaceDeformations));
00788 }
00789 
00791 void AlignmentProducer::writeForRunRange(cond::Time_t time)
00792 {
00793   if ( doTracker_ ) { // first tracker
00794     const AlignTransform *trackerGlobal = 0; // will be 'removed' from constants 
00795     if (globalPositions_) { // i.e. applied before in applyDB
00796       trackerGlobal = &align::DetectorGlobalPosition(*globalPositions_,
00797                                                      DetId(DetId::Tracker));
00798     }
00799         
00800     Alignments *alignments = theAlignableTracker->alignments();
00801     AlignmentErrors *alignmentErrors = theAlignableTracker->alignmentErrors();
00802     this->writeDB(alignments, "TrackerAlignmentRcd",
00803                   alignmentErrors, "TrackerAlignmentErrorRcd", trackerGlobal,
00804                   time);        
00805   }
00806       
00807   if ( doMuon_ ) { // now muon
00808     const AlignTransform *muonGlobal = 0; // will be 'removed' from constants 
00809     if (globalPositions_) { // i.e. applied before in applyDB
00810       muonGlobal = &align::DetectorGlobalPosition(*globalPositions_,
00811                                                   DetId(DetId::Muon));
00812     }
00813     // Get alignments+errors, first DT - ownership taken over by writeDB(..), so no delete
00814     Alignments      *alignments       = theAlignableMuon->dtAlignments();
00815     AlignmentErrors *alignmentErrors  = theAlignableMuon->dtAlignmentErrors();
00816     this->writeDB(alignments, "DTAlignmentRcd",
00817                   alignmentErrors, "DTAlignmentErrorRcd", muonGlobal,
00818                   time);
00819     
00820     // Get alignments+errors, now CSC - ownership taken over by writeDB(..), so no delete
00821     alignments       = theAlignableMuon->cscAlignments();
00822     alignmentErrors  = theAlignableMuon->cscAlignmentErrors();
00823     this->writeDB(alignments, "CSCAlignmentRcd",
00824                   alignmentErrors, "CSCAlignmentErrorRcd", muonGlobal,
00825                   time);
00826   }
00827       
00828   // Save surface deformations to database
00829   if (saveDeformationsToDB_ && doTracker_) {
00830     AlignmentSurfaceDeformations *alignmentSurfaceDeformations = theAlignableTracker->surfaceDeformations();
00831     this->writeDB(alignmentSurfaceDeformations, "TrackerSurfaceDeformationRcd", time);
00832   }
00833 }
00834 
00836 void AlignmentProducer::writeDB(Alignments *alignments,
00837                                 const std::string &alignRcd,
00838                                 AlignmentErrors *alignmentErrors,
00839                                 const std::string &errRcd,
00840                                 const AlignTransform *globalCoordinates,
00841                                 cond::Time_t time) const
00842 {
00843   Alignments * tempAlignments = alignments;
00844   AlignmentErrors * tempAlignmentErrors = alignmentErrors;
00845 
00846   // Call service
00847   edm::Service<cond::service::PoolDBOutputService> poolDb;
00848   if (!poolDb.isAvailable()) { // Die if not available
00849     delete tempAlignments;      // promised to take over ownership...
00850     delete tempAlignmentErrors; // dito
00851     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00852   }
00853 
00854   if (globalCoordinates  // happens only if (applyDbAlignment_ == true)
00855       && globalCoordinates->transform() != AlignTransform::Transform::Identity) {
00856 
00857     tempAlignments = new Alignments();            // temporary storage for
00858     tempAlignmentErrors = new AlignmentErrors();  // final alignments and errors
00859 
00860     GeometryAligner aligner;
00861     aligner.removeGlobalTransform(alignments, alignmentErrors,
00862                                   *globalCoordinates,
00863                                   tempAlignments, tempAlignmentErrors);
00864     
00865     delete alignments;       // have to delete original alignments
00866     delete alignmentErrors;  // same thing for the errors
00867 
00868     edm::LogInfo("Alignment") << "@SUB=AlignmentProducer::writeDB"
00869                               << "globalCoordinates removed from alignments (" << alignRcd
00870                               << ") and errors (" << alignRcd << ").";
00871   }
00872   
00873   if (saveToDB_) {
00874     edm::LogInfo("Alignment") << "Writing Alignments to " << alignRcd << ".";
00875     poolDb->writeOne<Alignments>(tempAlignments, time, alignRcd);
00876   } else { // poolDb->writeOne(..) takes over 'alignments' ownership,...
00877     delete tempAlignments; // ...otherwise we have to delete, as promised!
00878   }
00879 
00880   if (saveApeToDB_) {
00881     edm::LogInfo("Alignment") << "Writing AlignmentErrors to " << errRcd << ".";
00882     poolDb->writeOne<AlignmentErrors>(tempAlignmentErrors, time, errRcd);
00883   } else { // poolDb->writeOne(..) takes over 'alignmentErrors' ownership,...
00884     delete tempAlignmentErrors; // ...otherwise we have to delete, as promised!
00885   }
00886 }
00887 
00888 
00890 void AlignmentProducer::writeDB(AlignmentSurfaceDeformations *alignmentSurfaceDeformations,
00891                                 const std::string &surfaceDeformationRcd,
00892                                 cond::Time_t time) const
00893 {
00894   // Call service
00895   edm::Service<cond::service::PoolDBOutputService> poolDb;
00896   if (!poolDb.isAvailable()) { // Die if not available
00897     delete alignmentSurfaceDeformations; // promised to take over ownership...
00898     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00899   }
00900   
00901   if (saveDeformationsToDB_) {
00902     edm::LogInfo("Alignment") << "Writing AlignmentSurfaceDeformations to "
00903                               << surfaceDeformationRcd  << ".";
00904     poolDb->writeOne<AlignmentSurfaceDeformations>(alignmentSurfaceDeformations, time,
00905                                                    surfaceDeformationRcd);
00906   } else { // poolDb->writeOne(..) takes over 'surfaceDeformation' ownership,...
00907     delete alignmentSurfaceDeformations; // ...otherwise we have to delete, as promised!
00908   }
00909 }
00910 
00911 AlignmentProducer::RunRanges
00912 AlignmentProducer::makeNonOverlappingRunRanges(const edm::VParameterSet& RunRangeSelectionVPSet)
00913 {
00914   static bool oldRunRangeSelectionWarning = false;
00915 
00916   const RunNumber beginValue = cond::timeTypeSpecs[cond::runnumber].beginValue;
00917   const RunNumber endValue = cond::timeTypeSpecs[cond::runnumber].endValue;
00918   
00919   RunRanges uniqueRunRanges;
00920   if (!RunRangeSelectionVPSet.empty()) {
00921 
00922     std::map<RunNumber,RunNumber> uniqueFirstRunNumbers;
00923     
00924     for (std::vector<edm::ParameterSet>::const_iterator ipset = RunRangeSelectionVPSet.begin();
00925          ipset != RunRangeSelectionVPSet.end();
00926          ++ipset) {
00927       const std::vector<std::string> RunRangeStrings = (*ipset).getParameter<std::vector<std::string> >("RunRanges");
00928       for (std::vector<std::string>::const_iterator irange = RunRangeStrings.begin();
00929            irange != RunRangeStrings.end();
00930            ++irange) {
00931         
00932         if ((*irange).find(':')==std::string::npos) {
00933           
00934           RunNumber first = beginValue;
00935           long int temp = strtol((*irange).c_str(), 0, 0);
00936           if (temp!=-1) first = temp;
00937           uniqueFirstRunNumbers[first] = first;
00938           
00939         } else {
00940           
00941           if (!oldRunRangeSelectionWarning) {
00942             edm::LogWarning("BadConfig") << "@SUB=AlignmentProducer::makeNonOverlappingRunRanges"
00943                                          << "Config file contains old format for 'RunRangeSelection'. Only the start run\n"
00944                                          << "number is used internally. The number of the last run is ignored and can be\n"
00945                                          << "safely removed from the config file.\n";
00946             oldRunRangeSelectionWarning = true;
00947           }
00948           
00949           std::vector<std::string> tokens = edm::tokenize(*irange, ":");
00950           long int temp;
00951           RunNumber first = beginValue;
00952           temp = strtol(tokens[0].c_str(), 0, 0);
00953           if (temp!=-1) first = temp;
00954           uniqueFirstRunNumbers[first] = first;
00955         }
00956       }
00957     }
00958 
00959     for (std::map<RunNumber,RunNumber>::iterator iFirst = uniqueFirstRunNumbers.begin();
00960          iFirst!=uniqueFirstRunNumbers.end();
00961          ++iFirst) {
00962       uniqueRunRanges.push_back(std::pair<RunNumber,RunNumber>((*iFirst).first, endValue));
00963     }
00964     for (unsigned int i = 0;i<uniqueRunRanges.size()-1;++i) {
00965       uniqueRunRanges[i].second = uniqueRunRanges[i+1].first - 1;
00966     }
00967     
00968   } else {
00969         
00970     uniqueRunRanges.push_back(std::pair<RunNumber,RunNumber>(beginValue, endValue));
00971     
00972   }
00973   
00974   return uniqueRunRanges;
00975 }
00976 
00977 DEFINE_FWK_LOOPER( AlignmentProducer );