Go to the documentation of this file.00001 using namespace std;
00002
00003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00004 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00005 #include "TBDataFormats/HcalTBObjects/interface/HcalTBRunData.h"
00006 #include "TBDataFormats/HcalTBObjects/interface/HcalTBEventPosition.h"
00007 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTiming.h"
00008 #include "TBDataFormats/HcalTBObjects/interface/HcalTBBeamCounters.h"
00009 #include "RecoTBCalo/HcalTBObjectUnpacker/plugins/HcalTBObjectUnpacker.h"
00010 #include "DataFormats/Common/interface/EDCollection.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include <iostream>
00013 #include <fstream>
00014
00015
00016 HcalTBObjectUnpacker::HcalTBObjectUnpacker(edm::ParameterSet const& conf):
00017 triggerFed_(conf.getUntrackedParameter<int>("HcalTriggerFED",-1)),
00018 sdFed_(conf.getUntrackedParameter<int>("HcalSlowDataFED",-1)),
00019 spdFed_(conf.getUntrackedParameter<int>("HcalSourcePositionFED",-1)),
00020 tdcFed_(conf.getUntrackedParameter<int>("HcalTDCFED",-1)),
00021 qadcFed_(conf.getUntrackedParameter<int>("HcalQADCFED",-1)),
00022 calibFile_(conf.getUntrackedParameter<string>("ConfigurationFile","")),
00023 tdcUnpacker_(conf.getUntrackedParameter<bool>("IncludeUnmatchedHits",false)),
00024 doRunData_(false),doTriggerData_(false),doEventPosition_(false),doTiming_(false),doSourcePos_(false),doBeamADC_(false),
00025 fedRawDataCollectionTag_(conf.getParameter<edm::InputTag>("fedRawDataCollectionTag"))
00026 {
00027
00028 if (triggerFed_ >=0) {
00029 std::cout << "HcalTBObjectUnpacker will unpack Trigger FED ";
00030 std::cout << triggerFed_ << endl;
00031 doTriggerData_=true;
00032 }
00033
00034 if (sdFed_ >=0) {
00035 std::cout << "HcalTBObjectUnpacker will unpack SlowData FED ";
00036 std::cout << sdFed_ << endl;
00037 doRunData_=true;
00038 doEventPosition_=true;
00039 }
00040
00041 if (tdcFed_ >=0) {
00042 std::cout << "HcalTBObjectUnpacker will unpack TDC FED ";
00043 std::cout << tdcFed_ << endl;
00044 doTiming_=true;
00045 doEventPosition_=true;
00046 }
00047
00048 if (qadcFed_ >=0) {
00049 std::cout << "HcalTBObjectUnpacker will unpack QADC FED ";
00050 std::cout << qadcFed_ << endl;
00051 doBeamADC_=true;
00052 }
00053
00054 if (spdFed_ >=0) {
00055 std::cout << "HcalTBObjectUnpacker will unpack Source Position Data FED ";
00056 std::cout << spdFed_ << endl;
00057 doSourcePos_=true;
00058 }
00059
00060
00061 if (tdcFed_ >= 0 || qadcFed_ >=0 ) {
00062 calibLines_.clear();
00063 if(calibFile_.size()>0){
00064
00065 parseCalib();
00066
00067 if(calibLines_.size()==0)
00068 throw cms::Exception("Incomplete configuration") <<
00069 "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found or is empty: "<<calibFile_<<endl;
00070 }
00071 else{
00072 throw cms::Exception("Incomplete configuration") <<
00073 "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found: "<<calibFile_<<endl;
00074 }
00075 }
00076
00077
00078 if (doTriggerData_) produces<HcalTBTriggerData>();
00079 if (doRunData_) produces<HcalTBRunData>();
00080 if (doEventPosition_) produces<HcalTBEventPosition>();
00081 if (doTiming_) produces<HcalTBTiming>();
00082
00083 if (doBeamADC_) {produces<HcalTBBeamCounters>();qadcUnpacker_.setCalib(calibLines_);}
00084
00085 if(doTiming_||doEventPosition_)tdcUnpacker_.setCalib(calibLines_);
00086 }
00087
00088
00089 HcalTBObjectUnpacker::~HcalTBObjectUnpacker() { }
00090
00091
00092 void HcalTBObjectUnpacker::produce(edm::Event& e, const edm::EventSetup&)
00093 {
00094
00095 edm::Handle<FEDRawDataCollection> rawraw;
00096 e.getByLabel(fedRawDataCollectionTag_, rawraw);
00097
00098
00099 std::auto_ptr<HcalTBTriggerData>
00100 trigd(new HcalTBTriggerData);
00101
00102 std::auto_ptr<HcalTBRunData>
00103 rund(new HcalTBRunData);
00104
00105 std::auto_ptr<HcalTBEventPosition>
00106 epd(new HcalTBEventPosition);
00107
00108 std::auto_ptr<HcalTBTiming>
00109 tmgd(new HcalTBTiming);
00110
00111 std::auto_ptr<HcalTBBeamCounters>
00112 bcntd(new HcalTBBeamCounters);
00113
00114 std::auto_ptr<HcalSourcePositionData>
00115 spd(new HcalSourcePositionData);
00116
00117 if (triggerFed_ >=0) {
00118
00119 const FEDRawData& fed = rawraw->FEDData(triggerFed_);
00120 tdUnpacker_.unpack(fed,*trigd);
00121 }
00122
00123 if (sdFed_ >=0) {
00124
00125 const FEDRawData& fed = rawraw->FEDData(sdFed_);
00126 sdUnpacker_.unpack(fed, *rund, *epd);
00127 }
00128
00129 if (tdcFed_ >=0) {
00130
00131 const FEDRawData& fed = rawraw->FEDData(tdcFed_);
00132 tdcUnpacker_.unpack(fed, *epd, *tmgd);
00133 }
00134
00135 if (qadcFed_ >=0) {
00136
00137 const FEDRawData& fed = rawraw->FEDData(qadcFed_);
00138 bool is04 = true;
00139 if(qadcFed_==8) is04=false;
00140 qadcUnpacker_.unpack(fed, *bcntd,is04);
00141 }
00142
00143 if (spdFed_ >=0) {
00144
00145 const FEDRawData& fed = rawraw->FEDData(spdFed_);
00146 spdUnpacker_.unpack(fed, *spd);
00147 }
00148
00149
00150 if (doTriggerData_) e.put(trigd);
00151 if (doRunData_) e.put(rund);
00152 if (doEventPosition_) e.put(epd);
00153 if (doTiming_) e.put(tmgd);
00154 if (doBeamADC_) e.put(bcntd);
00155 if (doSourcePos_) e.put(spd);
00156 }
00157
00158
00159 void HcalTBObjectUnpacker::parseCalib(){
00160
00161 if(calibFile_.size()==0){
00162 printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
00163 return;
00164 }
00165
00166 edm::FileInPath fip(calibFile_);
00167
00168
00169 ifstream infile(fip.fullPath().c_str());
00170
00171 char buffer [1024];
00172 string tmpStr;
00173
00174 while (infile.getline(buffer, 1024)) {
00175 if (buffer [0] == '#') continue;
00176 if (buffer [0] == '/' && buffer [1] == '/') continue;
00177 tmpStr = string(buffer);
00178 vector<string> lineVect;
00179
00180 int start = 0; bool empty = true;
00181 for (unsigned i=0; i<=tmpStr.size(); i++) {
00182 if (tmpStr[i] == ' ' || i==tmpStr.size()) {
00183 if (!empty) {
00184 std::string item(tmpStr, start, i-start);
00185 lineVect.push_back(item);
00186 empty = true;
00187
00188 }
00189 start = i+1;
00190 }
00191 else {
00192 if (empty) empty = false;
00193 }
00194 }
00195
00196 if(lineVect.size()>0) calibLines_.push_back(lineVect);
00197 }
00198
00199 infile.close();
00200 return;
00201 }
00202
00203 #include "FWCore/PluginManager/interface/ModuleDef.h"
00204 #include "FWCore/Framework/interface/MakerMacros.h"
00205
00206 DEFINE_FWK_MODULE(HcalTBObjectUnpacker);