CMS 3D CMS Logo

HcalRawToDigi.cc

Go to the documentation of this file.
00001 using namespace std;
00002 #include "EventFilter/HcalRawToDigi/plugins/HcalRawToDigi.h"
00003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00004 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00005 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00008 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include <iostream>
00011 
00012 HcalRawToDigi::HcalRawToDigi(edm::ParameterSet const& conf):
00013   dataTag_(conf.getParameter<edm::InputTag>("InputLabel")),
00014   unpacker_(conf.getUntrackedParameter<int>("HcalFirstFED",FEDNumbering::getHcalFEDIds().first),conf.getParameter<int>("firstSample"),conf.getParameter<int>("lastSample")),
00015   filter_(conf.getParameter<bool>("FilterDataQuality"),conf.getParameter<bool>("FilterDataQuality"),
00016           false,
00017           0, 0, 
00018           -1),
00019   fedUnpackList_(conf.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>())),
00020   firstFED_(conf.getUntrackedParameter<int>("HcalFirstFED",FEDNumbering::getHcalFEDIds().first)),
00021   unpackCalib_(conf.getUntrackedParameter<bool>("UnpackCalib",false)),
00022   unpackZDC_(conf.getUntrackedParameter<bool>("UnpackZDC",false)),
00023   silent_(conf.getUntrackedParameter<bool>("silent",true)),
00024   complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData",false))
00025 {
00026   if (fedUnpackList_.empty()) {
00027     for (int i=FEDNumbering::getHcalFEDIds().first; i<=FEDNumbering::getHcalFEDIds().second; i++)
00028       fedUnpackList_.push_back(i);
00029   } 
00030   
00031   std::ostringstream ss;
00032   for (unsigned int i=0; i<fedUnpackList_.size(); i++) 
00033     ss << fedUnpackList_[i] << " ";
00034   edm::LogInfo("HCAL") << "HcalRawToDigi will unpack FEDs ( " << ss.str() << ")";
00035     
00036   // products produced...
00037   produces<HBHEDigiCollection>();
00038   produces<HFDigiCollection>();
00039   produces<HODigiCollection>();
00040   produces<HcalTrigPrimDigiCollection>();
00041   produces<HOTrigPrimDigiCollection>();
00042   produces<HcalUnpackerReport>();
00043   if (unpackCalib_)
00044     produces<HcalCalibDigiCollection>();
00045   if (unpackZDC_)
00046     produces<ZDCDigiCollection>();
00047 
00048   memset(&stats_,0,sizeof(stats_));
00049 
00050 }
00051 
00052 // Virtual destructor needed.
00053 HcalRawToDigi::~HcalRawToDigi() { }  
00054 
00055 // Functions that gets called by framework every event
00056 void HcalRawToDigi::produce(edm::Event& e, const edm::EventSetup& es)
00057 {
00058   // Step A: Get Inputs 
00059   edm::Handle<FEDRawDataCollection> rawraw;  
00060   e.getByLabel(dataTag_,rawraw);
00061   // get the mapping
00062   edm::ESHandle<HcalDbService> pSetup;
00063   es.get<HcalDbRecord>().get( pSetup );
00064   const HcalElectronicsMap* readoutMap=pSetup->getHcalMapping();
00065   
00066   // Step B: Create empty output  : three vectors for three classes...
00067   std::vector<HBHEDataFrame> hbhe;
00068   std::vector<HODataFrame> ho;
00069   std::vector<HFDataFrame> hf;
00070   std::vector<HcalTriggerPrimitiveDigi> htp;
00071   std::vector<HcalCalibDataFrame> hc;
00072   std::vector<ZDCDataFrame> zdc;
00073   std::vector<HOTriggerPrimitiveDigi> hotp;
00074   std::auto_ptr<HcalUnpackerReport> report(new HcalUnpackerReport);
00075 
00076   // Heuristics: use ave+(max-ave)/8
00077   if (stats_.max_hbhe>0) hbhe.reserve(stats_.ave_hbhe+(stats_.max_hbhe-stats_.ave_hbhe)/8);
00078   if (stats_.max_ho>0) ho.reserve(stats_.ave_ho+(stats_.max_ho-stats_.ave_ho)/8);
00079   if (stats_.max_hf>0) hf.reserve(stats_.ave_hf+(stats_.max_hf-stats_.ave_hf)/8);
00080   if (stats_.max_calib>0) hc.reserve(stats_.ave_calib+(stats_.max_calib-stats_.ave_calib)/8);
00081   if (stats_.max_tp>0) htp.reserve(stats_.ave_tp+(stats_.max_tp-stats_.ave_tp)/8);
00082   if (stats_.max_tpho>0) hotp.reserve(stats_.ave_tpho+(stats_.max_tpho-stats_.ave_tpho)/8);
00083 
00084   if (unpackZDC_) zdc.reserve(24);
00085 
00086 
00087   HcalUnpacker::Collections colls;
00088   colls.hbheCont=&hbhe;
00089   colls.hoCont=&ho;
00090   colls.hfCont=&hf;
00091   colls.tpCont=&htp;
00092   colls.tphoCont=&hotp;
00093   colls.calibCont=&hc;
00094   colls.zdcCont=&zdc;
00095  
00096   // Step C: unpack all requested FEDs
00097   for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
00098     const FEDRawData& fed = rawraw->FEDData(*i);
00099     if (fed.size()==0) {
00100       if (complainEmptyData_) {
00101         if (!silent_) edm::LogWarning("EmptyData") << "No data for FED " << *i;
00102         report->addError(*i);
00103       }
00104     } else if (fed.size()<8*3) {
00105       if (!silent_) edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
00106       report->addError(*i);
00107     } else {
00108       try {
00109         unpacker_.unpack(fed,*readoutMap,colls, *report,silent_);
00110         report->addUnpacked(*i);
00111       } catch (cms::Exception& e) {
00112         if (!silent_) edm::LogWarning("Unpacking error") << e.what();
00113         report->addError(*i);
00114       } catch (...) {
00115         if (!silent_) edm::LogWarning("Unpacking exception");
00116         report->addError(*i);
00117       }
00118     }
00119   }
00120 
00121 
00122   // gather statistics
00123   stats_.max_hbhe=std::max(stats_.max_hbhe,(int)hbhe.size());
00124   stats_.ave_hbhe=(stats_.ave_hbhe*stats_.n+hbhe.size())/(stats_.n+1);
00125   stats_.max_ho=std::max(stats_.max_ho,(int)ho.size());
00126   stats_.ave_ho=(stats_.ave_ho*stats_.n+ho.size())/(stats_.n+1);
00127   stats_.max_hf=std::max(stats_.max_hf,(int)hf.size());
00128   stats_.ave_hf=(stats_.ave_hf*stats_.n+hf.size())/(stats_.n+1);
00129   stats_.max_tp=std::max(stats_.max_tp,(int)htp.size());
00130   stats_.ave_tp=(stats_.ave_tp*stats_.n+htp.size())/(stats_.n+1);
00131   stats_.max_tpho=std::max(stats_.max_tpho,(int)hotp.size());
00132   stats_.ave_tpho=(stats_.ave_tpho*stats_.n+hotp.size())/(stats_.n+1);
00133   stats_.max_calib=std::max(stats_.max_calib,(int)hc.size());
00134   stats_.ave_calib=(stats_.ave_calib*stats_.n+hc.size())/(stats_.n+1);
00135 
00136 
00137   stats_.n++;
00138 
00139   // Step B: encapsulate vectors in actual collections
00140   std::auto_ptr<HBHEDigiCollection> hbhe_prod(new HBHEDigiCollection()); 
00141   std::auto_ptr<HFDigiCollection> hf_prod(new HFDigiCollection());
00142   std::auto_ptr<HODigiCollection> ho_prod(new HODigiCollection());
00143   std::auto_ptr<HcalTrigPrimDigiCollection> htp_prod(new HcalTrigPrimDigiCollection());  
00144   std::auto_ptr<HOTrigPrimDigiCollection> hotp_prod(new HOTrigPrimDigiCollection());  
00145 
00146   hbhe_prod->swap_contents(hbhe);
00147   hf_prod->swap_contents(hf);
00148   ho_prod->swap_contents(ho);
00149   htp_prod->swap_contents(htp);
00150   hotp_prod->swap_contents(hotp);
00151 
00152   // Step C2: filter FEDs, if required
00153   if (filter_.active()) {
00154     HBHEDigiCollection filtered_hbhe=filter_.filter(*hbhe_prod,*report);
00155     HODigiCollection filtered_ho=filter_.filter(*ho_prod,*report);
00156     HFDigiCollection filtered_hf=filter_.filter(*hf_prod,*report);
00157     
00158     hbhe_prod->swap(filtered_hbhe);
00159     ho_prod->swap(filtered_ho);
00160     hf_prod->swap(filtered_hf);    
00161   }
00162 
00163 
00164   // Step D: Put outputs into event
00165   // just until the sorting is proven
00166   hbhe_prod->sort();
00167   ho_prod->sort();
00168   hf_prod->sort();
00169   htp_prod->sort();
00170   hotp_prod->sort();
00171 
00172   e.put(hbhe_prod);
00173   e.put(ho_prod);
00174   e.put(hf_prod);
00175   e.put(htp_prod);
00176   e.put(hotp_prod);
00177 
00179   if (unpackCalib_) {
00180     std::auto_ptr<HcalCalibDigiCollection> hc_prod(new HcalCalibDigiCollection());
00181     hc_prod->swap_contents(hc);
00182     hc_prod->sort();
00183     e.put(hc_prod);
00184   }
00185 
00187   if (unpackZDC_) {
00188     std::auto_ptr<ZDCDigiCollection> prod(new ZDCDigiCollection());
00189     prod->swap_contents(zdc);
00190     
00191     if (filter_.active()) {
00192       ZDCDigiCollection filtered_zdc=filter_.filter(*prod,*report);
00193       prod->swap(filtered_zdc);
00194     }
00195 
00196     prod->sort();
00197     e.put(prod);
00198   }
00199   e.put(report);
00200 
00201 
00202 }
00203 
00204 

Generated on Tue Jun 9 17:34:41 2009 for CMSSW by  doxygen 1.5.4