Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:23

0001 #include "CondFormats/L1TObjects/interface/L1MuCSCPtLut.h"
0002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0003 #include <sstream>
0004 #include <iostream>
0005 #include <cerrno>
0006 
0007 void L1MuCSCPtLut::readFromDBS(std::string& ptLUT) {
0008   //edm::LogInfo( "L1-O2O: L1MuCSCPtLut" ) <<" Reading from DBS";
0009 
0010   // the ptLUT returned by the OMDS query will have a structure like number"\n"number"\n"
0011   // e.g., 32896\n32896\n32896\n32896\n and so on
0012   // remove the \n separator to write the pt_lut[1<<21] line-by-line
0013   for (size_t pos = ptLUT.find("\\n"); pos != std::string::npos; pos = ptLUT.find("\\n", pos)) {
0014     ptLUT[pos] = ' ';
0015     ptLUT[pos + 1] = '\n';
0016   }
0017 
0018   unsigned long length = 1 << 21;  //length of the ptLUT file
0019 
0020   std::stringstream file(ptLUT);
0021   if (file.fail())
0022     throw cms::Exception("Cannot open the ptLUT") << "L1MuCSCPtLut cannot open "
0023                                                   << "ptLUT from DBS (errno=" << errno << ")" << std::endl;
0024 
0025   // filling the ptLUT
0026   unsigned int address = 0;
0027   for (address = 0; !file.eof() && address < length; address++) {
0028     char buff[1024];
0029     file.getline(buff, 1024);
0030     int ptOutput = atoi(buff);
0031 
0032     // uncomment if you want to see line-by-line
0033     //edm::LogInfo( "L1-O2O: L1MuCSCPtLut" ) << "writing line "
0034     //                     << ptOutput;
0035 
0036     // Warning: this may throw non-cms like exception
0037     pt_lut[address] = ptOutput;
0038   }
0039 
0040   if (address != length)
0041     throw cms::Exception("Incorrect LUT size")
0042         << "L1MuCSCPtLut read " << address << " words from DBS instead of expected " << length << std::endl;
0043 }