Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:23

0001 /**
0002  * \class L1GtPatternWriter
0003  * 
0004  * 
0005  * Description: see header file.  
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *   
0010  * \author: Thomas Themel - HEPHY Vienna
0011  * 
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternWriter.h"
0017 
0018 // system include files
0019 #include <iostream>
0020 #include <iomanip>
0021 #include <algorithm>
0022 
0023 // user include files
0024 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternMap.h"
0025 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPatternWriter.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 L1GtPatternWriter::L1GtPatternWriter(std::ostream& destination,
0029                                      const std::string& header,
0030                                      const std::string& footer,
0031                                      const std::vector<std::string>& columns,
0032                                      const std::vector<uint32_t>& lengths,
0033                                      const std::vector<uint32_t>& defaults,
0034                                      const std::vector<int>& bx,
0035                                      bool debug)
0036     : m_dest(destination),
0037       m_header(header),
0038       m_footer(footer),
0039       m_columns(columns),
0040       m_lengths(lengths),
0041       m_defaults(defaults),
0042       m_bx(bx),
0043       m_debug(debug),
0044       m_lineNo(0)
0045 
0046 {
0047   m_dest << m_header;
0048 }
0049 
0050 void L1GtPatternWriter::writePatterns(const L1GtPatternMap& patterns) {
0051   for (L1GtPatternMap::LineMap::const_iterator it = patterns.begin(); it != patterns.end(); ++it) {
0052     int event = it->first.first;
0053     int bx = it->first.second;
0054 
0055     if (edm::isDebugEnabled() && m_debug) {
0056       std::stringstream dump;
0057       patterns.print(dump);
0058       LogTrace("L1GtPatternGenerator") << dump.str();
0059     }
0060 
0061     if (m_bx.empty() || std::find(m_bx.begin(), m_bx.end(), bx) != m_bx.end()) {
0062       if (m_debug) {
0063         m_dest << "# Event " << std::dec << event << ", bx " << bx << std::endl;
0064       }
0065       writePatternLine(it->second);
0066       ++m_lineNo;
0067     } else {
0068       LogTrace("L1GtPatternGenerator") << "Skipping event " << it->first.first << " bx " << it->first.second
0069                                        << " because of bx filter";
0070     }
0071   }
0072 }
0073 
0074 void L1GtPatternWriter::writePatternLine(const L1GtPatternLine& line) {
0075   m_dest << std::setfill('0');
0076   // open each line with a line number
0077   // the line number is in decimal, while everything else is hex.
0078   m_dest << std::dec << std::setw(4) << m_lineNo << ' ' << std::hex;
0079 
0080   for (uint32_t i = 0; i < m_columns.size(); ++i) {
0081     // space beween fields
0082     if (i)
0083       m_dest << ' ';
0084 
0085     // retrieve column value
0086     uint32_t value;
0087     if (line.has(m_columns[i])) {
0088       // value comes from data
0089       value = line.get(m_columns[i]);
0090     } else if (m_defaults.size() > i) {
0091       // value was specified as a config default.
0092       value = m_defaults[i];
0093     } else {
0094       // no default specified, set to 0
0095       value = 0;
0096     }
0097     uint32_t digits = (m_lengths[i] + 3) / 4;
0098 
0099     // write to file with configured length (truncating value if neccessary)
0100     m_dest << std::setw(digits) << (value & mask(m_lengths[i]));
0101   }
0102 
0103   // next line
0104   m_dest << std::endl;
0105 }
0106 
0107 void L1GtPatternWriter::close() {
0108   if (m_dest) {
0109     m_dest << m_footer;
0110   }
0111 }
0112 
0113 L1GtPatternWriter::~L1GtPatternWriter() { close(); }
0114 
0115 uint32_t L1GtPatternWriter::mask(uint32_t length) {
0116   if (length < 32) {
0117     return ~((~0U) << length);
0118   } else {
0119     return ~0U;
0120   }
0121 }