mu2e_artdaq_core  v1_02_11
 All Classes Functions
DebugFragmentReader.hh
1 #ifndef mu2e_artdaq_core_Overlays_DebugFragmentReader_hh
2 #define mu2e_artdaq_core_Overlays_DebugFragmentReader_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib_except/exception.h"
6 
7 #include "mu2e-artdaq-core/Overlays/DetectorFragment.hh"
8 
9 #include <bitset>
10 #include <iostream>
11 #include <ostream>
12 #include <vector>
13 
14 namespace mu2e {
15 class DebugFragmentReader;
16 }
17 
19  public:
20  DebugFragmentReader(artdaq::Fragment const &f);
22 
23  // Debug Packet methods:
24  mu2e::DetectorFragment::adc_t serialFIFO_empty();
25  mu2e::DetectorFragment::adc_t serialFIFO_full();
26  mu2e::DetectorFragment::adc_t numEmptyFIFO();
27  mu2e::DetectorFragment::adc_t numFilledFIFO();
28  std::vector<mu2e::DetectorFragment::adc_t> debugData();
29  std::vector<std::vector<mu2e::DetectorFragment::adc_t> > debugInfo();
30  void printAll();
31 };
32 
33 mu2e::DebugFragmentReader::DebugFragmentReader(artdaq::Fragment const &f) : DetectorFragment(f) {}
34 
35 mu2e::DebugFragmentReader::~DebugFragmentReader() {}
36 
38 // Debug Header Packet methods
40 mu2e::DetectorFragment::adc_t mu2e::DebugFragmentReader::serialFIFO_empty() {
41  return mu2e::DetectorFragment::convertFromBinary(bitArray(dataBlockBegin()), 127 - 105, 127 - 104);
42 }
43 
44 mu2e::DetectorFragment::adc_t mu2e::DebugFragmentReader::serialFIFO_full() {
45  return mu2e::DetectorFragment::convertFromBinary(bitArray(dataBlockBegin()), 127 - 106, 127 - 105);
46 }
47 
48 mu2e::DetectorFragment::adc_t mu2e::DebugFragmentReader::numEmptyFIFO() {
49  return mu2e::DetectorFragment::convertFromBinary(bitArray(dataBlockBegin()), 127 - 120, 127 - 112);
50 }
51 
52 mu2e::DetectorFragment::adc_t mu2e::DebugFragmentReader::numFilledFIFO() {
53  return mu2e::DetectorFragment::convertFromBinary(bitArray(dataBlockBegin()), 127 - 128, 127 - 120);
54 }
56 
58 // Debug Data Packet methods
60 
61 std::vector<mu2e::DetectorFragment::adc_t> mu2e::DebugFragmentReader::debugData() {
62  std::vector<adc_t> theVector;
63  // Start after at the 0th 16-bit block of the first debug data packet:
64  for (size_t curPacketNum = 0; curPacketNum < packetCount(); curPacketNum++) {
65  for (size_t adcIdx = 1; adcIdx < 8;
66  adcIdx += 2) { // The Deserialized Data is in every other position starting at 1
67  theVector.push_back(*((adc_t const *)((dataBlockBegin() + 8 + 0) + adcIdx)));
68  }
69  }
70  return theVector;
71 }
72 
73 std::vector<std::vector<mu2e::DetectorFragment::adc_t> > mu2e::DebugFragmentReader::debugInfo() {
74  std::vector<std::vector<adc_t> > theVector;
75  // Start after at the 0th 16-bit block of the first debug data packet:
76  for (size_t curPacketNum = 0; curPacketNum < packetCount(); curPacketNum++) {
77  std::bitset<128> bitarray;
78  fillBitArray(bitarray, dataBlockBegin() + 8 + curPacketNum * 8);
79  for (size_t adcIdx = 0; adcIdx < 8; adcIdx += 2) { // The info field is in every other position starting at 1
80  std::vector<adc_t> infoVector;
81 
82  // FIFO Count
83  infoVector.push_back(convertFromBinary(bitarray, 127 - adcIdx * 16 - 11, 127 - adcIdx * 16 - 0));
84 
85  // serialFifo_empty
86  infoVector.push_back(convertFromBinary(bitarray, 127 - adcIdx * 16 - 13, 127 - adcIdx * 16 - 12));
87 
88  // serialFifo_full
89  infoVector.push_back(convertFromBinary(bitarray, 127 - adcIdx * 16 - 14, 127 - adcIdx * 16 - 13));
90 
91  theVector.push_back(infoVector);
92  }
93  }
94  return theVector;
95 }
96 
97 // mu2e::DetectorFragment::adc_t mu2e::DebugFragmentReader::numSamples() {
98 // return mu2e::DetectorFragment::convertFromBinary(bitArray(dataBlockBegin()+8),127-48,127-32);
99 //}
100 
101 void mu2e::DebugFragmentReader::printAll() {
102  std::cout << "\t\t"
103  << "Binary Representation: ";
104  printBitArray(bitArray(dataBlockBegin() + 8));
105 
106  std::cout << "\t\t"
107  << "Packet Type: " << (int)packetType() << std::endl;
108  std::cout << "\t\t"
109  << "Packet Count: " << (int)packetCount() << std::endl;
110  std::cout << "\t\t"
111  << "Serial FIFO Empty: " << (int)serialFIFO_empty() << std::endl;
112  std::cout << "\t\t"
113  << "Serial FIFO Full: " << (int)serialFIFO_full() << std::endl;
114  std::cout << "\t\t"
115  << "# Empty FIFO Entries: " << (int)numEmptyFIFO() << std::endl;
116  std::cout << "\t\t"
117  << "# Filled FIFO Entries: " << (int)numFilledFIFO() << std::endl;
118 
119  std::cout << "\t\t"
120  << "Debug Data: {[";
121  std::vector<mu2e::DetectorFragment::adc_t> ADCarray = debugData();
122  for (size_t i = 0; i < ADCarray.size(); i++) {
123  std::cout << (int)ADCarray[i];
124  if (i < ADCarray.size() - 1) {
125  std::cout << ",";
126  }
127  }
128  std::cout << "]}" << std::endl;
129 
130  std::cout << "\t\t"
131  << "Debug Info: {[";
132  std::vector<std::vector<mu2e::DetectorFragment::adc_t> > InfoArray = debugInfo();
133  for (size_t i = 0; i < InfoArray.size(); i++) {
134  std::cout << "{" << (int)InfoArray[i][0] << "," << (int)InfoArray[i][1] << "," << (int)InfoArray[i][2] << "}";
135  if (i < InfoArray.size() - 1) {
136  std::cout << ",";
137  }
138  }
139  std::cout << "]}" << std::endl;
140 }
141 
142 #endif /* mu2e_artdaq_core_Overlays_DebugFragmentReader_hh */