CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/L1Trigger/GlobalTriggerAnalyzer/src/L1GtPatternWriter.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternWriter.h"
00019 
00020 // system include files
00021 #include <iostream>
00022 #include <iomanip>
00023 #include <algorithm> 
00024 
00025 // user include files
00026 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternMap.h"
00027 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternWriter.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 
00030 L1GtPatternWriter::L1GtPatternWriter(std::ostream& destination, const std::string& header,
00031                     const std::string& footer, const std::vector<std::string> columns,
00032                     const std::vector<uint32_t>& lengths, const std::vector<uint32_t>& defaults, 
00033                     const std::vector<int>& bx, bool debug) :
00034     m_dest(destination),
00035     m_header(header),
00036     m_footer(footer),
00037     m_columns(columns),
00038     m_lengths(lengths),
00039     m_defaults(defaults),
00040     m_bx(bx),
00041     m_debug(debug),
00042     m_lineNo(0)
00043 
00044 {
00045     m_dest << m_header;
00046 }
00047 
00048 void L1GtPatternWriter::writePatterns(const L1GtPatternMap& patterns) { 
00049     for(L1GtPatternMap::LineMap::const_iterator it = patterns.begin(); it != patterns.end() ; ++it) { 
00050         int event = it->first.first;
00051         int bx = it->first.second;
00052 
00053         if(edm::isDebugEnabled() && m_debug) {
00054             std::stringstream dump;
00055             patterns.print(dump);
00056             LogTrace("L1GtPatternGenerator") << dump.str();
00057         }
00058 
00059         if(m_bx.empty() || std::find(m_bx.begin(), m_bx.end(), bx) != m_bx.end()) {
00060             if(m_debug) { 
00061                 m_dest << "# Event " << std::dec << event << ", bx " << bx << std::endl;
00062             }
00063             writePatternLine(it->second);
00064             ++m_lineNo;
00065         } else { 
00066             LogTrace("L1GtPatternGenerator") << "Skipping event " << it->first.first << " bx " << it->first.second << " because of bx filter";
00067         }
00068     }
00069 }
00070 
00071 void L1GtPatternWriter::writePatternLine(const L1GtPatternLine& line) { 
00072     m_dest << std::setfill('0');
00073     // open each line with a line number
00074     // the line number is in decimal, while everything else is hex.
00075     m_dest << std::dec << std::setw(4) << m_lineNo << ' ' << std::hex ;
00076     
00077     for(uint32_t i = 0 ; i < m_columns.size() ; ++i) { 
00078         // space beween fields
00079         if(i) m_dest << ' ';
00080       
00081         // retrieve column value
00082         uint32_t value;
00083         if(line.has(m_columns[i])) { 
00084            // value comes from data     
00085            value = line.get(m_columns[i]);
00086         } else if(m_defaults.size() > i) {
00087            // value was specified as a config default.
00088            value = m_defaults[i];
00089         } else  { 
00090            // no default specified, set to 0
00091            value = 0;
00092         } 
00093         uint32_t digits = (m_lengths[i]+3)/4;
00094         
00095         // write to file with configured length (truncating value if neccessary)
00096         m_dest << std::setw(digits) << (value & mask(m_lengths[i]));
00097     }
00098 
00099     // next line
00100     m_dest << std::endl;
00101 }
00102 
00103 void L1GtPatternWriter::close() { 
00104     if(m_dest) {
00105         m_dest << m_footer;
00106     }
00107 }
00108 
00109 
00110 L1GtPatternWriter::~L1GtPatternWriter() { 
00111     close();
00112 }
00113 
00114 uint32_t L1GtPatternWriter::mask(uint32_t length) { 
00115     if(length < 32) { 
00116         return ~((~0) << length);
00117     } else { 
00118         return ~0;
00119     }
00120 }