CMS 3D CMS Logo

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