CMS 3D CMS Logo

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         for(int sp=0; sp<12; sp++){
00014                 std::vector<std::string> regs = pset.getParameter<std::vector<std::string> >(name[sp]);
00015                 for(std::vector<std::string>::const_iterator line=regs.begin(); line!=regs.end(); line++)
00016                         registers[sp] += *line + "\n";
00017         }
00018         alignment  = pset.getParameter< std::vector<double> >("alignment");
00019         ptLUT_path = pset.getParameter< std::string >        ("ptLUT_path");
00020         setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd);
00021         setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd);
00022         setWhatProduced(this, &CSCTFConfigProducer::produceL1MuCSCPtLutRcd);
00023 }
00024 
00025 std::auto_ptr<L1MuCSCTFConfiguration> CSCTFConfigProducer::produceL1MuCSCTFConfigurationRcd(const L1MuCSCTFConfigurationRcd& iRecord){
00026         std::auto_ptr<L1MuCSCTFConfiguration> config = std::auto_ptr<L1MuCSCTFConfiguration>( new L1MuCSCTFConfiguration(registers) );
00027         return config;
00028 }
00029 
00030 std::auto_ptr<L1MuCSCTFAlignment> CSCTFConfigProducer::produceL1MuCSCTFAlignmentRcd(const L1MuCSCTFAlignmentRcd& iRecord){
00031         std::auto_ptr<L1MuCSCTFAlignment> al = std::auto_ptr<L1MuCSCTFAlignment>( new L1MuCSCTFAlignment(alignment) );
00032         return al;
00033 }
00034 
00035 std::auto_ptr<L1MuCSCPtLut> CSCTFConfigProducer::produceL1MuCSCPtLutRcd(const L1MuCSCPtLutRcd& iRecord){
00036         std::auto_ptr<L1MuCSCPtLut> pt_lut = std::auto_ptr<L1MuCSCPtLut>( new L1MuCSCPtLut() );
00037 
00038         if( ptLUT_path.length() ){
00039                         readLUT(ptLUT_path, (unsigned short *)pt_lut->pt_lut, 1<<21); //CSCBitWidths::kPtAddressWidth
00040         } else {
00041                 throw cms::Exception("Undefined pT LUT")<<"CSCTFConfigProducer is unable to generate LUTs on the fly.\nSpecify full LUT file names or just avoid using CSCTFConfigProducer by uncommenting PTLUT parameter sets in L1Trigger/CSCTrackFinder configuration."<<std::endl;
00042         }
00043         return pt_lut;
00044 }
00045 
00046 void CSCTFConfigProducer::readLUT(std::string path, unsigned short* lut, unsigned long length){
00047         // Reading
00048         if( path.find(".bin") != std::string::npos ) { // Binary format
00049                 std::ifstream file(path.c_str(), std::ios::binary);
00050                 file.read((char*)lut,length*sizeof(unsigned short));
00051                 if( file.fail() )
00052                         throw cms::Exception("Reading error")<<"CSCTFConfigProducer cannot read "<<length<<" words from "<<path<<" (errno="<<errno<<")"<<std::endl;
00053                 if( (unsigned int)file.gcount() != length*sizeof(unsigned short) )
00054                         throw cms::Exception("Incorrect LUT size")<<"CSCTFConfigProducer read "<<(file.gcount()/sizeof(unsigned short))<<" words from "<<path<<" instead of "<<length<<" (errno="<<errno<<")"<<std::endl;
00055                 file.close();
00056         } else {
00057                 std::ifstream file(path.c_str());
00058                 if( file.fail() )
00059                         throw cms::Exception("Cannot open file")<<"CSCTFConfigProducer cannot open "<<path<<" (errno="<<errno<<")"<<std::endl;
00060                 unsigned int address=0;
00061                 for(address=0; !file.eof() && address<length; address++)
00062                         file >> lut[address]; // Warning: this may throw non-cms like exception
00063                 if( address!=length ) throw cms::Exception("Incorrect LUT size")<<"CSCTFConfigProducer read "<<address<<" words from "<<path<<" instead of "<<length<<std::endl;
00064                 file.close();
00065         }
00066         LogDebug("CSCTFConfigProducer::readLUT")<<" read from "<<path<<" "<<length<<" words"<<std::endl;
00067 }

Generated on Tue Jun 9 17:40:26 2009 for CMSSW by  doxygen 1.5.4