CMS 3D CMS Logo

List of all members | Public Member Functions | Static Protected Member Functions | Private Attributes
L1GtPatternWriter Class Reference

#include <L1GtPatternWriter.h>

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< uint32_t > &lengths, const std::vector< 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 uint32_t mask (uint32_t length)
 

Private Attributes

std::vector< int > m_bx
 
std::vector< std::string > m_columns
 
bool m_debug
 
std::vector< uint32_t > m_defaults
 
std::ostream & m_dest
 
std::string m_footer
 
std::string m_header
 
std::vector< uint32_t > m_lengths
 
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

Description: see header file.
Implementation: <TODO: enter implementation details>

Author
: Thomas Themel - HEPHY Vienna

Definition at line 28 of file L1GtPatternWriter.h.

Constructor & Destructor Documentation

◆ L1GtPatternWriter()

L1GtPatternWriter::L1GtPatternWriter ( std::ostream &  destination,
const std::string &  header,
const std::string &  footer,
const std::vector< std::string > &  columns,
const std::vector< uint32_t > &  lengths,
const std::vector< 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 28 of file L1GtPatternWriter.cc.

References m_dest, and m_header.

38  m_footer(footer),
42  m_bx(bx),
43  m_debug(debug),
44  m_lineNo(0)
45 
46 {
47  m_dest << m_header;
48 }
std::ostream & m_dest
std::vector< std::string > m_columns
std::vector< uint32_t > m_lengths
#define debug
Definition: HDRShower.cc:19
std::vector< uint32_t > m_defaults
std::vector< int > m_bx

◆ ~L1GtPatternWriter()

L1GtPatternWriter::~L1GtPatternWriter ( )
virtual

Definition at line 113 of file L1GtPatternWriter.cc.

References close().

113 { close(); }

Member Function Documentation

◆ close()

void L1GtPatternWriter::close ( void  )

Close the output stream

Definition at line 107 of file L1GtPatternWriter.cc.

References m_dest, and m_footer.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and ~L1GtPatternWriter().

107  {
108  if (m_dest) {
109  m_dest << m_footer;
110  }
111 }
std::ostream & m_dest

◆ mask()

uint32_t L1GtPatternWriter::mask ( uint32_t  length)
staticprotected

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

Definition at line 115 of file L1GtPatternWriter.cc.

References mitigatedMETSequence_cff::U.

Referenced by writePatternLine().

115  {
116  if (length < 32) {
117  return ~((~0U) << length);
118  } else {
119  return ~0U;
120  }
121 }

◆ writePatternLine()

void L1GtPatternWriter::writePatternLine ( const L1GtPatternLine line)
virtual

Format a single line.

Definition at line 74 of file L1GtPatternWriter.cc.

References TauDecayModes::dec, mps_fire::i, mps_splice::line, m_columns, m_defaults, m_dest, m_lengths, m_lineNo, mask(), and relativeConstraints::value.

Referenced by writePatterns().

74  {
75  m_dest << std::setfill('0');
76  // open each line with a line number
77  // the line number is in decimal, while everything else is hex.
78  m_dest << std::dec << std::setw(4) << m_lineNo << ' ' << std::hex;
79 
80  for (uint32_t i = 0; i < m_columns.size(); ++i) {
81  // space beween fields
82  if (i)
83  m_dest << ' ';
84 
85  // retrieve column value
86  uint32_t value;
87  if (line.has(m_columns[i])) {
88  // value comes from data
89  value = line.get(m_columns[i]);
90  } else if (m_defaults.size() > i) {
91  // value was specified as a config default.
92  value = m_defaults[i];
93  } else {
94  // no default specified, set to 0
95  value = 0;
96  }
97  uint32_t digits = (m_lengths[i] + 3) / 4;
98 
99  // write to file with configured length (truncating value if neccessary)
100  m_dest << std::setw(digits) << (value & mask(m_lengths[i]));
101  }
102 
103  // next line
104  m_dest << std::endl;
105 }
std::ostream & m_dest
std::vector< std::string > m_columns
Definition: value.py:1
std::vector< uint32_t > m_lengths
std::vector< uint32_t > m_defaults
static uint32_t mask(uint32_t length)

◆ writePatterns()

void L1GtPatternWriter::writePatterns ( const L1GtPatternMap patterns)

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

Definition at line 50 of file L1GtPatternWriter.cc.

References L1GtPatternMap::begin(), simKBmtfDigis_cfi::bx, TauDecayModes::dec, submitPVValidationJobs::dump, L1GtPatternMap::end(), spr::find(), edm::isDebugEnabled(), LogTrace, m_bx, m_debug, m_dest, m_lineNo, L1GtPatternMap::print(), and writePatternLine().

50  {
51  for (L1GtPatternMap::LineMap::const_iterator it = patterns.begin(); it != patterns.end(); ++it) {
52  int event = it->first.first;
53  int bx = it->first.second;
54 
55  if (edm::isDebugEnabled() && m_debug) {
56  std::stringstream dump;
57  patterns.print(dump);
58  LogTrace("L1GtPatternGenerator") << dump.str();
59  }
60 
61  if (m_bx.empty() || std::find(m_bx.begin(), m_bx.end(), bx) != m_bx.end()) {
62  if (m_debug) {
63  m_dest << "# Event " << std::dec << event << ", bx " << bx << std::endl;
64  }
65  writePatternLine(it->second);
66  ++m_lineNo;
67  } else {
68  LogTrace("L1GtPatternGenerator") << "Skipping event " << it->first.first << " bx " << it->first.second
69  << " because of bx filter";
70  }
71  }
72 }
bool isDebugEnabled()
LineMap::const_iterator begin() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
#define LogTrace(id)
LineMap::const_iterator end() const
std::ostream & m_dest
void print(std::ostream &out) const
virtual void writePatternLine(const L1GtPatternLine &line)
std::vector< int > m_bx

Member Data Documentation

◆ m_bx

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

Definition at line 73 of file L1GtPatternWriter.h.

Referenced by writePatterns().

◆ m_columns

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

Definition at line 70 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

◆ m_debug

bool L1GtPatternWriter::m_debug
private

Definition at line 74 of file L1GtPatternWriter.h.

Referenced by writePatterns().

◆ m_defaults

std::vector<uint32_t> L1GtPatternWriter::m_defaults
private

Definition at line 72 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

◆ m_dest

std::ostream& L1GtPatternWriter::m_dest
private

Definition at line 67 of file L1GtPatternWriter.h.

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

◆ m_footer

std::string L1GtPatternWriter::m_footer
private

Definition at line 69 of file L1GtPatternWriter.h.

Referenced by close().

◆ m_header

std::string L1GtPatternWriter::m_header
private

Definition at line 68 of file L1GtPatternWriter.h.

Referenced by L1GtPatternWriter().

◆ m_lengths

std::vector<uint32_t> L1GtPatternWriter::m_lengths
private

Definition at line 71 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

◆ m_lineNo

uint32_t L1GtPatternWriter::m_lineNo
private

Definition at line 76 of file L1GtPatternWriter.h.

Referenced by writePatternLine(), and writePatterns().