00001 #ifndef mu2e_artdaq_core_Overlays_ArtFragment_hh
00002 #define mu2e_artdaq_core_Overlays_ArtFragment_hh
00003
00004 #include "artdaq-core/Data/Fragment.hh"
00005 #include "cetlib/exception.h"
00006
00007 #include "trace.h"
00008
00009 #include <iostream>
00010
00011 #include <ostream>
00012 #include <vector>
00013
00014
00015
00016
00017 #define DATA_BLOCKS_PER_MU2E_FRAGMENT 2500
00018
00019 namespace mu2e {
00020 class ArtFragment;
00021
00022
00023 std::ostream & operator << (std::ostream &, ArtFragment const &);
00024 }
00025
00026 class mu2e::ArtFragment {
00027 public:
00028
00029 typedef uint16_t adc_t;
00030
00031 ArtFragment(artdaq::Fragment const & f ) :
00032 artdaq_Fragment_(f)
00033 {
00034
00035
00036 block_count_ = 0;
00037 size_t curIndex = 0;
00038 const adc_t* curPos = dataBegin();
00039 if(dataBegin()!=dataEnd()) {
00040 while(curPos<dataEnd()) {
00041 block_count_++;
00042
00043 index[block_count_-1] = curIndex + *(curPos);
00044 curIndex += *(curPos);
00045 curPos = curPos + *(curPos) / 2;
00046 }
00047 }
00048
00049 }
00050
00051
00052 adc_t const * dataBegin() const {
00053 return reinterpret_cast<mu2e::ArtFragment::adc_t const *>(&*artdaq_Fragment_.dataBegin());
00054 }
00055
00056 adc_t const * dataEnd() const {
00057 return reinterpret_cast<mu2e::ArtFragment::adc_t const *>(&*artdaq_Fragment_.dataEnd());
00058 }
00059
00060
00061 size_t block_count() const { return block_count_; }
00062
00063 size_t byte_count() const {
00064 return index[block_count_-1];
00065 }
00066
00067
00068 size_t blockIndexBytes(size_t offset) const {
00069 if(offset>=block_count()) { return 0; }
00070 else if(offset==0) { return 0;}
00071 return index[ offset-1 ];
00072 }
00073
00074 size_t blockEndBytes(size_t offset) const {
00075 if(offset>=block_count()) { return byte_count(); }
00076 return index[ offset ];
00077 }
00078
00079
00080
00081 size_t blockSizeBytes(size_t offset) const {
00082 if(offset > block_count()-1) { return 0; }
00083 else if(offset==0) { return index[ offset ]; }
00084 return index[ offset ] - index[ offset-1 ];
00085 }
00086
00087
00088 adc_t const * dataAtBytes(size_t offset) const {
00089 return dataBegin() + (offset/2);
00090 }
00091
00092
00093 adc_t const * dataAtBlockIndex(size_t offset) const {
00094 return dataAtBytes(blockIndexBytes(offset));
00095 }
00096
00097 void printPacketAtByte(size_t byteIdx) const {
00098 std::cout << "\t\t" << "Packet Bits (128): " << std::endl ;
00099 for(int adcIdx = 0; adcIdx<8; adcIdx++) {
00100 std::cout << "\t";
00101 for(int offset = 15; offset>=0; offset--) {
00102 if( ( (*((adc_t const *)(dataAtBytes(byteIdx)+adcIdx))) & (1<<offset) ) != 0) {
00103 std::cout << "1";
00104 } else {
00105 std::cout << "0";
00106 }
00107 if(offset==7) {
00108 std::cout << " ";
00109 } else if(offset==0) {
00110 std::cout << std::endl;
00111 }
00112 }
00113 }
00114 std::cout << std::endl;
00115 return;
00116 }
00117
00118 private:
00119 artdaq::Fragment const & artdaq_Fragment_;
00120 size_t block_count_;
00121 size_t index[DATA_BLOCKS_PER_MU2E_FRAGMENT];
00122 };
00123
00124 #endif