CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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< 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

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 ( 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 28 of file L1GtPatternWriter.cc.

References m_dest, and m_header.

31  :
33  m_header(header),
34  m_footer(footer),
35  m_columns(columns),
38  m_bx(bx),
39  m_debug(debug),
40  m_lineNo(0)
41 
42 {
43  m_dest << m_header;
44 }
boost::uint32_t m_lineNo
std::vector< boost::uint32_t > m_defaults
string destination
std::vector< boost::uint32_t > m_lengths
std::ostream & m_dest
std::vector< std::string > m_columns
#define debug
Definition: HDRShower.cc:19
std::vector< int > m_bx
L1GtPatternWriter::~L1GtPatternWriter ( )
virtual

Definition at line 108 of file L1GtPatternWriter.cc.

References close().

108  {
109  close();
110 }

Member Function Documentation

void L1GtPatternWriter::close ( void  )
uint32_t L1GtPatternWriter::mask ( boost::uint32_t  length)
staticprotected

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

Definition at line 112 of file L1GtPatternWriter.cc.

Referenced by writePatternLine().

112  {
113  if(length < 32) {
114  return ~((~0) << length);
115  } else {
116  return ~0;
117  }
118 }
void L1GtPatternWriter::writePatternLine ( const L1GtPatternLine line)
virtual

Format a single line.

Definition at line 69 of file L1GtPatternWriter.cc.

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

Referenced by writePatterns().

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

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

Definition at line 46 of file L1GtPatternWriter.cc.

References L1GtPatternMap::begin(), TauDecayModes::dec, 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().

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

Member Data Documentation

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

Definition at line 71 of file L1GtPatternWriter.h.

Referenced by writePatterns().

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

Definition at line 68 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

bool L1GtPatternWriter::m_debug
private

Definition at line 72 of file L1GtPatternWriter.h.

Referenced by writePatterns().

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

Definition at line 70 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

std::ostream& L1GtPatternWriter::m_dest
private

Definition at line 65 of file L1GtPatternWriter.h.

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

std::string L1GtPatternWriter::m_footer
private

Definition at line 67 of file L1GtPatternWriter.h.

Referenced by close().

std::string L1GtPatternWriter::m_header
private

Definition at line 66 of file L1GtPatternWriter.h.

Referenced by L1GtPatternWriter().

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

Definition at line 69 of file L1GtPatternWriter.h.

Referenced by writePatternLine().

boost::uint32_t L1GtPatternWriter::m_lineNo
private

Definition at line 74 of file L1GtPatternWriter.h.

Referenced by writePatternLine(), and writePatterns().