CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CondTools/SiStrip/plugins/SiStripThresholdBuilder.cc

Go to the documentation of this file.
00001 #include "CondTools/SiStrip/plugins/SiStripThresholdBuilder.h"
00002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00003 #include <iostream>
00004 #include <fstream>
00005 
00006 SiStripThresholdBuilder::SiStripThresholdBuilder( 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",3)){}
00009 
00010 
00011 void SiStripThresholdBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup){
00012 
00013 
00014   unsigned int run=evt.id().run();
00015 
00016   edm::LogInfo("SiStripThresholdBuilder") << "... creating dummy SiStripThreshold Data for Run " << run << "\n " << std::endl;
00017 
00018   SiStripThreshold* obj = new SiStripThreshold();
00019 
00020   SiStripDetInfoFileReader reader(fp_.fullPath());
00021   
00022   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
00023 
00024   int count=-1;
00025   for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){    
00026     count++;
00027     //Generate Pedestal for det detid
00028     SiStripThreshold::Container theSiStripVector;   
00029     uint16_t strip=0;
00030     while(strip<128*it->second.nApvs){
00031       
00032       float lTh = (CLHEP::RandFlat::shoot(1.) * 64)/5;
00033       float hTh = (CLHEP::RandFlat::shoot(1.) * 64)/5;
00034       if (hTh < lTh){
00035         float tmp = hTh;
00036         hTh = lTh;
00037         lTh = tmp;
00038       }
00039       float cTh = (CLHEP::RandFlat::shoot(1.) * 30.);      
00040 
00041       obj->setData(strip,lTh,hTh,cTh,theSiStripVector);
00042       if (count<(int)printdebug_){
00043         std::stringstream ss;
00044         theSiStripVector.back().print(ss);      
00045         edm::LogInfo("SiStripThresholdBuilder") <<"detid: "  << it->first << " \n"
00046                                                 << "firstStrip: " << strip << " \t"
00047                                                 << "lTh: " << lTh       << " \t" 
00048                                                 << "hTh: " << hTh       << " \t" 
00049                                                 << "cTh: " << cTh       << " \t" 
00050                                                 << "FirstStrip_and_Hth: " << theSiStripVector.back().FirstStrip_and_Hth << " \n"
00051                                                 << ss.str()
00052                                                 << std::endl; 
00053       }     
00054       obj->setData(strip+1,lTh,hTh,theSiStripVector);
00055       strip=(uint16_t) (CLHEP::RandFlat::shoot(strip+2,128*it->second.nApvs));
00056     }      
00057     if ( ! obj->put(it->first,theSiStripVector) )
00058       edm::LogError("SiStripThresholdBuilder")<<"[SiStripThresholdBuilder::analyze] detid already exists"<<std::endl;
00059   }
00060   
00061 
00062   //End now write sistrippedestals data in DB
00063   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00064   
00065   if( mydbservice.isAvailable() ){
00066     if ( mydbservice->isNewTagRequest("SiStripThresholdRcd") ){
00067       mydbservice->createNewIOV<SiStripThreshold>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripThresholdRcd");
00068     } else {
00069       mydbservice->appendSinceTime<SiStripThreshold>(obj,mydbservice->currentTime(),"SiStripThresholdRcd");      
00070     }
00071   }else{
00072     edm::LogError("SiStripThresholdBuilder")<<"Service is unavailable"<<std::endl;
00073   }
00074 }
00075