CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CaloOnlineTools/EcalTools/plugins/EcalFEDWithCRCErrorProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalFEDWithCRCErrorProducer
00004 // Class:      EcalFEDWithCRCErrorProducer
00005 // 
00013 //
00014 // Original Author:  Giovanni FRANZONI
00015 //         Created:  Tue Jan 22 13:55:00 CET 2008
00016 // $Id: EcalFEDWithCRCErrorProducer.cc,v 1.5 2010/10/05 13:39:30 vlimant Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include "FWCore/Utilities/interface/InputTag.h"
00032 #include "FWCore/Framework/interface/EDProducer.h"
00033 
00034 #include <string>
00035 #include <iostream>
00036 #include <vector>
00037 #include <iomanip>
00038 
00039 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00040 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
00041 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00042 //
00043 // class declaration
00044 //
00045 
00046 class EcalFEDWithCRCErrorProducer : public edm::EDProducer 
00047 {
00048 public:
00049   explicit EcalFEDWithCRCErrorProducer(const edm::ParameterSet&);
00050   ~EcalFEDWithCRCErrorProducer();
00051   
00052 private:
00053   virtual void produce(edm::Event&, const edm::EventSetup&);
00054   
00055   // ----------member data ---------------------------
00056   
00057   edm::InputTag     DataLabel_;
00058   std::vector<int> fedUnpackList_;
00059   bool writeAllEcalFEDs_;
00060 };
00061 
00062 
00063 
00064 //
00065 // constructors and destructor
00066 //
00067 EcalFEDWithCRCErrorProducer::EcalFEDWithCRCErrorProducer(const edm::ParameterSet& iConfig)
00068 {
00069   //now do what ever initialization is needed
00070 
00071   DataLabel_     = iConfig.getParameter<edm::InputTag>("InputLabel");
00072   fedUnpackList_ = iConfig.getUntrackedParameter< std::vector<int> >("FEDs", std::vector<int>());
00073   writeAllEcalFEDs_ = iConfig.getUntrackedParameter<bool >("writeAllEcalFED", false);
00074   if (fedUnpackList_.empty()) 
00075     for (int i=FEDNumbering::MINECALFEDID; i<=FEDNumbering::MAXECALFEDID; i++)
00076       fedUnpackList_.push_back(i);
00077 
00078   produces< FEDRawDataCollection >();
00079 }
00080 
00081 
00082 EcalFEDWithCRCErrorProducer::~EcalFEDWithCRCErrorProducer()
00083 {
00084  
00085   // do anything here that needs to be done at desctruction time
00086   // (e.g. close files, deallocate resources etc.)
00087 
00088 }
00089 
00090 
00091 //
00092 // member functions
00093 //
00094 
00095 // ------------ method called on each new Event  ------------
00096 void
00097 EcalFEDWithCRCErrorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00098 {
00099   using namespace edm;
00100 
00101   edm::Handle<FEDRawDataCollection> rawdata;  
00102   iEvent.getByLabel(DataLabel_,rawdata);
00103 
00104   std::auto_ptr<FEDRawDataCollection> producedData(new FEDRawDataCollection);
00105   // get fed raw data and SM id
00106 
00107   // loop over FEDS
00108   for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) 
00109     {
00110 
00111       // get fed raw data and SM id
00112       const FEDRawData & fedData = rawdata->FEDData(*i);
00113       int length = fedData.size()/sizeof(uint64_t);
00114 
00115       //    LogDebug("EcalRawToDigi") << "raw data length: " << length ;
00116       //if data size is not null interpret data
00117       if ( length >= 1 )
00118         {
00119             uint64_t * pData = (uint64_t *)(fedData.data());
00120             //When crc error is found return true
00121             uint64_t * fedTrailer = pData + (length - 1);
00122             bool crcError = (*fedTrailer >> 2 ) & 0x1; 
00123             // this fed has data -- lets copy it
00124             if (writeAllEcalFEDs_ || crcError)
00125               {
00126                 FEDRawData & fedDataProd = producedData->FEDData(*i);
00127                 if ( fedDataProd.size() != 0 ) 
00128                   {
00129                     //                std::cout << " More than one FEDRawDataCollection with data in FED ";
00130                     //                std::cout << j << " Skipping the 2nd\n";
00131                     continue;
00132                   }
00133                 fedDataProd.resize(fedData.size());
00134                 unsigned char *dataProd=fedDataProd.data();
00135                 const unsigned char *data=fedData.data();
00136                 for ( unsigned int k=0; k<fedData.size(); ++k ) 
00137                   {
00138                     dataProd[k]=data[k];
00139                   }
00140               }
00141         }
00142     }
00143   
00144   iEvent.put(producedData);  
00145 }
00146 
00147 //define this as a plug-in
00148 DEFINE_FWK_MODULE(EcalFEDWithCRCErrorProducer);