Skip to content

Commit

Permalink
Merge pull request #1 from Mu2e/eflumerf/Mu2eArtdaqRework
Browse files Browse the repository at this point in the history
Simplify the Overlays directory by removing old code. Create
  • Loading branch information
gianipez authored Jun 15, 2023
2 parents 4001086 + 21262a6 commit af5b14b
Show file tree
Hide file tree
Showing 31 changed files with 225 additions and 1,477 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake_minimum_required (VERSION 3.19 FATAL_ERROR)

find_package(cetmodules)

project(artdaq_core_mu2e VERSION 1.08.08)
project(artdaq_core_mu2e VERSION 1.09.00)

include(CetCMakeEnv)
cet_cmake_env()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "artdaq-core-mu2e/Overlays/ArtFragment.hh"
#include "artdaq-core-mu2e/Data/ArtFragment.hh"

#include <iomanip>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#define mu2e_artdaq_core_Overlays_ArtFragment_hh

#include "artdaq-core/Data/Fragment.hh"
#include "artdaq-core/Data/dictionarycontrol.hh"
#include "cetlib_except/exception.h"
#if HIDE_FROM_ROOT
#include "dtcInterfaceLib/DTC_Packets.h"
#endif

#include <iostream>

Expand All @@ -14,70 +17,72 @@
// May contain multiple DataBlocks from the same ROC

namespace mu2e {
class ArtFragment;
struct ArtFragment;
using ArtFragments = std::vector<ArtFragment>;

// Let the "<<" operator dump the ArtFragment's data to stdout
std::ostream &operator<<(std::ostream &, ArtFragment const &);
} // namespace mu2e

class mu2e::ArtFragment
struct mu2e::ArtFragment
{
public:
explicit ArtFragment(artdaq::Fragment const &f)
{
// Initialize the index array
block_count_ = 0;
auto curPos = reinterpret_cast<uint8_t const *>(&*f.dataBegin());
auto end = reinterpret_cast<uint8_t const *>(&*f.dataEnd());
ArtFragment() {}

while (curPos < end)
{
block_count_++;
index_.push_back(new DTCLib::DTC_DataBlock(curPos));
curPos += index_.back()->byteSize;
}
explicit ArtFragment(std::vector<uint8_t> const& data)
: data_(data) {
}

ArtFragment(const void *ptr, size_t sz) {
// Initialize the index array
block_count_ = 0;
auto curPos = static_cast<uint8_t const *>(ptr);
auto end = curPos + sz;

while (curPos < end)
{
block_count_++;
index_.push_back(new DTCLib::DTC_DataBlock(curPos));
curPos += index_.back()->byteSize;
#if HIDE_FROM_ROOT // Hide most things from ROOT
explicit ArtFragment(DTCLib::DTC_SubEvent const &se)
{
data_ = std::vector<uint8_t>(se.GetSubEventByteCount());
memcpy(&data_[0], se.GetHeader(), sizeof(DTCLib::DTC_SubEventHeader));
size_t offset = sizeof(DTCLib::DTC_SubEventHeader);

for(auto& bl : se.GetDataBlocks()) {
memcpy(&data_[0] + offset, bl.blockPointer, bl.byteSize);
offset += bl.byteSize;
}

auto ptr = data_.data();
event_ = DTCLib::DTC_SubEvent(ptr);
setup_ = true;
}

explicit ArtFragment(std::pair<const void *, size_t> p)
: ArtFragment(p.first, p.second) {}
void setup_event() const {
auto ptr = data_.data();
event_ = DTCLib::DTC_SubEvent(ptr);
setup_ = true;
}

// const getter functions for the data in the header
size_t block_count() const { return block_count_; }
size_t block_count() const {
if (!setup_) {setup_event();}
return event_.GetDataBlockCount(); }

// Return size of block at given DataBlock index
size_t blockSizeBytes(size_t blockIndex) const
{
if (!setup_) setup_event();
if (blockIndex > block_count())
{
return 0;
}

return index_[blockIndex]->byteSize;
return event_.GetDataBlock(blockIndex)->byteSize;
}

// Return pointer to beginning of DataBlock at given DataBlock index
DTCLib::DTC_DataBlock const *dataAtBlockIndex(size_t blockIndex) const
{
if (!setup_) setup_event();
if (blockIndex > block_count()) return nullptr;
return index_.at(blockIndex);
return event_.GetDataBlock(blockIndex);
}

void printPacketAtByte(size_t blockIndex, size_t byteIdx) const
{
if (!setup_) setup_event();
auto dataPtr = reinterpret_cast<uint16_t const *>(reinterpret_cast<uint8_t const *>(dataAtBlockIndex(blockIndex)->GetData()) + byteIdx);
std::cout << "\t\t"
<< "Packet Bits (128): " << std::endl;
Expand Down Expand Up @@ -107,10 +112,15 @@ public:
std::cout << std::endl;
return;
}
#endif


mutable bool setup_{false};
std::vector<uint8_t> data_;

private:
size_t block_count_;
std::vector<DTCLib::DTC_DataBlock const *> index_;
#if HIDE_FROM_ROOT // Hide most things from ROOT
mutable DTCLib::DTC_SubEvent event_;
#endif
};

#endif /* mu2e_artdaq_Overlays_ArtFragment_hh */
6 changes: 6 additions & 0 deletions artdaq-core-mu2e/Data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ EventHeader.cc
RunHeader.cc
SubRunHeader.cc
TimeStamp.cc
Mu2eEventHeader.cc
ArtFragment.cc
CalorimeterFragment.cc
CRVFragment.cc
TrackerFragment.cc
LIBRARIES PUBLIC
artdaq_core_mu2e::Overlays
)

include(ArtDictionary)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "artdaq-core-mu2e/Overlays/CRVFragment.hh"
#include "artdaq-core-mu2e/Data/CRVFragment.hh"

std::unique_ptr<mu2e::CRVFragment::CRVROCStatusPacket> mu2e::CRVFragment::GetCRVROCStatusPacket(size_t blockIndex) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef MU2E_ARTDAQ_CORE_OVERLAYS_CRVFRAGMENT_HH
#define MU2E_ARTDAQ_CORE_OVERLAYS_CRVFRAGMENT_HH

#include "artdaq-core-mu2e/Overlays/ArtFragment.hh"
#include "artdaq-core-mu2e/Data/ArtFragment.hh"
#include <memory>
#include <vector>
#include <array>
Expand All @@ -11,14 +11,16 @@ namespace mu2e {
class CRVFragment : public ArtFragment
{
public:
explicit CRVFragment(artdaq::Fragment const& f)
: ArtFragment(f) {}
CRVFragment()
: ArtFragment() {}

CRVFragment(const void* ptr, size_t sz)
: ArtFragment(ptr, sz) {}
CRVFragment(std::vector<uint8_t> data)
: ArtFragment(data) {}

explicit CRVFragment(std::pair<const void*, size_t> p)
: CRVFragment(p.first, p.second) {}
#if HIDE_FROM_ROOT
explicit CRVFragment(DTCLib::DTC_SubEvent const& f)
: ArtFragment(f)
{}

struct CRVROCStatusPacket
{
Expand All @@ -45,9 +47,9 @@ public:
uint8_t Errors;
uint8_t EventType;

uint16_t MicroBunchNumberLow;
uint16_t MicroBunchNumberLow;

uint16_t MicroBunchNumberHigh;
uint16_t MicroBunchNumberHigh;

CRVROCStatusPacket()
: unused1(0)
Expand Down Expand Up @@ -87,17 +89,18 @@ public:
uint16_t HitTime : 12;
uint16_t NumSamples : 4;

CRVHitWaveformSample WaveformSamples[8];
CRVHitWaveformSample WaveformSamples[8];

CRVHitReadoutPacket()
: SiPMID(0)
, HitTime(0)
, NumSamples(0)
{}
, NumSamples(0)
{}
};

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "artdaq-core-mu2e/Overlays/CalorimeterFragment.hh"
#include "artdaq-core-mu2e/Data/CalorimeterFragment.hh"

std::unique_ptr<mu2e::CalorimeterFragment::CalorimeterDataPacket> mu2e::CalorimeterFragment::GetCalorimeterData(size_t blockIndex) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#ifndef MU2E_ARTDAQ_CORE_OVERLAYS_CALORIMETERFRAGMENT_HH
#define MU2E_ARTDAQ_CORE_OVERLAYS_CALORIMETERFRAGMENT_HH

#include "artdaq-core-mu2e/Overlays/ArtFragment.hh"
#include "artdaq-core-mu2e/Data/ArtFragment.hh"

namespace mu2e {
class CalorimeterFragment : public ArtFragment
{
public:
explicit CalorimeterFragment(artdaq::Fragment const& f)
: ArtFragment(f) {}

CalorimeterFragment(const void* ptr, size_t sz)
: ArtFragment(ptr, sz) {}
CalorimeterFragment() : ArtFragment() {}

CalorimeterFragment(std::vector<uint8_t> data)
: ArtFragment(data) {}

#if HIDE_FROM_ROOT
explicit CalorimeterFragment(DTCLib::DTC_SubEvent const& f)
: ArtFragment(f) {}

explicit CalorimeterFragment(std::pair<const void*, size_t> p)
: CalorimeterFragment(p.first, p.second) {}

struct CalorimeterDataPacket
{
Expand Down Expand Up @@ -54,6 +56,7 @@ public:
std::unique_ptr<CalorimeterBoardID> GetCalorimeterBoardID(size_t blockIndex) const;
std::vector<std::pair<CalorimeterHitReadoutPacket, std::vector<uint16_t>>> GetCalorimeterHits(size_t blockIndex) const;
std::vector<std::pair<CalorimeterHitReadoutPacket, uint16_t>> GetCalorimeterHitsForTrigger(size_t blockIndex) const;
#endif
};
} // namespace mu2e

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "artdaq-core-mu2e/Overlays/Mu2eEventHeader.hh"
#include "artdaq-core-mu2e/Data/Mu2eEventHeader.hh"

mu2e::Mu2eEventHeader::Mu2eEventHeader(uint64_t timestamp, uint8_t mode)
: EventWindowTag(timestamp), EventMode(mode)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "artdaq-core-mu2e/Overlays/TrackerFragment.hh"
#include "artdaq-core-mu2e/Data/TrackerFragment.hh"

#include <vector>
#include "TrackerFragment.hh"

namespace mu2e {
TrackerFragment::TrackerFragment(artdaq::Fragment const& f)
: ArtFragment(f)
TrackerFragment::TrackerFragment(DTCLib::DTC_SubEvent const& evt)
: ArtFragment(evt)
{
if (block_count() > 0)
{
Expand All @@ -18,8 +18,8 @@ TrackerFragment::TrackerFragment(artdaq::Fragment const& f)
}
}

TrackerFragment::TrackerFragment(const void* ptr, size_t sz)
: ArtFragment(ptr, sz)
TrackerFragment::TrackerFragment(std::vector<uint8_t> data)
: ArtFragment(data)
{
if (block_count() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#ifndef MU2E_ARTDAQ_CORE_OVERLAYS_TRACKERFRAGMENT_HH
#define MU2E_ARTDAQ_CORE_OVERLAYS_TRACKERFRAGMENT_HH
#ifndef MU2E_ARTDAQ_CORE_DATA_TRACKERFRAGMENT_HH
#define MU2E_ARTDAQ_CORE_DATA_TRACKERFRAGMENT_HH

#include "artdaq-core-mu2e/Overlays/ArtFragment.hh"
#include "artdaq-core-mu2e/Data/ArtFragment.hh"

#include <vector>

Expand All @@ -12,11 +12,11 @@ class TrackerFragment : public ArtFragment
public:
static constexpr int TRACKER_FORMAT_VERSION = 1;

explicit TrackerFragment(artdaq::Fragment const& f);
explicit TrackerFragment(const void* ptr, size_t sz);
TrackerFragment() : ArtFragment() {}
explicit TrackerFragment(std::vector<uint8_t> data);

explicit TrackerFragment(std::pair<const void*, size_t> p)
: TrackerFragment(p.first, p.second) {}
#if HIDE_FROM_ROOT
explicit TrackerFragment(DTCLib::DTC_SubEvent const& evt);

struct TrackerDataPacketV0
{
Expand Down Expand Up @@ -289,7 +289,8 @@ private:
std::vector<uint16_t> GetWaveform(const TrackerDataPacket* input) const;

mutable std::vector<TrackerDataPacket> upgraded_data_packets_;
#endif
};
} // namespace mu2e

#endif // MU2E_ARTDAQ_CORE_OVERLAYS_TRACKERFRAGMENT_HH
#endif // MU2E_ARTDAQ_CORE_DATA_TRACKERFRAGMENT_HH
7 changes: 7 additions & 0 deletions artdaq-core-mu2e/Data/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
#include "artdaq-core-mu2e/Data/RunHeader.hh"
#include "artdaq-core-mu2e/Data/SubRunHeader.hh"
#include "artdaq-core-mu2e/Data/EventHeader.hh"
#include "artdaq-core-mu2e/Data/Mu2eEventHeader.hh"

#include "artdaq-core-mu2e/Data/ArtFragment.hh"
#include "artdaq-core-mu2e/Data/TrackerFragment.hh"
#include "artdaq-core-mu2e/Data/CalorimeterFragment.hh"
#include "artdaq-core-mu2e/Data/CRVFragment.hh"

#include "canvas/Persistency/Common/Wrapper.h"
23 changes: 21 additions & 2 deletions artdaq-core-mu2e/Data/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

<class name="mu2e::TimeStamp" />
<class name="mu2e::RunHeader" />
<class name="mu2e::SubRunHeader" />
<class name="mu2e::EventHeader" />
<class name="art::Wrapper<mu2e::RunHeader>"/>
<class name="mu2e::SubRunHeader" />
<class name="art::Wrapper<mu2e::SubRunHeader>"/>
<class name="mu2e::EventHeader" />
<class name="art::Wrapper<mu2e::EventHeader>"/>
<class name="mu2e::Mu2eEventHeader" />
<class name="art::Wrapper<mu2e::Mu2eEventHeader>"/>

<class name="mu2e::ArtFragment" />
<class name="std::vector<mu2e::ArtFragment>" />
<class name="art::Wrapper<mu2e::ArtFragment>" />
<class name="art::Wrapper<std::vector<mu2e::ArtFragment>>" />
<class name="mu2e::TrackerFragment" />
<class name="std::vector<mu2e::TrackerFragment>" />
<class name="art::Wrapper<mu2e::TrackerFragment>" />
<class name="art::Wrapper<std::vector<mu2e::TrackerFragment>>" />
<class name="mu2e::CalorimeterFragment" />
<class name="std::vector<mu2e::CalorimeterFragment>" />
<class name="art::Wrapper<mu2e::CalorimeterFragment>" />
<class name="art::Wrapper<std::vector<mu2e::CalorimeterFragment>>" />
<class name="mu2e::CRVFragment" />
<class name="std::vector<mu2e::CRVFragment>" />
<class name="art::Wrapper<mu2e::CRVFragment>" />
<class name="art::Wrapper<std::vector<mu2e::CRVFragment>>" />
</lcgdict>
Loading

0 comments on commit af5b14b

Please sign in to comment.