Skip to content

Commit

Permalink
use o2::mch::Digit instead of DigitStruct (removed)
Browse files Browse the repository at this point in the history
  • Loading branch information
pillot committed Mar 4, 2020
1 parent 9be6688 commit ffafe2c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 230 deletions.
5 changes: 2 additions & 3 deletions Detectors/MUON/MCH/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ o2_add_library(MCHBase
SOURCES
src/ClusterBlock.cxx
src/Digit.cxx
src/DigitBlock.cxx
src/Mapping.cxx
src/PreClusterBlock.cxx
src/TrackBlock.cxx
src/PreClusterBlock.cxx
src/TrackBlock.cxx
PUBLIC_LINK_LIBRARIES ROOT::Core FairRoot::Base FairMQ::FairMQ)

o2_target_root_dictionary(MCHBase
Expand Down
98 changes: 0 additions & 98 deletions Detectors/MUON/MCH/Base/include/MCHBase/DigitBlock.h

This file was deleted.

12 changes: 6 additions & 6 deletions Detectors/MUON/MCH/Base/include/MCHBase/PreClusterBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <ostream>
#include <vector>

#include "MCHBase/DigitBlock.h"
#include "MCHBase/Digit.h"

namespace o2
{
Expand All @@ -31,8 +31,8 @@ namespace mch
* hit reconstruction and correlated into a common cluster.
*/
struct PreClusterStruct {
uint16_t nDigits; // number of digits attached to this precluster
const DigitStruct* digits; // pointer to the 1st element of the array of digits
uint16_t nDigits; // number of digits attached to this precluster
const Digit* digits; // pointer to the 1st element of the array of digits
};

/**
Expand Down Expand Up @@ -83,13 +83,13 @@ class PreClusterBlock
* Method to fill the buffer with a new precluster and its first digit
* @param digit Reference to the first digit to add to the new precluster.
*/
int startPreCluster(const DigitStruct& digit);
int startPreCluster(const Digit& digit);

/**
* Method to add a new digit to the current precluster
* @param digit Reference to the digit to add to the current precluster.
*/
int addDigit(const DigitStruct& digit);
int addDigit(const Digit& digit);

/**
* Return the number of bytes currently used for the data block in the buffer.
Expand Down Expand Up @@ -124,7 +124,7 @@ class PreClusterBlock
int readBuffer();

static constexpr uint32_t SSizeOfUShort = sizeof(uint16_t);
static constexpr uint32_t SSizeOfDigit = sizeof(DigitStruct);
static constexpr uint32_t SSizeOfDigit = sizeof(Digit);

/// running pointer on the buffer
/**
Expand Down
58 changes: 0 additions & 58 deletions Detectors/MUON/MCH/Base/src/DigitBlock.cxx

This file was deleted.

18 changes: 9 additions & 9 deletions Detectors/MUON/MCH/Base/src/PreClusterBlock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int PreClusterBlock::reset(void* buffer, uint32_t size, bool write)
}

//_________________________________________________________________________________________________
int PreClusterBlock::startPreCluster(const DigitStruct& digit)
int PreClusterBlock::startPreCluster(const Digit& digit)
{
/// start a new precluster

Expand All @@ -107,9 +107,9 @@ int PreClusterBlock::startPreCluster(const DigitStruct& digit)
mCurrentSize += SSizeOfUShort;

// store digit and increment buffer
auto lastDigit = reinterpret_cast<DigitStruct*>(mBuffer);
auto lastDigit = reinterpret_cast<Digit*>(mBuffer);
*lastDigit = digit;
mBuffer = (reinterpret_cast<DigitStruct*>(mBuffer) + 1);
mBuffer = (reinterpret_cast<Digit*>(mBuffer) + 1);
mCurrentSize += SSizeOfDigit;

// increment number of pre-clusters
Expand All @@ -123,7 +123,7 @@ int PreClusterBlock::startPreCluster(const DigitStruct& digit)
}

//_________________________________________________________________________________________________
int PreClusterBlock::addDigit(const DigitStruct& digit)
int PreClusterBlock::addDigit(const Digit& digit)
{
/// add a new digit to the current precluster

Expand All @@ -142,8 +142,8 @@ int PreClusterBlock::addDigit(const DigitStruct& digit)
*mLastNDigits += 1;

// assign digit to the buffer and increment buffer
*(reinterpret_cast<DigitStruct*>(mBuffer)) = digit;
mBuffer = (reinterpret_cast<DigitStruct*>(mBuffer) + 1);
*(reinterpret_cast<Digit*>(mBuffer)) = digit;
mBuffer = (reinterpret_cast<Digit*>(mBuffer) + 1);
mCurrentSize += SSizeOfDigit;

// increment number of digits in the stored cluster
Expand Down Expand Up @@ -191,8 +191,8 @@ int PreClusterBlock::readBuffer()
// read the digits
if (nDigits && (*nDigits) > 0 && mCurrentSize + (*nDigits) * SSizeOfDigit <= mSize) {

auto digit = reinterpret_cast<DigitStruct*>(mBuffer);
mBuffer = (reinterpret_cast<DigitStruct*>(mBuffer) + (*nDigits));
auto digit = reinterpret_cast<Digit*>(mBuffer);
mBuffer = (reinterpret_cast<Digit*>(mBuffer) + (*nDigits));
mCurrentSize += (*nDigits) * SSizeOfDigit;

// store
Expand Down Expand Up @@ -234,7 +234,7 @@ std::ostream& operator<<(std::ostream& stream, const PreClusterStruct& cluster)
{
stream << "{nDigits= " << cluster.nDigits;
for (int i = 0; i < cluster.nDigits; ++i) {
stream << ", digit[" << i << "]= " << cluster.digits[i];
stream << ", digit[" << i << "]= " << cluster.digits[i].getPadID();
}
stream << "}";

Expand Down
40 changes: 14 additions & 26 deletions Detectors/MUON/MCH/PreClustering/src/DigitSamplerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "Framework/Output.h"
#include "Framework/Task.h"

#include "MCHBase/DigitBlock.h"
#include "MCHBase/Digit.h"

namespace o2
{
Expand All @@ -37,7 +37,6 @@ namespace mch

using namespace std;
using namespace o2::framework;
using namespace o2::mch;

class DigitSamplerTask
{
Expand All @@ -60,56 +59,46 @@ class DigitSamplerTask
this->mInputFile.close();
};
ic.services().get<CallbackService>().set(CallbackService::Id::Stop, stop);

mPrint = ic.options().get<bool>("print");
}

//_________________________________________________________________________________________________
void run(framework::ProcessingContext& pc)
{
/// send the digits of the current event

DigitBlock digitBlock{};
mInputFile.read(reinterpret_cast<char*>(&digitBlock), SSizeOfDigitBlock);
int nDigits(0);
mInputFile.read(reinterpret_cast<char*>(&nDigits), SSizeOfInt);
if (mInputFile.fail()) {
pc.services().get<ControlService>().endOfStream();
return; // probably reached eof
}

if (digitBlock.header.fRecordWidth != SSizeOfDigitStruct) {
throw length_error("incorrect size of digits. Content changed?");
}

// create the output message
auto size = digitBlock.header.fNrecords * SSizeOfDigitStruct;
auto msgOut = pc.outputs().make<char>(Output{"MCH", "DIGITS", 0, Lifetime::Timeframe}, SSizeOfDigitBlock + size);
if (msgOut.size() != SSizeOfDigitBlock + size) {
auto size = nDigits * SSizeOfDigit;
auto msgOut = pc.outputs().make<char>(Output{"MCH", "DIGITS", 0, Lifetime::Timeframe}, SSizeOfInt + size);
if (msgOut.size() != SSizeOfInt + size) {
throw length_error("incorrect message payload");
}

auto bufferPtr = msgOut.data();

// fill header info
memcpy(bufferPtr, &digitBlock, SSizeOfDigitBlock);
bufferPtr += SSizeOfDigitBlock;
// fill number of digits
memcpy(bufferPtr, &nDigits, SSizeOfInt);
bufferPtr += SSizeOfInt;

// fill digits info
// fill digits if any
if (size > 0) {
mInputFile.read(bufferPtr, size);
} else {
LOG(INFO) << "event is empty";
}

if (mPrint) {
LOG(INFO) << "block: " << *reinterpret_cast<const DigitBlock*>(msgOut.data());
}
}

private:
static constexpr uint32_t SSizeOfDigitBlock = sizeof(DigitBlock);
static constexpr uint32_t SSizeOfDigitStruct = sizeof(DigitStruct);
static constexpr uint32_t SSizeOfInt = sizeof(int);
static constexpr uint32_t SSizeOfDigit = sizeof(Digit);

std::ifstream mInputFile{}; ///< input file
bool mPrint = false; ///< print digits
};

//_________________________________________________________________________________________________
Expand All @@ -120,8 +109,7 @@ o2::framework::DataProcessorSpec getDigitSamplerSpec()
Inputs{},
Outputs{OutputSpec{"MCH", "DIGITS", 0, Lifetime::Timeframe}},
AlgorithmSpec{adaptFromTask<DigitSamplerTask>()},
Options{{"infile", VariantType::String, "", {"input file name"}},
{"print", VariantType::Bool, false, {"print digits"}}}};
Options{{"infile", VariantType::String, "", {"input file name"}}}};
}

} // end namespace mch
Expand Down
Loading

0 comments on commit ffafe2c

Please sign in to comment.