CMS 3D CMS Logo

SiStripNoiseDB.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/ESHandle.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 
00004 
00005 #include "CalibTracker/SiStripPedestals/interface/SiStripNoiseDB.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00009 
00010 #include <FWCore/Framework/interface/EventSetup.h>
00011 #include "DataFormats/Common/interface/Handle.h"
00012 
00013 // data formats
00014 
00015 // std
00016 #include <cstdlib>
00017 
00018 using namespace std;
00019 
00020 SiStripNoiseDB::SiStripNoiseDB(const edm::ParameterSet& iConfig)
00021 {
00022    conf_ = iConfig;
00023    pedsPSet_ = conf_.getParameter<edm::ParameterSet>("PedestalsPSet");
00024    nEvTot_=0;
00025    apvFactory_=0;
00026    theEventInitNumber_ =  pedsPSet_.getParameter<int>("NumberOfEventsForInit");
00027    theEventIterNumber_ = pedsPSet_.getParameter<int>("NumberOfEventsForIteration");
00028    NumCMstripsInGroup_ = pedsPSet_.getParameter<int>("NumCMstripsInGroup");
00029 
00030 }
00031 
00032 
00033 SiStripNoiseDB::~SiStripNoiseDB()
00034 {
00035   if (apvFactory_) {delete apvFactory_;} 
00036 }
00037 
00038 
00039 void SiStripNoiseDB::beginJob(const edm::EventSetup& es){
00040    // retrieve parameters from configuration file
00041   using namespace edm;
00042   SelectedDetIds.clear();
00043 
00044   //ApvAnalysisFactory
00045   apvFactory_ = new ApvAnalysisFactory(pedsPSet_);
00046   
00047 //getting det id from the fed cabling
00048   edm::ESHandle<SiStripFedCabling> cabling;
00049   es.get<SiStripFedCablingRcd>().get( cabling );
00050   fedCabling_ = const_cast<SiStripFedCabling*>( cabling.product() );
00051 
00052   
00053   map<uint32_t, int> detIdApv;
00054   detIdApv.clear();
00055   //To do so I need to access cabling from FED and so on ... see rob's code
00056    // Retrieve FED ids from cabling map and iterate through 
00057   const vector<uint16_t>& fed_ids = fedCabling_->feds(); 
00058   vector<uint16_t>::const_iterator ifed;
00059   for ( ifed = fed_ids.begin(); ifed != fed_ids.end(); ifed++ ) {  
00060     for ( uint16_t channel = 0; channel < 96; channel++ ) {
00061       const FedChannelConnection& conn = fedCabling_->connection( *ifed, channel );
00062       uint32_t key_id =  conn.detId();
00063       int napvs = (conn.nApvPairs())*2;
00064       if(key_id > 0 && napvs >0) { 
00065         
00066         //      cout <<"DetId before the map "<<key_id<< " "<<conn.nApvPairs()<<endl;
00067         bool newDetId =   apvFactory_->instantiateApvs(key_id,napvs);
00068         if(newDetId) 
00069           SelectedDetIds.push_back(key_id);
00070       }
00071     }
00072     
00073   }
00074 
00075 }
00076 
00077 
00078 // ------------ method called to produce the data  ------------
00079 void SiStripNoiseDB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00080 {
00081   nEvTot_++;
00082   //Increment # of Events
00083   using namespace edm;
00084   // retrieve producer name of input StripDigiCollection
00085     std::string digiProducer = conf_.getParameter<std::string>("DigiProducer");
00086     // get DigiCollection object from Event
00087     edm::Handle< edm::DetSetVector<SiStripRawDigi> > digi_collection;
00088     std::string digiType = "VirginRaw";
00089     //you have a collection as there are all the digis for the event for every detector
00090     iEvent.getByLabel(digiProducer, digiType, digi_collection);
00091     //Noises object ...
00092 
00093     SiStripNoises_ = new SiStripNoises();
00094     
00095     // loop over all DetIds to be implement
00096     for(vector<uint32_t>::const_iterator myDet = SelectedDetIds.begin();myDet!=SelectedDetIds.end();myDet++)
00097       {
00098         uint32_t detid = *myDet;
00099         vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = digi_collection->find( detid );
00100         if ( digis->data.empty() ) { 
00101           edm::LogError("MonitorDigi_tmp") << "[SiStripRawDigiToRaw::createFedBuffers] Zero digis found!"; 
00102         } 
00103         //cout <<"Data size "<<digis->data.size()<<endl;
00104         apvFactory_->update(detid, (*digis));
00105         //asking for the status
00106         if((nEvTot_ - theEventInitNumber_)%theEventIterNumber_ == 1)
00107           {
00108             mSiStripNoises.clear();
00109             //Generate Pedestal for det detid
00110             SiStripNoises::InputVector theSiStripVector;  
00111             vector<float> tmp_noise;
00112             tmp_noise.clear();
00113             apvFactory_->getNoise(detid, tmp_noise);
00114             TkApvMask::MaskType temp;
00115             apvFactory_->getMask(detid, temp);
00116             int ibin=0;
00117             for (vector<float>::const_iterator iped=tmp_noise.begin(); iped!=tmp_noise.end();iped++) {
00118               float noise = *iped;
00119               bool disable = true;
00120               if(temp[ibin] == 0) disable = false;
00121 
00122               SiStripNoises_->setData(noise,theSiStripVector);
00123               ibin++;
00124             } 
00125             mSiStripNoises.push_back(make_pair(detid,theSiStripVector));
00126           }
00127       }
00128 }
00129 
00130 void SiStripNoiseDB::endJob(void){
00131 
00132   edm::LogInfo("SiStripNoiseDB") << "... now write sistripnoise data in DB" << std::endl;
00133 
00134   for (std::vector< std::pair<uint32_t, SiStripNoises::InputVector > >::const_iterator iter=mSiStripNoises.begin(); iter!=mSiStripNoises.end();iter++)
00135     {
00136       if ( ! SiStripNoises_->put(iter->first,iter->second) )
00137         edm::LogError("SiStripNoiseDB") <<"[SiStripNoiseDB::analyze] detid " << iter->first << "already exists"<<endl;
00138     }    
00139         
00140   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00141   
00142   if( mydbservice.isAvailable() ){
00143     try{
00144       edm::LogInfo("SiStripNoiseDB")<<"current time "<<mydbservice->currentTime()<<std::endl;
00145       mydbservice->createNewIOV<SiStripNoises>(SiStripNoises_,mydbservice->beginOfTime(),mydbservice->endOfTime(), "SiStripNoisesRcd");      
00146     }catch(const cond::Exception& er){
00147       edm::LogError("SiStripNoiseDB")<<er.what()<<std::endl;
00148     }catch(const std::exception& er){
00149       edm::LogError("SiStripNoiseDB")<<"caught std::exception "<<er.what()<<std::endl;
00150     }catch(...){
00151       edm::LogError("SiStripNoiseDB")<<"Funny error"<<std::endl;
00152     }
00153   }else{
00154     edm::LogError("SiStripNoiseDB")<<"Service is unavailable"<<std::endl;
00155   }
00156 }
00157 
00158 
00159 

Generated on Tue Jun 9 17:25:51 2009 for CMSSW by  doxygen 1.5.4