CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CalibTracker/SiStripCommon/plugins/ShallowDigisProducer.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/ShallowDigisProducer.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "DataFormats/Common/interface/DetSetVector.h"
00008 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00009 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00010 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00011 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00012 #include "boost/foreach.hpp"
00013 
00014 ShallowDigisProducer::ShallowDigisProducer(const edm::ParameterSet& conf)
00015   : inputTags(conf.getParameter<std::vector<edm::InputTag> >("DigiProducersList")) 
00016 {
00017   produces<std::vector<unsigned> >("id");
00018   produces<std::vector<unsigned> >("subdet");
00019   produces<std::vector<unsigned> >("strip");
00020   produces<std::vector<unsigned> >("adc");
00021   produces<std::vector<float> >("noise");
00022 }  
00023 
00024 void ShallowDigisProducer::
00025 insert(products& p, edm::Event& e) {
00026   e.put(p.id,     "id");
00027   e.put(p.subdet, "subdet");
00028   e.put(p.strip,  "strip");
00029   e.put(p.adc,    "adc");
00030   e.put(p.noise,  "noise");
00031 }
00032 
00033 template<class T>
00034 inline
00035 void ShallowDigisProducer::
00036 recordDigis(const T& digiCollection, products& p) {
00037   BOOST_FOREACH(const typename T::value_type set, digiCollection) {
00038     SiStripNoises::Range detNoiseRange = noiseHandle->getRange(set.detId());
00039     BOOST_FOREACH(const SiStripDigi digi, set) {
00040       p.id->push_back(set.detId());
00041       p.subdet->push_back((set.detId()>>25)&0x7);
00042       p.strip->push_back(digi.strip());
00043       p.adc->push_back(digi.adc());
00044       p.noise->push_back(noiseHandle->getNoise( digi.strip(), detNoiseRange));
00045     }
00046   }
00047 }
00048 
00049 void ShallowDigisProducer::
00050 produce(edm::Event& e, const edm::EventSetup& es) {  
00051   products p;
00052   edm::Handle< edm::DetSetVector<SiStripDigi> >     inputOld;  
00053   edm::Handle< edmNew::DetSetVector<SiStripDigi> >  inputNew;  
00054   es.get<SiStripNoisesRcd>().get(noiseHandle);
00055   if( findInput(inputOld, e) ) recordDigis(*inputOld, p); else 
00056     if( findInput(inputNew, e) ) recordDigis(*inputNew, p); else
00057       edm::LogWarning("Input Not Found");
00058   insert(p,e);
00059 }
00060 
00061 template<class T>
00062 inline
00063 bool ShallowDigisProducer::
00064 findInput(edm::Handle<T>& handle, const edm::Event& e) {
00065   BOOST_FOREACH( const edm::InputTag inputTag, inputTags) {
00066     e.getByLabel(inputTag, handle);
00067     if( handle.isValid() && !handle->empty() ) {
00068       LogDebug("Input") << inputTag;
00069       return true;
00070     }
00071   }
00072   return false;
00073 }