CMS 3D CMS Logo

L1GtPatternWriter.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iostream>
20 #include <iomanip>
21 #include <algorithm>
22 
23 // user include files
27 
29  const std::string& header,
30  const std::string& footer,
31  const std::vector<std::string>& columns,
32  const std::vector<uint32_t>& lengths,
33  const std::vector<uint32_t>& defaults,
34  const std::vector<int>& bx,
35  bool debug)
36  : m_dest(destination),
37  m_header(header),
38  m_footer(footer),
39  m_columns(columns),
40  m_lengths(lengths),
41  m_defaults(defaults),
42  m_bx(bx),
43  m_debug(debug),
44  m_lineNo(0)
45 
46 {
47  m_dest << m_header;
48 }
49 
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 }
73 
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 }
106 
108  if (m_dest) {
109  m_dest << m_footer;
110  }
111 }
112 
114 
115 uint32_t L1GtPatternWriter::mask(uint32_t length) {
116  if (length < 32) {
117  return ~((~0U) << length);
118  } else {
119  return ~0U;
120  }
121 }
bool isDebugEnabled()
void writePatterns(const L1GtPatternMap &patterns)
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
std::vector< std::string > m_columns
Definition: value.py:1
std::vector< uint32_t > m_lengths
void print(std::ostream &out) const
#define debug
Definition: HDRShower.cc:19
virtual void writePatternLine(const L1GtPatternLine &line)
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)
std::vector< uint32_t > m_defaults
static uint32_t mask(uint32_t length)
std::vector< int > m_bx