CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/EventFilter/HcalRawToDigi/plugins/HcalCalibFEDSelector.cc

Go to the documentation of this file.
00001 // user include files
00002 #include "FWCore/Framework/interface/Frameworkfwd.h"
00003 #include "FWCore/Framework/interface/EDProducer.h"
00004 
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/MakerMacros.h"
00007 
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 
00011 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00012 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00013 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00014 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00015 #include "EventFilter/HcalRawToDigi/interface/HcalFEDList.h"
00016 
00017 class HcalCalibFEDSelector : public edm::EDProducer {
00018 public:
00019   HcalCalibFEDSelector(const edm::ParameterSet&);
00020   ~HcalCalibFEDSelector();
00021 
00022 
00023 private:
00024   virtual void beginJob() ;
00025   virtual void produce(edm::Event&, const edm::EventSetup&);
00026   virtual void endJob() ;
00027 
00028   // ----------member data ---------------------------
00029   edm::InputTag rawInLabel_ ;
00030   std::vector<int> extraFEDs_ ; 
00031   
00032 };
00033 
00034 
00035 
00036 
00037 HcalCalibFEDSelector::HcalCalibFEDSelector(const edm::ParameterSet& iConfig)
00038 {
00039   rawInLabel_ = iConfig.getParameter<edm::InputTag>("rawInputLabel");
00040   extraFEDs_  = iConfig.getParameter< std::vector<int> >("extraFEDsToKeep") ; 
00041   produces<FEDRawDataCollection>();  
00042 }
00043 
00044 HcalCalibFEDSelector::~HcalCalibFEDSelector()
00045 {
00046 }
00047 
00048 void
00049 HcalCalibFEDSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00050 {
00051 
00052   std::auto_ptr<FEDRawDataCollection> producedData(new FEDRawDataCollection);
00053 
00054   edm::Handle<FEDRawDataCollection> rawIn;
00055   iEvent.getByLabel(rawInLabel_,rawIn);
00056  
00057   std::vector<int> selFEDs;
00058 
00059   //--- Get the list of FEDs to be kept ---//
00060   int calibType = -1 ; 
00061   for (int i=FEDNumbering::MINHCALFEDID;
00062        i<=FEDNumbering::MAXHCALFEDID; i++) {
00063     const FEDRawData& fedData = rawIn->FEDData(i) ; 
00064     if ( fedData.size() < 24 ) continue ; // FED is empty
00065     int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ; 
00066     if ( calibType < 0 ) {
00067       calibType = value ; 
00068     } else { 
00069       if ( calibType != value ) 
00070         edm::LogWarning("HcalCalibFEDSelector") << "Conflicting calibration types found: " 
00071                                                 << calibType << " vs. " << value
00072                                                 << ".  Staying with " << calibType ; 
00073     }
00074   }
00075 
00076   HcalFEDList calibFeds(calibType) ; 
00077   selFEDs = calibFeds.getListOfFEDs() ; 
00078   for (unsigned int i=0; i<extraFEDs_.size(); i++) {
00079     bool duplicate = false ; 
00080     for (unsigned int j=0; j<selFEDs.size(); j++) { 
00081       if (extraFEDs_.at(i) == selFEDs.at(j)) {
00082         duplicate = true ; 
00083         break ; 
00084       }
00085     }
00086     if ( !duplicate ) selFEDs.push_back( extraFEDs_.at(i) ) ; 
00087   }
00088 
00089   // Copying:
00090   const FEDRawDataCollection *rdc=rawIn.product();
00091   
00092   for ( int j=0; j< FEDNumbering::lastFEDId(); ++j ) 
00093     {
00094       bool rightFED=false;
00095       for (uint32_t k=0; k<selFEDs.size(); k++)
00096         {
00097           if (j==selFEDs[k])
00098            {
00099              rightFED=true;
00100            }
00101        }
00102      if (!rightFED) continue;
00103      const FEDRawData & fedData = rdc->FEDData(j);
00104      size_t size=fedData.size();
00105      
00106      if ( size > 0 ) 
00107        {
00108        // this fed has data -- lets copy it
00109          FEDRawData & fedDataProd = producedData->FEDData(j);
00110          if ( fedDataProd.size() != 0 ) {
00111            continue;
00112          }
00113          fedDataProd.resize(size);
00114          unsigned char *dataProd=fedDataProd.data();
00115          const unsigned char *data=fedData.data();
00116          // memcpy is at-least-as-fast as assignment and can be much faster
00117          memcpy(dataProd, data, size);
00118        }
00119    }
00120 
00121  iEvent.put(producedData);
00122 }
00123 
00124 
00125 // ------------ method called once each job just before starting event loop  ------------
00126 void HcalCalibFEDSelector::beginJob()
00127 {
00128 }
00129 
00130 // ------------ method called once each job just after ending the event loop  ------------
00131 void HcalCalibFEDSelector::endJob() {
00132 }
00133 
00134 DEFINE_FWK_MODULE(HcalCalibFEDSelector) ;