CMS 3D CMS Logo

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