Skip to content
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
4 changes: 2 additions & 2 deletions DataFormats/Detectors/TOF/include/DataFormatsTOF/CTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ struct CompressedInfos {
std::vector<uint16_t> stripID; /// increment of stripID wrt that of prev. strip
std::vector<uint8_t> chanInStrip; /// channel in strip 0-95 (ordered in time)
std::vector<uint16_t> tot; /// Time-Over-Threshold in TOF channel (about 48.8 ps)
std::vector<uint32_t> pattMap; /// explict patterns container
std::vector<uint8_t> pattMap; /// explict patterns container

CompressedInfos() = default;

void clear();

ClassDefNV(CompressedInfos, 2);
ClassDefNV(CompressedInfos, 3);
};

/// wrapper for the Entropy-encoded clusters of the TF
Expand Down
4 changes: 2 additions & 2 deletions Detectors/CTF/test/test_ctf_io_tof.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)

std::vector<Digit> digits;
std::vector<ReadoutWindowData> rows;
std::vector<uint32_t> pattVec;
std::vector<uint8_t> pattVec;

TStopwatch sw;
sw.Start();
Expand Down Expand Up @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)

std::vector<Digit> digitsD;
std::vector<ReadoutWindowData> rowsD;
std::vector<uint32_t> pattVecD;
std::vector<uint8_t> pattVecD;
sw.Start();
const auto ctfImage = CTF::getImage(vec.data());
{
Expand Down
3 changes: 2 additions & 1 deletion Detectors/TOF/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ o2_add_library(TOFBase
src/Strip.cxx
src/WindowFiller.cxx
PUBLIC_LINK_LIBRARIES Boost::serialization FairRoot::Base ms_gsl::ms_gsl
O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw)
O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw
O2::DataFormatsTOF)

o2_target_root_dictionary(TOFBase
HEADERS include/TOFBase/Geo.h include/TOFBase/Digit.h
Expand Down
4 changes: 2 additions & 2 deletions Detectors/TOF/base/include/TOFBase/WindowFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class WindowFiller
memset(mChannelCounts, 0, o2::tof::Geo::NCHANNELS * sizeof(mChannelCounts[0]));
}

std::vector<uint32_t>& getPatterns() { return mPatterns; }
std::vector<uint8_t>& getPatterns() { return mPatterns; }
void addPattern(const uint32_t val, int icrate, int orbit, int bc) { mCratePatterns.emplace_back(val, icrate, orbit * 3 + (bc + 100) / Geo::BC_IN_WINDOW); }
void addCrateHeaderData(unsigned long orbit, int crate, int32_t bc, uint32_t eventCounter);

Expand Down Expand Up @@ -111,7 +111,7 @@ class WindowFiller
// arrays with digit and MCLabels out of the current readout windows (stored to fill future readout window)
std::vector<Digit> mFutureDigits;

std::vector<uint32_t> mPatterns;
std::vector<uint8_t> mPatterns;
std::vector<uint64_t> mErrors;

std::vector<PatternData> mCratePatterns;
Expand Down
54 changes: 45 additions & 9 deletions Detectors/TOF/base/src/WindowFiller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>
#include <cassert>
#include "FairLogger.h"
#include "DataFormatsTOF/CompressedDataFormat.h"

using namespace o2::tof;

Expand Down Expand Up @@ -190,18 +191,51 @@ void WindowFiller::fillOutputContainer(std::vector<Digit>& digits)
int npatterns = 0;

// check if patterns are in the current row
unsigned int initrow = mFirstIR.orbit * Geo::NWINDOW_IN_ORBIT;
for (std::vector<PatternData>::reverse_iterator it = mCratePatterns.rbegin(); it != mCratePatterns.rend(); ++it) {
if (it->row > mReadoutWindowCurrent) {
//printf("pattern row=%ld current=%ld\n",it->row - initrow,mReadoutWindowCurrent);

if (it->row - initrow > mReadoutWindowCurrent) {
break;
}

if (it->row < mReadoutWindowCurrent) { // this should not happen
if (it->row - initrow < mReadoutWindowCurrent) { // this should not happen
LOG(ERROR) << "One pattern skipped because appears to occur early of the current row " << it->row << " < " << mReadoutWindowCurrent << " ?!";
} else {
mPatterns.push_back(it->pattern);
info.addedDiagnostic(it->icrate);
uint32_t cpatt = it->pattern;
auto dpatt = reinterpret_cast<compressed::Diagnostic_t*>(&cpatt);
uint8_t slot = dpatt->slotID;
uint32_t cbit = 1;

mPatterns.push_back(slot + 28); // add slot
info.addedDiagnostic(it->icrate);
npatterns++;

for (int ibit = 0; ibit < 28; ibit++) {
if (dpatt->faultBits & cbit) {
mPatterns.push_back(ibit); // add bit error
info.addedDiagnostic(it->icrate);
npatterns++;
}
cbit <<= 1;
}
// uint8_t w1 = cpatt & 0xff;
// uint8_t w2 = (cpatt >> 8) & 0xff;
// uint8_t w3 = (cpatt >> 16) & 0xff;
// uint8_t w4 = (cpatt >> 24) & 0xff;
//// cpatt = w1 + (w2 + (w3 + uint(w4)*256)*256)*256;
// mPatterns.push_back(w1);
// info.addedDiagnostic(it->icrate);
// npatterns++;
// mPatterns.push_back(w2);
// info.addedDiagnostic(it->icrate);
// npatterns++;
// mPatterns.push_back(w3);
// info.addedDiagnostic(it->icrate);
// npatterns++;
// mPatterns.push_back(w4);
// info.addedDiagnostic(it->icrate);
// npatterns++;
}
mCratePatterns.pop_back();
}
Expand Down Expand Up @@ -265,12 +299,14 @@ void WindowFiller::flushOutputContainer(std::vector<Digit>& digits)
checkIfReuseFutureDigitsRO();
}

int nwindowperTF = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * Geo::NWINDOW_IN_ORBIT;

for (Int_t i = 0; i < MAXWINDOWS; i++) {
fillOutputContainer(digits); // fill last readout windows
if (mReadoutWindowData.size() < nwindowperTF) {
fillOutputContainer(digits); // fill last readout windows
}
}

int nwindowperTF = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * Geo::NWINDOW_IN_ORBIT;

// check that all orbits are complete in terms of number of readout windows
while ((mReadoutWindowData.size() % nwindowperTF)) {
fillOutputContainer(digits); // fill windows without digits to complete all orbits in the last TF
Expand Down Expand Up @@ -306,7 +342,7 @@ void WindowFiller::checkIfReuseFutureDigits()
int isnext = Int_t(timestamp * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent + 1); // to be replaced with uncalibrated time

if (isnext < 0) { // we jump too ahead in future, digit will be not stored
LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
LOG(DEBUG) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";

// remove digit from array in the future
int labelremoved = digit->getLabel();
Expand Down Expand Up @@ -375,7 +411,7 @@ void WindowFiller::checkIfReuseFutureDigitsRO() // the same but using readout in
int isnext = row - mReadoutWindowCurrent;

if (isnext < 0) { // we jump too ahead in future, digit will be not stored
LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
LOG(DEBUG) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";

// remove digit from array in the future
int labelremoved = digit->getLabel();
Expand Down
6 changes: 1 addition & 5 deletions Detectors/TOF/calibration/src/TOFFEElightConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ TOFFEEchannelConfig* TOFFEElightConfig::getChannelConfig(int icrate, int itrm, i

// return the channel config for the given crate, trm, chain, tdc, tdcchannel

return icrate >= Geo::kNCrate ? nullptr : itrm >= Geo::kNTRM ? nullptr
: ichain >= Geo::kNChain ? nullptr
: itdc >= Geo::kNTdc ? nullptr
: ichtdc >= Geo::kNCh ? nullptr
: &mChannelConfig[icrate][itrm][ichain][itdc][ichtdc];
return icrate >= Geo::kNCrate ? nullptr : itrm >= Geo::kNTRM ? nullptr : ichain >= Geo::kNChain ? nullptr : itdc >= Geo::kNTdc ? nullptr : ichtdc >= Geo::kNCh ? nullptr : &mChannelConfig[icrate][itrm][ichain][itdc][ichtdc];
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase

/// entropy-encode clusters to buffer with CTF
template <typename VEC>
void encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec);
void encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec);

/// entropy decode clusters from buffer with CTF
template <typename VROF, typename VDIG, typename VPAT>
Expand All @@ -49,14 +49,14 @@ class CTFCoder : public o2::ctf::CTFCoderBase

private:
/// compres compact clusters to CompressedInfos
void compress(CompressedInfos& cc, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec);
void compress(CompressedInfos& cc, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec);
size_t estimateCompressedSize(const CompressedInfos& cc);
/// decompress CompressedInfos to compact clusters
template <typename VROF, typename VDIG, typename VPAT>
void decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdigVec, VPAT& pattVec);

void appendToTree(TTree& tree, CTF& ec);
void readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec);
void readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint8_t>& pattVec);

protected:
ClassDefNV(CTFCoder, 1);
Expand All @@ -65,7 +65,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
///___________________________________________________________________________________
/// entropy-encode digits to buffer with CTF
template <typename VEC>
void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec)
void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec)
{
using MD = o2::ctf::Metadata::OptStore;
// what to do which each field: see o2::ctd::Metadata explanation
Expand Down Expand Up @@ -180,7 +180,7 @@ void CTFCoder::decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdig

int firstDig = digCount;

int BCrow = prevIR.orbit * Geo::BC_IN_ORBIT + prevIR.bc;
int64_t BCrow = prevIR.toLong();

digCopy.resize(cc.ndigROF[irof]);
for (uint32_t idig = 0; idig < cc.ndigROF[irof]; idig++) {
Expand All @@ -192,7 +192,7 @@ void CTFCoder::decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdig
} else {
ctdc += cc.timeTDCInc[digCount];
}
LOGF(DEBUG, "BC=%d, TDC=%d, TOT=%d, CH=%d", uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow, ctdc % 1024, cc.tot[digCount], uint32_t(cc.stripID[digCount]) * 96 + cc.chanInStrip[digCount]);
LOGF(DEBUG, "BC=%ld, TDC=%d, TOT=%d, CH=%d", uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow, ctdc % 1024, cc.tot[digCount], uint32_t(cc.stripID[digCount]) * 96 + cc.chanInStrip[digCount]);

digit.setBC(uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow);
digit.setTDC(ctdc % 1024);
Expand Down
13 changes: 6 additions & 7 deletions Detectors/TOF/reconstruction/src/CTFCoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CTFCoder::appendToTree(TTree& tree, CTF& ec)

///___________________________________________________________________________________
// extract and decode data from the tree
void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec)
void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint8_t>& pattVec)
{
assert(entry >= 0 && entry < tree.GetEntries());
CTF ec;
Expand All @@ -39,7 +39,7 @@ void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowDat
void CTFCoder::compress(CompressedInfos& cc,
const gsl::span<const ReadoutWindowData>& rofRecVec,
const gsl::span<const Digit>& cdigVec,
const gsl::span<const uint32_t>& pattVec)
const gsl::span<const uint8_t>& pattVec)
{
// store in the header the orbit of 1st ROF
cc.clear();
Expand All @@ -49,7 +49,7 @@ void CTFCoder::compress(CompressedInfos& cc,
const auto& rofRec0 = rofRecVec[0];
int nrof = rofRecVec.size();

LOGF(INFO, "TOF compress %d ReadoutWindow with %ld digits", nrof, cdigVec.size());
LOGF(DEBUG, "TOF compress %d ReadoutWindow with %ld digits", nrof, cdigVec.size());

cc.header.nROFs = nrof;
cc.header.firstOrbit = rofRec0.getBCData().orbit;
Expand All @@ -68,7 +68,7 @@ void CTFCoder::compress(CompressedInfos& cc,
cc.stripID.resize(cc.header.nDigits);
cc.chanInStrip.resize(cc.header.nDigits);
cc.tot.resize(cc.header.nDigits);
cc.pattMap.resize(cc.header.nPatternBytes);
cc.pattMap.resize(pattVec.size());

uint16_t prevBC = cc.header.firstBC;
uint32_t prevOrbit = cc.header.firstOrbit;
Expand All @@ -79,7 +79,7 @@ void CTFCoder::compress(CompressedInfos& cc,
const auto& rofRec = rofRecVec[irof];

const auto& intRec = rofRec.getBCData();
int rofInBC = intRec.toLong();
int64_t rofInBC = intRec.toLong();
// define interaction record
if (intRec.orbit == prevOrbit) {
cc.orbitIncROF[irof] = 0;
Expand Down Expand Up @@ -150,7 +150,6 @@ void CTFCoder::compress(CompressedInfos& cc,
LOGF(DEBUG, "%d) TF=%d, TDC=%d, STRIP=%d, CH=%d, TOT=%d", idig, cc.timeFrameInc[idig], cc.timeTDCInc[idig], cc.stripID[idig], cc.chanInStrip[idig], cc.tot[idig]);
}
}
// store explicit patters as they are
memcpy(cc.pattMap.data(), pattVec.data(), cc.header.nPatternBytes); // RSTODO: do we need this?
}

Expand Down Expand Up @@ -219,6 +218,6 @@ size_t CTFCoder::estimateCompressedSize(const CompressedInfos& cc)
sz += ESTSIZE(cc.pattMap, CTF::BLCpattMap);
// clang-format on
sz *= 2. / 3; // if needed, will be autoexpanded
LOG(INFO) << "Estimated output size is " << sz << " bytes";
LOG(DEBUG) << "Estimated output size is " << sz << " bytes";
return sz;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CompressedDecodingTask : public DecoderBase, public Task
bool mHasToBePosted = false;
bool mConetMode = false;
uint32_t mInitOrbit = 0;
uint32_t mCurrentOrbit = 0;
bool mRowFilter = false;
bool mMaskNoise = false;
int mNoiseRate = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DigitReader : public Task
std::vector<o2::tof::Digit> mDigits, *mPdigits = &mDigits;
std::vector<o2::tof::ReadoutWindowData> mRow, *mProw = &mRow;
std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> mLabels, *mPlabels = &mLabels;
std::vector<uint32_t> mPatterns, *mPpatterns = &mPatterns;
std::vector<uint8_t> mPatterns, *mPpatterns = &mPatterns;
};

/// create a processor spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TOFDigitWriterSplitter : public Task
{
using OutputType = std::vector<o2::tof::Digit>;
using ReadoutWinType = std::vector<o2::tof::ReadoutWindowData>;
using PatternType = std::vector<uint32_t>;
using PatternType = std::vector<uint8_t>;
using ErrorType = std::vector<uint64_t>;
using HeaderType = o2::tof::DigitHeader;

Expand Down
28 changes: 23 additions & 5 deletions Detectors/TOF/workflow/src/CompressedDecodingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void CompressedDecodingTask::postData(ProcessingContext& pc)
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe}, *alldigits);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe}, *row);

std::vector<uint32_t>& patterns = mDecoder.getPatterns();
std::vector<uint8_t>& patterns = mDecoder.getPatterns();

pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "PATTERNS", 0, Lifetime::Timeframe}, patterns);

std::vector<uint64_t>& errors = mDecoder.getErrors();
Expand Down Expand Up @@ -179,6 +180,10 @@ void CompressedDecodingTask::headerHandler(const CrateHeader_t* crateHeader, con
LOG(DEBUG) << "Crate found" << crateHeader->drmID;

mInitOrbit = crateOrbit->orbitID;
if (mCurrentOrbit > 0) {
mInitOrbit = mCurrentOrbit;
}

if (mNCrateOpenTF == 0) {
mDecoder.setFirstIR({0, mInitOrbit});
}
Expand All @@ -195,14 +200,22 @@ void CompressedDecodingTask::trailerHandler(const CrateHeader_t* crateHeader, co
mNCrateCloseTF++;
}

mDecoder.addCrateHeaderData(crateOrbit->orbitID, crateHeader->drmID, crateHeader->bunchID, crateTrailer->eventCounter);
if (mCurrentOrbit > 0) {
mDecoder.addCrateHeaderData(mCurrentOrbit, crateHeader->drmID, crateHeader->bunchID, crateTrailer->eventCounter);
} else {
mDecoder.addCrateHeaderData(crateOrbit->orbitID, crateHeader->drmID, crateHeader->bunchID, crateTrailer->eventCounter);
}

// Diagnostics used to fill digit patterns
auto numberOfDiagnostics = crateTrailer->numberOfDiagnostics;
auto numberOfErrors = crateTrailer->numberOfErrors;
for (int i = 0; i < numberOfDiagnostics; i++) {
const uint32_t* val = reinterpret_cast<const uint32_t*>(&(diagnostics[i]));
mDecoder.addPattern(*val, crateHeader->drmID, crateOrbit->orbitID, crateHeader->bunchID);
if (mCurrentOrbit > 0) {
mDecoder.addPattern(*val, crateHeader->drmID, mCurrentOrbit, crateHeader->bunchID); // take orbit from crateHeader instead of crateOrbit (it can be wrong, check also for digits!)
} else {
mDecoder.addPattern(*val, crateHeader->drmID, crateOrbit->orbitID, crateHeader->bunchID);
}

/*
int islot = (*val & 15);
Expand Down Expand Up @@ -336,8 +349,9 @@ void CompressedDecodingTask::rdhHandler(const o2::header::RAWDataHeader* rdh)
{
const auto& rdhr = *rdh;
// set first orbtìt here (to be check in future), please not remove this!!!
mCurrentOrbit = RDHUtils::getHeartBeatOrbit(rdhr);
if (mNCrateOpenTF == 0) {
mInitOrbit = RDHUtils::getHeartBeatOrbit(rdhr);
mInitOrbit = mCurrentOrbit;
mDecoder.setFirstIR({0, mInitOrbit});
}

Expand All @@ -360,7 +374,11 @@ void CompressedDecodingTask::frameHandler(const CrateHeader_t* crateHeader, cons
{
for (int i = 0; i < frameHeader->numberOfHits; ++i) {
auto packedHit = packedHits + i;
mDecoder.InsertDigit(crateHeader->drmID, frameHeader->trmID, packedHit->tdcID, packedHit->chain, packedHit->channel, crateOrbit->orbitID, crateHeader->bunchID, frameHeader->frameID << 13, packedHit->time, packedHit->tot);
if (mCurrentOrbit > 0) {
mDecoder.InsertDigit(crateHeader->drmID, frameHeader->trmID, packedHit->tdcID, packedHit->chain, packedHit->channel, mCurrentOrbit, crateHeader->bunchID, frameHeader->frameID << 13, packedHit->time, packedHit->tot);
} else {
mDecoder.InsertDigit(crateHeader->drmID, frameHeader->trmID, packedHit->tdcID, packedHit->chain, packedHit->channel, crateOrbit->orbitID, crateHeader->bunchID, frameHeader->frameID << 13, packedHit->time, packedHit->tot);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion Detectors/TOF/workflow/src/EntropyEncoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc)
auto cput = mTimer.CpuTime();
mTimer.Start(false);
auto compDigits = pc.inputs().get<gsl::span<Digit>>("compDigits");
auto pspan = pc.inputs().get<gsl::span<uint32_t>>("patterns");
auto pspan = pc.inputs().get<gsl::span<uint8_t>>("patterns");
auto rofs = pc.inputs().get<gsl::span<ReadoutWindowData>>("ROframes");

auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{o2::header::gDataOriginTOF, "CTFDATA", 0, Lifetime::Timeframe});
Expand Down
Loading