-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from LDMX-Software/iss_40
Iss 40
- Loading branch information
Showing
12 changed files
with
599 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef pflib_decoding_PolarfirePacket_h | ||
#define pflib_decoding_PolarfirePacket_h 1 | ||
|
||
#include "pflib/decoding/RocPacket.h" | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
/** \class This class decodes the innermost part of an HGCROC packet given | ||
a pointer to a series of unsigned 32-bit integers and a length. | ||
*/ | ||
class PolarfirePacket { | ||
public: | ||
PolarfirePacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { } | ||
|
||
int length() const { if (length_<1) return -1; return data_[0]&0xFFF; } | ||
int nlinks() const { if (length_<1) return -1; return (data_[0]>>14)&0x3F; } | ||
int fpgaid() const { if (length_<1) return -1; return (data_[0]>>20)&0xFF; } | ||
int formatversion() const { if (length_<1) return -1; return (data_[0]>>28)&0xF; } | ||
|
||
int length_for_elink(int ilink) const { if (ilink>=nlinks()) return 0; return (data_[2+(ilink/4)]>>(8*(ilink%4)))&0x3F; } | ||
|
||
int bxid() const { if (length_<2) return -1; return (data_[1]>>20)&0xFFF;} | ||
|
||
int rreq() const { if (length_<2) return -1; return (data_[1]>>10)&0x3FF;} | ||
|
||
int orbit() const { if (length_<2) return -1; return data_[1]&0x3FF;} | ||
|
||
int linklen(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8))&0x3F;} | ||
|
||
int linkcrc(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8+6))&0x1;} | ||
|
||
int linkrid(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8+7))&0x1;} | ||
|
||
RocPacket roc(int iroc) const; | ||
private: | ||
int offset_to_elink(int iroc) const; | ||
|
||
const uint32_t* data_; | ||
int length_; | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif// pflib_decoding_PolarfirePacket_h | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef pflib_decoding_RocPacket_h | ||
#define pflib_decoding_RocPacket_h 1 | ||
|
||
#include <stdint.h> | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
/** \class This class decodes the innermost part of an HGCROC packet given | ||
a pointer to a series of unsigned 32-bit integers and a length. | ||
*/ | ||
class RocPacket { | ||
public: | ||
RocPacket(const uint32_t* header_ptr, int len); | ||
|
||
int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} | ||
|
||
int crc() const {if (length_==0) return -1; return (data_[0]>>15)&0x1;} | ||
|
||
int bxid() const { if (length_<3) return -1; return (data_[2]>>11)&0x7FF;} | ||
|
||
int wadd() const { if (length_<3) return -1; return (data_[2]>>3)&0xFF;} | ||
|
||
bool has_chan(int ichan) const { return offset_to_chan(ichan)>=0; } | ||
|
||
int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>20)&0xFFF;} | ||
|
||
int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>10)&0x3FF;} | ||
|
||
int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x3FF;} | ||
|
||
void dump() const; | ||
|
||
private: | ||
int offset_to_chan(int ichan) const; | ||
|
||
const uint32_t* data_; | ||
int length_; | ||
|
||
}; | ||
|
||
} | ||
} | ||
|
||
#endif// pflib_decoding_RocPacket_h | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef pflib_decoding_SuperPacket_h | ||
#define pflib_decoding_SuperPacket_h 1 | ||
|
||
#include "pflib/decoding/PolarfirePacket.h" | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
/** \class This class decodes the outer level of a multisample packet | ||
*/ | ||
class SuperPacket { | ||
public: | ||
SuperPacket(const uint32_t* header_ptr, int len); | ||
|
||
int length64() const; | ||
int length32() const; | ||
int fpgaid() const {if (length_ == 0) return -1; return (data_[0]>>20)&0xFF;} | ||
int nsamples() const {if (length_ == 0) return -1; return (data_[0]>>16)&0xF;} | ||
int formatversion() const {if (length_ == 0) return -1; return (data_[0]>>28)&0xF;} | ||
int length32_for_sample(int isample) const; | ||
|
||
PolarfirePacket sample(int isample) const; | ||
private: | ||
const uint32_t* data_; | ||
int length_; | ||
int version_; | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif// pflib_decoding_PolarfirePacket_h | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "pflib/decoding/PolarfirePacket.h" | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
RocPacket PolarfirePacket::roc(int ilink) const { | ||
int offset=offset_to_elink(ilink); | ||
if (offset<0) return RocPacket(0,0); | ||
else return RocPacket(data_+offset,length_for_elink(ilink)); | ||
} | ||
|
||
int PolarfirePacket::offset_to_elink(int ilink) const { | ||
if (ilink<0 || ilink>=nlinks()) return -1; | ||
int offset=2+((nlinks()+3)/4); // header words | ||
for (int i=0; i<ilink; i++) | ||
offset+=length_for_elink(i); | ||
return offset; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "pflib/decoding/RocPacket.h" | ||
#include <stdio.h> | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
RocPacket::RocPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { | ||
|
||
} | ||
|
||
void RocPacket::dump() const { | ||
for (int i=0; i<length_; i++) { | ||
printf("%2d %08x ",i,data_[i]); | ||
if (i<36 && has_chan(i)) printf(" %d",get_adc(i)); | ||
printf("\n"); | ||
} | ||
} | ||
|
||
int RocPacket::offset_to_chan(int ichan) const { | ||
if (length_<2 || ichan<0 || ichan>=36) return -1; | ||
int offset=0; | ||
|
||
uint64_t readout_map=(uint64_t(data_[0])<<32)|data_[1]; | ||
|
||
int inominal=ichan+1; // first word in ROC V2 is header | ||
if (ichan>=18) inominal+=2; // common mode and calib in the middle | ||
|
||
for (int i=0; i<inominal; i++) { | ||
if (readout_map&0x1) offset++; | ||
readout_map=readout_map>>1; | ||
} | ||
if (readout_map&0x1) return offset+2; // +2 for the two Polarfire header words | ||
else return -1; | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "pflib/decoding/SuperPacket.h" | ||
#include <stdio.h> | ||
|
||
namespace pflib { | ||
namespace decoding { | ||
|
||
SuperPacket::SuperPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len}{ | ||
bool found_header=false; | ||
while (length_>0 && !found_header) { | ||
if (*data_==0xBEEF2021u) found_header=true; | ||
length_--; | ||
data_++; | ||
} | ||
} | ||
|
||
int SuperPacket::length64() const { return -1;} | ||
int SuperPacket::length32() const { return -1;} | ||
int SuperPacket::length32_for_sample(int isample) const { | ||
if (isample<0 || isample>=nsamples()) return 0; | ||
return (data_[1+(isample/2)]>>(16*(isample%2)))&0xFFF; | ||
} | ||
|
||
PolarfirePacket SuperPacket::sample(int isample) const { | ||
int offset=1+((nsamples()+1)/2); | ||
for (int i=0; i<isample; i++) | ||
offset+=length32_for_sample(i); | ||
return PolarfirePacket(data_+offset,length32_for_sample(isample)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.