CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtPatternWriter.cc
Go to the documentation of this file.
1 
17 // this class header
19 
20 // system include files
21 #include <iostream>
22 #include <iomanip>
23 #include <algorithm>
24 
25 // user include files
29 
30 L1GtPatternWriter::L1GtPatternWriter(std::ostream& destination, const std::string& header,
31  const std::string& footer, const std::vector<std::string>& columns,
32  const std::vector<uint32_t>& lengths, const std::vector<uint32_t>& defaults,
33  const std::vector<int>& bx, bool debug) :
34  m_dest(destination),
35  m_header(header),
36  m_footer(footer),
37  m_columns(columns),
38  m_lengths(lengths),
39  m_defaults(defaults),
40  m_bx(bx),
41  m_debug(debug),
42  m_lineNo(0)
43 
44 {
45  m_dest << m_header;
46 }
47 
49  for(L1GtPatternMap::LineMap::const_iterator it = patterns.begin(); it != patterns.end() ; ++it) {
50  int event = it->first.first;
51  int bx = it->first.second;
52 
53  if(edm::isDebugEnabled() && m_debug) {
54  std::stringstream dump;
55  patterns.print(dump);
56  LogTrace("L1GtPatternGenerator") << dump.str();
57  }
58 
59  if(m_bx.empty() || std::find(m_bx.begin(), m_bx.end(), bx) != m_bx.end()) {
60  if(m_debug) {
61  m_dest << "# Event " << std::dec << event << ", bx " << bx << std::endl;
62  }
63  writePatternLine(it->second);
64  ++m_lineNo;
65  } else {
66  LogTrace("L1GtPatternGenerator") << "Skipping event " << it->first.first << " bx " << it->first.second << " because of bx filter";
67  }
68  }
69 }
70 
72  m_dest << std::setfill('0');
73  // open each line with a line number
74  // the line number is in decimal, while everything else is hex.
75  m_dest << std::dec << std::setw(4) << m_lineNo << ' ' << std::hex ;
76 
77  for(uint32_t i = 0 ; i < m_columns.size() ; ++i) {
78  // space beween fields
79  if(i) m_dest << ' ';
80 
81  // retrieve column value
82  uint32_t value;
83  if(line.has(m_columns[i])) {
84  // value comes from data
85  value = line.get(m_columns[i]);
86  } else if(m_defaults.size() > i) {
87  // value was specified as a config default.
88  value = m_defaults[i];
89  } else {
90  // no default specified, set to 0
91  value = 0;
92  }
93  uint32_t digits = (m_lengths[i]+3)/4;
94 
95  // write to file with configured length (truncating value if neccessary)
96  m_dest << std::setw(digits) << (value & mask(m_lengths[i]));
97  }
98 
99  // next line
100  m_dest << std::endl;
101 }
102 
104  if(m_dest) {
105  m_dest << m_footer;
106  }
107 }
108 
109 
111  close();
112 }
113 
114 uint32_t L1GtPatternWriter::mask(uint32_t length) {
115  if(length < 32) {
116  return ~((~0) << length);
117  } else {
118  return ~0;
119  }
120 }
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
void writePatterns(const L1GtPatternMap &patterns)
LineMap::const_iterator begin() const
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)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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)
std::ostream & m_dest
std::vector< std::string > m_columns
LineMap::const_iterator end() const
bool has(const std::string &colname) const
#define LogTrace(id)
void print(std::ostream &out) const
virtual void writePatternLine(const L1GtPatternLine &line)
#define debug
Definition: MEtoEDMFormat.h:34
std::vector< int > m_bx