CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MP7PacketReader.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 using std::cout;
6 using std::endl;
7 
8 MP7PacketReader::MP7PacketReader(const std::string& path, uint32_t striphdr, uint32_t stripftr, uint32_t ikey)
9  : reader_(path), header_(striphdr), footer_(stripftr), ikey_(ikey) {
10  if (!reader_.valid())
11  return;
12  load();
13 }
14 
15 //MP7PacketReader::MP7PacketReader(MP7FileReader rdr,
16 // uint32_t striphdr,
17 // uint32_t stripftr) :
18 // reader_( rdr ),
19 // header_(striphdr),
20 // footer_(stripftr)
21 //{
22 // if ( !reader_.valid() ) return;
23 // load();
24 //}
25 
27 
29  buffers_.reserve(reader_.size());
31  for (; it != reader_.end(); ++it) {
32  const FileData& raw = *it;
33 
34  // Check channel alignment
35  std::set<std::vector<PacketRange> > rangeSet;
36 
37  for (size_t k(0); k < raw.size(); ++k) {
38  std::vector<PacketRange> ranges = findPackets(raw.link(ikey_));
39  rangeSet.insert(ranges);
40  }
41  //cout << "Number of different patterns: " << rangeSet.size() << endl;
42  if (rangeSet.size() != 1)
43  throw std::runtime_error("Links are not aligned!");
44 
45  std::vector<PacketRange> pr = *(rangeSet.begin());
46 
47  // Create the container
49  data.name_ = raw.name();
50 
51  data.packets_.reserve(pr.size());
52 
53  // loop over the ranges to build packets
54  for (auto const& p : pr) {
55  // Check if the header/footer zeroed the packet
56  if (p.second - p.first - header_ - footer_ <= 0) {
57  // Turn this into an error message
58  //cout << "Error: packet length is zero (or less) after header/footer stripping. Skipping." << endl;
59  continue;
60  }
61 
62  Packet pkt;
63  FileData::const_iterator lIt = raw.begin();
64  for (; lIt != raw.end(); ++lIt) {
65  // Here the 64 bit uint is converted into a 32 bit uint, the data valid bit is stripped in the 64->32 bit conversion.
66  pkt.links_[lIt->first] = std::vector<uint32_t>(lIt->second.begin() + p.first + header_,
67  lIt->second.begin() + p.second - footer_ + 1);
68  }
69  pkt.first_ = p.first + header_;
70  pkt.last_ = p.second - footer_;
71 
72  data.packets_.push_back(pkt);
73  }
74 
75  buffers_.push_back(data);
76  }
77 }
78 
79 std::vector<PacketRange> MP7PacketReader::findPackets(std::vector<uint64_t> data) {
80  std::vector<PacketRange> ranges;
81  bool v = false;
82  int32_t begin(-1), end(-1);
83  for (size_t i(0); i < data.size(); ++i) {
84  uint64_t x = data[i];
85  if (not v) {
86  if ((x >> 32) & 1) {
87  v = true;
88  begin = i;
89  }
90  continue;
91  } else {
92  if (not((x >> 32) & 1)) {
93  v = false;
94  end = i - 1;
95  ranges.push_back(std::make_pair(begin, end));
96  }
97  continue;
98  }
99  }
100 
101  if (v && (begin != -1)) {
102  end = data.size() - 1;
103  ranges.push_back(std::make_pair(begin, end));
104  }
105 
106  return ranges;
107 }
LinkMap links_
virtual ~MP7PacketReader()
const_iterator end()
vector&#39;s end iterator
Definition: MP7FileReader.h:68
std::vector< PacketData > buffers_
std::string name_
MP7PacketReader(const std::string &path, uint32_t striphdr=0, uint32_t stripftr=0, uint32_t ikey=0)
LinkMap::const_iterator begin() const
Definition: MP7FileReader.h:33
size_t size() const
number of rawdata objects stored
Definition: MP7FileReader.h:71
size_t size() const
Definition: MP7FileReader.h:31
uint32_t last_
MP7FileReader reader_
std::vector< Packet > packets_
const_iterator end() const
LinkMap::const_iterator const_iterator
Definition: MP7FileReader.h:25
string ranges
Definition: diffTwoXMLs.py:79
unsigned long long uint64_t
Definition: Time.h:13
const_iterator begin() const
uint32_t first_
const std::string & name() const
Definition: MP7FileReader.h:27
LinkMap::const_iterator end() const
Definition: MP7FileReader.h:34
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< FileData >::const_iterator const_iterator
expose vector&#39;s const iterator
Definition: MP7FileReader.h:46
const std::vector< uint64_t > & link(uint32_t i) const
tuple cout
Definition: gather_cfg.py:144
static std::vector< PacketRange > findPackets(std::vector< uint64_t > data)
bool valid() const
reader status. valid() == 1 indicates that data was successfully read from file
Definition: MP7FileReader.h:53
const_iterator begin()
vector&#39;s begin iterator
Definition: MP7FileReader.h:65