Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ehrlich uva develop #4

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions artdaq-core-mu2e/Data/CRVFragment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,38 @@ std::unique_ptr<mu2e::CRVFragment::CRVROCStatusPacket> mu2e::CRVFragment::GetCRV
return output;
}

std::vector<mu2e::CRVFragment::CRVHitReadoutPacket> mu2e::CRVFragment::GetCRVHitReadoutPackets(size_t blockIndex) const
std::vector<mu2e::CRVFragment::CRVHit> mu2e::CRVFragment::GetCRVHits(size_t blockIndex) const
{
auto dataPtr = dataAtBlockIndex(blockIndex);
if (dataPtr == nullptr) return std::vector<CRVHitReadoutPacket>();
if (dataPtr == nullptr) return std::vector<CRVHit>();

auto crvRocHdr = reinterpret_cast<CRVROCStatusPacket const*>(dataPtr->GetData());
size_t nHits = 0;
if(2*crvRocHdr->ControllerEventWordCount>sizeof(CRVROCStatusPacket))
nHits = (2*crvRocHdr->ControllerEventWordCount-sizeof(CRVROCStatusPacket)) / sizeof(CRVHitReadoutPacket);

std::vector<CRVHitReadoutPacket> output(nHits);

memcpy(&output[0], reinterpret_cast<CRVHitReadoutPacket const*>(crvRocHdr + 1), nHits * sizeof(CRVHitReadoutPacket));
size_t eventSize = 2*crvRocHdr->ControllerEventWordCount;
size_t pos = sizeof(CRVROCStatusPacket);

std::vector<mu2e::CRVFragment::CRVHit> output;
while(pos<eventSize)
{
output.resize(output.size()+1);

memcpy(&output.back().first, reinterpret_cast<const uint8_t*>(dataPtr->GetData())+pos, sizeof(CRVHitInfo));
pos += sizeof(CRVHitInfo);

size_t nWaveformSamples = output.back().first.NumSamples;
output.back().second.resize(nWaveformSamples);
memcpy(&output.back().second[0], reinterpret_cast<const uint8_t*>(dataPtr->GetData())+pos, nWaveformSamples*sizeof(CRVHitWaveformSample));
pos += sizeof(CRVHitWaveformSample)*nWaveformSamples;

if(pos>eventSize)
{
std::cerr << "************************************************" << std::endl;
std::cerr << "Corrupted data in blockIndex " << blockIndex << std::endl;
std::cerr << "ROCID " << (uint16_t)crvRocHdr->ControllerID << std::endl;
std::cerr << "TriggerCount " << crvRocHdr->TriggerCount << std::endl;
std::cerr << "EventWindowTag " << crvRocHdr->GetEventWindowTag() << std::endl;
std::cerr << "************************************************" << std::endl;
}
}

return output;
}

65 changes: 38 additions & 27 deletions artdaq-core-mu2e/Data/CRVFragment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "artdaq-core-mu2e/Data/ArtFragment.hh"
#include <memory>
#include <vector>
#include <array>
#include <bitset>

namespace mu2e {
class CRVFragment : public ArtFragment
Expand Down Expand Up @@ -38,18 +38,11 @@ public:

uint16_t TriggerCount;

uint8_t Status;
uint8_t unused3;
uint16_t MicroBunchStatus;

uint8_t unused4;
uint8_t unused5;
uint16_t EventWindowTag1;

uint8_t Errors;
uint8_t EventType;

uint16_t MicroBunchNumberLow;

uint16_t MicroBunchNumberHigh;
uint16_t EventWindowTag0;

CRVROCStatusPacket()
: unused1(0)
Expand All @@ -61,15 +54,28 @@ public:
, ActiveFEBFlags0(0)
, ActiveFEBFlags1(0)
, TriggerCount(0)
, Status(0)
, unused3(0)
, unused4(0)
, unused5(0)
, Errors(0)
, EventType(0)
, MicroBunchNumberLow(0)
, MicroBunchNumberHigh(0)
, MicroBunchStatus(0)
, EventWindowTag1(0)
, EventWindowTag0(0)
{}

std::bitset<24> GetActiveFEBFlags() const
{
uint32_t ActiveFEBFlags = ActiveFEBFlags2;
ActiveFEBFlags<<=8;
ActiveFEBFlags|=ActiveFEBFlags1;
ActiveFEBFlags<<=8;
ActiveFEBFlags|=ActiveFEBFlags0;
return std::bitset<24>(ActiveFEBFlags); //only need the 24 lowest bits
}

uint32_t GetEventWindowTag() const
{
uint32_t EventWindowTag = EventWindowTag1;
EventWindowTag<<=16;
EventWindowTag|=EventWindowTag0;
return EventWindowTag;
}
};

struct CRVHitWaveformSample
Expand All @@ -82,24 +88,29 @@ public:
{}
};

struct CRVHitReadoutPacket
struct CRVHitInfo
{
uint16_t SiPMID;
uint16_t febChannel : 6;
uint16_t portNumber : 5;
uint16_t controllerNumber : 5;

uint16_t HitTime : 12;
uint16_t NumSamples : 4;

CRVHitWaveformSample WaveformSamples[8];

CRVHitReadoutPacket()
: SiPMID(0)
CRVHitInfo()
: febChannel(0)
, portNumber(0)
, controllerNumber(0)
, HitTime(0)
, NumSamples(0)
{}
{}
};

typedef std::vector<CRVHitWaveformSample> CRVHitWaveform;
typedef std::pair<CRVHitInfo,CRVHitWaveform> CRVHit;

std::unique_ptr<CRVROCStatusPacket> GetCRVROCStatusPacket(size_t blockIndex) const;
std::vector<CRVHitReadoutPacket> GetCRVHitReadoutPackets(size_t blockIndex) const;
std::vector<CRVHit> GetCRVHits(size_t blockIndex) const;
#endif
};
} // namespace mu2e
Expand Down