Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:14

0001 #include <L1TriggerConfig/CSCTFConfigProducers/interface/CSCTFConfigProducer.h>
0002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0003 
0004 #include <cerrno>
0005 #include <cstdio>
0006 #include <fstream>
0007 #include <iostream>
0008 #include <memory>
0009 
0010 CSCTFConfigProducer::CSCTFConfigProducer(const edm::ParameterSet& pset) {
0011   const char* name[12] = {"registersSP1",
0012                           "registersSP2",
0013                           "registersSP3",
0014                           "registersSP4",
0015                           "registersSP5",
0016                           "registersSP6",
0017                           "registersSP7",
0018                           "registersSP8",
0019                           "registersSP9",
0020                           "registersSP10",
0021                           "registersSP11",
0022                           "registersSP12"};
0023 
0024   for (int sp = 0; sp < 12; sp++) {
0025     std::vector<std::string> regs = pset.getParameter<std::vector<std::string> >(name[sp]);
0026     for (std::vector<std::string>::const_iterator line = regs.begin(); line != regs.end(); line++)
0027       registers[sp] += *line + "\n";
0028   }
0029 
0030   alignment = pset.getParameter<std::vector<double> >("alignment");
0031   ptLUT_path = pset.getParameter<std::string>("ptLUT_path");
0032   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd);
0033   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd);
0034   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCPtLutRcd);
0035 }
0036 
0037 std::unique_ptr<L1MuCSCTFConfiguration> CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd(
0038     const L1MuCSCTFConfigurationRcd& iRecord) {
0039   edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
0040                                               << " L1MuCSCTFConfiguration from PSET";
0041 
0042   std::unique_ptr<L1MuCSCTFConfiguration> config = std::make_unique<L1MuCSCTFConfiguration>(registers);
0043   return config;
0044 }
0045 
0046 std::unique_ptr<L1MuCSCTFAlignment> CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd(
0047     const L1MuCSCTFAlignmentRcd& iRecord) {
0048   edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
0049                                               << " L1MuCSCTFAlignment from PSET";
0050 
0051   std::unique_ptr<L1MuCSCTFAlignment> al = std::make_unique<L1MuCSCTFAlignment>(alignment);
0052   return al;
0053 }
0054 
0055 std::unique_ptr<L1MuCSCPtLut> CSCTFConfigProducer::produceL1MuCSCPtLutRcd(const L1MuCSCPtLutRcd& iRecord) {
0056   edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
0057                                               << " L1MuCSCPtLut from PSET";
0058 
0059   std::unique_ptr<L1MuCSCPtLut> pt_lut = std::make_unique<L1MuCSCPtLut>();
0060 
0061   if (ptLUT_path.length()) {
0062     readLUT(ptLUT_path, (unsigned short*)pt_lut->pt_lut, 1 << 21);  //CSCBitWidths::kPtAddressWidth
0063   } else {
0064     throw cms::Exception("Undefined pT LUT")
0065         << "CSCTFConfigProducer is unable to generate LUTs on the fly.\n"
0066            "Specify full LUT file names or just avoid using CSCTFConfigProducer by uncommenting PTLUT "
0067            "parameter sets in L1Trigger/CSCTrackFinder configuration."
0068         << std::endl;
0069   }
0070   return pt_lut;
0071 }
0072 
0073 void CSCTFConfigProducer::readLUT(std::string path, unsigned short* lut, unsigned long length) {
0074   // Reading
0075   if (path.find(".bin") != std::string::npos) {  // Binary format
0076     std::ifstream file(path.c_str(), std::ios::binary);
0077     file.read((char*)lut, length * sizeof(unsigned short));
0078     if (file.fail())
0079       throw cms::Exception("Reading error") << "CSCTFConfigProducer cannot read " << length << " words from " << path
0080                                             << " (errno=" << errno << ")" << std::endl;
0081     if ((unsigned int)file.gcount() != length * sizeof(unsigned short))
0082       throw cms::Exception("Incorrect LUT size")
0083           << "CSCTFConfigProducer read " << (file.gcount() / sizeof(unsigned short)) << " words from " << path
0084           << " instead of " << length << " (errno=" << errno << ")" << std::endl;
0085     file.close();
0086   } else {
0087     std::ifstream file(path.c_str());
0088     if (file.fail())
0089       throw cms::Exception("Cannot open file")
0090           << "CSCTFConfigProducer cannot open " << path << " (errno=" << errno << ")" << std::endl;
0091     unsigned int address = 0;
0092     for (address = 0; !file.eof() && address < length; address++)
0093       file >> lut[address];  // Warning: this may throw non-cms like exception
0094     if (address != length)
0095       throw cms::Exception("Incorrect LUT size")
0096           << "CSCTFConfigProducer read " << address << " words from " << path << " instead of " << length << std::endl;
0097     file.close();
0098   }
0099   LogDebug("CSCTFConfigProducer::readLUT") << " read from " << path << " " << length << " words" << std::endl;
0100 }