CMS 3D CMS Logo

CSCTFConfigProducer.cc
Go to the documentation of this file.
3 
4 #include <cstdio>
5 #include <cerrno>
6 #include <iostream>
7 #include <fstream>
8 
10  const char* name[12] = {"registersSP1",
11  "registersSP2",
12  "registersSP3",
13  "registersSP4",
14  "registersSP5",
15  "registersSP6",
16  "registersSP7",
17  "registersSP8",
18  "registersSP9",
19  "registersSP10",
20  "registersSP11",
21  "registersSP12"};
22 
23  for (int sp = 0; sp < 12; sp++) {
24  std::vector<std::string> regs = pset.getParameter<std::vector<std::string> >(name[sp]);
25  for (std::vector<std::string>::const_iterator line = regs.begin(); line != regs.end(); line++)
26  registers[sp] += *line + "\n";
27  }
28 
29  alignment = pset.getParameter<std::vector<double> >("alignment");
30  ptLUT_path = pset.getParameter<std::string>("ptLUT_path");
34 }
35 
36 std::unique_ptr<L1MuCSCTFConfiguration> CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd(
37  const L1MuCSCTFConfigurationRcd& iRecord) {
38  edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
39  << " L1MuCSCTFConfiguration from PSET";
40 
41  std::unique_ptr<L1MuCSCTFConfiguration> config =
42  std::unique_ptr<L1MuCSCTFConfiguration>(new L1MuCSCTFConfiguration(registers));
43  return config;
44 }
45 
46 std::unique_ptr<L1MuCSCTFAlignment> CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd(
47  const L1MuCSCTFAlignmentRcd& iRecord) {
48  edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
49  << " L1MuCSCTFAlignment from PSET";
50 
51  std::unique_ptr<L1MuCSCTFAlignment> al = std::unique_ptr<L1MuCSCTFAlignment>(new L1MuCSCTFAlignment(alignment));
52  return al;
53 }
54 
55 std::unique_ptr<L1MuCSCPtLut> CSCTFConfigProducer::produceL1MuCSCPtLutRcd(const L1MuCSCPtLutRcd& iRecord) {
56  edm::LogInfo("L1-O2O: CSCTFConfigProducer") << "Producing "
57  << " L1MuCSCPtLut from PSET";
58 
59  std::unique_ptr<L1MuCSCPtLut> pt_lut = std::unique_ptr<L1MuCSCPtLut>(new L1MuCSCPtLut());
60 
61  if (ptLUT_path.length()) {
62  readLUT(ptLUT_path, (unsigned short*)pt_lut->pt_lut, 1 << 21); //CSCBitWidths::kPtAddressWidth
63  } else {
64  throw cms::Exception("Undefined pT LUT")
65  << "CSCTFConfigProducer is unable to generate LUTs on the fly.\n"
66  "Specify full LUT file names or just avoid using CSCTFConfigProducer by uncommenting PTLUT "
67  "parameter sets in L1Trigger/CSCTrackFinder configuration."
68  << std::endl;
69  }
70  return pt_lut;
71 }
72 
73 void CSCTFConfigProducer::readLUT(std::string path, unsigned short* lut, unsigned long length) {
74  // Reading
75  if (path.find(".bin") != std::string::npos) { // Binary format
76  std::ifstream file(path.c_str(), std::ios::binary);
77  file.read((char*)lut, length * sizeof(unsigned short));
78  if (file.fail())
79  throw cms::Exception("Reading error") << "CSCTFConfigProducer cannot read " << length << " words from " << path
80  << " (errno=" << errno << ")" << std::endl;
81  if ((unsigned int)file.gcount() != length * sizeof(unsigned short))
82  throw cms::Exception("Incorrect LUT size")
83  << "CSCTFConfigProducer read " << (file.gcount() / sizeof(unsigned short)) << " words from " << path
84  << " instead of " << length << " (errno=" << errno << ")" << std::endl;
85  file.close();
86  } else {
87  std::ifstream file(path.c_str());
88  if (file.fail())
89  throw cms::Exception("Cannot open file")
90  << "CSCTFConfigProducer cannot open " << path << " (errno=" << errno << ")" << std::endl;
91  unsigned int address = 0;
92  for (address = 0; !file.eof() && address < length; address++)
93  file >> lut[address]; // Warning: this may throw non-cms like exception
94  if (address != length)
95  throw cms::Exception("Incorrect LUT size")
96  << "CSCTFConfigProducer read " << address << " words from " << path << " instead of " << length << std::endl;
97  file.close();
98  }
99  LogDebug("CSCTFConfigProducer::readLUT") << " read from " << path << " " << length << " words" << std::endl;
100 }
L1MuCSCTFConfiguration
Definition: L1MuCSCTFConfiguration.h:9
MessageLogger.h
edm::LogInfo
Definition: MessageLogger.h:254
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd
std::unique_ptr< L1MuCSCTFAlignment > produceL1MuCSCTFAlignmentRcd(const L1MuCSCTFAlignmentRcd &iRecord)
Definition: CSCTFConfigProducer.cc:46
CSCTFConfigProducer::registers
std::string registers[12]
Definition: CSCTFConfigProducer.h:21
L1MuCSCTFConfigurationRcd
Definition: L1MuCSCTFConfigurationRcd.h:13
alignment
Definition: alignment.py:1
config
Definition: config.py:1
L1MuCSCTFAlignmentRcd
Definition: L1MuCSCTFAlignmentRcd.h:12
looper.config
config
Definition: looper.py:291
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
L1MuCSCPtLutRcd
Definition: L1MuCSCPtLutRcd.h:12
CSCTFConfigProducer::ptLUT_path
std::string ptLUT_path
Definition: CSCTFConfigProducer.h:23
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
CSCTFConfigProducer.h
CSCTFConfigProducer::CSCTFConfigProducer
CSCTFConfigProducer(const edm::ParameterSet &pset)
Definition: CSCTFConfigProducer.cc:9
Exception
Definition: hltDiff.cc:246
CSCTFConfigProducer::readLUT
void readLUT(std::string path, unsigned short *lut, unsigned long length)
Definition: CSCTFConfigProducer.cc:73
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd
std::unique_ptr< L1MuCSCTFConfiguration > produceL1MuCSCTFConfigurationRcd(const L1MuCSCTFConfigurationRcd &iRecord)
Definition: CSCTFConfigProducer.cc:36
L1MuCSCPtLut
Definition: L1MuCSCPtLut.h:11
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
L1MuCSCTFAlignment
Definition: L1MuCSCTFAlignment.h:8
mps_splice.line
line
Definition: mps_splice.py:76
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
CSCTFConfigProducer::produceL1MuCSCPtLutRcd
std::unique_ptr< L1MuCSCPtLut > produceL1MuCSCPtLutRcd(const L1MuCSCPtLutRcd &iRecord)
Definition: CSCTFConfigProducer.cc:55