CMS 3D CMS Logo

Public Member Functions | Static Protected Member Functions | Private Attributes

L1GtPatternWriter Class Reference

#include <L1GtPatternWriter.h>

List of all members.

Public Member Functions

void close ()
 L1GtPatternWriter (std::ostream &destination, const std::string &header, const std::string &footer, const std::vector< std::string > columns, const std::vector< boost::uint32_t > &lengths, const std::vector< boost::uint32_t > &defaultValues, const std::vector< int > &bx, bool debug=false)
virtual void writePatternLine (const L1GtPatternLine &line)
void writePatterns (const L1GtPatternMap &patterns)
virtual ~L1GtPatternWriter ()

Static Protected Member Functions

static boost::uint32_t mask (boost::uint32_t length)

Private Attributes

std::vector< int > m_bx
std::vector< std::string > m_columns
bool m_debug
std::vector< boost::uint32_t > m_defaults
std::ostream & m_dest
std::string m_footer
std::string m_header
std::vector< boost::uint32_t > m_lengths
boost::uint32_t m_lineNo

Detailed Description

The L1GtPatternWriter object is responsible for the actual formatting of the content of one or more L1GtPatternMaps into a text file.

Description: Formats L1GtPatternMaps into text files.

Implementation: <TODO: enter implementation details>

Author:
: Thomas Themel - HEPHY Vienna

$Date$ $Revision$

Description: see header file.

Implementation: <TODO: enter implementation details>

Author:
: Thomas Themel - HEPHY Vienna

$Date$ $Revision$

Definition at line 30 of file L1GtPatternWriter.h.


Constructor & Destructor Documentation

L1GtPatternWriter::L1GtPatternWriter ( std::ostream &  destination,
const std::string &  header,
const std::string &  footer,
const std::vector< std::string >  columns,
const std::vector< boost::uint32_t > &  lengths,
const std::vector< boost::uint32_t > &  defaultValues,
const std::vector< int > &  bx,
bool  debug = false 
)

Construct a new pattern writer.

Parameters:
destinationoutput stream to write to
headerstring to be written before pattern lines
footerstring to be written after pattern lines
columnsvector of column names for each pattern line
lengthvector of column lengths (in bits!) for each pattern line
defaultsvector of default values (written if the pattern data does not contain entries for the column). Indexed like columns.
bxvector of bunch crossing numbers to print (empty for 'all')
debugset to true to enable extensive debug logging

Definition at line 30 of file L1GtPatternWriter.cc.

References m_dest, and m_header.

                                                          :
    m_dest(destination),
    m_header(header),
    m_footer(footer),
    m_columns(columns),
    m_lengths(lengths),
    m_defaults(defaults),
    m_bx(bx),
    m_debug(debug),
    m_lineNo(0)

{
    m_dest << m_header;
}
L1GtPatternWriter::~L1GtPatternWriter ( ) [virtual]

Definition at line 110 of file L1GtPatternWriter.cc.

References close().

                                      { 
    close();
}

Member Function Documentation

void L1GtPatternWriter::close ( void  )

Close the output stream

Definition at line 103 of file L1GtPatternWriter.cc.

References m_dest, and m_footer.

Referenced by ~L1GtPatternWriter().

                              { 
    if(m_dest) {
        m_dest << m_footer;
    }
}
static boost::uint32_t L1GtPatternWriter::mask ( boost::uint32_t  length) [static, protected]

Returns an and-mask to truncate an boost::uint32_t to a specified length.

Referenced by writePatternLine().

void L1GtPatternWriter::writePatternLine ( const L1GtPatternLine line) [virtual]

Format a single line.

Definition at line 71 of file L1GtPatternWriter.cc.

References L1GtPatternLine::get(), L1GtPatternLine::has(), i, m_columns, m_defaults, m_dest, m_lengths, m_lineNo, mask(), and relativeConstraints::value.

Referenced by writePatterns().

                                                                    { 
    m_dest << std::setfill('0');
    // open each line with a line number
    // the line number is in decimal, while everything else is hex.
    m_dest << std::dec << std::setw(4) << m_lineNo << ' ' << std::hex ;
    
    for(uint32_t i = 0 ; i < m_columns.size() ; ++i) { 
        // space beween fields
        if(i) m_dest << ' ';
      
        // retrieve column value
        uint32_t value;
        if(line.has(m_columns[i])) { 
           // value comes from data     
           value = line.get(m_columns[i]);
        } else if(m_defaults.size() > i) {
           // value was specified as a config default.
           value = m_defaults[i];
        } else  { 
           // no default specified, set to 0
           value = 0;
        } 
        uint32_t digits = (m_lengths[i]+3)/4;
        
        // write to file with configured length (truncating value if neccessary)
        m_dest << std::setw(digits) << (value & mask(m_lengths[i]));
    }

    // next line
    m_dest << std::endl;
}
void L1GtPatternWriter::writePatterns ( const L1GtPatternMap patterns)

Write the lines from a pattern map to the output stream.

Definition at line 48 of file L1GtPatternWriter.cc.

References L1GtPatternMap::begin(), hcal_timing_source_file_cfg::dump, L1GtPatternMap::end(), spr::find(), edm::isDebugEnabled(), LogTrace, m_bx, m_debug, m_dest, m_lineNo, L1GtPatternMap::print(), and writePatternLine().

                                                                    { 
    for(L1GtPatternMap::LineMap::const_iterator it = patterns.begin(); it != patterns.end() ; ++it) { 
        int event = it->first.first;
        int bx = it->first.second;

        if(edm::isDebugEnabled() && m_debug) {
            std::stringstream dump;
            patterns.print(dump);
            LogTrace("L1GtPatternGenerator") << dump.str();
        }

        if(m_bx.empty() || std::find(m_bx.begin(), m_bx.end(), bx) != m_bx.end()) {
            if(m_debug) { 
                m_dest << "# Event " << std::dec << event << ", bx " << bx << std::endl;
            }
            writePatternLine(it->second);
            ++m_lineNo;
        } else { 
            LogTrace("L1GtPatternGenerator") << "Skipping event " << it->first.first << " bx " << it->first.second << " because of bx filter";
        }
    }
}

Member Data Documentation

std::vector<int> L1GtPatternWriter::m_bx [private]

Definition at line 73 of file L1GtPatternWriter.h.

Referenced by writePatterns().

std::vector<std::string> L1GtPatternWriter::m_columns [private]

Definition at line 70 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

Definition at line 74 of file L1GtPatternWriter.h.

Referenced by writePatterns().

std::vector<boost::uint32_t> L1GtPatternWriter::m_defaults [private]

Definition at line 72 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

std::ostream& L1GtPatternWriter::m_dest [private]

Definition at line 67 of file L1GtPatternWriter.h.

Referenced by close(), L1GtPatternWriter(), writePatternLine(), and writePatterns().

std::string L1GtPatternWriter::m_footer [private]

Definition at line 69 of file L1GtPatternWriter.h.

Referenced by close().

std::string L1GtPatternWriter::m_header [private]

Definition at line 68 of file L1GtPatternWriter.h.

Referenced by L1GtPatternWriter().

std::vector<boost::uint32_t> L1GtPatternWriter::m_lengths [private]

Definition at line 71 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

boost::uint32_t L1GtPatternWriter::m_lineNo [private]

Definition at line 76 of file L1GtPatternWriter.h.

Referenced by writePatternLine(), and writePatterns().