CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/L1TriggerConfig/CSCTFConfigProducers/src/CSCTFConfigProducer.cc

Go to the documentation of this file.
00001 #include <L1TriggerConfig/CSCTFConfigProducers/interface/CSCTFConfigProducer.h>
00002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00003 
00004 #include <stdio.h>
00005 #include <errno.h>
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 CSCTFConfigProducer::CSCTFConfigProducer(const edm::ParameterSet& pset) {
00010   const char *name[12] = {"registersSP1", "registersSP2", "registersSP3", "registersSP4",
00011                           "registersSP5", "registersSP6", "registersSP7", "registersSP8",
00012                           "registersSP9", "registersSP10","registersSP11","registersSP12"};
00013         
00014   for(int sp=0; sp<12; sp++){
00015     std::vector<std::string> regs = pset.getParameter<std::vector<std::string> >(name[sp]);
00016     for(std::vector<std::string>::const_iterator line=regs.begin(); line!=regs.end(); line++)
00017       registers[sp] += *line + "\n";
00018   }
00019         
00020   alignment  = pset.getParameter< std::vector<double> >("alignment");
00021   ptLUT_path = pset.getParameter< std::string >        ("ptLUT_path");
00022   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd);
00023   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd);
00024   setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCPtLutRcd);
00025 
00026 }
00027 
00028 std::auto_ptr<L1MuCSCTFConfiguration> CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd(const L1MuCSCTFConfigurationRcd& iRecord){
00029 
00030   edm::LogInfo( "L1-O2O: CSCTFConfigProducer" ) << "Producing "
00031                                                 << " L1MuCSCTFConfiguration from PSET";
00032                                                 
00033   std::auto_ptr<L1MuCSCTFConfiguration> config = std::auto_ptr<L1MuCSCTFConfiguration>( new L1MuCSCTFConfiguration(registers) );
00034   return config;
00035 }
00036 
00037 std::auto_ptr<L1MuCSCTFAlignment> CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd(const L1MuCSCTFAlignmentRcd& iRecord){
00038   edm::LogInfo( "L1-O2O: CSCTFConfigProducer" ) << "Producing "
00039                                                 << " L1MuCSCTFAlignment from PSET";
00040   
00041 
00042   std::auto_ptr<L1MuCSCTFAlignment> al = std::auto_ptr<L1MuCSCTFAlignment>( new L1MuCSCTFAlignment(alignment) );
00043   return al;
00044 }
00045 
00046 std::auto_ptr<L1MuCSCPtLut> CSCTFConfigProducer::produceL1MuCSCPtLutRcd(const L1MuCSCPtLutRcd& iRecord){
00047   edm::LogInfo( "L1-O2O: CSCTFConfigProducer" ) << "Producing "
00048                                                 << " L1MuCSCPtLut from PSET";
00049   
00050 
00051 
00052   std::auto_ptr<L1MuCSCPtLut> pt_lut = std::auto_ptr<L1MuCSCPtLut>( new L1MuCSCPtLut() );
00053 
00054   if( ptLUT_path.length() ){
00055     readLUT(ptLUT_path, (unsigned short *)pt_lut->pt_lut, 1<<21); //CSCBitWidths::kPtAddressWidth
00056   } else {
00057     throw cms::Exception("Undefined pT LUT")<<"CSCTFConfigProducer is unable to generate LUTs on the fly.\n"
00058       "Specify full LUT file names or just avoid using CSCTFConfigProducer by uncommenting PTLUT "
00059       "parameter sets in L1Trigger/CSCTrackFinder configuration."<<std::endl;
00060   }
00061   return pt_lut;
00062 }
00063 
00064 void CSCTFConfigProducer::readLUT(std::string path, unsigned short* lut, unsigned long length){
00065   // Reading
00066   if( path.find(".bin") != std::string::npos ) { // Binary format
00067     std::ifstream file(path.c_str(), std::ios::binary);
00068     file.read((char*)lut,length*sizeof(unsigned short));
00069     if( file.fail() )
00070       throw cms::Exception("Reading error")<<"CSCTFConfigProducer cannot read "<<length<<" words from "<<path<<" (errno="<<errno<<")"<<std::endl;
00071     if( (unsigned int)file.gcount() != length*sizeof(unsigned short) )
00072       throw cms::Exception("Incorrect LUT size")<<"CSCTFConfigProducer read "<<(file.gcount()/sizeof(unsigned short))<<" words from "<<path<<" instead of "<<length<<" (errno="<<errno<<")"<<std::endl;
00073     file.close();
00074   } else {
00075     std::ifstream file(path.c_str());
00076     if( file.fail() )
00077       throw cms::Exception("Cannot open file")<<"CSCTFConfigProducer cannot open "<<path<<" (errno="<<errno<<")"<<std::endl;
00078     unsigned int address=0;
00079     for(address=0; !file.eof() && address<length; address++)
00080       file >> lut[address]; // Warning: this may throw non-cms like exception
00081     if( address!=length ) throw cms::Exception("Incorrect LUT size")<<"CSCTFConfigProducer read "<<address<<" words from "<<path<<" instead of "<<length<<std::endl;
00082     file.close();
00083   }
00084   LogDebug("CSCTFConfigProducer::readLUT")<<" read from "<<path<<" "<<length<<" words"<<std::endl;
00085 }