CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CalibCalorimetry/EcalTrivialCondModules/src/EcalTrivialConditionRetriever.cc

Go to the documentation of this file.
00001 //
00002 // $Id: EcalTrivialConditionRetriever.cc,v 1.50 2011/03/28 20:04:52 depasse Exp $
00003 // Created: 2 Mar 2006
00004 //          Shahram Rahatlou, University of Rome & INFN
00005 //
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 #include "CalibCalorimetry/EcalTrivialCondModules/interface/EcalTrivialConditionRetriever.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 
00013 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00014 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00015 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00016 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00017 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00018 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00019 
00020 //#include "DataFormats/Provenance/interface/Timestamp.h"
00021 
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 
00025 using namespace edm;
00026 
00027 EcalTrivialConditionRetriever::EcalTrivialConditionRetriever( const edm::ParameterSet&  ps)
00028 {
00029   // initilize parameters used to produce cond DB objects
00030   adcToGeVEBConstant_ = ps.getUntrackedParameter<double>("adcToGeVEBConstant",0.035);
00031   adcToGeVEEConstant_ = ps.getUntrackedParameter<double>("adcToGeVEEConstant",0.060);
00032 
00033   intercalibConstantMeanMC_ = ps.getUntrackedParameter<double>("intercalibConstantMeanMC",1.0);
00034   intercalibConstantSigmaMC_ = ps.getUntrackedParameter<double>("intercalibConstantSigmaMC",0.0);
00035 
00036   intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean",1.0);
00037   intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma",0.0);
00038   intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
00039 
00040   timeCalibConstantMean_ = ps.getUntrackedParameter<double>("timeCalibConstantMean",0.0);
00041   timeCalibConstantSigma_ = ps.getUntrackedParameter<double>("timeCalibConstantSigma",0.0);
00042   timeCalibErrorMean_ = ps.getUntrackedParameter<double>("timeCalibErrorMean",0.0);
00043 
00044   laserAlphaMean_  = ps.getUntrackedParameter<double>("laserAlphaMean",1.55);
00045   laserAlphaSigma_ = ps.getUntrackedParameter<double>("laserAlphaSigma",0);
00046 
00047   laserAPDPNTime1_ = (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime1","1").c_str());
00048   laserAPDPNTime2_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime2","0").c_str());
00049   laserAPDPNTime3_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime3","0").c_str());
00050 
00051   laserAPDPNRefMean_ = ps.getUntrackedParameter<double>("laserAPDPNRefMean",1.0);
00052   laserAPDPNRefSigma_ = ps.getUntrackedParameter<double>("laserAPDPNRefSigma",0.0);
00053 
00054   laserAPDPNMean_ = ps.getUntrackedParameter<double>("laserAPDPNMean",1.0);
00055   laserAPDPNSigma_ = ps.getUntrackedParameter<double>("laserAPDPNSigma",0.0);
00056 
00057   localContCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("localContCorrParameters", std::vector<double>(0) );
00058   crackCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("crackCorrParameters", std::vector<double>(0) );
00059   energyCorrectionParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionParameters", std::vector<double>(0) );
00060   energyUncertaintyParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyUncertaintyParameters", std::vector<double>(0) );
00061 
00062   EBpedMeanX12_ = ps.getUntrackedParameter<double>("EBpedMeanX12", 200.);
00063   EBpedRMSX12_  = ps.getUntrackedParameter<double>("EBpedRMSX12",  1.10);
00064   EBpedMeanX6_  = ps.getUntrackedParameter<double>("EBpedMeanX6",  200.);
00065   EBpedRMSX6_   = ps.getUntrackedParameter<double>("EBpedRMSX6",   0.90);
00066   EBpedMeanX1_  = ps.getUntrackedParameter<double>("EBpedMeanX1",  200.);
00067   EBpedRMSX1_   = ps.getUntrackedParameter<double>("EBpedRMSX1",   0.62);
00068 
00069   EEpedMeanX12_ = ps.getUntrackedParameter<double>("EEpedMeanX12", 200.);
00070   EEpedRMSX12_  = ps.getUntrackedParameter<double>("EEpedRMSX12",  2.50);
00071   EEpedMeanX6_  = ps.getUntrackedParameter<double>("EEpedMeanX6",  200.);
00072   EEpedRMSX6_   = ps.getUntrackedParameter<double>("EEpedRMSX6",   2.00);
00073   EEpedMeanX1_  = ps.getUntrackedParameter<double>("EEpedMeanX1",  200.);
00074   EEpedRMSX1_   = ps.getUntrackedParameter<double>("EEpedRMSX1",   1.40);
00075 
00076   gainRatio12over6_ = ps.getUntrackedParameter<double>("gainRatio12over6", 2.0);
00077   gainRatio6over1_  = ps.getUntrackedParameter<double>("gainRatio6over1",  6.0);
00078 
00079   getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile",false);
00080 
00081   nTDCbins_ = 1;
00082 
00083   weightsForAsynchronousRunning_ = ps.getUntrackedParameter<bool>("weightsForTB",false);
00084 
00085   if (weightsForAsynchronousRunning_)
00086     {
00087       getWeightsFromFile_ = true; //override user request 
00088       //nTDCbins_ = 25;
00089       nTDCbins_ = 50; //modif Alex-21-07-2006
00090     }
00091 
00092   std::string path="CalibCalorimetry/EcalTrivialCondModules/data/";
00093   std::string weightType;
00094   std::ostringstream str;
00095 
00096   if (!weightsForAsynchronousRunning_)
00097     str << "_CMS.txt" ;
00098   else
00099     str << "_TB.txt" ;
00100 
00101   weightType = str.str();
00102 
00103   amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile",path+"ampWeights"+weightType);
00104   amplWeightsAftFile_ = ps.getUntrackedParameter<std::string>("amplWeightsAftFile",path+"ampWeightsAfterGainSwitch"+weightType);
00105   pedWeightsFile_ = ps.getUntrackedParameter<std::string>("pedWeightsFile",path+"pedWeights"+weightType);
00106   pedWeightsAftFile_ = ps.getUntrackedParameter<std::string>("pedWeightsAftFile",path+"pedWeightsAfterGainSwitch"+weightType);
00107   jittWeightsFile_ = ps.getUntrackedParameter<std::string>("jittWeightsFile",path+"timeWeights"+weightType);
00108   jittWeightsAftFile_ = ps.getUntrackedParameter<std::string>("jittWeightsAftFile",path+"timeWeightsAfterGainSwitch"+weightType);
00109   chi2MatrixFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixFile",path+"chi2Matrix"+weightType);
00110   chi2MatrixAftFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixAftFile",path+"chi2MatrixAfterGainSwitch"+weightType);
00111 
00112   amplWeights_.resize(nTDCbins_);  
00113   amplWeightsAft_.resize(nTDCbins_); 
00114   pedWeights_.resize(nTDCbins_);  
00115   pedWeightsAft_.resize(nTDCbins_); 
00116   jittWeights_.resize(nTDCbins_);  
00117   jittWeightsAft_.resize(nTDCbins_); 
00118   chi2Matrix_.resize(nTDCbins_);
00119   chi2MatrixAft_.resize(nTDCbins_);
00120 
00121   // default weights for MGPA shape after pedestal subtraction
00122   getWeightsFromConfiguration(ps);
00123 
00124   producedEcalPedestals_ = ps.getUntrackedParameter<bool>("producedEcalPedestals",true);
00125   producedEcalWeights_ = ps.getUntrackedParameter<bool>("producedEcalWeights",true);
00126 
00127   producedEcalGainRatios_ = ps.getUntrackedParameter<bool>("producedEcalGainRatios",true);
00128   producedEcalADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedEcalADCToGeVConstant",true);
00129 
00130   producedEcalMappingElectronics_ = ps.getUntrackedParameter<bool>("producedEcalMappingElectronics",true);
00131   mappingFile_ = ps.getUntrackedParameter<std::string>("mappingFile","");
00132 
00133   if ( producedEcalMappingElectronics_ ) {
00134     if ( mappingFile_ != "" ) { // if file provided read channel map
00135       setWhatProduced( this, &EcalTrivialConditionRetriever::getMappingFromConfiguration );
00136     } else { 
00137       setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalMappingElectronics );
00138     }
00139     findingRecord<EcalMappingElectronicsRcd>();
00140   }
00141   // Alignment from file
00142   getEBAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEBAlignmentFromFile",false);
00143   if(getEBAlignmentFromFile_) {
00144     EBAlignmentFile_ = ps.getUntrackedParameter<std::string>("EBAlignmentFile",path+"EBAlignment.txt");
00145   }
00146 
00147   getEEAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEEAlignmentFromFile",false);
00148   if(getEEAlignmentFromFile_) {
00149     EEAlignmentFile_ = ps.getUntrackedParameter<std::string>("EEAlignmentFile",path+"EEAlignment.txt");
00150   }
00151 
00152   getESAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getESAlignmentFromFile",false);
00153   if(getESAlignmentFromFile_)
00154     ESAlignmentFile_ = ps.getUntrackedParameter<std::string>("ESAlignmentFile",path+"ESAlignment.txt");
00155 
00156   verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
00157 
00158   //Tell Producer what we produce
00159   //setWhatproduce(this);
00160   if (producedEcalPedestals_)
00161     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalPedestals );
00162 
00163   if (producedEcalWeights_) {
00164       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalWeightXtalGroups );
00165       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTBWeights );
00166     }
00167 
00168   if (producedEcalGainRatios_)
00169     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalGainRatios );
00170 
00171   if (producedEcalADCToGeVConstant_)
00172     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalADCToGeVConstant );
00173 
00174   // intercalibration constants
00175   producedEcalIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstants",true);
00176   intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile","") ;
00177 
00178   if (producedEcalIntercalibConstants_) { // user asks to produce constants
00179     if(intercalibConstantsFile_ != "") {  // if file provided read constants
00180         setWhatProduced (this, &EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration ) ;
00181     } else { // set all constants to 1. or smear as specified by user
00182         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstants ) ;
00183     }
00184     findingRecord<EcalIntercalibConstantsRcd> () ;
00185   }
00186   // MC intercalibrations
00187   producedEcalIntercalibConstantsMC_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstantsMC",true);
00188 
00189   if (producedEcalIntercalibConstantsMC_) { // user asks to produce constants
00190     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC ) ;
00191     findingRecord<EcalIntercalibConstantsMCRcd> () ;
00192   }
00193 
00194   // intercalibration constants
00195   producedEcalIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibErrors",true);
00196   intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
00197 
00198   if (producedEcalIntercalibErrors_) { // user asks to produce constants
00199     if(intercalibErrorsFile_ != "") {  // if file provided read constants
00200         setWhatProduced (this, &EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration ) ;
00201     } else { // set all constants to 1. or smear as specified by user
00202         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibErrors ) ;
00203     }
00204     findingRecord<EcalIntercalibErrorsRcd> () ;
00205   }
00206 
00207   // time calibration constants
00208   producedEcalTimeCalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibConstants",true);
00209   timeCalibConstantsFile_ = ps.getUntrackedParameter<std::string>("timeCalibConstantsFile","") ;
00210 
00211   if (producedEcalTimeCalibConstants_) { // user asks to produce constants
00212     if(timeCalibConstantsFile_ != "") {  // if file provided read constants
00213         setWhatProduced (this, &EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration ) ;
00214     } else { // set all constants to 1. or smear as specified by user
00215         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalTimeCalibConstants ) ;
00216     }
00217     findingRecord<EcalTimeCalibConstantsRcd> () ;
00218   }
00219 
00220   // time calibration constants
00221   producedEcalTimeCalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibErrors",true);
00222   timeCalibErrorsFile_ = ps.getUntrackedParameter<std::string>("timeCalibErrorsFile","") ;
00223 
00224   if (producedEcalTimeCalibErrors_) { // user asks to produce constants
00225     if(timeCalibErrorsFile_ != "") {  // if file provided read constants
00226         setWhatProduced (this, &EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration ) ;
00227     } else { // set all constants to 1. or smear as specified by user
00228         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalTimeCalibErrors ) ;
00229     }
00230     findingRecord<EcalTimeCalibErrorsRcd> () ;
00231   }
00232 
00233   // cluster corrections
00234   producedEcalClusterLocalContCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterLocalContCorrParameters", true);
00235   producedEcalClusterCrackCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterCrackCorrParameters", true);
00236   producedEcalClusterEnergyCorrectionParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionParameters", true);
00237   producedEcalClusterEnergyUncertaintyParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyUncertaintyParameters", true);
00238   if ( producedEcalClusterLocalContCorrParameters_ ) {
00239           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters );
00240           findingRecord<EcalClusterLocalContCorrParametersRcd>();
00241   }
00242   if ( producedEcalClusterCrackCorrParameters_ ) {
00243           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters );
00244           findingRecord<EcalClusterCrackCorrParametersRcd>();
00245   }
00246   if ( producedEcalClusterEnergyCorrectionParameters_ ) {
00247           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters );
00248           findingRecord<EcalClusterEnergyCorrectionParametersRcd>();
00249   }
00250   if ( producedEcalClusterEnergyUncertaintyParameters_ ) {
00251           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters );
00252           findingRecord<EcalClusterEnergyUncertaintyParametersRcd>();
00253   }
00254 
00255   // laser correction
00256   producedEcalLaserCorrection_ = ps.getUntrackedParameter<bool>("producedEcalLaserCorrection",true);
00257   if (producedEcalLaserCorrection_) { // user asks to produce constants
00258     // set all constants to 1. or smear as specified by user
00259     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAlphas ) ;
00260     findingRecord<EcalLaserAlphasRcd> () ;
00261     getLaserAlphaFromFile_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFile",false);
00262     std::cout << " getLaserAlphaFromFile_ " <<  getLaserAlphaFromFile_ << std::endl;
00263     if(getLaserAlphaFromFile_) {
00264       EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EBLaserAlphaFile",path+"EBLaserAlpha.txt");
00265       EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EELaserAlphaFile",path+"EELaserAlpha.txt");
00266       std::cout << " EELaserAlphaFile_ " <<  EELaserAlphaFile_.c_str() << std::endl;
00267     }
00268     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef ) ;
00269     findingRecord<EcalLaserAPDPNRatiosRefRcd> () ;
00270     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios) ;
00271     findingRecord<EcalLaserAPDPNRatiosRcd> () ;
00272   }
00273 
00274   // channel status
00275   producedEcalChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalChannelStatus",true);
00276   channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile","");
00277 
00278   if ( producedEcalChannelStatus_ ) {
00279           if ( channelStatusFile_ != "" ) { // if file provided read channel map
00280                   setWhatProduced( this, &EcalTrivialConditionRetriever::getChannelStatusFromConfiguration );
00281           } else { // set all channels to working -- FIXME might be changed
00282                   setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalChannelStatus );
00283           }
00284           findingRecord<EcalChannelStatusRcd>();
00285   }
00286   // DQM channel status
00287   producedEcalDQMChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMChannelStatus",true);
00288   if ( producedEcalDQMChannelStatus_ ) {
00289     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDQMChannelStatus );
00290     findingRecord<EcalDQMChannelStatusRcd>();
00291   }
00292   // DCS Tower status
00293   producedEcalDCSTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDCSTowerStatus",true);
00294   if ( producedEcalDCSTowerStatus_ ) {
00295     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDCSTowerStatus );
00296     findingRecord<EcalDCSTowerStatusRcd>();
00297   }
00298   // DAQ Tower status
00299   producedEcalDAQTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDAQTowerStatus",true);
00300   if ( producedEcalDAQTowerStatus_ ) {
00301     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDAQTowerStatus );
00302     findingRecord<EcalDAQTowerStatusRcd>();
00303   }
00304   // DQM Tower status
00305   producedEcalDQMTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMTowerStatus",true);
00306   if ( producedEcalDQMTowerStatus_ ) {
00307     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDQMTowerStatus );
00308     findingRecord<EcalDQMTowerStatusRcd>();
00309   }
00310 
00311   // trigger channel status
00312   producedEcalTrgChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalTrgChannelStatus",true);
00313   trgChannelStatusFile_ = ps.getUntrackedParameter<std::string>("trgChannelStatusFile","");
00314 
00315   if ( producedEcalTrgChannelStatus_ ) {
00316           if ( trgChannelStatusFile_ != "" ) { // if file provided read channel map
00317                   setWhatProduced( this, &EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration );
00318           } else { // set all channels to working -- FIXME might be changed
00319                   setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalTrgChannelStatus );
00320           }
00321           findingRecord<EcalTPGCrystalStatusRcd>();
00322   }
00323 
00324   // Alignment
00325   producedEcalAlignmentEB_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEB",true);
00326   if ( producedEcalAlignmentEB_ ) {
00327     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentEB );
00328     findingRecord<EBAlignmentRcd>();
00329   }
00330   producedEcalAlignmentEE_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEE",true);
00331   if ( producedEcalAlignmentEE_ ) {
00332     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentEE );
00333     findingRecord<EEAlignmentRcd>();
00334   }
00335   producedEcalAlignmentES_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentES",true);
00336   if ( producedEcalAlignmentES_ ) {
00337     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentES );
00338     findingRecord<ESAlignmentRcd>();
00339   }
00340   //Tell Finder what records we find
00341   if (producedEcalPedestals_)  findingRecord<EcalPedestalsRcd>();
00342 
00343   if (producedEcalWeights_) {
00344       findingRecord<EcalWeightXtalGroupsRcd>();
00345       findingRecord<EcalTBWeightsRcd>();
00346     }
00347 
00348   if (producedEcalGainRatios_)  findingRecord<EcalGainRatiosRcd>();
00349 
00350   if (producedEcalADCToGeVConstant_)  findingRecord<EcalADCToGeVConstantRcd>();
00351 
00352 }
00353 
00354 EcalTrivialConditionRetriever::~EcalTrivialConditionRetriever()
00355 {
00356 }
00357 
00358 //
00359 // member functions
00360 //
00361 void
00362 EcalTrivialConditionRetriever::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& rk,
00363                                                const edm::IOVSyncValue& iTime,
00364                                                edm::ValidityInterval& oValidity)
00365 {
00366   if(verbose_>=1) std::cout << "EcalTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
00367   //For right now, we will just use an infinite interval of validity
00368   oValidity = edm::ValidityInterval( edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime() );
00369 }
00370 
00371 //produce methods
00372 std::auto_ptr<EcalPedestals>
00373 EcalTrivialConditionRetriever::produceEcalPedestals( const EcalPedestalsRcd& ) {
00374   std::auto_ptr<EcalPedestals>  peds = std::auto_ptr<EcalPedestals>( new EcalPedestals() );
00375   EcalPedestals::Item EBitem;
00376   EcalPedestals::Item EEitem;
00377   
00378   EBitem.mean_x1  = EBpedMeanX1_;
00379   EBitem.rms_x1   = EBpedRMSX1_;
00380   EBitem.mean_x6  = EBpedMeanX6_;
00381   EBitem.rms_x6   = EBpedRMSX6_;
00382   EBitem.mean_x12 = EBpedMeanX12_;
00383   EBitem.rms_x12  = EBpedRMSX12_;
00384 
00385   EEitem.mean_x1  = EEpedMeanX1_;
00386   EEitem.rms_x1   = EEpedRMSX1_;
00387   EEitem.mean_x6  = EEpedMeanX6_;
00388   EEitem.rms_x6   = EEpedRMSX6_;
00389   EEitem.mean_x12 = EEpedMeanX12_;
00390   EEitem.rms_x12  = EEpedRMSX12_;
00391   
00392   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00393     if(iEta==0) continue;
00394     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00395       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00396       if (EBDetId::validDetId(iEta,iPhi))
00397         {
00398           EBDetId ebdetid(iEta,iPhi);
00399           peds->insert(std::make_pair(ebdetid.rawId(),EBitem));
00400         }
00401     }
00402   }
00403   
00404   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00405     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00406       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00407       if (EEDetId::validDetId(iX,iY,1))
00408         {
00409           EEDetId eedetidpos(iX,iY,1);
00410           peds->insert(std::make_pair(eedetidpos.rawId(),EEitem));
00411         }
00412       if(EEDetId::validDetId(iX,iY,-1))
00413         {
00414           EEDetId eedetidneg(iX,iY,-1);
00415           peds->insert(std::make_pair(eedetidneg.rawId(),EEitem));
00416         }
00417     }
00418   }
00419 
00420   //return std::auto_ptr<EcalPedestals>( peds );
00421   return peds;
00422 }
00423 
00424 std::auto_ptr<EcalWeightXtalGroups>
00425 EcalTrivialConditionRetriever::produceEcalWeightXtalGroups( const EcalWeightXtalGroupsRcd& )
00426 {
00427   std::auto_ptr<EcalWeightXtalGroups> xtalGroups = std::auto_ptr<EcalWeightXtalGroups>( new EcalWeightXtalGroups() );
00428   EcalXtalGroupId defaultGroupId(1);
00429   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00430     if(ieta==0) continue;
00431     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00432       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00433       if (EBDetId::validDetId(ieta,iphi))
00434         {
00435           EBDetId ebid(ieta,iphi);
00436           //      xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
00437           xtalGroups->setValue(ebid.rawId(), defaultGroupId ); // define rings in eta
00438         }
00439     }
00440   }
00441 
00442   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00443     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00444       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00445       if (EEDetId::validDetId(iX,iY,1))
00446         {
00447           EEDetId eedetidpos(iX,iY,1);
00448           xtalGroups->setValue(eedetidpos.rawId(), defaultGroupId ); 
00449         }
00450       if(EEDetId::validDetId(iX,iY,-1))
00451         {
00452           EEDetId eedetidneg(iX,iY,-1);
00453           xtalGroups->setValue(eedetidneg.rawId(), defaultGroupId ); 
00454         }
00455     }
00456   }
00457   return xtalGroups;
00458 }
00459 
00460 std::auto_ptr<EcalIntercalibConstants>
00461 EcalTrivialConditionRetriever::produceEcalIntercalibConstants( const EcalIntercalibConstantsRcd& )
00462 {
00463   std::auto_ptr<EcalIntercalibConstants>  ical = std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
00464 
00465   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00466     if(ieta==0) continue;
00467     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00468       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00469       if (EBDetId::validDetId(ieta,iphi))
00470         {
00471           EBDetId ebid(ieta,iphi);
00472           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00473           ical->setValue( ebid.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
00474         }
00475     }
00476   }
00477 
00478   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00479     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00480       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00481       if (EEDetId::validDetId(iX,iY,1))
00482         {
00483           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00484           EEDetId eedetidpos(iX,iY,1);
00485           ical->setValue( eedetidpos.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
00486         }
00487       if(EEDetId::validDetId(iX,iY,-1))
00488         {
00489           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00490           EEDetId eedetidneg(iX,iY,-1);
00491           ical->setValue( eedetidneg.rawId(), intercalibConstantMean_ + r1*intercalibConstantSigma_ );
00492         }
00493     }
00494   }
00495   
00496   return ical;
00497 }
00498 
00499 std::auto_ptr<EcalIntercalibConstantsMC>
00500 EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC( const EcalIntercalibConstantsMCRcd& )
00501 {
00502   std::auto_ptr<EcalIntercalibConstantsMC>  ical = std::auto_ptr<EcalIntercalibConstantsMC>( new EcalIntercalibConstantsMC() );
00503 
00504   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00505     if(ieta==0) continue;
00506     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00507       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00508       if (EBDetId::validDetId(ieta,iphi))
00509         {
00510           EBDetId ebid(ieta,iphi);
00511           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00512           ical->setValue( ebid.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
00513         }
00514     }
00515   }
00516 
00517   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00518     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00519       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00520       if (EEDetId::validDetId(iX,iY,1))
00521         {
00522           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00523           EEDetId eedetidpos(iX,iY,1);
00524           ical->setValue( eedetidpos.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
00525         }
00526       if(EEDetId::validDetId(iX,iY,-1))
00527         {
00528           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00529           EEDetId eedetidneg(iX,iY,-1);
00530           ical->setValue( eedetidneg.rawId(), intercalibConstantMeanMC_ + r1*intercalibConstantSigmaMC_ );
00531         }
00532     }
00533   }
00534   
00535   return ical;
00536 }
00537 
00538 std::auto_ptr<EcalIntercalibErrors>
00539 EcalTrivialConditionRetriever::produceEcalIntercalibErrors( const EcalIntercalibErrorsRcd& )
00540 {
00541   std::auto_ptr<EcalIntercalibErrors>  ical = std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
00542 
00543   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00544     if(ieta==0) continue;
00545     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00546       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00547       if (EBDetId::validDetId(ieta,iphi))
00548         {
00549           EBDetId ebid(ieta,iphi);
00550           ical->setValue( ebid.rawId(), intercalibErrorMean_);
00551         }
00552     }
00553   }
00554 
00555   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00556     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00557       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00558       if (EEDetId::validDetId(iX,iY,1))
00559         {
00560           EEDetId eedetidpos(iX,iY,1);
00561           ical->setValue( eedetidpos.rawId(), intercalibErrorMean_ );
00562         }
00563       if(EEDetId::validDetId(iX,iY,-1))
00564         {
00565           EEDetId eedetidneg(iX,iY,-1);
00566           ical->setValue( eedetidneg.rawId(), intercalibErrorMean_ );
00567         }
00568     }
00569   }
00570   
00571   return ical;
00572 }
00573 
00574 std::auto_ptr<EcalTimeCalibConstants>
00575 EcalTrivialConditionRetriever::produceEcalTimeCalibConstants( const EcalTimeCalibConstantsRcd& )
00576 {
00577   std::auto_ptr<EcalTimeCalibConstants>  ical = std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
00578 
00579   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00580     if(ieta==0) continue;
00581     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00582       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00583       if (EBDetId::validDetId(ieta,iphi))
00584         {
00585           EBDetId ebid(ieta,iphi);
00586           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00587           ical->setValue( ebid.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
00588         }
00589     }
00590   }
00591 
00592   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00593     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00594       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00595       if (EEDetId::validDetId(iX,iY,1))
00596         {
00597           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00598           EEDetId eedetidpos(iX,iY,1);
00599           ical->setValue( eedetidpos.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
00600         }
00601       if(EEDetId::validDetId(iX,iY,-1))
00602         {
00603           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00604           EEDetId eedetidneg(iX,iY,-1);
00605           ical->setValue( eedetidneg.rawId(), timeCalibConstantMean_ + r1*timeCalibConstantSigma_ );
00606         }
00607     }
00608   }
00609   
00610   return ical;
00611 }
00612 
00613 std::auto_ptr<EcalTimeCalibErrors>
00614 EcalTrivialConditionRetriever::produceEcalTimeCalibErrors( const EcalTimeCalibErrorsRcd& )
00615 {
00616   std::auto_ptr<EcalTimeCalibErrors>  ical = std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
00617 
00618   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00619     if(ieta==0) continue;
00620     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00621       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00622       if (EBDetId::validDetId(ieta,iphi))
00623         {
00624           EBDetId ebid(ieta,iphi);
00625           ical->setValue( ebid.rawId(), timeCalibErrorMean_);
00626         }
00627     }
00628   }
00629 
00630   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00631     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00632       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00633       if (EEDetId::validDetId(iX,iY,1))
00634         {
00635           EEDetId eedetidpos(iX,iY,1);
00636           ical->setValue( eedetidpos.rawId(), timeCalibErrorMean_ );
00637         }
00638       if(EEDetId::validDetId(iX,iY,-1))
00639         {
00640           EEDetId eedetidneg(iX,iY,-1);
00641           ical->setValue( eedetidneg.rawId(), timeCalibErrorMean_ );
00642         }
00643     }
00644   }
00645   
00646   return ical;
00647 }
00648 
00649 std::auto_ptr<EcalGainRatios>
00650 EcalTrivialConditionRetriever::produceEcalGainRatios( const EcalGainRatiosRcd& )
00651 {
00652   std::auto_ptr<EcalGainRatios> gratio = std::auto_ptr<EcalGainRatios>( new EcalGainRatios() );
00653   EcalMGPAGainRatio gr;
00654   gr.setGain12Over6( gainRatio12over6_ );
00655   gr.setGain6Over1( gainRatio6over1_ );
00656 
00657   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00658     if(ieta==0) continue;
00659     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00660       if (EBDetId::validDetId(ieta,iphi))
00661         {
00662           EBDetId ebid(ieta,iphi);
00663           gratio->setValue( ebid.rawId(), gr );
00664         }
00665     }
00666   }
00667   
00668   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00669     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00670       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00671       if (EEDetId::validDetId(iX,iY,1))
00672         {
00673           EEDetId eedetidpos(iX,iY,1);
00674           gratio->setValue( eedetidpos.rawId(), gr );
00675         }
00676       if (EEDetId::validDetId(iX,iY,-1))
00677         {
00678           EEDetId eedetidneg(iX,iY,-1);
00679           gratio->setValue( eedetidneg.rawId(), gr );
00680         }
00681     }
00682   }
00683   
00684   return gratio;
00685 }
00686 
00687 std::auto_ptr<EcalADCToGeVConstant>
00688 EcalTrivialConditionRetriever::produceEcalADCToGeVConstant( const EcalADCToGeVConstantRcd& )
00689 {
00690   return std::auto_ptr<EcalADCToGeVConstant>( new EcalADCToGeVConstant(adcToGeVEBConstant_,adcToGeVEEConstant_) );
00691 }
00692 
00693 std::auto_ptr<EcalTBWeights>
00694 EcalTrivialConditionRetriever::produceEcalTBWeights( const EcalTBWeightsRcd& )
00695 {
00696   // create weights for the test-beam
00697   std::auto_ptr<EcalTBWeights> tbwgt = std::auto_ptr<EcalTBWeights>( new EcalTBWeights() );
00698 
00699   // create weights for each distinct group ID
00700   //  int nMaxTDC = 10;
00701 //   for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
00702 //     if(igrp==0) continue; 
00703   int igrp=1;
00704   for(int itdc=1; itdc<=nTDCbins_; ++itdc) {
00705     // generate random number
00706     //    double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00707     
00708     // make a new set of weights
00709     EcalWeightSet wgt;
00710     //typedef std::vector< std::vector<EcalWeight> > EcalWeightSet::EcalWeightMatrix;
00711     EcalWeightSet::EcalWeightMatrix& mat1 = wgt.getWeightsBeforeGainSwitch();
00712     EcalWeightSet::EcalWeightMatrix& mat2 = wgt.getWeightsAfterGainSwitch();
00713     
00714 //     if(verbose_>=1) {
00715 //       std::cout << "initial size of mat1: " << mat1.size() << std::endl;
00716 //       std::cout << "initial size of mat2: " << mat2.size() << std::endl;
00717 //     }
00718     
00719     // generate random numbers to use as weights
00734     // use values provided by user
00735     mat1.Place_in_row(amplWeights_[itdc-1],0,0);
00736     mat1.Place_in_row(pedWeights_[itdc-1],1,0);
00737     mat1.Place_in_row(jittWeights_[itdc-1],2,0);
00738     
00739     // wdights after gain switch 
00740     mat2.Place_in_row(amplWeightsAft_[itdc-1],0,0);
00741     mat2.Place_in_row(pedWeightsAft_[itdc-1],1,0);
00742     mat2.Place_in_row(jittWeightsAft_[itdc-1],2,0);
00743     
00744     // fill the chi2 matrcies with random numbers
00745     //    r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00746     EcalWeightSet::EcalChi2WeightMatrix& mat3 = wgt.getChi2WeightsBeforeGainSwitch();
00747     EcalWeightSet::EcalChi2WeightMatrix& mat4 = wgt.getChi2WeightsAfterGainSwitch();
00748     mat3=chi2Matrix_[itdc-1];
00749     mat4=chi2MatrixAft_[itdc-1];
00750     
00751     //     for(size_t i=0; i<10; ++i) 
00752     //       {
00753     //  mat3.push_back(chi2Matrix_[itdc-1][i]);
00754     //  mat4.push_back(chi2MatrixAft_[itdc-1][i]);
00755     //       }
00756     //       std::vector<EcalWeight> tv1, tv2;
00757     //       for(size_t j=0; j<10; ++j) {
00758     //  double ww = igrp*itdc*r + i*10. + j;
00759     //  tv1.push_back( EcalWeight(1000+ww) );
00760     //  tv2.push_back( EcalWeight(1000+100+ww) );
00761     //       }
00762     
00763   
00764     
00765     
00766 //     if(verbose_>=1) {
00767 //       std::cout << "group: " << igrp << " TDC: " << itdc 
00768 //              << " mat1: " << mat1.size() << " mat2: " << mat2.size()
00769 //              << " mat3: " << mat3.size() << " mat4: " << mat4.size()
00770 //              << std::endl;
00771 //     }
00772     
00773     // put the weight in the container
00774     tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
00775   } 
00776   //   }
00777   return tbwgt;
00778 }
00779 
00780 
00781 // cluster functions/corrections
00782 std::auto_ptr<EcalClusterLocalContCorrParameters>
00783 EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters( const EcalClusterLocalContCorrParametersRcd &)
00784 {
00785         std::auto_ptr<EcalClusterLocalContCorrParameters> ipar = std::auto_ptr<EcalClusterLocalContCorrParameters>( new EcalClusterLocalContCorrParameters() );
00786         for (size_t i = 0; i < localContCorrParameters_.size(); ++i ) {
00787                 ipar->params().push_back( localContCorrParameters_[i] );
00788         }
00789         return ipar;
00790 }
00791 std::auto_ptr<EcalClusterCrackCorrParameters>
00792 EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters( const EcalClusterCrackCorrParametersRcd &)
00793 {
00794         std::auto_ptr<EcalClusterCrackCorrParameters> ipar = std::auto_ptr<EcalClusterCrackCorrParameters>( new EcalClusterCrackCorrParameters() );
00795         for (size_t i = 0; i < crackCorrParameters_.size(); ++i ) {
00796                 ipar->params().push_back( crackCorrParameters_[i] );
00797         }
00798         return ipar;
00799 }
00800 std::auto_ptr<EcalClusterEnergyCorrectionParameters>
00801 EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters( const EcalClusterEnergyCorrectionParametersRcd &)
00802 {
00803         std::auto_ptr<EcalClusterEnergyCorrectionParameters> ipar = std::auto_ptr<EcalClusterEnergyCorrectionParameters>( new EcalClusterEnergyCorrectionParameters() );
00804         for (size_t i = 0; i < energyCorrectionParameters_.size(); ++i ) {
00805                 ipar->params().push_back( energyCorrectionParameters_[i] );
00806         }
00807         return ipar;
00808 }
00809 std::auto_ptr<EcalClusterEnergyUncertaintyParameters>
00810 EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters( const EcalClusterEnergyUncertaintyParametersRcd &)
00811 {
00812         std::auto_ptr<EcalClusterEnergyUncertaintyParameters> ipar = std::auto_ptr<EcalClusterEnergyUncertaintyParameters>( new EcalClusterEnergyUncertaintyParameters() );
00813         for (size_t i = 0; i < energyUncertaintyParameters_.size(); ++i ) {
00814                 ipar->params().push_back( energyUncertaintyParameters_[i] );
00815         }
00816         return ipar;
00817 }
00818 
00819 
00820 // laser records
00821 std::auto_ptr<EcalLaserAlphas>
00822 EcalTrivialConditionRetriever::produceEcalLaserAlphas( const EcalLaserAlphasRcd& )
00823 {
00824 
00825   std::cout << " produceEcalLaserAlphas " << std::endl;
00826   std::auto_ptr<EcalLaserAlphas> ical = std::auto_ptr<EcalLaserAlphas>( new EcalLaserAlphas() );
00827   if(getLaserAlphaFromFile_) {
00828     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
00829     int SMpos[36] = {-10, 4, -7, -16, 6, -9, 11, -17, 5, 18, 3, -8, 1, -3, -13, 14, -6, 2,
00830                      15, -18, 8, 17, -2, 9, -1, 10, -5, 7, -12, -11, 16, -4, -15, -14, 12, 13};
00831     // check!
00832     int SMCal[36] = {12,17,10, 1, 8, 4,27,20,23,25, 6,34,35,15,18,30,21, 9,
00833                      24,22,13,31,26,16, 2,11, 5, 0,29,28,14,33,32, 3, 7,19};
00834     /*
00835   int slot_to_constr[37]={-1,12,17,10,1,8,4,27,20,23,25,6,34,35,15,18,30,21,9
00836                           ,24,22,13,31,26,16,2,11,5,0,29,28,14,33,32,3,7,19};
00837   int constr_to_slot[36]={28,4,25,34,6,27,11,35,5,18,3,26,1,21,31,14,24,2,15,
00838                           36,8,17,20,9,19,10,23,7,30,29,16,22,33,32,12,13  };
00839     */
00840     for(int SMcons = 0; SMcons < 36; SMcons++) {
00841       int SM = SMpos[SMcons];
00842       if(SM < 0) SM = 17 + abs(SM);
00843       else SM--;
00844       if(SMCal[SM] != SMcons)
00845          std::cout << " SM pb : read SM " <<  SMcons<< " SMpos " << SM
00846                    << " SMCal " << SMCal[SM] << std::endl;
00847     }
00848     // check
00849     std::string type, batch;
00850     int readSM, pos, bar, bar2;
00851     float alpha = 0;
00852     for(int SMcons = 0; SMcons < 36; SMcons++) {
00853       int SM = SMpos[SMcons];
00854       for(int ic = 0; ic < 1700; ic++) {
00855         fEB >> readSM >> pos >> bar >>  bar2 >> type >> batch;
00856         //      if(ic == 0) std::cout << readSM << " " << pos << " " << bar << " " << bar2 << " " 
00857         //                            << type << " " << batch << std::endl;
00858         if(readSM != SMcons || pos != ic + 1) 
00859           std::cout << " barrel read pb read SM " << readSM << " const SM " << SMcons
00860                     << " read pos " << pos << " ic " << ic << std::endl;
00861         if(SM < 0) SM = 18 + abs(SM);
00862         EBDetId ebdetid(SM, pos, EBDetId::SMCRYSTALMODE);
00863         if(bar == 33101 || bar == 30301 )
00864           alpha = 1.52;
00865         else if(bar == 33106) {
00866           if(bar2 <= 2000)
00867             alpha = 1.0;
00868           else {
00869             std::cout << " problem with barcode first " << bar << " last " << bar2 
00870                       << " read SM " << readSM << " read pos " << pos << std::endl;
00871             alpha = 0.0;
00872           }
00873         }
00874         ical->setValue( ebdetid, alpha );
00875       }
00876     }  // loop over SMcons
00877   }   // laserAlpha from a file
00878   else {
00879     for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00880       if(ieta==0) continue;
00881       for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00882         if (EBDetId::validDetId(ieta,iphi)) {
00883           EBDetId ebid(ieta,iphi);
00884           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00885           ical->setValue( ebid, laserAlphaMean_ + r*laserAlphaSigma_ );
00886         }
00887       }  // loop over iphi
00888     }  // loop over ieta
00889   }   // do not read a file
00890 
00891   std::cout << " produceEcalLaserAlphas EE" << std::endl;
00892   if(getLaserAlphaFromFile_) {
00893     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
00894     int check[101][101];
00895     for(int x = 1; x < 101; x++)
00896       for(int y = 1; y < 101; y++)
00897         check[x][y] = -1;
00898     for(int crystal = 0; crystal < 14648; crystal++) {
00899       int x, y ,z, bid, bar, bar2;
00900       float LY, alpha = 0;
00901       fEE >> z >> x >> y >> LY >> bid >> bar >> bar2;
00902       if(x < 1 || x > 100 || y < 1 || y > 100)
00903         std::cout << " wrong coordinates for barcode " << bar 
00904                   << " x " << x << " y " << y << " z " << z << std::endl;
00905       else {
00906         if(z == 1) check[x][y] = 1;
00907         else check[x][y] = 0;
00908         if(bar == 33201 || (bar == 30399 && bar2 < 568))
00909           alpha = 1.52;
00910         else if((bar == 33106 && bar2 > 2000 && bar2 < 4669) 
00911                 || (bar == 30399 && bar2 > 567))
00912           alpha = 1.0;
00913         else {
00914           std::cout << " problem with barcode " << bar << " " << bar2 
00915                     << " x " << x << " y " << y << " z " << z << std::endl;
00916           alpha = 0.0;
00917         }
00918       } 
00919       if (EEDetId::validDetId(x, y, z)) {
00920         EEDetId eedetidpos(x, y, z);
00921         ical->setValue( eedetidpos, alpha );
00922       }
00923       else // should not occur
00924         std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
00925     }  // loop over crystal in file
00926     for(int x = 1; x < 101; x++)
00927       for(int y = 1; y < 101; y++)
00928         if(check[x][y] == 1) std::cout << " missing x " << x << " y " << y << std::endl;
00929   }  // laserAlpha from a file
00930   else {
00931     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00932       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00933         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00934         if (EEDetId::validDetId(iX,iY,1)) {
00935           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00936           EEDetId eedetidpos(iX,iY,1);
00937           ical->setValue( eedetidpos, laserAlphaMean_ + r*laserAlphaSigma_ );
00938         }
00939 
00940         if (EEDetId::validDetId(iX,iY,-1)) {
00941           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00942           EEDetId eedetidneg(iX,iY,-1);
00943           ical->setValue( eedetidneg, laserAlphaMean_ + r1*laserAlphaSigma_ );
00944         }
00945       } // loop over iY
00946     } // loop over iX
00947   }  // do not read a file
00948   
00949   return ical;
00950 }
00951 
00952 
00953 std::auto_ptr<EcalLaserAPDPNRatiosRef>
00954 EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef( const EcalLaserAPDPNRatiosRefRcd& )
00955 {
00956   std::auto_ptr<EcalLaserAPDPNRatiosRef>  ical = std::auto_ptr<EcalLaserAPDPNRatiosRef>( new EcalLaserAPDPNRatiosRef() );
00957   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00958     if(ieta==0) continue;
00959     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00960       if (EBDetId::validDetId(ieta,iphi)) {
00961           EBDetId ebid(ieta,iphi);
00962           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00963           ical->setValue( ebid, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
00964       }
00965     }
00966   }
00967 
00968    for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00969      for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00970        // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00971        if (EEDetId::validDetId(iX,iY,1)) {
00972           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00973           EEDetId eedetidpos(iX,iY,1);
00974           ical->setValue( eedetidpos, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
00975        }
00976 
00977        if (EEDetId::validDetId(iX,iY,-1)) {
00978           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00979           EEDetId eedetidneg(iX,iY,-1);
00980           ical->setValue( eedetidneg, laserAPDPNRefMean_ + r1*laserAPDPNRefSigma_ );
00981        }
00982      }
00983    }
00984   
00985   return ical;
00986 }
00987 
00988 
00989 std::auto_ptr<EcalLaserAPDPNRatios>
00990 EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios( const EcalLaserAPDPNRatiosRcd& )
00991 {
00992 
00993   std::auto_ptr<EcalLaserAPDPNRatios>  ical = std::auto_ptr<EcalLaserAPDPNRatios>( new EcalLaserAPDPNRatios() );
00994   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00995     if(ieta==0) continue;
00996     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00997       if (EBDetId::validDetId(ieta,iphi)) {
00998           EBDetId ebid(ieta,iphi);
00999           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01000 
01001           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01002           pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01003           pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01004           pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01005           ical->setValue( ebid, pairAPDPN );
01006       }
01007      }
01008   }
01009 
01010    for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01011      for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01012        // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01013        if (EEDetId::validDetId(iX,iY,1)) {
01014           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01015           EEDetId eedetidpos(iX,iY,1);
01016 
01017           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01018           pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01019           pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01020           pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01021           ical->setValue( eedetidpos, pairAPDPN );
01022        }
01023 
01024        if (EEDetId::validDetId(iX,iY,-1)) {
01025           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
01026           EEDetId eedetidneg(iX,iY,-1);
01027 
01028           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01029           pairAPDPN.p1 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01030           pairAPDPN.p2 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01031           pairAPDPN.p3 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01032           ical->setValue( eedetidneg, pairAPDPN );
01033        }
01034      }
01035    }
01036 
01037   EcalLaserAPDPNRatios::EcalLaserTimeStamp TimeStamp;
01038   //  for(int i=1; i<=92; i++){
01039   for(int i=0; i<92; i++){
01040     TimeStamp.t1 = Timestamp(laserAPDPNTime1_);
01041     if(laserAPDPNTime2_ == 0 ){ 
01042       TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
01043     } else {
01044       TimeStamp.t2 = Timestamp(laserAPDPNTime2_);
01045     }
01046     if(laserAPDPNTime3_ == 0 ){ 
01047       TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
01048     } else {
01049       TimeStamp.t3 = Timestamp(laserAPDPNTime3_);
01050     }
01051 
01052     ical->setTime( i, TimeStamp );
01053   }
01054   
01055   return ical;
01056 
01057 }
01058 
01059   
01060 void EcalTrivialConditionRetriever::getWeightsFromConfiguration(const edm::ParameterSet& ps)
01061 {
01062 
01063   std::vector < std::vector<double> > amplwgtv(nTDCbins_);
01064 
01065   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01066     {
01067       std::vector<double> vampl;
01068       //As default using simple 3+1 weights
01069       vampl.push_back( -0.33333 );
01070       vampl.push_back( -0.33333 );
01071       vampl.push_back( -0.33333 );
01072       vampl.push_back(  0. );
01073       vampl.push_back(  0. );
01074       vampl.push_back(  1. );
01075       vampl.push_back(  0. );
01076       vampl.push_back(  0. );
01077       vampl.push_back(  0. );
01078       vampl.push_back(  0. );
01079       amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
01080     }
01081   else if (getWeightsFromFile_)
01082     {
01083       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str() ;
01084       std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
01085       int tdcBin=0;
01086       while (!amplFile.eof() && tdcBin < nTDCbins_) 
01087         {
01088           for(int j = 0; j < 10; ++j) {
01089             float ww;
01090             amplFile >> ww;
01091             amplwgtv[tdcBin].push_back(ww);
01092           }
01093           ++tdcBin;
01094         }
01095       assert (tdcBin == nTDCbins_);
01096       //Read from file
01097     }
01098   else
01099     {
01100       //Not supported
01101       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01102       throw cms::Exception("WrongConfig");
01103     }
01104 
01105   
01106   for (int i=0;i<nTDCbins_;i++)
01107     {
01108       assert(amplwgtv[i].size() == 10);
01109       int j=0;
01110       for(std::vector<double>::const_iterator it = amplwgtv[i].begin(); it != amplwgtv[i].end(); ++it) 
01111         {
01112           (amplWeights_[i])[j]=*it;
01113           j++;
01114         }
01115     }
01116   
01117 
01118   std::vector < std::vector<double> > amplwgtvAftGain(nTDCbins_);
01119 
01120   if (!getWeightsFromFile_ && nTDCbins_ == 1 )
01121     {
01122       std::vector<double> vamplAftGain;
01123       vamplAftGain.push_back(  0. );
01124       vamplAftGain.push_back(  0. );
01125       vamplAftGain.push_back(  0. );
01126       vamplAftGain.push_back(  0. );
01127       vamplAftGain.push_back(  0. );
01128       vamplAftGain.push_back(  1. );
01129       vamplAftGain.push_back(  0. );
01130       vamplAftGain.push_back(  0. );
01131       vamplAftGain.push_back(  0. );
01132       vamplAftGain.push_back(  0. );
01133       amplwgtvAftGain[0] = ps.getUntrackedParameter< std::vector<double> >("amplWeightsAftGain", vamplAftGain);
01134     }
01135   else if (getWeightsFromFile_)
01136     {
01137       //Read from file
01138       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights aftre gain switch from file " << edm::FileInPath(amplWeightsAftFile_).fullPath().c_str() ;
01139       std::ifstream amplFile(edm::FileInPath(amplWeightsAftFile_).fullPath().c_str());
01140       int tdcBin=0;
01141       while (!amplFile.eof() && tdcBin < nTDCbins_) 
01142         {
01143           for(int j = 0; j < 10; ++j) {
01144             float ww;
01145             amplFile >> ww;
01146             amplwgtvAftGain[tdcBin].push_back(ww);
01147           }
01148           ++tdcBin;
01149         }
01150       assert (tdcBin == nTDCbins_);
01151     }
01152   else
01153     {
01154       //Not supported
01155       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01156       throw cms::Exception("WrongConfig");
01157     }
01158 
01159   for (int i=0;i<nTDCbins_;i++)
01160     {
01161       assert(amplwgtvAftGain[i].size() == 10);
01162       int j=0;
01163       for(std::vector<double>::const_iterator it = amplwgtvAftGain[i].begin(); it != amplwgtvAftGain[i].end(); ++it) {
01164         (amplWeightsAft_[i])[j]=*it;
01165         j++;
01166       }
01167     }
01168       
01169   // default weights to reco amplitude w/o pedestal subtraction
01170 
01171   std::vector< std::vector<double> > pedwgtv(nTDCbins_);
01172 
01173   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01174     {
01175       std::vector<double> vped;
01176       vped.push_back( 0.33333 );
01177       vped.push_back( 0.33333 );
01178       vped.push_back( 0.33333 );
01179       vped.push_back( 0. );
01180       vped.push_back( 0. );
01181       vped.push_back( 0. );
01182       vped.push_back( 0. );
01183       vped.push_back( 0. );
01184       vped.push_back( 0. );
01185       vped.push_back( 0. );
01186       pedwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeights", vped);
01187     }
01188   else if (getWeightsFromFile_)
01189     {
01190       //Read from file
01191       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal weights from file " << edm::FileInPath(pedWeightsFile_).fullPath().c_str() ;
01192       std::ifstream pedFile(edm::FileInPath(pedWeightsFile_).fullPath().c_str());
01193       int tdcBin=0;
01194       while (!pedFile.eof() && tdcBin < nTDCbins_) 
01195         {
01196           for(int j = 0; j < 10; ++j) {
01197             float ww;
01198             pedFile >> ww;
01199             pedwgtv[tdcBin].push_back(ww);
01200           }
01201           ++tdcBin;
01202         }
01203       assert (tdcBin == nTDCbins_);
01204     }
01205   else
01206     {
01207       //Not supported
01208       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01209       throw cms::Exception("WrongConfig");
01210     }
01211 
01212   for (int i=0;i<nTDCbins_;i++)
01213     {
01214       assert(pedwgtv[i].size() == 10);
01215       int j=0;
01216       for(std::vector<double>::const_iterator it = pedwgtv[i].begin(); it != pedwgtv[i].end(); ++it) {
01217         (pedWeights_[i])[j] = *it;
01218         j++;
01219       }
01220     }
01221   
01222   std::vector< std::vector<double> > pedwgtvaft(nTDCbins_);
01223 
01224   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01225     {
01226       std::vector<double> vped;
01227       vped.push_back( 0. );
01228       vped.push_back( 0. );
01229       vped.push_back( 0. );
01230       vped.push_back( 0. );
01231       vped.push_back( 0. );
01232       vped.push_back( 0. );
01233       vped.push_back( 0. );
01234       vped.push_back( 0. );
01235       vped.push_back( 0. );
01236       vped.push_back( 0. );
01237       pedwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeightsAft", vped);
01238     }
01239   else if (getWeightsFromFile_)
01240     {
01241       //Read from file
01242       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal after gain switch weights from file " << edm::FileInPath(pedWeightsAftFile_).fullPath().c_str() ;
01243       std::ifstream pedFile(edm::FileInPath(pedWeightsAftFile_).fullPath().c_str());
01244       int tdcBin=0;
01245       while (!pedFile.eof() && tdcBin < nTDCbins_) 
01246         {
01247           for(int j = 0; j < 10; ++j) {
01248             float ww;
01249             pedFile >> ww;
01250             pedwgtvaft[tdcBin].push_back(ww);
01251           }
01252           ++tdcBin;
01253         }
01254       assert (tdcBin == nTDCbins_);
01255     }
01256   else
01257     {
01258       //Not supported
01259       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01260       throw cms::Exception("WrongConfig");
01261     }
01262   
01263   for (int i=0;i<nTDCbins_;i++)
01264     {
01265       assert(pedwgtvaft[i].size() == 10);
01266       int j=0;
01267       for(std::vector<double>::const_iterator it = pedwgtvaft[i].begin(); it != pedwgtvaft[i].end(); ++it) {
01268         (pedWeightsAft_[i])[j]=*it;
01269         j++;
01270       }
01271     }
01272   
01273   
01274   
01275   // default weights to reco jitter
01276 
01277   std::vector< std::vector<double> > jittwgtv(nTDCbins_);
01278 
01279   if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01280     {
01281       std::vector<double> vjitt;
01282       vjitt.push_back( 0.04066309 );
01283       vjitt.push_back( 0.04066309 );
01284       vjitt.push_back( 0.04066309 );
01285       vjitt.push_back( 0.000 );
01286       vjitt.push_back( 1.325176 );
01287       vjitt.push_back( -0.04997078 );
01288       vjitt.push_back( -0.504338 );
01289       vjitt.push_back( -0.5024844 );
01290       vjitt.push_back( -0.3903718 );
01291       vjitt.push_back( 0.000 );
01292       jittwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeights", vjitt);
01293     }
01294   else if (getWeightsFromFile_)
01295     {
01296       //Read from file
01297       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter weights from file " << edm::FileInPath(jittWeightsFile_).fullPath().c_str() ;
01298       std::ifstream jittFile(edm::FileInPath(jittWeightsFile_).fullPath().c_str());
01299       int tdcBin=0;
01300       while (!jittFile.eof() && tdcBin < nTDCbins_) 
01301         {
01302           for(int j = 0; j < 10; ++j) {
01303             float ww;
01304             jittFile >> ww;
01305             jittwgtv[tdcBin].push_back(ww);
01306           }
01307           ++tdcBin;
01308         }
01309       assert (tdcBin == nTDCbins_);
01310     }
01311   else
01312     {
01313       //Not supported
01314       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01315       throw cms::Exception("WrongConfig");
01316     }
01317   
01318   for (int i=0;i<nTDCbins_;i++)
01319     {
01320       assert(jittwgtv[i].size() == 10);
01321       int j=0;
01322       for(std::vector<double>::const_iterator it = jittwgtv[i].begin(); it != jittwgtv[i].end(); ++it) {
01323         (jittWeights_[i])[j]= *it;
01324         j++;
01325       }
01326     }
01327   
01328   std::vector< std::vector<double> > jittwgtvaft(nTDCbins_);
01329 
01330   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01331     {
01332       std::vector<double> vjitt;
01333       vjitt.push_back( 0. );
01334       vjitt.push_back( 0. );
01335       vjitt.push_back( 0. );
01336       vjitt.push_back( 0. );
01337       vjitt.push_back( 1.097871 );
01338       vjitt.push_back( -0.04551035 );
01339       vjitt.push_back( -0.4159156 );
01340       vjitt.push_back( -0.4185352 );
01341       vjitt.push_back( -0.3367127 );
01342       vjitt.push_back( 0. );
01343       jittwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeightsAft", vjitt);
01344     }
01345   else if (getWeightsFromFile_)
01346     {
01347       //Read from file
01348       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter after gain switch weights from file " << edm::FileInPath(jittWeightsAftFile_).fullPath().c_str() ;
01349       std::ifstream jittFile(edm::FileInPath(jittWeightsAftFile_).fullPath().c_str());
01350       int tdcBin=0;
01351       while (!jittFile.eof() && tdcBin < nTDCbins_) 
01352         {
01353           for(int j = 0; j < 10; ++j) {
01354             float ww;
01355             jittFile >> ww;
01356             jittwgtvaft[tdcBin].push_back(ww);
01357           }
01358           ++tdcBin;
01359         }
01360       assert (tdcBin == nTDCbins_);
01361     }
01362   else
01363     {
01364       //Not supported
01365       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01366       throw cms::Exception("WrongConfig");
01367     }
01368   
01369   for (int i=0;i<nTDCbins_;i++)
01370     {
01371       assert(jittwgtvaft[i].size() == 10);
01372       int j=0;
01373       for(std::vector<double>::const_iterator it = jittwgtvaft[i].begin(); it != jittwgtvaft[i].end(); ++it) {
01374         (jittWeightsAft_[i])[j]= *it;
01375         j++;
01376       }
01377     }
01378 
01379    
01380    std::vector<  EcalWeightSet::EcalChi2WeightMatrix > chi2Matrix(nTDCbins_);
01381    if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01382      {
01383        //        chi2Matrix[0].resize(10);
01384        //        for (int i=0;i<10;i++)
01385          //      chi2Matrix[0][i].resize(10);
01386 
01387        chi2Matrix[0](0,0) = 0.694371;
01388        chi2Matrix[0](0,1) = -0.305629;  
01389        chi2Matrix[0](0,2) = -0.305629;
01390        chi2Matrix[0](0,3) = 0.;
01391        chi2Matrix[0](0,4) = 0.;
01392        chi2Matrix[0](0,5) = 0.;
01393        chi2Matrix[0](0,6) = 0.;
01394        chi2Matrix[0](0,7) = 0.;
01395        chi2Matrix[0](0,8) = 0.;
01396        chi2Matrix[0](0,9) = 0.;
01397        chi2Matrix[0](1,0) = -0.305629;
01398        chi2Matrix[0](1,1) = 0.694371;
01399        chi2Matrix[0](1,2) = -0.305629;
01400        chi2Matrix[0](1,3) = 0.;
01401        chi2Matrix[0](1,4) = 0.;
01402        chi2Matrix[0](1,5) = 0.;
01403        chi2Matrix[0](1,6) = 0.;
01404        chi2Matrix[0](1,7) = 0.;
01405        chi2Matrix[0](1,8) = 0.;
01406        chi2Matrix[0](1,9) = 0.;
01407        chi2Matrix[0](2,0) = -0.305629;
01408        chi2Matrix[0](2,1) = -0.305629;
01409        chi2Matrix[0](2,2) = 0.694371;
01410        chi2Matrix[0](2,3) = 0.;
01411        chi2Matrix[0](2,4) = 0.;
01412        chi2Matrix[0](2,5) = 0.;
01413        chi2Matrix[0](2,6) = 0.;
01414        chi2Matrix[0](2,7) = 0.;
01415        chi2Matrix[0](2,8) = 0.;
01416        chi2Matrix[0](2,9) = 0.;
01417        chi2Matrix[0](3,0) = 0.;
01418        chi2Matrix[0](3,1) = 0.;
01419        chi2Matrix[0](3,2) = 0.;
01420        chi2Matrix[0](3,3) = 0.;
01421        chi2Matrix[0](3,4) = 0.;
01422        chi2Matrix[0](3,5) = 0.;
01423        chi2Matrix[0](3,6) = 0.;
01424        chi2Matrix[0](3,7) = 0.;
01425        chi2Matrix[0](3,8) = 0.;
01426        chi2Matrix[0](3,9) = 0.; 
01427        chi2Matrix[0](4,0) = 0.;
01428        chi2Matrix[0](4,1) = 0.;
01429        chi2Matrix[0](4,2) = 0.;
01430        chi2Matrix[0](4,3) = 0.;
01431        chi2Matrix[0](4,4) = 0.8027116;
01432        chi2Matrix[0](4,5) = -0.2517103;
01433        chi2Matrix[0](4,6) = -0.2232882;
01434        chi2Matrix[0](4,7) = -0.1716192;
01435        chi2Matrix[0](4,8) = -0.1239006;
01436        chi2Matrix[0](4,9) = 0.; 
01437        chi2Matrix[0](5,0) = 0.;
01438        chi2Matrix[0](5,1) = 0.;
01439        chi2Matrix[0](5,2) = 0.;
01440        chi2Matrix[0](5,3) = 0.;
01441        chi2Matrix[0](5,4) = -0.2517103;
01442        chi2Matrix[0](5,5) = 0.6528964;
01443        chi2Matrix[0](5,6) = -0.2972839;
01444        chi2Matrix[0](5,7) = -0.2067162;
01445        chi2Matrix[0](5,8) = -0.1230729;
01446        chi2Matrix[0](5,9) = 0.;
01447        chi2Matrix[0](6,0) = 0.;
01448        chi2Matrix[0](6,1) = 0.;
01449        chi2Matrix[0](6,2) = 0.;
01450        chi2Matrix[0](6,3) = 0.;
01451        chi2Matrix[0](6,4) = -0.2232882;
01452        chi2Matrix[0](6,5) = -0.2972839;
01453        chi2Matrix[0](6,6) = 0.7413607;
01454        chi2Matrix[0](6,7) = -0.1883866;
01455        chi2Matrix[0](6,8) = -0.1235052;
01456        chi2Matrix[0](6,9) = 0.; 
01457        chi2Matrix[0](7,0) = 0.;
01458        chi2Matrix[0](7,1) = 0.;
01459        chi2Matrix[0](7,2) = 0.;
01460        chi2Matrix[0](7,3) = 0.;
01461        chi2Matrix[0](7,4) = -0.1716192;
01462        chi2Matrix[0](7,5) = -0.2067162;
01463        chi2Matrix[0](7,6) = -0.1883866;
01464        chi2Matrix[0](7,7) = 0.844935;
01465        chi2Matrix[0](7,8) = -0.124291;
01466        chi2Matrix[0](7,9) = 0.; 
01467        chi2Matrix[0](8,0) = 0.;
01468        chi2Matrix[0](8,1) = 0.;
01469        chi2Matrix[0](8,2) = 0.;
01470        chi2Matrix[0](8,3) = 0.;
01471        chi2Matrix[0](8,4) = -0.1239006;
01472        chi2Matrix[0](8,5) = -0.1230729;
01473        chi2Matrix[0](8,6) = -0.1235052;
01474        chi2Matrix[0](8,7) = -0.124291;
01475        chi2Matrix[0](8,8) = 0.8749833;
01476        chi2Matrix[0](8,9) = 0.;
01477        chi2Matrix[0](9,0) = 0.;
01478        chi2Matrix[0](9,1) = 0.;
01479        chi2Matrix[0](9,2) = 0.;
01480        chi2Matrix[0](9,3) = 0.;
01481        chi2Matrix[0](9,4) = 0.;
01482        chi2Matrix[0](9,5) = 0.;
01483        chi2Matrix[0](9,6) = 0.;
01484        chi2Matrix[0](9,7) = 0.;
01485        chi2Matrix[0](9,8) = 0.;
01486        chi2Matrix[0](9,9) = 0.; 
01487      }
01488    else if (getWeightsFromFile_)
01489     {
01490       //Read from file
01491       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2Matrix from file " << edm::FileInPath(chi2MatrixFile_).fullPath().c_str() ;
01492       std::ifstream chi2MatrixFile(edm::FileInPath(chi2MatrixFile_).fullPath().c_str());
01493       int tdcBin=0;
01494       while (!chi2MatrixFile.eof() && tdcBin < nTDCbins_) 
01495         {
01496           //      chi2Matrix[tdcBin].resize(10);
01497           for(int j = 0; j < 10; ++j) {
01498             for(int l = 0; l < 10; ++l) {
01499               float ww;
01500               chi2MatrixFile >> ww;
01501               chi2Matrix[tdcBin](j,l)=ww;
01502             }
01503           }
01504           ++tdcBin;
01505         }
01506       assert (tdcBin == nTDCbins_);
01507     }
01508   else
01509     {
01510       //Not supported
01511       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01512       throw cms::Exception("WrongConfig");
01513     }
01514    
01515 //    for (int i=0;i<nTDCbins_;i++)
01516 //      {
01517        //       assert(chi2Matrix[i].size() == 10);
01518    chi2Matrix_ =  chi2Matrix;
01519 //      }
01520 
01521    std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2MatrixAft(nTDCbins_);
01522    if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01523      {
01524        //       chi2MatrixAft[0].resize(10);
01525        //       for (int i=0;i<10;i++)
01526          //      chi2MatrixAft[0][i].resize(10);
01527 
01528        chi2MatrixAft[0](0,0) = 0.;
01529        chi2MatrixAft[0](0,1) = 0.;  
01530        chi2MatrixAft[0](0,2) = 0.;
01531        chi2MatrixAft[0](0,3) = 0.;
01532        chi2MatrixAft[0](0,4) = 0.;
01533        chi2MatrixAft[0](0,5) = 0.;
01534        chi2MatrixAft[0](0,6) = 0.;
01535        chi2MatrixAft[0](0,7) = 0.;
01536        chi2MatrixAft[0](0,8) = 0.;
01537        chi2MatrixAft[0](0,9) = 0.;
01538        chi2MatrixAft[0](1,0) = 0.;
01539        chi2MatrixAft[0](1,1) = 0.;
01540        chi2MatrixAft[0](1,2) = 0.;
01541        chi2MatrixAft[0](1,3) = 0.;
01542        chi2MatrixAft[0](1,4) = 0.;
01543        chi2MatrixAft[0](1,5) = 0.;
01544        chi2MatrixAft[0](1,6) = 0.;
01545        chi2MatrixAft[0](1,7) = 0.;
01546        chi2MatrixAft[0](1,8) = 0.;
01547        chi2MatrixAft[0](1,9) = 0.;
01548        chi2MatrixAft[0](2,0) = 0.;
01549        chi2MatrixAft[0](2,1) = 0.;
01550        chi2MatrixAft[0](2,2) = 0.;
01551        chi2MatrixAft[0](2,3) = 0.;
01552        chi2MatrixAft[0](2,4) = 0.;
01553        chi2MatrixAft[0](2,5) = 0.;
01554        chi2MatrixAft[0](2,6) = 0.;
01555        chi2MatrixAft[0](2,7) = 0.;
01556        chi2MatrixAft[0](2,8) = 0.;
01557        chi2MatrixAft[0](2,9) = 0.;
01558        chi2MatrixAft[0](3,0) = 0.;
01559        chi2MatrixAft[0](3,1) = 0.;
01560        chi2MatrixAft[0](3,2) = 0.;
01561        chi2MatrixAft[0](3,3) = 0.;
01562        chi2MatrixAft[0](3,4) = 0.;
01563        chi2MatrixAft[0](3,5) = 0.;
01564        chi2MatrixAft[0](3,6) = 0.;
01565        chi2MatrixAft[0](3,7) = 0.;
01566        chi2MatrixAft[0](3,8) = 0.;
01567        chi2MatrixAft[0](3,9) = 0.; 
01568        chi2MatrixAft[0](4,0) = 0.;
01569        chi2MatrixAft[0](4,1) = 0.;
01570        chi2MatrixAft[0](4,2) = 0.;
01571        chi2MatrixAft[0](4,3) = 0.;
01572        chi2MatrixAft[0](4,4) = 0.8030884;
01573        chi2MatrixAft[0](4,5) = -0.2543541;
01574        chi2MatrixAft[0](4,6) = -0.2243544;
01575        chi2MatrixAft[0](4,7) = -0.1698177;
01576        chi2MatrixAft[0](4,8) = -0.1194506;
01577        chi2MatrixAft[0](4,9) = 0.; 
01578        chi2MatrixAft[0](5,0) = 0.;
01579        chi2MatrixAft[0](5,1) = 0.;
01580        chi2MatrixAft[0](5,2) = 0.;
01581        chi2MatrixAft[0](5,3) = 0.;
01582        chi2MatrixAft[0](5,4) = -0.2543541;
01583        chi2MatrixAft[0](5,5) = 0.6714465;
01584        chi2MatrixAft[0](5,6) = -0.2898025;
01585        chi2MatrixAft[0](5,7) = -0.2193564;
01586        chi2MatrixAft[0](5,8) = -0.1542964;
01587        chi2MatrixAft[0](5,9) = 0.;
01588        chi2MatrixAft[0](6,0) = 0.;
01589        chi2MatrixAft[0](6,1) = 0.;
01590        chi2MatrixAft[0](6,2) = 0.;
01591        chi2MatrixAft[0](6,3) = 0.;
01592        chi2MatrixAft[0](6,4) = -0.2243544;
01593        chi2MatrixAft[0](6,5) = -0.2898025;
01594        chi2MatrixAft[0](6,6) = 0.7443781;
01595        chi2MatrixAft[0](6,7) = -0.1934846;
01596        chi2MatrixAft[0](6,8) = -0.136098;
01597        chi2MatrixAft[0](6,9) = 0.; 
01598        chi2MatrixAft[0](7,0) = 0.;
01599        chi2MatrixAft[0](7,1) = 0.;
01600        chi2MatrixAft[0](7,2) = 0.;
01601        chi2MatrixAft[0](7,3) = 0.;
01602        chi2MatrixAft[0](7,4) = -0.1698177;
01603        chi2MatrixAft[0](7,5) = -0.2193564;
01604        chi2MatrixAft[0](7,6) = -0.1934846;
01605        chi2MatrixAft[0](7,7) = 0.8535482;
01606        chi2MatrixAft[0](7,8) = -0.1030149;
01607        chi2MatrixAft[0](7,9) = 0.; 
01608        chi2MatrixAft[0](8,0) = 0.;
01609        chi2MatrixAft[0](8,1) = 0.;
01610        chi2MatrixAft[0](8,2) = 0.;
01611        chi2MatrixAft[0](8,3) = 0.;
01612        chi2MatrixAft[0](8,4) = -0.1194506;
01613        chi2MatrixAft[0](8,5) = -0.1542964;
01614        chi2MatrixAft[0](8,6) = -0.136098;
01615        chi2MatrixAft[0](8,7) = -0.1030149;
01616        chi2MatrixAft[0](8,8) = 0.9275388;
01617        chi2MatrixAft[0](8,9) = 0.;
01618        chi2MatrixAft[0](9,0) = 0.;
01619        chi2MatrixAft[0](9,1) = 0.;
01620        chi2MatrixAft[0](9,2) = 0.;
01621        chi2MatrixAft[0](9,3) = 0.;
01622        chi2MatrixAft[0](9,4) = 0.;
01623        chi2MatrixAft[0](9,5) = 0.;
01624        chi2MatrixAft[0](9,6) = 0.;
01625        chi2MatrixAft[0](9,7) = 0.;
01626        chi2MatrixAft[0](9,8) = 0.;
01627        chi2MatrixAft[0](9,9) = 0.; 
01628      }
01629    else if (getWeightsFromFile_)
01630     {
01631       //Read from file
01632       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2MatrixAft from file " << edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str() ;
01633       std::ifstream chi2MatrixAftFile(edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str());
01634       int tdcBin=0;
01635       while (!chi2MatrixAftFile.eof() && tdcBin < nTDCbins_) 
01636         {
01637           //      chi2MatrixAft[tdcBin].resize(10);
01638           for(int j = 0; j < 10; ++j) {
01639             for(int l = 0; l < 10; ++l) {
01640               float ww;
01641               chi2MatrixAftFile >> ww;
01642               chi2MatrixAft[tdcBin](j,l)=ww;
01643             }
01644           }
01645           ++tdcBin;
01646         }
01647       assert (tdcBin == nTDCbins_);
01648     }
01649   else
01650     {
01651       //Not supported
01652       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01653       throw cms::Exception("WrongConfig");
01654     }
01655    
01656 //    for (int i=0;i<nTDCbins_;i++)
01657 //      {
01658        //       assert(chi2MatrixAft[i].size() == 10);
01659    chi2MatrixAft_ =  chi2MatrixAft;
01660    //      }
01661 
01662 }
01663 
01664 
01665 // --------------------------------------------------------------------------------
01666 
01667 std::auto_ptr<EcalChannelStatus>
01668 EcalTrivialConditionRetriever::getChannelStatusFromConfiguration (const EcalChannelStatusRcd&)
01669 {
01670   std::auto_ptr<EcalChannelStatus> ecalStatus = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
01671   
01672 
01673   // start by setting all statuses to 0
01674   
01675   // barrel
01676   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01677     if(ieta==0) continue;
01678     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01679       if (EBDetId::validDetId(ieta,iphi)) {
01680         EBDetId ebid(ieta,iphi);
01681         ecalStatus->setValue( ebid, 0 );
01682       }
01683     }
01684   }
01685   // endcap
01686   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01687     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01688       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01689       if (EEDetId::validDetId(iX,iY,1)) {
01690         EEDetId eedetidpos(iX,iY,1);
01691         ecalStatus->setValue( eedetidpos, 0 );
01692       }
01693       if (EEDetId::validDetId(iX,iY,-1)) {
01694         EEDetId eedetidneg(iX,iY,-1);
01695         ecalStatus->setValue( eedetidneg, 0 );
01696       }
01697     }
01698   }
01699   
01700   
01701   
01702   // overwrite the statuses which are in the file
01703   
01704   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
01705   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
01706   if ( !statusFile.good() ) {
01707     edm::LogError ("EcalTrivialConditionRetriever") 
01708       << "*** Problems opening file: " << channelStatusFile_ ;
01709     throw cms::Exception ("Cannot open ECAL channel status file") ;
01710   }
01711   
01712   std::string EcalSubDet;
01713   std::string str;
01714   int hashIndex(0);
01715   int status(0);
01716   
01717   while (!statusFile.eof()) 
01718     {
01719       statusFile >> EcalSubDet;
01720       if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
01721         {
01722           std::getline(statusFile,str);
01723           continue;
01724         }
01725       else
01726         {
01727           statusFile>> hashIndex >> status;
01728         }
01729       // std::cout << EcalSubDet << " " << hashIndex << " " << status;
01730       
01731       if(EcalSubDet==std::string("EB"))
01732         {
01733           EBDetId ebid = EBDetId::unhashIndex(hashIndex);
01734           ecalStatus->setValue( ebid, status );
01735         }
01736       else if(EcalSubDet==std::string("EE"))
01737         {
01738           EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
01739           ecalStatus->setValue( eedetid, status );
01740         }
01741       else
01742         {
01743           edm::LogError ("EcalTrivialConditionRetriever") 
01744             << " *** " << EcalSubDet << " is neither EB nor EE ";
01745         }
01746       
01747     }
01748   // the file is supposed to be in the form  -- FIXME
01749   
01750   
01751   statusFile.close();
01752   return ecalStatus;
01753 }
01754 
01755 
01756 
01757 std::auto_ptr<EcalChannelStatus>
01758 EcalTrivialConditionRetriever::produceEcalChannelStatus( const EcalChannelStatusRcd& )
01759 {
01760 
01761         std::auto_ptr<EcalChannelStatus>  ical = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
01762         // barrel
01763         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01764                 if(ieta==0) continue;
01765                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01766                         if (EBDetId::validDetId(ieta,iphi)) {
01767                                 EBDetId ebid(ieta,iphi);
01768                                 ical->setValue( ebid, 0 );
01769                         }
01770                 }
01771         }
01772         // endcap
01773         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01774                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01775                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01776                         if (EEDetId::validDetId(iX,iY,1)) {
01777                                 EEDetId eedetidpos(iX,iY,1);
01778                                 ical->setValue( eedetidpos, 0 );
01779                         }
01780                         if (EEDetId::validDetId(iX,iY,-1)) {
01781                                 EEDetId eedetidneg(iX,iY,-1);
01782                                 ical->setValue( eedetidneg, 0 );
01783                         }
01784                 }
01785         }
01786         return ical;
01787 }
01788 
01789 // --------------------------------------------------------------------------------
01790 std::auto_ptr<EcalDQMChannelStatus>
01791 EcalTrivialConditionRetriever::produceEcalDQMChannelStatus( const EcalDQMChannelStatusRcd& )
01792 {
01793   uint32_t sta(0);
01794 
01795         std::auto_ptr<EcalDQMChannelStatus>  ical = std::auto_ptr<EcalDQMChannelStatus>( new EcalDQMChannelStatus() );
01796         // barrel
01797         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01798                 if(ieta==0) continue;
01799                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01800                         if (EBDetId::validDetId(ieta,iphi)) {
01801                                 EBDetId ebid(ieta,iphi);
01802                                 ical->setValue( ebid, sta );
01803                         }
01804                 }
01805         }
01806         // endcap
01807         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01808                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01809                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01810                         if (EEDetId::validDetId(iX,iY,1)) {
01811                                 EEDetId eedetidpos(iX,iY,1);
01812                                 ical->setValue( eedetidpos, sta );
01813                         }
01814                         if (EEDetId::validDetId(iX,iY,-1)) {
01815                                 EEDetId eedetidneg(iX,iY,-1);
01816                                 ical->setValue( eedetidneg, sta );
01817                         }
01818                 }
01819         }
01820         return ical;
01821 }
01822 // --------------------------------------------------------------------------------
01823 
01824 std::auto_ptr<EcalDQMTowerStatus>
01825 EcalTrivialConditionRetriever::produceEcalDQMTowerStatus( const EcalDQMTowerStatusRcd& )
01826 {
01827 
01828         std::auto_ptr<EcalDQMTowerStatus>  ical = std::auto_ptr<EcalDQMTowerStatus>( new EcalDQMTowerStatus() );
01829 
01830         uint32_t sta(0);
01831         
01832         // barrel
01833         int iz=0;
01834         for(int k=0 ; k<2; k++ ) {
01835           if(k==0) iz=-1;
01836           if(k==1) iz=+1;
01837           for(int i=1 ; i<73; i++) {
01838             for(int j=1 ; j<18; j++) {
01839               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
01840                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
01841 
01842                 ical->setValue( ebid, sta );
01843               }
01844             }
01845           }
01846         }
01847 
01848 
01849         // endcap
01850         for(int k=0 ; k<2; k++ ) {
01851           if(k==0) iz=-1;
01852           if(k==1) iz=+1;
01853           for(int i=1 ; i<21; i++) {
01854             for(int j=1 ; j<21; j++) {
01855               if (EcalScDetId::validDetId(i,j,iz )){
01856                 EcalScDetId eeid(i,j,iz);
01857                 ical->setValue( eeid, sta );
01858               }
01859             }
01860           }
01861         }
01862 
01863         return ical;
01864 }
01865 
01866 // --------------------------------------------------------------------------------
01867 std::auto_ptr<EcalDCSTowerStatus>
01868 EcalTrivialConditionRetriever::produceEcalDCSTowerStatus( const EcalDCSTowerStatusRcd& )
01869 {
01870 
01871         std::auto_ptr<EcalDCSTowerStatus>  ical = std::auto_ptr<EcalDCSTowerStatus>( new EcalDCSTowerStatus() );
01872 
01873         int status(0);
01874         
01875         // barrel
01876         int iz=0;
01877         for(int k=0 ; k<2; k++ ) {
01878           if(k==0) iz=-1;
01879           if(k==1) iz=+1;
01880           for(int i=1 ; i<73; i++) {
01881             for(int j=1 ; j<18; j++) {
01882               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
01883                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
01884 
01885                 ical->setValue( ebid, status );
01886               }
01887             }
01888           }
01889         }
01890 
01891 
01892         // endcap
01893         for(int k=0 ; k<2; k++ ) {
01894           if(k==0) iz=-1;
01895           if(k==1) iz=+1;
01896           for(int i=1 ; i<21; i++) {
01897             for(int j=1 ; j<21; j++) {
01898               if (EcalScDetId::validDetId(i,j,iz )){
01899                 EcalScDetId eeid(i,j,iz);
01900                 ical->setValue( eeid, status );
01901               }
01902             }
01903           }
01904         }
01905 
01906         return ical;
01907 }
01908 // --------------------------------------------------------------------------------
01909 
01910 std::auto_ptr<EcalDAQTowerStatus>
01911 EcalTrivialConditionRetriever::produceEcalDAQTowerStatus( const EcalDAQTowerStatusRcd& )
01912 {
01913 
01914         std::auto_ptr<EcalDAQTowerStatus>  ical = std::auto_ptr<EcalDAQTowerStatus>( new EcalDAQTowerStatus() );
01915 
01916         int status(0);
01917         
01918         // barrel
01919         int iz=0;
01920         for(int k=0 ; k<2; k++ ) {
01921           if(k==0) iz=-1;
01922           if(k==1) iz=+1;
01923           for(int i=1 ; i<73; i++) {
01924             for(int j=1 ; j<18; j++) {
01925               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
01926                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
01927 
01928                 ical->setValue( ebid, status );
01929               }
01930             }
01931           }
01932         }
01933 
01934 
01935         // endcap
01936         for(int k=0 ; k<2; k++ ) {
01937           if(k==0) iz=-1;
01938           if(k==1) iz=+1;
01939           for(int i=1 ; i<21; i++) {
01940             for(int j=1 ; j<21; j++) {
01941               if (EcalScDetId::validDetId(i,j,iz )){
01942                 EcalScDetId eeid(i,j,iz);
01943                 ical->setValue( eeid, status );
01944               }
01945             }
01946           }
01947         }
01948 
01949         return ical;
01950 }
01951 // --------------------------------------------------------------------------------
01952 
01953 std::auto_ptr<EcalTPGCrystalStatus>
01954 EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration (const EcalTPGCrystalStatusRcd&)
01955 {
01956   std::auto_ptr<EcalTPGCrystalStatus> ecalStatus = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
01957   
01958 
01959   // start by setting all statuses to 0
01960   
01961   // barrel
01962   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01963     if(ieta==0) continue;
01964     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01965       if (EBDetId::validDetId(ieta,iphi)) {
01966         EBDetId ebid(ieta,iphi);
01967         ecalStatus->setValue( ebid, 0 );
01968       }
01969     }
01970   }
01971   // endcap
01972   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01973     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01974       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01975       if (EEDetId::validDetId(iX,iY,1)) {
01976         EEDetId eedetidpos(iX,iY,1);
01977         ecalStatus->setValue( eedetidpos, 0 );
01978       }
01979       if (EEDetId::validDetId(iX,iY,-1)) {
01980         EEDetId eedetidneg(iX,iY,-1);
01981         ecalStatus->setValue( eedetidneg, 0 );
01982       }
01983     }
01984   }
01985   
01986   
01987   
01988   // overwrite the statuses which are in the file
01989   
01990   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
01991   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
01992   if ( !statusFile.good() ) {
01993     edm::LogError ("EcalTrivialConditionRetriever") 
01994       << "*** Problems opening file: " << channelStatusFile_ ;
01995     throw cms::Exception ("Cannot open ECAL channel status file") ;
01996   }
01997   
01998   std::string EcalSubDet;
01999   std::string str;
02000   int hashIndex(0);
02001   int status(0);
02002   
02003   while (!statusFile.eof()) 
02004     {
02005       statusFile >> EcalSubDet;
02006       if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
02007         {
02008           std::getline(statusFile,str);
02009           continue;
02010         }
02011       else
02012         {
02013           statusFile>> hashIndex >> status;
02014         }
02015       // std::cout << EcalSubDet << " " << hashIndex << " " << status;
02016       
02017       if(EcalSubDet==std::string("EB"))
02018         {
02019           EBDetId ebid = EBDetId::unhashIndex(hashIndex);
02020           ecalStatus->setValue( ebid, status );
02021         }
02022       else if(EcalSubDet==std::string("EE"))
02023         {
02024           EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
02025           ecalStatus->setValue( eedetid, status );
02026         }
02027       else
02028         {
02029           edm::LogError ("EcalTrivialConditionRetriever") 
02030             << " *** " << EcalSubDet << " is neither EB nor EE ";
02031         }
02032       
02033     }
02034   // the file is supposed to be in the form  -- FIXME
02035   
02036   
02037   statusFile.close();
02038   return ecalStatus;
02039 }
02040 
02041 
02042 
02043 std::auto_ptr<EcalTPGCrystalStatus>
02044 EcalTrivialConditionRetriever::produceEcalTrgChannelStatus( const EcalTPGCrystalStatusRcd& )
02045 {
02046 
02047         std::auto_ptr<EcalTPGCrystalStatus>  ical = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
02048         // barrel
02049         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
02050                 if(ieta==0) continue;
02051                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
02052                         if (EBDetId::validDetId(ieta,iphi)) {
02053                                 EBDetId ebid(ieta,iphi);
02054                                 ical->setValue( ebid, 0 );
02055                         }
02056                 }
02057         }
02058         // endcap
02059         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
02060                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
02061                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
02062                         if (EEDetId::validDetId(iX,iY,1)) {
02063                                 EEDetId eedetidpos(iX,iY,1);
02064                                 ical->setValue( eedetidpos, 0 );
02065                         }
02066                         if (EEDetId::validDetId(iX,iY,-1)) {
02067                                 EEDetId eedetidneg(iX,iY,-1);
02068                                 ical->setValue( eedetidneg, 0 );
02069                         }
02070                 }
02071         }
02072         return ical;
02073 }
02074 
02075 
02076 
02077 // --------------------------------------------------------------------------------
02078 
02079 
02080 std::auto_ptr<EcalIntercalibConstants> 
02081 EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration 
02082 ( const EcalIntercalibConstantsRcd& )
02083 {
02084   std::auto_ptr<EcalIntercalibConstants>  ical = 
02085       std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
02086 
02087   // Read the values from a txt file
02088   // -------------------------------
02089 
02090   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
02091                                                 << intercalibConstantsFile_.c_str() ;
02092 
02093   FILE *inpFile ;
02094   inpFile = fopen (intercalibConstantsFile_.c_str (),"r") ;
02095   if (!inpFile) 
02096     {
02097       edm::LogError ("EcalTrivialConditionRetriever") 
02098          << "*** Can not open file: " << intercalibConstantsFile_ ;
02099       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02100     }
02101 
02102   char line[256] ;
02103   std::ostringstream str ;
02104   fgets (line,255,inpFile) ;
02105   int sm_number=atoi (line) ;
02106   str << "sm: " << sm_number ;  
02107 
02108   fgets (line,255,inpFile) ;
02109   //int nevents=atoi (line) ; // not necessary here just for online conddb
02110 
02111   fgets (line,255,inpFile) ;
02112   std::string gen_tag = line ;
02113   str << "gen tag: " << gen_tag ;  // should I use this? 
02114 
02115   fgets (line,255,inpFile) ;
02116   std::string cali_method = line ;
02117   str << "cali method: " << cali_method << std::endl ; // not important 
02118 
02119   fgets (line,255,inpFile) ;
02120   std::string cali_version = line ;
02121   str << "cali version: " << cali_version << std::endl ; // not important 
02122 
02123   fgets (line,255,inpFile) ;
02124   std::string cali_type = line ;
02125   str << "cali type: " << cali_type ; // not important
02126 
02127   edm::LogInfo("EcalTrivialConditionRetriever")
02128             << "[PIETRO] Intercalibration file - " 
02129             << str.str () << std::endl ;
02130 
02131   float calib[1700]={1} ;
02132   float calib_rms[1700]={0} ;
02133   int calib_nevents[1700]={0} ;
02134   int calib_status[1700]={0} ;
02135 
02136   int ii = 0 ;
02137 
02138   while (fgets (line,255,inpFile)) 
02139     {
02140       ii++;
02141       int dmy_num = 0 ;
02142       float dmy_calib = 0. ;
02143       float dmy_RMS = 0. ;
02144       int dmy_events = 0 ;
02145       int dmy_status = 0 ;
02146       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02147                                       &dmy_RMS, &dmy_events,
02148                                       &dmy_status) ;
02149       assert (dmy_num >= 1) ;
02150       assert (dmy_num <= 1700) ;
02151       calib[dmy_num-1] = dmy_calib ; 
02152       calib_rms[dmy_num-1] = dmy_RMS  ;
02153       calib_nevents[dmy_num-1] = dmy_events ;
02154       calib_status[dmy_num-1] = dmy_status ;
02155 
02156 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02157 //                 << "[PIETRO] cry = " << dmy_num 
02158 //                 << " calib = " << calib[dmy_num-1] 
02159 //                 << " RMS = " << calib_rms[dmy_num-1] 
02160 //                 << " events = " << calib_nevents[dmy_num-1] 
02161 //                 << " status = " << calib_status[dmy_num-1] 
02162 //                 << std::endl ;
02163     }
02164 
02165   fclose (inpFile) ;           // close inp. file
02166   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ; 
02167   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02168                 << "Some crystals missing, set to 1" << std::endl ;
02169 
02170   // Transfer the data to the inter-calibration coefficients container
02171   // -----------------------------------------------------------------
02172 
02173   // DB supermodule always set to 1 for the TestBeam FIXME
02174   int sm_db=1 ;
02175   // loop over channels 
02176   for (int i=0 ; i<1700 ; i++)
02177     {
02178       //if (EBDetId::validDetId(iEta,iPhi)) {
02179       // CANNOT be used -- validDetId only checks ETA PHI method
02180       // doing a check by hand, here is the only place in CMSSW 
02181       // outside TB code and EcalRawToDigi where needed
02182       // => no need for changing the DetId interface
02183       //
02184       // checking only sm_db -- guess can change with the above FIXME
02185       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02186         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02187         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02188         else ical->setValue (ebid.rawId (), 1.) ;
02189       }
02190       //}
02191     } // loop over channels 
02192         
02193 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02194   return ical;
02195 }
02196 
02197 
02198 std::auto_ptr<EcalIntercalibErrors> 
02199 EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration 
02200 ( const EcalIntercalibErrorsRcd& )
02201 {
02202   std::auto_ptr<EcalIntercalibErrors>  ical = 
02203       std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
02204 
02205   // Read the values from a txt file
02206   // -------------------------------
02207 
02208   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
02209                                                 << intercalibErrorsFile_.c_str() ;
02210 
02211   FILE *inpFile ;
02212   inpFile = fopen (intercalibErrorsFile_.c_str (),"r") ;
02213   if (!inpFile) 
02214     {
02215       edm::LogError ("EcalTrivialConditionRetriever") 
02216          << "*** Can not open file: " << intercalibErrorsFile_ ;
02217       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02218     }
02219 
02220   char line[256] ;
02221   std::ostringstream str ;
02222   fgets (line,255,inpFile) ;
02223   int sm_number=atoi (line) ;
02224   str << "sm: " << sm_number ;  
02225 
02226   fgets (line,255,inpFile) ;
02227   //int nevents=atoi (line) ; // not necessary here just for online conddb
02228 
02229   fgets (line,255,inpFile) ;
02230   std::string gen_tag = line ;
02231   str << "gen tag: " << gen_tag ;  // should I use this? 
02232 
02233   fgets (line,255,inpFile) ;
02234   std::string cali_method = line ;
02235   str << "cali method: " << cali_method << std::endl ; // not important 
02236 
02237   fgets (line,255,inpFile) ;
02238   std::string cali_version = line ;
02239   str << "cali version: " << cali_version << std::endl ; // not important 
02240 
02241   fgets (line,255,inpFile) ;
02242   std::string cali_type = line ;
02243   str << "cali type: " << cali_type ; // not important
02244 
02245   edm::LogInfo("EcalTrivialConditionRetriever")
02246             << "[PIETRO] Intercalibration file - " 
02247             << str.str () << std::endl ;
02248 
02249   float calib[1700]={1} ;
02250   float calib_rms[1700]={0} ;
02251   int calib_nevents[1700]={0} ;
02252   int calib_status[1700]={0} ;
02253 
02254   int ii = 0 ;
02255 
02256   while (fgets (line,255,inpFile)) 
02257     {
02258       ii++;
02259       int dmy_num = 0 ;
02260       float dmy_calib = 0. ;
02261       float dmy_RMS = 0. ;
02262       int dmy_events = 0 ;
02263       int dmy_status = 0 ;
02264       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02265                                       &dmy_RMS, &dmy_events,
02266                                       &dmy_status) ;
02267       assert (dmy_num >= 1) ;
02268       assert (dmy_num <= 1700) ;
02269       calib[dmy_num-1] = dmy_calib ; 
02270       calib_rms[dmy_num-1] = dmy_RMS  ;
02271       calib_nevents[dmy_num-1] = dmy_events ;
02272       calib_status[dmy_num-1] = dmy_status ;
02273 
02274 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02275 //                 << "[PIETRO] cry = " << dmy_num 
02276 //                 << " calib = " << calib[dmy_num-1] 
02277 //                 << " RMS = " << calib_rms[dmy_num-1] 
02278 //                 << " events = " << calib_nevents[dmy_num-1] 
02279 //                 << " status = " << calib_status[dmy_num-1] 
02280 //                 << std::endl ;
02281     }
02282 
02283   fclose (inpFile) ;           // close inp. file
02284   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ; 
02285   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02286                 << "Some crystals missing, set to 1" << std::endl ;
02287 
02288   // Transfer the data to the inter-calibration coefficients container
02289   // -----------------------------------------------------------------
02290 
02291   // DB supermodule always set to 1 for the TestBeam FIXME
02292   int sm_db=1 ;
02293   // loop over channels 
02294   for (int i=0 ; i<1700 ; i++)
02295     {
02296       //if (EBDetId::validDetId(iEta,iPhi)) {
02297       // CANNOT be used -- validDetId only checks ETA PHI method
02298       // doing a check by hand, here is the only place in CMSSW 
02299       // outside TB code and EcalRawToDigi where needed
02300       // => no need for changing the DetId interface
02301       //
02302       // checking only sm_db -- guess can change with the above FIXME
02303       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02304         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02305         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02306         else ical->setValue (ebid.rawId (), 1.) ;
02307       }
02308       //}
02309     } // loop over channels 
02310         
02311 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02312   return ical;
02313 }
02314 
02315 // --------------------------------------------------------------------------------
02316 
02317 
02318 std::auto_ptr<EcalTimeCalibConstants> 
02319 EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration 
02320 ( const EcalTimeCalibConstantsRcd& )
02321 {
02322   std::auto_ptr<EcalTimeCalibConstants>  ical = 
02323       std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
02324 
02325   // Read the values from a txt file
02326   // -------------------------------
02327 
02328   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading time calibration constants from file "
02329                                                 << timeCalibConstantsFile_.c_str() ;
02330 
02331   FILE *inpFile ;
02332   inpFile = fopen (timeCalibConstantsFile_.c_str (),"r") ;
02333   if (!inpFile) 
02334     {
02335       edm::LogError ("EcalTrivialConditionRetriever") 
02336          << "*** Can not open file: " << timeCalibConstantsFile_ ;
02337       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02338     }
02339 
02340   char line[256] ;
02341   std::ostringstream str ;
02342   fgets (line,255,inpFile) ;
02343   int sm_number=atoi (line) ;
02344   str << "sm: " << sm_number ;  
02345 
02346   fgets (line,255,inpFile) ;
02347   //int nevents=atoi (line) ; // not necessary here just for online conddb
02348 
02349   fgets (line,255,inpFile) ;
02350   std::string gen_tag = line ;
02351   str << "gen tag: " << gen_tag ;  // should I use this? 
02352 
02353   fgets (line,255,inpFile) ;
02354   std::string cali_method = line ;
02355   str << "cali method: " << cali_method << std::endl ; // not important 
02356 
02357   fgets (line,255,inpFile) ;
02358   std::string cali_version = line ;
02359   str << "cali version: " << cali_version << std::endl ; // not important 
02360 
02361   fgets (line,255,inpFile) ;
02362   std::string cali_type = line ;
02363   str << "cali type: " << cali_type ; // not important
02364 
02365   edm::LogInfo("EcalTrivialConditionRetriever")
02366             << "TimeCalibration file - " 
02367             << str.str () << std::endl ;
02368 
02369   float calib[1700]={1} ;
02370   float calib_rms[1700]={0} ;
02371   int calib_nevents[1700]={0} ;
02372   int calib_status[1700]={0} ;
02373 
02374   int ii = 0 ;
02375 
02376   while (fgets (line,255,inpFile)) 
02377     {
02378       ii++;
02379       int dmy_num = 0 ;
02380       float dmy_calib = 0. ;
02381       float dmy_RMS = 0. ;
02382       int dmy_events = 0 ;
02383       int dmy_status = 0 ;
02384       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02385                                       &dmy_RMS, &dmy_events,
02386                                       &dmy_status) ;
02387       assert (dmy_num >= 1) ;
02388       assert (dmy_num <= 1700) ;
02389       calib[dmy_num-1] = dmy_calib ; 
02390       calib_rms[dmy_num-1] = dmy_RMS  ;
02391       calib_nevents[dmy_num-1] = dmy_events ;
02392       calib_status[dmy_num-1] = dmy_status ;
02393 
02394 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02395 //                 << "[PIETRO] cry = " << dmy_num 
02396 //                 << " calib = " << calib[dmy_num-1] 
02397 //                 << " RMS = " << calib_rms[dmy_num-1] 
02398 //                 << " events = " << calib_nevents[dmy_num-1] 
02399 //                 << " status = " << calib_status[dmy_num-1] 
02400 //                 << std::endl ;
02401     }
02402 
02403   fclose (inpFile) ;           // close inp. file
02404   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read timeCalibrations for " << ii << " xtals " ; 
02405   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02406                 << "Some crystals missing, set to 1" << std::endl ;
02407 
02408   // Transfer the data to the inter-calibration coefficients container
02409   // -----------------------------------------------------------------
02410 
02411   // DB supermodule always set to 1 for the TestBeam FIXME
02412   int sm_db=1 ;
02413   // loop over channels 
02414   for (int i=0 ; i<1700 ; i++)
02415     {
02416       //if (EBDetId::validDetId(iEta,iPhi)) {
02417       // CANNOT be used -- validDetId only checks ETA PHI method
02418       // doing a check by hand, here is the only place in CMSSW 
02419       // outside TB code and EcalRawToDigi where needed
02420       // => no need for changing the DetId interface
02421       //
02422       // checking only sm_db -- guess can change with the above FIXME
02423       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02424         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02425         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02426         else ical->setValue (ebid.rawId (), 1.) ;
02427       }
02428       //}
02429     } // loop over channels 
02430         
02431 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02432   return ical;
02433 }
02434 
02435 
02436 std::auto_ptr<EcalTimeCalibErrors> 
02437 EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration 
02438 ( const EcalTimeCalibErrorsRcd& )
02439 {
02440   std::auto_ptr<EcalTimeCalibErrors>  ical = 
02441       std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
02442 
02443   // Read the values from a txt file
02444   // -------------------------------
02445 
02446   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading timeCalibration constants from file "
02447                                                 << timeCalibErrorsFile_.c_str() ;
02448 
02449   FILE *inpFile ;
02450   inpFile = fopen (timeCalibErrorsFile_.c_str (),"r") ;
02451   if (!inpFile) 
02452     {
02453       edm::LogError ("EcalTrivialConditionRetriever") 
02454          << "*** Can not open file: " << timeCalibErrorsFile_ ;
02455       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02456     }
02457 
02458   char line[256] ;
02459   std::ostringstream str ;
02460   fgets (line,255,inpFile) ;
02461   int sm_number=atoi (line) ;
02462   str << "sm: " << sm_number ;  
02463 
02464   fgets (line,255,inpFile) ;
02465   //int nevents=atoi (line) ; // not necessary here just for online conddb
02466 
02467   fgets (line,255,inpFile) ;
02468   std::string gen_tag = line ;
02469   str << "gen tag: " << gen_tag ;  // should I use this? 
02470 
02471   fgets (line,255,inpFile) ;
02472   std::string cali_method = line ;
02473   str << "cali method: " << cali_method << std::endl ; // not important 
02474 
02475   fgets (line,255,inpFile) ;
02476   std::string cali_version = line ;
02477   str << "cali version: " << cali_version << std::endl ; // not important 
02478 
02479   fgets (line,255,inpFile) ;
02480   std::string cali_type = line ;
02481   str << "cali type: " << cali_type ; // not important
02482 
02483   edm::LogInfo("EcalTrivialConditionRetriever")
02484             << "TimeCalibration file - " 
02485             << str.str () << std::endl ;
02486 
02487   float calib[1700]={1} ;
02488   float calib_rms[1700]={0} ;
02489   int calib_nevents[1700]={0} ;
02490   int calib_status[1700]={0} ;
02491 
02492   int ii = 0 ;
02493 
02494   while (fgets (line,255,inpFile)) 
02495     {
02496       ii++;
02497       int dmy_num = 0 ;
02498       float dmy_calib = 0. ;
02499       float dmy_RMS = 0. ;
02500       int dmy_events = 0 ;
02501       int dmy_status = 0 ;
02502       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02503                                       &dmy_RMS, &dmy_events,
02504                                       &dmy_status) ;
02505       assert (dmy_num >= 1) ;
02506       assert (dmy_num <= 1700) ;
02507       calib[dmy_num-1] = dmy_calib ; 
02508       calib_rms[dmy_num-1] = dmy_RMS  ;
02509       calib_nevents[dmy_num-1] = dmy_events ;
02510       calib_status[dmy_num-1] = dmy_status ;
02511 
02512 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02513 //                 << "[PIETRO] cry = " << dmy_num 
02514 //                 << " calib = " << calib[dmy_num-1] 
02515 //                 << " RMS = " << calib_rms[dmy_num-1] 
02516 //                 << " events = " << calib_nevents[dmy_num-1] 
02517 //                 << " status = " << calib_status[dmy_num-1] 
02518 //                 << std::endl ;
02519     }
02520 
02521   fclose (inpFile) ;           // close inp. file
02522   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read time calibrations for " << ii << " xtals " ; 
02523   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02524                 << "Some crystals missing, set to 1" << std::endl ;
02525 
02526   // Transfer the data to the inter-calibration coefficients container
02527   // -----------------------------------------------------------------
02528 
02529   // DB supermodule always set to 1 for the TestBeam FIXME
02530   int sm_db=1 ;
02531   // loop over channels 
02532   for (int i=0 ; i<1700 ; i++)
02533     {
02534       //if (EBDetId::validDetId(iEta,iPhi)) {
02535       // CANNOT be used -- validDetId only checks ETA PHI method
02536       // doing a check by hand, here is the only place in CMSSW 
02537       // outside TB code and EcalRawToDigi where needed
02538       // => no need for changing the DetId interface
02539       //
02540       // checking only sm_db -- guess can change with the above FIXME
02541       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02542         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02543         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02544         else ical->setValue (ebid.rawId (), 1.) ;
02545       }
02546       //}
02547     } // loop over channels 
02548         
02549 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02550   return ical;
02551 }
02552 
02553 // --------------------------------------------------------------------------------
02554 
02555 std::auto_ptr<EcalMappingElectronics>
02556 EcalTrivialConditionRetriever::getMappingFromConfiguration (const EcalMappingElectronicsRcd&)
02557 {
02558   std::auto_ptr<EcalMappingElectronics> mapping = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
02559   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading mapping from file " << edm::FileInPath(mappingFile_).fullPath().c_str() ;
02560   
02561   std::ifstream f(edm::FileInPath(mappingFile_).fullPath().c_str());
02562   if (!f.good())
02563     {
02564       edm::LogError("EcalTrivialConditionRetriever") << "File not found";
02565       throw cms::Exception("FileNotFound");
02566     }
02567   
02568   // uint32_t detid, elecid, triggerid;
02569   
02570   int ix, iy, iz, CL;
02571   // int dccid, towerid, stripid, xtalid;
02572   // int tccid, tower, ipseudostrip, xtalinps;
02573   int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
02574   int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
02575   
02576   while ( ! f.eof()) 
02577     {
02578       // f >> detid >> elecid >> triggerid; 
02579       f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >> 
02580         pseudostrip_in_TCC >> pseudostrip_in_TT ;
02581       
02582 //       if (!EEDetId::validDetId(ix,iy,iz))
02583 //        continue;
02584           
02585       EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
02586       // std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
02587       EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
02588       // std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
02589       EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
02590       EcalMappingElement aElement;
02591       aElement.electronicsid = elecid.rawId();
02592       aElement.triggerid = triggerid.rawId();
02593       (*mapping).setValue(detid, aElement);
02594     }
02595   
02596   f.close();
02597   return mapping;
02598 }
02599 
02600 
02601 
02602 std::auto_ptr<EcalMappingElectronics>
02603 EcalTrivialConditionRetriever::produceEcalMappingElectronics( const EcalMappingElectronicsRcd& )
02604 {
02605 
02606         std::auto_ptr<EcalMappingElectronics>  ical = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
02607         return ical;
02608 }
02609 
02610 // --------------------------------------------------------------------------------
02611 
02612 std::auto_ptr<Alignments>
02613 EcalTrivialConditionRetriever::produceEcalAlignmentEB( const EBAlignmentRcd& ) {
02614   double mytrans[3] = {0., 0., 0.};
02615   double myeuler[3] = {0., 0., 0.};
02616   std::ifstream f(edm::FileInPath(EBAlignmentFile_).fullPath().c_str());
02617   std::vector<AlignTransform> my_align;
02618   int ieta = 1;
02619   int iphi = 0;
02620   for(int SM = 1 ; SM < 37; SM++ ) {
02621     // make an EBDetId since we need EBDetId::rawId()
02622     if(SM > 18) { 
02623       iphi = 1 + (SM - 19) * 20;
02624       ieta = -1;
02625     }
02626     else
02627       iphi = SM * 20;
02628     EBDetId ebdetId(ieta,iphi);
02629     if(getEBAlignmentFromFile_) {
02630       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02631       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02632            << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02633     }
02634     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02635     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02636     AlignTransform transform( translation, euler, ebdetId );
02637     my_align.push_back(transform);
02638   }
02639   /*
02640   // check
02641   uint32_t m_rawid;
02642   double m_x, m_y, m_z;
02643   double m_phi, m_theta, m_psi;
02644   int SM = 0;
02645   for (std::vector<AlignTransform>::const_iterator i = my_align.begin(); i != my_align.end(); ++i){     
02646     m_rawid = i->rawId();
02647     CLHEP::Hep3Vector translation = i->translation();
02648     m_x = translation.x();
02649     m_y = translation.y();
02650     m_z = translation.z();
02651     CLHEP::HepRotation rotation = i->rotation();
02652     m_phi = rotation.getPhi();
02653     m_theta = rotation.getTheta();
02654     m_psi = rotation.getPsi();
02655     SM++;
02656     std::cout << " SM " << SM << " Id " << m_rawid << " x " << m_x << " y " << m_y << " z " << m_z
02657               << " phi " << m_phi << " theta " << m_theta << " psi " << m_psi << std::endl;
02658   }
02659   */
02660   Alignments a; 
02661   a.m_align = my_align; 
02662 
02663   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02664   return ical;
02665 }
02666 
02667 std::auto_ptr<Alignments>
02668 EcalTrivialConditionRetriever::produceEcalAlignmentEE( const EEAlignmentRcd& ) {
02669   double mytrans[3] = {0., 0., 0.};
02670   double myeuler[3] = {0., 0., 0.};
02671   std::ifstream f(edm::FileInPath(EEAlignmentFile_).fullPath().c_str());
02672   std::vector<AlignTransform> my_align;
02673   int ix = 20;
02674   int iy = 50;
02675   int side = -1;
02676   for(int Dee = 0 ; Dee < 4; Dee++ ) {
02677     // make an EEDetId since we need EEDetId::rawId()
02678     if(Dee == 1 || Dee == 3) 
02679       ix = 70;
02680     else ix = 20;
02681     if(Dee == 2)
02682       side = 1;
02683     EEDetId eedetId(ix, iy, side);
02684     if(getEEAlignmentFromFile_) {
02685       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02686       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02687            << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02688     }
02689     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02690     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02691     AlignTransform transform( translation, euler, eedetId );
02692     my_align.push_back(transform);
02693   }
02694   Alignments a; 
02695   a.m_align = my_align; 
02696   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02697   return ical;
02698 }
02699 
02700 std::auto_ptr<Alignments>
02701 EcalTrivialConditionRetriever::produceEcalAlignmentES( const ESAlignmentRcd& ) {
02702   double mytrans[3] = {0., 0., 0.};
02703   double myeuler[3] = {0., 0., 0.};
02704   std::ifstream f(edm::FileInPath(ESAlignmentFile_).fullPath().c_str());
02705   std::vector<AlignTransform> my_align;
02706   //  int ix_vect[10] = {10, 30, 30, 50, 10, 30, 10, 30};
02707   int pl_vect[10] = {2, 2, 1, 1, 1, 1, 2, 2};
02708   int iy = 10;
02709   int side = -1;
02710   int strip = 1;
02711   for(int layer = 0 ; layer < 8; layer++ ) {
02712     // make an ESDetId since we need ESDetId::rawId()
02713     int ix = 10 + (layer%2) * 20;
02714     int plane = pl_vect[layer];
02715     if(layer > 3) side = 1;
02716     ESDetId esdetId(strip, ix, iy, plane, side);
02717     if(getESAlignmentFromFile_) {
02718       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02719       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02720                 << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02721     }
02722     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02723     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02724     AlignTransform transform( translation, euler, esdetId );
02725     my_align.push_back(transform);
02726   }
02727   Alignments a; 
02728   a.m_align = my_align; 
02729   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02730   return ical;
02731 }