Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:17

0001 
0002 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
0003 #include "TBDataFormats/HcalTBObjects/interface/HcalTBRunData.h"
0004 #include "TBDataFormats/HcalTBObjects/interface/HcalTBEventPosition.h"
0005 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTiming.h"
0006 #include "TBDataFormats/HcalTBObjects/interface/HcalTBBeamCounters.h"
0007 #include "RecoTBCalo/HcalTBObjectUnpacker/plugins/HcalTBObjectUnpacker.h"
0008 #include "DataFormats/Common/interface/EDCollection.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include <iostream>
0011 #include <fstream>
0012 using namespace std;
0013 
0014 HcalTBObjectUnpacker::HcalTBObjectUnpacker(edm::ParameterSet const& conf)
0015     : triggerFed_(conf.getUntrackedParameter<int>("HcalTriggerFED", -1)),
0016       sdFed_(conf.getUntrackedParameter<int>("HcalSlowDataFED", -1)),
0017       spdFed_(conf.getUntrackedParameter<int>("HcalSourcePositionFED", -1)),
0018       tdcFed_(conf.getUntrackedParameter<int>("HcalTDCFED", -1)),
0019       qadcFed_(conf.getUntrackedParameter<int>("HcalQADCFED", -1)),
0020       calibFile_(conf.getUntrackedParameter<string>("ConfigurationFile", "")),
0021       tdcUnpacker_(conf.getUntrackedParameter<bool>("IncludeUnmatchedHits", false)),
0022       doRunData_(false),
0023       doTriggerData_(false),
0024       doEventPosition_(false),
0025       doTiming_(false),
0026       doSourcePos_(false),
0027       doBeamADC_(false) {
0028   tok_raw_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("fedRawDataCollectionTag"));
0029 
0030   if (triggerFed_ >= 0) {
0031     std::cout << "HcalTBObjectUnpacker will unpack Trigger FED ";
0032     std::cout << triggerFed_ << endl;
0033     doTriggerData_ = true;
0034   }
0035 
0036   if (sdFed_ >= 0) {
0037     std::cout << "HcalTBObjectUnpacker will unpack SlowData FED ";
0038     std::cout << sdFed_ << endl;
0039     doRunData_ = true;
0040     doEventPosition_ = true;  // at least the table
0041   }
0042 
0043   if (tdcFed_ >= 0) {
0044     std::cout << "HcalTBObjectUnpacker will unpack TDC FED ";
0045     std::cout << tdcFed_ << endl;
0046     doTiming_ = true;
0047     doEventPosition_ = true;  // at least the WC
0048   }
0049 
0050   if (qadcFed_ >= 0) {
0051     std::cout << "HcalTBObjectUnpacker will unpack QADC FED ";
0052     std::cout << qadcFed_ << endl;
0053     doBeamADC_ = true;
0054   }
0055 
0056   if (spdFed_ >= 0) {
0057     std::cout << "HcalTBObjectUnpacker will unpack Source Position Data FED ";
0058     std::cout << spdFed_ << endl;
0059     doSourcePos_ = true;
0060   }
0061 
0062   if (tdcFed_ >= 0 || qadcFed_ >= 0) {
0063     calibLines_.clear();
0064     if (!calibFile_.empty()) {
0065       parseCalib();
0066       //  printf("I got %d lines!\n",calibLines_.size());
0067       if (calibLines_.empty())
0068         throw cms::Exception("Incomplete configuration")
0069             << "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found or is empty: " << calibFile_ << endl;
0070     } else {
0071       throw cms::Exception("Incomplete configuration")
0072           << "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found: " << calibFile_ << endl;
0073     }
0074   }
0075 
0076   if (doTriggerData_)
0077     produces<HcalTBTriggerData>();
0078   if (doRunData_)
0079     produces<HcalTBRunData>();
0080   if (doEventPosition_)
0081     produces<HcalTBEventPosition>();
0082   if (doTiming_)
0083     produces<HcalTBTiming>();
0084   //    if (doBeamADC_) produces<HcalTBBeamCounters>();
0085   if (doBeamADC_) {
0086     produces<HcalTBBeamCounters>();
0087     qadcUnpacker_.setCalib(calibLines_);
0088   }
0089   if (doSourcePos_)
0090     produces<HcalSourcePositionData>();
0091   if (doTiming_ || doEventPosition_)
0092     tdcUnpacker_.setCalib(calibLines_);
0093 }
0094 
0095 // Virtual destructor needed.
0096 HcalTBObjectUnpacker::~HcalTBObjectUnpacker() {}
0097 
0098 // Functions that gets called by framework every event
0099 void HcalTBObjectUnpacker::produce(edm::Event& e, const edm::EventSetup&) {
0100   // Step A: Get Inputs
0101   edm::Handle<FEDRawDataCollection> rawraw;
0102   e.getByToken(tok_raw_, rawraw);
0103 
0104   // Step B: Create empty output
0105   auto trigd = std::make_unique<HcalTBTriggerData>();
0106 
0107   auto rund = std::make_unique<HcalTBRunData>();
0108 
0109   auto epd = std::make_unique<HcalTBEventPosition>();
0110 
0111   auto tmgd = std::make_unique<HcalTBTiming>();
0112 
0113   auto bcntd = std::make_unique<HcalTBBeamCounters>();
0114 
0115   auto spd = std::make_unique<HcalSourcePositionData>();
0116 
0117   if (triggerFed_ >= 0) {
0118     // Step C: unpack all requested FEDs
0119     const FEDRawData& fed = rawraw->FEDData(triggerFed_);
0120     tdUnpacker_.unpack(fed, *trigd);
0121   }
0122 
0123   if (sdFed_ >= 0) {
0124     // Step C: unpack all requested FEDs
0125     const FEDRawData& fed = rawraw->FEDData(sdFed_);
0126     sdUnpacker_.unpack(fed, *rund, *epd);
0127   }
0128 
0129   if (tdcFed_ >= 0) {
0130     // Step C: unpack all requested FEDs
0131     const FEDRawData& fed = rawraw->FEDData(tdcFed_);
0132     tdcUnpacker_.unpack(fed, *epd, *tmgd);
0133   }
0134 
0135   if (qadcFed_ >= 0) {
0136     // Step C: unpack all requested FEDs
0137     const FEDRawData& fed = rawraw->FEDData(qadcFed_);
0138     bool is04 = true;
0139     if (qadcFed_ == 8)
0140       is04 = false;
0141     qadcUnpacker_.unpack(fed, *bcntd, is04);
0142   }
0143 
0144   if (spdFed_ >= 0) {
0145     // Step C: unpack all requested FEDs
0146     const FEDRawData& fed = rawraw->FEDData(spdFed_);
0147     spdUnpacker_.unpack(fed, *spd);
0148   }
0149 
0150   // Step D: Put outputs into event
0151   if (doTriggerData_)
0152     e.put(std::move(trigd));
0153   if (doRunData_)
0154     e.put(std::move(rund));
0155   if (doEventPosition_)
0156     e.put(std::move(epd));
0157   if (doTiming_)
0158     e.put(std::move(tmgd));
0159   if (doBeamADC_)
0160     e.put(std::move(bcntd));
0161   if (doSourcePos_)
0162     e.put(std::move(spd));
0163 }
0164 
0165 void HcalTBObjectUnpacker::parseCalib() {
0166   if (calibFile_.empty()) {
0167     printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
0168     return;
0169   }
0170 
0171   edm::FileInPath fip(calibFile_);
0172 
0173   ifstream infile(fip.fullPath().c_str());
0174 
0175   char buffer[1024];
0176   string tmpStr;
0177 
0178   while (infile.getline(buffer, 1024)) {
0179     if (buffer[0] == '#')
0180       continue;  //ignore comment
0181     if (buffer[0] == '/' && buffer[1] == '/')
0182       continue;  //ignore comment
0183     tmpStr = string(buffer);
0184     vector<string> lineVect;
0185 
0186     int start = 0;
0187     bool empty = true;
0188     for (unsigned i = 0; i <= tmpStr.size(); i++) {
0189       if (tmpStr[i] == ' ' || i == tmpStr.size()) {
0190         if (!empty) {
0191           std::string item(tmpStr, start, i - start);
0192           lineVect.push_back(item);
0193           empty = true;
0194           //      printf("Got: %s\n",item.c_str());
0195         }
0196         start = i + 1;
0197       } else {
0198         if (empty)
0199           empty = false;
0200       }
0201     }
0202 
0203     if (!lineVect.empty())
0204       calibLines_.push_back(lineVect);
0205   }
0206 
0207   infile.close();
0208   return;
0209 }
0210 
0211 #include "FWCore/PluginManager/interface/ModuleDef.h"
0212 #include "FWCore/Framework/interface/MakerMacros.h"
0213 
0214 DEFINE_FWK_MODULE(HcalTBObjectUnpacker);