CMS 3D CMS Logo

CastorRawToDigi.cc

Go to the documentation of this file.
00001 using namespace std;
00002 #include "EventFilter/CastorRawToDigi/plugins/CastorRawToDigi.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/CastorObjects/interface/CastorDbService.h"
00008 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include <iostream>
00011 
00012 CastorRawToDigi::CastorRawToDigi(edm::ParameterSet const& conf):
00013   dataTag_(conf.getParameter<edm::InputTag>("InputLabel")),
00014   unpacker_(conf.getUntrackedParameter<int>("CastorFirstFED",FEDNumbering::getHcalFEDIds().first),conf.getParameter<int>("firstSample"),conf.getParameter<int>("lastSample")),
00015   // unpacker_(conf.getUntrackedParameter<int>("CastorFirstFED",FEDNumbering::getCastorFEDIds().first),conf.getParameter<int>("firstSample"),conf.getParameter<int>("lastSample")),
00016   filter_(conf.getParameter<bool>("FilterDataQuality"),conf.getParameter<bool>("FilterDataQuality"),
00017           false,
00018           0, 0, 
00019           -1),
00020   fedUnpackList_(conf.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>())),
00021   firstFED_(conf.getUntrackedParameter<int>("CastorFirstFED",FEDNumbering::getHcalFEDIds().first)),
00022 //  firstFED_(conf.getUntrackedParameter<int>("CastorFirstFED",FEDNumbering::getCastorFEDIds().first)),
00023 //  unpackCalib_(conf.getUntrackedParameter<bool>("UnpackCalib",false)),
00024 
00025   complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData",false))
00026 {
00027   if (fedUnpackList_.empty()) {
00028     for (int i=FEDNumbering::getHcalFEDIds().first; i<=FEDNumbering::getHcalFEDIds().second; i++)
00029     // for (int i=FEDNumbering::getCastorFEDIds().first; i<=FEDNumbering::getCastorFEDIds().second; i++)
00030       fedUnpackList_.push_back(i);
00031   } 
00032   
00033   std::ostringstream ss;
00034   for (unsigned int i=0; i<fedUnpackList_.size(); i++) 
00035     ss << fedUnpackList_[i] << " ";
00036   edm::LogInfo("CASTOR") << "CastorRawToDigi will unpack FEDs ( " << ss.str() << ")";
00037     
00038   // products produced...
00039   produces<CastorDigiCollection>();
00040 //  produces<CastorTrigPrimDigiCollection>();
00041   produces<HcalUnpackerReport>();
00042 //  if (unpackCalib_)
00043 //    produces<HcalCalibDigiCollection>();
00044 
00045 }
00046 
00047 // Virtual destructor needed.
00048 CastorRawToDigi::~CastorRawToDigi() { }  
00049 
00050 // Functions that gets called by framework every event
00051 void CastorRawToDigi::produce(edm::Event& e, const edm::EventSetup& es)
00052 {
00053   // Step A: Get Inputs 
00054   edm::Handle<FEDRawDataCollection> rawraw;  
00055   e.getByLabel(dataTag_,rawraw);
00056   // get the mapping
00057   edm::ESHandle<CastorDbService> pSetup;
00058   es.get<CastorDbRecord>().get( pSetup );
00059   const CastorElectronicsMap* readoutMap=pSetup->getCastorMapping();
00060   
00061   // Step B: Create empty output  : three vectors for three classes...
00062   std::vector<CastorDataFrame> castor;
00063   //std::vector<CastorTriggerPrimitiveDigi> htp;
00064   //std::vector<CastorCalibDataFrame> hc;
00065   //std::auto_ptr<CastorUnpackerReport> report(new CastorUnpackerReport);
00066   std::auto_ptr<HcalUnpackerReport> report(new HcalUnpackerReport);
00067 
00068   CastorUnpacker::Collections colls;
00069   colls.castorCont=&castor;
00070   //colls.tpCont=&htp;
00071   //colls.calibCont=&hc;
00072  
00073   // Step C: unpack all requested FEDs
00074   for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
00075     const FEDRawData& fed = rawraw->FEDData(*i);
00076     if (fed.size()==0) {
00077       if (complainEmptyData_) {
00078         edm::LogWarning("EmptyData") << "No data for FED " << *i;
00079         report->addError(*i);
00080       }
00081     } else if (fed.size()<8*3) {
00082       edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
00083       report->addError(*i);
00084     } else {
00085       try {
00086         unpacker_.unpack(fed,*readoutMap,colls, *report);
00087         report->addUnpacked(*i);
00088       } catch (cms::Exception& e) {
00089         edm::LogWarning("Unpacking error") << e.what();
00090         report->addError(*i);
00091       } catch (...) {
00092         edm::LogWarning("Unpacking exception");
00093         report->addError(*i);
00094       }
00095     }
00096   }
00097 
00098   // Step B: encapsulate vectors in actual collections
00099   std::auto_ptr<CastorDigiCollection> castor_prod(new CastorDigiCollection()); 
00100   // std::auto_ptr<CastorTrigPrimDigiCollection> htp_prod(new CastorTrigPrimDigiCollection());  
00101 
00102   castor_prod->swap_contents(castor);
00103   // htp_prod->swap_contents(htp);
00104 
00105   // Step C2: filter FEDs, if required
00106   if (filter_.active()) {
00107     CastorDigiCollection filtered_castor=filter_.filter(*castor_prod,*report);
00108     
00109     castor_prod->swap(filtered_castor);
00110   }
00111 
00112 
00113   // Step D: Put outputs into event
00114   // just until the sorting is proven
00115   castor_prod->sort();
00116   // htp_prod->sort();
00117 
00118   e.put(castor_prod);
00119   // e.put(htp_prod);
00120 
00122 //  if (unpackCalib_) {
00123 //    std::auto_ptr<CastorCalibDigiCollection> hc_prod(new CastorCalibDigiCollection());
00124 //    hc_prod->swap_contents(hc);
00125 //    hc_prod->sort();
00126 //    e.put(hc_prod);
00127 //  }
00128 
00130 
00131   e.put(report);
00132 }
00133 
00134 

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