test
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 
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& footer, const std::vector<std::string>& columns,
30  const std::vector<uint32_t>& lengths, const std::vector<uint32_t>& defaults,
31  const std::vector<int>& bx, bool debug) :
32  m_dest(destination),
33  m_header(header),
34  m_footer(footer),
35  m_columns(columns),
36  m_lengths(lengths),
37  m_defaults(defaults),
38  m_bx(bx),
39  m_debug(debug),
40  m_lineNo(0)
41 
42 {
43  m_dest << m_header;
44 }
45 
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 }
68 
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 }
100 
102  if(m_dest) {
103  m_dest << m_footer;
104  }
105 }
106 
107 
109  close();
110 }
111 
112 uint32_t L1GtPatternWriter::mask(uint32_t length) {
113  if(length < 32) {
114  return ~((~0) << length);
115  } else {
116  return ~0;
117  }
118 }
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
#define debug
Definition: HDRShower.cc:19
virtual void writePatternLine(const L1GtPatternLine &line)
std::vector< int > m_bx