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
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
00023
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
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
00039 produces<CastorDigiCollection>();
00040
00041 produces<HcalUnpackerReport>();
00042
00043
00044
00045 }
00046
00047
00048 CastorRawToDigi::~CastorRawToDigi() { }
00049
00050
00051 void CastorRawToDigi::produce(edm::Event& e, const edm::EventSetup& es)
00052 {
00053
00054 edm::Handle<FEDRawDataCollection> rawraw;
00055 e.getByLabel(dataTag_,rawraw);
00056
00057 edm::ESHandle<CastorDbService> pSetup;
00058 es.get<CastorDbRecord>().get( pSetup );
00059 const CastorElectronicsMap* readoutMap=pSetup->getCastorMapping();
00060
00061
00062 std::vector<CastorDataFrame> castor;
00063
00064
00065
00066 std::auto_ptr<HcalUnpackerReport> report(new HcalUnpackerReport);
00067
00068 CastorUnpacker::Collections colls;
00069 colls.castorCont=&castor;
00070
00071
00072
00073
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
00099 std::auto_ptr<CastorDigiCollection> castor_prod(new CastorDigiCollection());
00100
00101
00102 castor_prod->swap_contents(castor);
00103
00104
00105
00106 if (filter_.active()) {
00107 CastorDigiCollection filtered_castor=filter_.filter(*castor_prod,*report);
00108
00109 castor_prod->swap(filtered_castor);
00110 }
00111
00112
00113
00114
00115 castor_prod->sort();
00116
00117
00118 e.put(castor_prod);
00119
00120
00122
00123
00124
00125
00126
00127
00128
00130
00131 e.put(report);
00132 }
00133
00134