Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:45

0001 #include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
0002 #include "EventFilter/HGCalRawToDigi/interface/HGCalUnpacker.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <iomanip>
0006 #include <fstream>
0007 
0008 uint16_t enabledERXMapping(uint16_t sLink, uint8_t captureBlock, uint8_t econd) {
0009   if (sLink == 0 && captureBlock == 0 && econd == 3) {
0010     return 0b1;
0011   }
0012   return 0b11;
0013 }
0014 
0015 HGCalElectronicsId logicalMapping(HGCalElectronicsId elecID) { return elecID; }
0016 
0017 int main(int argc, char* argv[]) {
0018   std::vector<uint32_t> testInput;
0019   if (argc > 1) {
0020     std::ifstream file(argv[1], std::ios::in | std::ios::binary);
0021     std::vector<uint8_t> data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
0022     for (size_t i = 0; i < data.size(); i += 4)
0023       testInput.emplace_back(((data.at(i)) & 0xff << 24) | ((data.at(i + 1) & 0xff) << 16) |
0024                              ((data.at(i + 2) & 0xff) << 8) | (data.at(i + 3) & 0xff));
0025     std::cout << ":::: test input ::::" << std::endl;
0026     for (const auto& word : testInput)
0027       std::cout << std::hex << std::setw(8) << (int)word << std::endl;
0028     std::cout << ":::: total size: " << testInput.size() << std::endl;
0029   } else
0030     testInput = std::vector<uint32_t>{
0031         0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xfffff000, 0xaa0250bf, 0x00000000, 0xfdfffffc,
0032         0x00000007, 0x0fffff1f, 0xfc2fffff, 0x3fffff7f, 0xffffffff, 0xffffff00, 0xffffffff, 0x00000000, 0x00000000,
0033         0xaa0010ff, 0x00000000, 0xaa001f7f, 0x00000000, 0xaa0a30bf, 0x00000000, 0xfdffffff, 0xffffffff, 0xffffffff,
0034         0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0035         0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0036         0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0037         0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0038         0x00000000, 0xffffffff, 0xffffffd3, 0xaa0050bf, 0x00000000, 0xffffffff, 0x00000000, 0xaa0090bf, 0x00000000,
0039         0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};
0040 
0041   HGCalUnpackerConfig config;
0042   config.sLinkCaptureBlockMax = 2;
0043   HGCalUnpacker<HGCalElectronicsId> unpacker(config);
0044   unpacker.parseSLink(testInput, enabledERXMapping, logicalMapping);
0045 
0046   auto channeldata = unpacker.channelData();
0047   auto cms = unpacker.commonModeIndex();
0048   for (unsigned int i = 0; i < channeldata.size(); i++) {
0049     auto data = channeldata.at(i);
0050     auto cm = cms.at(i);
0051     auto id = data.id();
0052     auto idraw = id.raw();
0053     auto raw = data.raw();
0054     std::cout << "id=" << idraw << ", raw=" << raw << ", common mode index=" << cm << std::endl;
0055   }
0056   if (auto badECONDs = unpacker.badECOND(); !badECONDs.empty()) {
0057     std::cerr << "bad ECON-Ds: " << std::dec;
0058     std::string sep;
0059     for (auto badECOND : badECONDs)
0060       std::cerr << sep << badECOND, sep = ", ";
0061     std::cerr << std::endl;
0062   }
0063   return 0;
0064 }