Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:58

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 // Functions that gets called by framework every event
0096 void HcalTBObjectUnpacker::produce(edm::Event& e, const edm::EventSetup&) {
0097   // Step A: Get Inputs
0098   edm::Handle<FEDRawDataCollection> rawraw;
0099   e.getByToken(tok_raw_, rawraw);
0100 
0101   // Step B: Create empty output
0102   auto trigd = std::make_unique<HcalTBTriggerData>();
0103 
0104   auto rund = std::make_unique<HcalTBRunData>();
0105 
0106   auto epd = std::make_unique<HcalTBEventPosition>();
0107 
0108   auto tmgd = std::make_unique<HcalTBTiming>();
0109 
0110   auto bcntd = std::make_unique<HcalTBBeamCounters>();
0111 
0112   auto spd = std::make_unique<HcalSourcePositionData>();
0113 
0114   if (triggerFed_ >= 0) {
0115     // Step C: unpack all requested FEDs
0116     const FEDRawData& fed = rawraw->FEDData(triggerFed_);
0117     tdUnpacker_.unpack(fed, *trigd);
0118   }
0119 
0120   if (sdFed_ >= 0) {
0121     // Step C: unpack all requested FEDs
0122     const FEDRawData& fed = rawraw->FEDData(sdFed_);
0123     sdUnpacker_.unpack(fed, *rund, *epd);
0124   }
0125 
0126   if (tdcFed_ >= 0) {
0127     // Step C: unpack all requested FEDs
0128     const FEDRawData& fed = rawraw->FEDData(tdcFed_);
0129     tdcUnpacker_.unpack(fed, *epd, *tmgd);
0130   }
0131 
0132   if (qadcFed_ >= 0) {
0133     // Step C: unpack all requested FEDs
0134     const FEDRawData& fed = rawraw->FEDData(qadcFed_);
0135     bool is04 = true;
0136     if (qadcFed_ == 8)
0137       is04 = false;
0138     qadcUnpacker_.unpack(fed, *bcntd, is04);
0139   }
0140 
0141   if (spdFed_ >= 0) {
0142     // Step C: unpack all requested FEDs
0143     const FEDRawData& fed = rawraw->FEDData(spdFed_);
0144     spdUnpacker_.unpack(fed, *spd);
0145   }
0146 
0147   // Step D: Put outputs into event
0148   if (doTriggerData_)
0149     e.put(std::move(trigd));
0150   if (doRunData_)
0151     e.put(std::move(rund));
0152   if (doEventPosition_)
0153     e.put(std::move(epd));
0154   if (doTiming_)
0155     e.put(std::move(tmgd));
0156   if (doBeamADC_)
0157     e.put(std::move(bcntd));
0158   if (doSourcePos_)
0159     e.put(std::move(spd));
0160 }
0161 
0162 void HcalTBObjectUnpacker::parseCalib() {
0163   if (calibFile_.empty()) {
0164     printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
0165     return;
0166   }
0167 
0168   edm::FileInPath fip(calibFile_);
0169 
0170   ifstream infile(fip.fullPath().c_str());
0171 
0172   char buffer[1024];
0173   string tmpStr;
0174 
0175   while (infile.getline(buffer, 1024)) {
0176     if (buffer[0] == '#')
0177       continue;  //ignore comment
0178     if (buffer[0] == '/' && buffer[1] == '/')
0179       continue;  //ignore comment
0180     tmpStr = string(buffer);
0181     vector<string> lineVect;
0182 
0183     int start = 0;
0184     bool empty = true;
0185     for (unsigned i = 0; i <= tmpStr.size(); i++) {
0186       if (tmpStr[i] == ' ' || i == tmpStr.size()) {
0187         if (!empty) {
0188           std::string item(tmpStr, start, i - start);
0189           lineVect.push_back(item);
0190           empty = true;
0191           //      printf("Got: %s\n",item.c_str());
0192         }
0193         start = i + 1;
0194       } else {
0195         if (empty)
0196           empty = false;
0197       }
0198     }
0199 
0200     if (!lineVect.empty())
0201       calibLines_.push_back(lineVect);
0202   }
0203 
0204   infile.close();
0205   return;
0206 }
0207 
0208 #include "FWCore/PluginManager/interface/ModuleDef.h"
0209 #include "FWCore/Framework/interface/MakerMacros.h"
0210 
0211 DEFINE_FWK_MODULE(HcalTBObjectUnpacker);