CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CondFormats/L1TObjects/src/L1MuCSCPtLut.cc

Go to the documentation of this file.
00001 #include "CondFormats/L1TObjects/interface/L1MuCSCPtLut.h"
00002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00003 #include <sstream>
00004 #include <iostream>
00005 #include <errno.h>
00006 
00007 void L1MuCSCPtLut::readFromDBS( std::string& ptLUT )
00008 {
00009 
00010   //edm::LogInfo( "L1-O2O: L1MuCSCPtLut" ) <<" Reading from DBS";
00011 
00012   // the ptLUT returned by the OMDS query will have a structure like number"\n"number"\n"
00013   // e.g., 32896\n32896\n32896\n32896\n and so on
00014   // remove the \n separator to write the pt_lut[1<<21] line-by-line
00015   for(size_t pos=ptLUT.find("\\n"); pos!=std::string::npos; pos=ptLUT.find("\\n",pos)){ 
00016     ptLUT[pos]=' '; 
00017     ptLUT[pos+1]='\n'; 
00018   }
00019   
00020   unsigned long length = 1<<21; //length of the ptLUT file
00021 
00022   std::stringstream file(ptLUT);
00023   if( file.fail() )
00024     throw cms::Exception("Cannot open the ptLUT")<<"L1MuCSCPtLut cannot open "
00025                                                  <<"ptLUT from DBS (errno="
00026                                                  <<errno<<")"<<std::endl;
00027   
00028   // filling the ptLUT
00029   unsigned int address=0;
00030   for(address=0; !file.eof() && address<length; address++) {
00031     char buff[1024];
00032     file.getline(buff,1024);
00033     int ptOutput = atoi(buff);
00034 
00035     // uncomment if you want to see line-by-line
00036     //edm::LogInfo( "L1-O2O: L1MuCSCPtLut" ) << "writing line " 
00037     //                                 << ptOutput;
00038 
00039     // Warning: this may throw non-cms like exception
00040     pt_lut[address] = ptOutput; 
00041   }
00042   
00043   if( address!=length ) 
00044     throw cms::Exception("Incorrect LUT size")<<"L1MuCSCPtLut read "<<address
00045                                               <<" words from DBS instead of expected "
00046                                               <<length <<std::endl;
00047 }