CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CondTools/Ecal/src/EcalTestDevDB.cc

Go to the documentation of this file.
00001 #include "FWCore/ServiceRegistry/interface/Service.h"
00002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00003 
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 
00008 #include "DataFormats/Common/interface/Handle.h"
00009 
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
00013 
00014 #include "DataFormats/Provenance/interface/Timestamp.h"
00015 
00016 #include "CondTools/Ecal/interface/EcalTestDevDB.h"
00017 
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include <map>
00021 #include <vector>
00022 
00023 using namespace std;
00024 
00025 EcalTestDevDB::EcalTestDevDB(const edm::ParameterSet& iConfig) :
00026   m_timetype(iConfig.getParameter<std::string>("timetype")),
00027   m_cacheIDs(),
00028   m_records()
00029 {
00030 
00031   std::string container;
00032   std::string tag;
00033   std::string record;
00034 
00035   m_firstRun=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("firstRun").c_str()));
00036   m_lastRun=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("lastRun").c_str()));
00037   m_interval=static_cast<unsigned long>(atoi( iConfig.getParameter<std::string>("interval").c_str()));
00038 
00039   typedef std::vector< edm::ParameterSet > Parameters;
00040   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
00041   for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
00042     container = i->getParameter<std::string>("container");
00043     record = i->getParameter<std::string>("record");
00044     m_cacheIDs.insert( std::make_pair(container, 0) );
00045     m_records.insert( std::make_pair(container, record) );
00046   }
00047   
00048 }
00049 
00050 
00051 EcalTestDevDB::~EcalTestDevDB()
00052 {
00053   
00054 }
00055 
00056 void EcalTestDevDB::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
00057 {
00058 
00059   edm::Service<cond::service::PoolDBOutputService> dbOutput;
00060   if ( !dbOutput.isAvailable() ) {
00061     throw cms::Exception("PoolDBOutputService is not available");
00062   }
00063 
00064  
00065 
00066   std::string container;
00067   std::string record;
00068   typedef std::map<std::string, std::string>::const_iterator recordIter;
00069   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00070     container = (*i).first;
00071     record = (*i).second;
00072 
00073     std::string recordName = m_records[container];
00074 
00075     
00076     // Loop through each of the runs
00077 
00078     unsigned long nrec=(m_lastRun-m_firstRun)/m_interval+1;
00079     unsigned long nstart=0;
00080     if (m_firstRun == 0 && m_lastRun == 0) {
00081        // it should do at least once the loop
00082       nstart=0;
00083       nrec=1;
00084     }
00085 
00086     for(unsigned long i=nstart; i<nrec; i++) {
00087       unsigned long irun=m_firstRun+i*m_interval;
00088  
00089  
00090       // Arguments 0 0 mean infinite IOV
00091       if (m_firstRun == 0 && m_lastRun == 0) {
00092         std::cout << "Infinite IOV mode" << std::endl;
00093         irun = edm::IOVSyncValue::endOfTime().eventID().run();
00094       }
00095 
00096       std::cout << "Starting Transaction for run " << irun << "..." << std::flush;
00097     
00098       if (container == "EcalPedestals") {
00099         EcalPedestals* condObject= generateEcalPedestals();
00100 
00101         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00102           // create new
00103           std::cout<<"First One "<<std::endl;
00104           dbOutput->createNewIOV<const EcalPedestals>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00105         } else {
00106           // append
00107           std::cout<<"Old One "<<std::endl;
00108           dbOutput->appendSinceTime<const EcalPedestals>( condObject, irun , recordName);
00109         }
00110         
00111       } else if (container == "EcalADCToGeVConstant") {
00112         
00113         EcalADCToGeVConstant* condObject= generateEcalADCToGeVConstant();
00114         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00115           // create new
00116           std::cout<<"First One "<<std::endl;
00117           dbOutput->createNewIOV<const EcalADCToGeVConstant>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00118         } else {
00119           // append
00120           std::cout<<"Old One "<<std::endl;
00121           dbOutput->appendSinceTime<const EcalADCToGeVConstant>( condObject, irun , recordName);
00122         }
00123         
00124         
00125       } else if (container == "EcalIntercalibConstants") {
00126         EcalIntercalibConstants* condObject= generateEcalIntercalibConstants();
00127         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00128           // create new
00129           std::cout<<"First One "<<std::endl;
00130           dbOutput->createNewIOV<const EcalIntercalibConstants>( condObject, dbOutput->beginOfTime(),dbOutput->endOfTime() ,recordName);
00131         } else {
00132           // append
00133           std::cout<<"Old One "<<std::endl;
00134           dbOutput->appendSinceTime<const EcalIntercalibConstants>( condObject, irun , recordName);
00135         }
00136         
00137       } else if (container == "EcalGainRatios") {
00138         EcalGainRatios* condObject= generateEcalGainRatios();
00139         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00140           // create new
00141           std::cout<<"First One "<<std::endl;
00142           dbOutput->createNewIOV<const EcalGainRatios>( condObject,dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00143         } else {
00144           // append
00145           std::cout<<"Old One "<<std::endl;
00146           dbOutput->appendSinceTime<const EcalGainRatios>( condObject, irun , recordName);
00147         }
00148         
00149       } else if (container == "EcalWeightXtalGroups") {
00150         EcalWeightXtalGroups* condObject= generateEcalWeightXtalGroups();
00151         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00152           // create new
00153           std::cout<<"First One "<<std::endl;
00154           dbOutput->createNewIOV<const EcalWeightXtalGroups>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00155         } else {
00156           // append
00157           std::cout<<"Old One "<<std::endl;
00158           dbOutput->appendSinceTime<const EcalWeightXtalGroups>( condObject, irun , recordName);
00159         }
00160         
00161       } else if (container == "EcalTBWeights") {
00162         EcalTBWeights* condObject= generateEcalTBWeights();
00163         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00164           // create new
00165           std::cout<<"First One "<<std::endl;
00166           dbOutput->createNewIOV<const EcalTBWeights>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00167         } else {
00168           // append
00169           std::cout<<"Old One "<<std::endl;
00170           dbOutput->appendSinceTime<const EcalTBWeights>( condObject, irun , recordName);
00171         }
00172         
00173       } else if (container == "EcalLaserAPDPNRatios") {
00174         EcalLaserAPDPNRatios* condObject= generateEcalLaserAPDPNRatios(irun);
00175         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00176           // create new
00177           std::cout<<"First One "<<std::endl;
00178           dbOutput->createNewIOV<const EcalLaserAPDPNRatios>( condObject,dbOutput->beginOfTime(),  dbOutput->endOfTime() ,recordName);
00179         } else {
00180           // append
00181           std::cout<<"Old One "<<std::endl;
00182           dbOutput->appendSinceTime<const EcalLaserAPDPNRatios>( condObject, irun , recordName);
00183         }
00184       } else if (container == "EcalLaserAPDPNRatiosRef") {
00185         EcalLaserAPDPNRatiosRef* condObject= generateEcalLaserAPDPNRatiosRef();
00186         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00187           // create new
00188           std::cout<<"First One "<<std::endl;
00189           dbOutput->createNewIOV<const EcalLaserAPDPNRatiosRef>( condObject, dbOutput->beginOfTime(), dbOutput->endOfTime() ,recordName);
00190         } else {
00191           // append
00192           std::cout<<"Old One "<<std::endl;
00193           dbOutput->appendSinceTime<const EcalLaserAPDPNRatiosRef>( condObject, irun , recordName);
00194         }
00195       } else if (container == "EcalLaserAlphas") {
00196         EcalLaserAlphas* condObject= generateEcalLaserAlphas();
00197         if(irun==m_firstRun && dbOutput->isNewTagRequest(recordName)) {
00198           // create new
00199           std::cout<<"First One "<<std::endl;
00200           dbOutput->createNewIOV<const EcalLaserAlphas>( condObject,dbOutput->beginOfTime(),  dbOutput->endOfTime() ,recordName);
00201         } else {
00202           // append
00203           std::cout<<"Old One "<<std::endl;
00204           dbOutput->appendSinceTime<const EcalLaserAlphas>( condObject, irun , recordName);
00205         }
00206       } else {
00207         std::cout << "it does not work yet for " << container << "..." << std::flush;
00208         
00209       }
00210       
00211       
00212     }
00213     
00214     
00215   }
00216   
00217   
00218 }
00219 
00220 
00221 //-------------------------------------------------------------
00222 EcalPedestals*
00223 EcalTestDevDB::generateEcalPedestals() {
00224 //-------------------------------------------------------------
00225 
00226   EcalPedestals* peds = new EcalPedestals();
00227   EcalPedestals::Item item;
00228   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00229     if(iEta==0) continue;
00230     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00231       item.mean_x1  = 200.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00232       item.rms_x1   = (double)std::rand()/(double(RAND_MAX)+double(1));
00233       item.mean_x6  = 1200.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00234       item.rms_x6   = 6.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00235       item.mean_x12 = 2400.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00236       item.rms_x12  = 12.*( (double)std::rand()/(double(RAND_MAX)+double(1)) );
00237 
00238       EBDetId ebdetid(iEta,iPhi);
00239       peds->insert(std::make_pair(ebdetid.rawId(),item));
00240     }
00241   }
00242   return peds;
00243 }
00244 
00245 //-------------------------------------------------------------
00246 EcalADCToGeVConstant*
00247 EcalTestDevDB::generateEcalADCToGeVConstant() {
00248 //-------------------------------------------------------------
00249   
00250   double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00251   EcalADCToGeVConstant* agc = new EcalADCToGeVConstant(36.+r*4., 60.+r*4);
00252   return agc;
00253 }
00254 
00255 //-------------------------------------------------------------
00256 EcalIntercalibConstants*
00257 EcalTestDevDB::generateEcalIntercalibConstants() {
00258 //-------------------------------------------------------------
00259 
00260   EcalIntercalibConstants* ical = new EcalIntercalibConstants();
00261 
00262   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00263     if(ieta==0) continue;
00264     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00265 
00266       EBDetId ebid(ieta,iphi);
00267 
00268       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00269       ical->setValue( ebid.rawId(), 0.85 + r*0.3 );
00270     } // loop over phi
00271   } // loop over eta
00272   return ical;
00273 }
00274 
00275 //-------------------------------------------------------------
00276 EcalGainRatios*
00277 EcalTestDevDB::generateEcalGainRatios() {
00278 //-------------------------------------------------------------
00279 
00280   // create gain ratios
00281   EcalGainRatios* gratio = new EcalGainRatios;
00282 
00283   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00284     if(ieta==0) continue;
00285     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00286 
00287       EBDetId ebid(ieta,iphi);
00288 
00289       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00290 
00291       EcalMGPAGainRatio gr;
00292       gr.setGain12Over6( 1.9 + r*0.2 );
00293       gr.setGain6Over1( 5.9 + r*0.2 );
00294 
00295       gratio->setValue( ebid.rawId(), gr );
00296 
00297     } // loop over phi
00298   } // loop over eta
00299   return gratio;
00300 }
00301 
00302 //-------------------------------------------------------------
00303 EcalWeightXtalGroups*
00304 EcalTestDevDB::generateEcalWeightXtalGroups() {
00305 //-------------------------------------------------------------
00306 
00307   EcalWeightXtalGroups* xtalGroups = new EcalWeightXtalGroups();
00308   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00309     if(ieta==0) continue;
00310     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId:: MAX_IPHI; ++iphi) {
00311       EBDetId ebid(ieta,iphi);
00312       xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
00313     }
00314   }
00315   return xtalGroups;
00316 }
00317 
00318 //-------------------------------------------------------------
00319 EcalTBWeights*
00320 EcalTestDevDB::generateEcalTBWeights() {
00321 //-------------------------------------------------------------
00322 
00323   EcalTBWeights* tbwgt = new EcalTBWeights();
00324 
00325   // create weights for each distinct group ID
00326   int nMaxTDC = 10;
00327   for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
00328     if(igrp==0) continue;
00329     for(int itdc=1; itdc<=nMaxTDC; ++itdc) {
00330       // generate random number
00331       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00332 
00333       // make a new set of weights
00334       EcalWeightSet wgt;
00335       EcalWeightSet::EcalWeightMatrix& mat1 = wgt.getWeightsBeforeGainSwitch();
00336       EcalWeightSet::EcalWeightMatrix& mat2 = wgt.getWeightsAfterGainSwitch();
00337 
00338       for(size_t i=0; i<3; ++i) {
00339         for(size_t j=0; j<10; ++j) {
00340           double ww = igrp*itdc*r + i*10. + j;
00341           //std::cout << "row: " << i << " col: " << j << " -  val: " << ww  << std::endl;
00342           mat1(i,j)=ww;
00343           mat2(i,j)=100+ww;
00344         }
00345       }
00346 
00347       // fill the chi2 matrcies
00348       r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00349       EcalWeightSet::EcalChi2WeightMatrix& mat3 = wgt.getChi2WeightsBeforeGainSwitch();
00350       EcalWeightSet::EcalChi2WeightMatrix& mat4 = wgt.getChi2WeightsAfterGainSwitch();
00351       for(size_t i=0; i<10; ++i) {
00352         for(size_t j=0; j<10; ++j) {
00353           double ww = igrp*itdc*r + i*10. + j;
00354           mat3(i,j)=1000+ww;
00355           mat4(i,j)=1000+100+ww;
00356         }
00357       }
00358 
00359       // put the weight in the container
00360       tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
00361     }
00362   }
00363   return tbwgt;
00364 }
00365 
00366 
00367 
00368 //--------------------------------------------------------------
00369 EcalLaserAPDPNRatios*
00370 EcalTestDevDB::generateEcalLaserAPDPNRatios(uint32_t i_run) {
00371 //--------------------------------------------------------------
00372 
00373   EcalLaserAPDPNRatios* laser = new EcalLaserAPDPNRatios();
00374 
00375   EcalLaserAPDPNRatios::EcalLaserAPDPNpair APDPNpair;
00376   EcalLaserAPDPNRatios::EcalLaserTimeStamp TimeStamp;
00377 
00378   //  if((m_firstRun == 0 && i_run == 0) || (m_firstRun == 1 && i_run == 1)){ 
00379 
00380   std::cout << "First & last run: " << i_run << " " << m_firstRun << " " << m_lastRun << " " << std::endl;
00381   if (m_firstRun == i_run && (i_run == 0 || i_run == 1) ) {
00382 
00383     APDPNpair.p1= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10))))/double(2);
00384     APDPNpair.p2= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10)+double(10))))/double(2);
00385     APDPNpair.p3= double(0);
00386     std::cout << i_run << " " << m_firstRun << " " << APDPNpair.p1 << " " << APDPNpair.p2 << std::endl;
00387 
00388     for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00389       if(iEta==0) continue;
00390       for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00391         //APDPNpair.p1= double(1);
00392         //APDPNpair.p2= double(1);
00393         
00394         EBDetId ebid(iEta,iPhi);        
00395         int hi = ebid.hashedIndex();
00396 
00397         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00398           laser->setValue(hi, APDPNpair);
00399         } else {
00400           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00401           continue;
00402         }
00403       }
00404     }
00405 
00406     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00407       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00408         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00409 
00410         if (!EEDetId::validDetId(iX,iY,1))
00411           continue;
00412 
00413         EEDetId eedetidpos(iX,iY,1);
00414         //APDPNpair.p1 = double(1);
00415         //APDPNpair.p2 = double(1);
00416         
00417         int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00418         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00419           laser->setValue(hi, APDPNpair);
00420         } else {
00421           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00422           continue;
00423         }
00424         
00425         if (!EEDetId::validDetId(iX,iY,-1))
00426           continue;
00427 
00428         EEDetId eedetidneg(iX,iY,-1);
00429         //APDPNpair.p1 = double(1);
00430         //APDPNpair.p2 = double(1);
00431         hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00432         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00433           laser->setValue(hi, APDPNpair);
00434         } else {
00435               edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;             
00436               continue;
00437         }
00438       }
00439     }
00440     
00441     std::cout << std::endl;
00442     for(int i=0; i<92; i++){
00443       if (i< static_cast<int>(laser->getTimeMap().size())) {
00444         TimeStamp.t1 = edm::Timestamp(1380*(i_run-m_firstRun) + 15*i);
00445         TimeStamp.t2 = edm::Timestamp(1380*(i_run-m_firstRun + 1) + 15*i);
00446         laser->setTime(i, TimeStamp);
00447         //std::cout << " Timestamp for " << i << " : " << TimeStamp.t1.value() << " , " << TimeStamp.t2.value() << std::endl;
00448       } else {
00449         edm::LogError("EcalTestDevDB") << "error with laser Map (time)!" << std::endl;            
00450         continue;
00451       }
00452     }
00453     
00454   }else{
00455 
00456     APDPNpair.p1= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10))))/double(2);
00457     APDPNpair.p2= (double(1)+1/double(log(exp(1)+double((i_run-m_firstRun)*10)+double(10))))/double(2);
00458     APDPNpair.p3= double(0);
00459     std::cout << i_run << " " << m_firstRun << " " << APDPNpair.p1 << " " << APDPNpair.p2 << std::endl;
00460 
00461     for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00462       if(iEta==0) continue;
00463       for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00464         EBDetId ebid(iEta,iPhi);
00465         int hi = ebid.hashedIndex();
00466 
00467         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00468           laser->setValue(hi, APDPNpair);
00469         } else {
00470           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00471         }
00472       }
00473     }
00474     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00475       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00476         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00477 
00478         if (!EEDetId::validDetId(iX,iY,1))
00479           continue;
00480         
00481         EEDetId eedetidpos(iX,iY,1);    
00482         int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00483         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00484           laser->setValue(hi, APDPNpair);
00485         } else {
00486           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00487           continue;
00488         }
00489         
00490         if (!EEDetId::validDetId(iX,iY,-1))
00491           continue;    
00492         
00493         EEDetId eedetidneg(iX,iY,-1);
00494         hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00495         if (hi< static_cast<int>(laser->getLaserMap().size())) {
00496           laser->setValue(hi, APDPNpair);
00497         } else {
00498           edm::LogError("EcalTestDevDB") << "error with laser Map (ratio)!" << std::endl;         
00499           continue;
00500         }
00501       }           
00502     }
00503  
00504     std::cout << std::endl;
00505     for(int i=0; i<92; i++){
00506       if (i< static_cast<int>(laser->getTimeMap().size())) {
00507         TimeStamp.t1 = edm::Timestamp(1380*(i_run-m_firstRun) + 15*i);
00508         TimeStamp.t2 = edm::Timestamp(1380*(i_run-m_firstRun + 1) + 15*i);
00509         laser->setTime(i, TimeStamp);
00510         //std::cout << " Timestamp for " << i << " : " << TimeStamp.t1.value() << " , " << TimeStamp.t2.value() << std::endl;
00511       } else {
00512         edm::LogError("EcalTestDevDB") << "error with laser Map (time)!" << std::endl;            
00513         continue;
00514       }
00515     }
00516     
00517   }
00518 
00519   return laser;
00520 }
00521 
00522 
00523 //--------------------------------------------------------------
00524 EcalLaserAPDPNRatiosRef*
00525 EcalTestDevDB::generateEcalLaserAPDPNRatiosRef() {
00526 //--------------------------------------------------------------
00527 
00528   EcalLaserAPDPNRatiosRef* laser = new EcalLaserAPDPNRatiosRef();
00529 
00530   EcalLaserAPDPNref APDPNref;
00531  
00532  
00533   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00534     if(iEta==0) continue;
00535     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00536       APDPNref=double(1.5);   
00537       EBDetId ebid(iEta,iPhi);
00538 
00539       int hi = ebid.hashedIndex();
00540       if (hi< static_cast<int>(laser->getMap().size())) {
00541         laser->setValue(hi, APDPNref);
00542       } else {
00543         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00544       }
00545       
00546     }
00547   }
00548 
00549   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00550     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00551       
00552       if (!EEDetId::validDetId(iX,iY,1))
00553         continue;         
00554       
00555       EEDetId eedetidpos(iX,iY,1);
00556       APDPNref=double(1.5);
00557       
00558       int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00559       if (hi< static_cast<int>(laser->getMap().size())) {
00560         laser->setValue(hi, APDPNref);
00561       } else {
00562         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00563       }
00564       
00565       if (!EEDetId::validDetId(iX,iY,-1))
00566         continue;         
00567   
00568       EEDetId eedetidneg(iX,iY,-1);
00569       APDPNref=double(1.5);
00570       
00571       hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00572       if (hi< static_cast<int>(laser->getMap().size())) {
00573         laser->setValue(hi, APDPNref);
00574       } else {
00575         edm::LogError("EcalTestDevDB") << "error with laser Map (ref)!" << std::endl;             
00576       }
00577     }   
00578   }
00579 
00580   return laser;
00581 }
00582 
00583 //--------------------------------------------------------------
00584 EcalLaserAlphas*
00585 EcalTestDevDB::generateEcalLaserAlphas() {
00586 //--------------------------------------------------------------
00587 
00588   EcalLaserAlphas* laser = new EcalLaserAlphas();
00589 
00590   EcalLaserAlpha Alpha;
00591  
00592   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00593     if(iEta==0) continue;
00594     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00595       Alpha = double(1.55);
00596       EBDetId ebid(iEta,iPhi);
00597 
00598       int hi = ebid.hashedIndex();
00599       if (hi< static_cast<int>(laser->getMap().size())) {
00600         laser->setValue(hi, Alpha);
00601       } else {
00602         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;                 
00603       }
00604     }
00605   }
00606 
00607   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00608     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00609 
00610       if (!EEDetId::validDetId(iX,iY,1))
00611         continue;         
00612 
00613       EEDetId eedetidpos(iX,iY,1);
00614       Alpha = double(1.55);
00615       
00616       int hi = eedetidpos.hashedIndex() + EBDetId::MAX_HASH + 1;
00617       if (hi< static_cast<int>(laser->getMap().size())) {
00618         laser->setValue(hi, Alpha);
00619       } else {
00620         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;           
00621       }
00622       
00623       if (!EEDetId::validDetId(iX,iY,-1))
00624         continue;         
00625       EEDetId eedetidneg(iX,iY,-1);
00626       Alpha = double(1.55);
00627       
00628       hi = eedetidneg.hashedIndex() + EBDetId::MAX_HASH + 1;
00629       if (hi< static_cast<int>(laser->getMap().size())) {
00630         laser->setValue(hi, Alpha);
00631       } else {
00632         edm::LogError("EcalTestDevDB") << "error with laser Map (alpha)!" << std::endl;           
00633       }
00634     }
00635   }
00636   
00637   return laser;
00638 }