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