CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CondTools/SiStrip/plugins/SiStripSummaryBuilder.cc

Go to the documentation of this file.
00001 #include "CondTools/SiStrip/plugins/SiStripSummaryBuilder.h"
00002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00003 #include <iostream>
00004 #include <fstream>
00005 
00006 SiStripSummaryBuilder::SiStripSummaryBuilder( const edm::ParameterSet& iConfig ):
00007   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00008   printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)),
00009   iConfig_(iConfig){}
00010 
00011 void SiStripSummaryBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup){
00012 
00013   unsigned int run=evt.id().run();
00014   edm::LogInfo("SiStripSummaryBuilder") << "... creating dummy SiStripSummary Data for Run " << run << "\n " << std::endl;
00015 
00016 
00017   SiStripSummary* obj = new SiStripSummary();
00018   obj->setRunNr(run);
00019 
00020 
00021   //* DISCOVER SET OF HISTOGRAMS & QUANTITIES TO BE UPLOADED*//
00022   
00023   std::vector<std::string> userDBContent;
00024   typedef std::vector<edm::ParameterSet> VParameters;
00025   VParameters histoList = iConfig_.getParameter<VParameters>("histoList");
00026   VParameters::iterator ithistoList = histoList.begin();
00027   VParameters::iterator ithistoListEnd = histoList.end();
00028   
00029   for(; ithistoList != ithistoListEnd; ++ithistoList ) {    
00030     std::string keyName = ithistoList->getUntrackedParameter<std::string>("keyName");
00031     std::vector<std::string> Quantities = ithistoList->getUntrackedParameter<std::vector<std::string> >("quantitiesToExtract"); 
00032     for (size_t i=0;i<Quantities.size();++i){
00033       
00034       if  ( Quantities[i] == "landau" ){ 
00035         userDBContent.push_back(keyName+std::string("@")+std::string("landauPeak"));
00036         userDBContent.push_back(keyName+std::string("@")+std::string("landauPeakErr"));
00037         userDBContent.push_back(keyName+std::string("@")+std::string("landauSFWHM"));
00038         userDBContent.push_back(keyName+std::string("@")+std::string("landauChi2NDF"));
00039       }
00040       else if  ( Quantities[i] == "gauss" ){ 
00041         userDBContent.push_back(keyName+std::string("@")+std::string("gaussMean"));
00042         userDBContent.push_back(keyName+std::string("@")+std::string("gaussSigma"));
00043         userDBContent.push_back(keyName+std::string("@")+std::string("gaussChi2NDF"));
00044       } 
00045       else if  ( Quantities[i] == "stat" ){ 
00046         userDBContent.push_back(keyName+std::string("@")+std::string("entries"));
00047         userDBContent.push_back(keyName+std::string("@")+std::string("mean"));
00048         userDBContent.push_back(keyName+std::string("@")+std::string("rms"));
00049       }
00050       else{
00051         edm::LogError("SiStripSummaryBuilder") 
00052           << "Quantity " << Quantities[i] 
00053           << " cannot be handled\nAllowed quantities are" 
00054           << "\n  'stat'   that includes: entries, mean, rms"
00055           << "\n  'landau' that includes: landauPeak, landauPeakErr, landauSFWHM, landauChi2NDF"
00056           << "\n  'gauss'  that includes: gaussMean, gaussSigma, gaussChi2NDF"
00057           << std::endl;
00058       }
00059     }
00060   }
00061   obj->setUserDBContent(userDBContent);
00062     
00063   std::stringstream ss1;
00064   ss1 << "QUANTITIES TO BE INSERTED IN DB :" << " \n";  
00065   std::vector<std::string> userDBContentA = obj->getUserDBContent();
00066   for (size_t i=0;i<userDBContentA.size();++i) ss1 << userDBContentA[i]<< std::endl;
00067   edm::LogInfo("SiStripSummaryBuilder") << ss1.str();
00068 
00069 
00070   //* Loop over detids and create dummy data for each *//
00071   
00072   
00073   std::stringstream ss2;
00074   for (uint32_t detid=0; detid<430; detid++)
00075   {  
00076 
00077      SiStripSummary::InputVector values;
00078      for (unsigned int i=0; i<userDBContent.size(); i++) values.push_back((float) CLHEP::RandGauss::shoot(50.,30.));
00079      
00080      ss2<< "\n\tdetid " << detid;
00081      for(size_t j=0;j<values.size();++j)  ss2 << "\n\t\t "<< userDBContent[j] <<" "<< values[j];
00082         
00083      obj->put(detid,values,userDBContent);
00084     
00085      // See CondFormats/SiStripObjects/SiStripSummary.h for detid definitions
00086      
00087      if (detid == 4)   detid =  10;
00088      if (detid == 14)  detid =  20;
00089      if (detid == 26)  detid =  30;
00090      if (detid == 32)  detid =  40;
00091      if (detid == 42)  detid = 310;
00092      if (detid == 313) detid = 320;
00093      if (detid == 323) detid = 410;
00094      if (detid == 419) detid = 420;
00095   }
00096   
00097   edm::LogInfo("SiStripSummaryBuilder") << ss2.str();
00098 
00099 
00100 
00101   //* Insert summary informations in the DB *//
00102   
00103    
00104   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00105   
00106   if( mydbservice.isAvailable() ){
00107     if( mydbservice->isNewTagRequest("SiStripSummaryRcd") ){
00108       mydbservice->createNewIOV<SiStripSummary>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripSummaryRcd");      
00109     } else {
00110       mydbservice->appendSinceTime<SiStripSummary>(obj,mydbservice->currentTime(),"SiStripSummaryRcd");      
00111     }
00112   }else{
00113     edm::LogError("SiStripSummaryBuilder")<<"Service is unavailable"<<std::endl;
00114   }
00115   
00116   
00117 }
00118