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