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

fix: +1 for L1 latency and trigger class check improved #13682

Merged
merged 18 commits into from
Nov 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ namespace ctp
struct TriggerOffsetsParam : public o2::conf::ConfigurableParamHelper<TriggerOffsetsParam> {
static constexpr int MaxNDet = 32; // take with margin to account for possible changes / upgrades
int64_t LM_L0 = 15;
int64_t L0_L1 = 280;
int64_t L0_L1 = 281; // trigger input latency
int64_t globalInputsShift = 0; // Global shift of inps; customOffset[CTP] is global shift of classes
int64_t customOffset[MaxNDet] = {};
int64_t L0_L1_classes = 280; // trigger input latency
O2ParamDef(TriggerOffsetsParam, "TriggerOffsetsParam"); // boilerplate stuff + make principal key
};
} // namespace ctp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "DetectorsBase/CTFCoderBase.h"
#include "CTPReconstruction/CTFHelper.h"
#include "CTPReconstruction/RawDataDecoder.h"
#include "DataFormatsCTP/Configuration.h"

class TTree;

Expand Down Expand Up @@ -53,6 +54,9 @@ class CTFCoder : public o2::ctf::CTFCoderBase

void createCoders(const std::vector<char>& bufVec, o2::ctf::CTFCoderBase::OpType op) final;
void setDecodeInps(bool decodeinps) { mDecodeInps = decodeinps; }
void setCTPConfig(CTPConfiguration cfg) { mCTPConfig = std::move(cfg); }
bool getDecodeInps() { return mDecodeInps; }
CTPConfiguration& getCTPConfig() { return mCTPConfig; }
bool canApplyBCShiftInputs(const o2::InteractionRecord& ir) const { return canApplyBCShift(ir, mBCShiftInputs); }

private:
Expand All @@ -62,6 +66,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
void appendToTree(TTree& tree, CTF& ec);
void readFromTree(TTree& tree, int entry, std::vector<CTPDigit>& data, LumiInfo& lumi);
std::vector<CTPDigit> mDataFilt;
CTPConfiguration mCTPConfig;
int mBCShiftInputs = 0;
bool mDecodeInps = false;
};
Expand Down Expand Up @@ -215,8 +220,13 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& data, LumiInfo& l
}
}
if (mDecodeInps) {
uint64_t trgclassmask = 0xffffffffffffffff;
if (mCTPConfig.getRunNumber() != 0) {
trgclassmask = mCTPConfig.getTriggerClassMask();
}
// std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
o2::pmr::vector<CTPDigit> digits;
o2::ctp::RawDataDecoder::shiftInputs(digitsMap, digits, mFirstTFOrbit);
o2::ctp::RawDataDecoder::shiftInputs(digitsMap, digits, mFirstTFOrbit, trgclassmask);
for (auto const& dig : digits) {
data.emplace_back(dig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Framework/InputRecord.h"
#include "DataFormatsCTP/Digits.h"
#include "DataFormatsCTP/LumiInfo.h"
#include "DataFormatsCTP/Configuration.h"

namespace o2
{
Expand All @@ -43,14 +44,16 @@ class RawDataDecoder
void setVerbose(bool v) { mVerbose = v; }
void setMAXErrors(int m) { mErrorMax = m; }
int setLumiInp(int lumiinp, std::string inp);
void setCTPConfig(CTPConfiguration cfg) { mCTPConfig = std::move(cfg); };
uint32_t getIRRejected() const { return mIRRejected; }
uint32_t getTCRRejected() const { return mTCRRejected; }
std::vector<uint32_t>& getTFOrbits() { return mTFOrbits; }
int getErrorIR() { return mErrorIR; }
int getErrorTCR() { return mErrorTCR; }
CTPConfiguration& getCTPConfig() { return mCTPConfig; }
int init();
static int shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit, std::bitset<48>& inpmask, int64_t shift, int level, std::map<o2::InteractionRecord, CTPDigit>& digmap);
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit);
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask = 0xffffffffffffffff);

private:
static constexpr uint32_t TF_TRIGGERTYPE_MASK = 0x800;
Expand Down Expand Up @@ -79,6 +82,7 @@ class RawDataDecoder
int mErrorTCR = 0;
int mErrorMax = 3;
bool mStickyError = false;
CTPConfiguration mCTPConfig;
};
} // namespace ctp
} // namespace o2
Expand Down
25 changes: 20 additions & 5 deletions Detectors/CTP/reconstruction/src/RawDataDecoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& d
}
} else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1 - 1;
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have already L0_L1_classes as 280, do you need to subtract 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was like that before: there was '-1' with 280 always for classes. So I keep it backward compatible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lietava what about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, what do you mean - I commented above:
It was like that before: there was '-1' with 280 always for classes. So I keep it backward compatible.
And as L0_L1_classes is not in old database onjects - it will be 280 in that case as before (default in old TriggerOffsetParams). For new CCDB we should put also 280. Or we actually do not need new entry as with the current
L0_L1 classes is default of class and L0_L1 inputs is 281.
Or let me know if something not correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @shahor02 ,
I did validation 559672 and 559243.
Validation means that o2-ctp-reco-workflow --no-lumi --ctpinputs-decoding
gives that same digits as CTF decoder
and both are consistent wirh filling scheme.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lietava yes, you have ignored the comment above, could you please check?

LOG(debug) << "tcr ir ori:" << ir;
if ((ir.orbit <= mTFOrbit) && ((int32_t)ir.bc < offset)) {
// LOG(warning) << "Loosing tclass:" << ir;
Expand Down Expand Up @@ -293,7 +293,12 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
// std::cout << "last lumi:" << nhb << std::endl;
}
if (mDoDigits & mDecodeInps) {
shiftInputs(digitsMap, digits, mTFOrbit);
uint64_t trgclassmask = 0xffffffffffffffff;
if (mCTPConfig.getRunNumber() != 0) {
trgclassmask = mCTPConfig.getTriggerClassMask();
}
// std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
shiftInputs(digitsMap, digits, mTFOrbit, trgclassmask);
}
if (mDoDigits && !mDecodeInps) {
for (auto const& dig : digitsMap) {
Expand Down Expand Up @@ -519,14 +524,15 @@ int RawDataDecoder::shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit
}
//

int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit)
int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask)
{
// int nClasswoInp = 0; // counting classes without input which should never happen
int nLM = 0;
int nL0 = 0;
int nL1 = 0;
int nTwI = 0;
int nTwoI = 0;
int nTwoIlost = 0;
std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
auto L0shift = o2::ctp::TriggerOffsetsParam::Instance().LM_L0;
auto L1shift = L0shift + o2::ctp::TriggerOffsetsParam::Instance().L0_L1;
Expand Down Expand Up @@ -594,18 +600,27 @@ int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digit
if ((d.CTPInputMask & L1MASKInputs).count()) {
nL1++;
}
if (d.CTPClassMask.count()) {
if ((d.CTPClassMask).to_ulong() & trgclassmask) {
if (d.CTPInputMask.count()) {
nTwI++;
} else {
nTwoI++;
if (d.intRecord.bc == (o2::constants::lhc::LHCMaxBunches - L1shift)) { // input can be lost because latency class-l1input = 1
nTwoIlost++;
} else {
// LOG(error) << d.intRecord << " " << d.CTPClassMask << " " << d.CTPInputMask;
// std::cout << "ERROR:" << std::hex << d.CTPClassMask << " " << d.CTPInputMask << std::dec << std::endl;
nTwoI++;
}
}
}
digits.push_back(dig.second);
}
if (nTwoI) { // Trigger class wo Input
LOG(error) << "LM:" << nLM << " L0:" << nL0 << " L1:" << nL1 << " TwI:" << nTwI << " Trigger classes wo input:" << nTwoI;
}
if (nTwoIlost) {
LOG(warn) << " Trigger classes wo input from diff latency 1:" << nTwoIlost;
}
return 0;
}
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class EntropyDecoderSpec : public o2::framework::Task
void init(o2::framework::InitContext& ic) final;
void endOfStream(o2::framework::EndOfStreamContext& ec) final;
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final;
void updateTimeDependentParams(framework::ProcessingContext& pc);

private:
o2::ctp::CTFCoder mCTFCoder;
Expand Down
3 changes: 3 additions & 0 deletions Detectors/CTP/workflow/include/CTPWorkflow/RawDecoderSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <deque>
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "Framework/WorkflowSpec.h"
#include "DataFormatsCTP/Digits.h"
#include "DataFormatsCTP/LumiInfo.h"
#include "CTPReconstruction/RawDataDecoder.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ class RawDecoderSpec : public framework::Task
/// Input RawData: {"ROUT", "RAWDATA", 0, Lifetime::Timeframe}
/// Output HW errors: {"CTP", "RAWHWERRORS", 0, Lifetime::Timeframe} -later
void run(framework::ProcessingContext& ctx) final;
void updateTimeDependentParams(framework::ProcessingContext& pc);

protected:
private:
Expand All @@ -68,6 +70,7 @@ class RawDecoderSpec : public framework::Task
uint32_t mNTFToIntegrate = 1;
uint32_t mNHBIntegratedT = 0;
uint32_t mNHBIntegratedV = 0;
bool mDecodeinputs = 0;
std::deque<size_t> mHistoryT;
std::deque<size_t> mHistoryV;
RawDataDecoder mDecoder;
Expand Down
19 changes: 16 additions & 3 deletions Detectors/CTP/workflow/src/EntropyDecoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ void EntropyDecoderSpec::run(ProcessingContext& pc)
mTimer.Start(false);
o2::ctf::CTFIOSize iosize;

mCTFCoder.updateTimeDependentParams(pc, true);
updateTimeDependentParams(pc);
auto buff = pc.inputs().get<gsl::span<o2::ctf::BufferType>>("ctf_CTP");

auto& digits = pc.outputs().make<std::vector<CTPDigit>>(OutputRef{"digits"});
auto& lumi = pc.outputs().make<LumiInfo>(OutputRef{"CTPLumi"});

Expand All @@ -76,6 +75,20 @@ void EntropyDecoderSpec::endOfStream(EndOfStreamContext& ec)
LOGF(info, "CTP Entropy Decoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
}
void EntropyDecoderSpec::updateTimeDependentParams(framework::ProcessingContext& pc)
{
mCTFCoder.updateTimeDependentParams(pc, true);
if (pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged) {
const auto ctpcfg = pc.inputs().get<o2::ctp::CTPConfiguration*>("ctpconfig");
if (mCTFCoder.getDecodeInps()) {
const auto ctpcfg = pc.inputs().get<o2::ctp::CTPConfiguration*>("ctpconfig");
if (ctpcfg != nullptr) {
mCTFCoder.setCTPConfig(*ctpcfg);
LOG(info) << "ctpconfig for run done:" << mCTFCoder.getCTPConfig().getRunNumber();
}
}
}
}

DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
{
Expand All @@ -88,7 +101,7 @@ DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
inputs.emplace_back("ctf_CTP", "CTP", "CTFDATA", sspec, Lifetime::Timeframe);
inputs.emplace_back("ctfdict_CTP", "CTP", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/CTFDictionaryTree"));
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));

inputs.emplace_back("ctpconfig", "CTP", "CTPCONFIG", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/Config", 1));
return DataProcessorSpec{
"ctp-entropy-decoder",
inputs,
Expand Down
28 changes: 24 additions & 4 deletions Detectors/CTP/workflow/src/RawDecoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
#include <fairlogger/Logger.h>
#include "Framework/InputRecordWalker.h"
#include "Framework/DataRefUtils.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/ConfigParamRegistry.h"
#include "DetectorsRaw/RDHUtils.h"
#include "CTPWorkflow/RawDecoderSpec.h"
#include "CommonUtils/VerbosityConfig.h"
#include "Framework/InputRecord.h"
#include "DataFormatsCTP/TriggerOffsetsParam.h"
#include "Framework/CCDBParamSpec.h"
#include "DataFormatsCTP/Configuration.h"

using namespace o2::ctp::reco_workflow;

void RawDecoderSpec::init(framework::InitContext& ctx)
{
bool decodeinps = ctx.options().get<bool>("ctpinputs-decoding");
mDecoder.setDecodeInps(decodeinps);
mDecodeinputs = ctx.options().get<bool>("ctpinputs-decoding");
mDecoder.setDecodeInps(mDecodeinputs);
mNTFToIntegrate = ctx.options().get<int>("ntf-to-average");
mVerbose = ctx.options().get<bool>("use-verbose-mode");
int maxerrors = ctx.options().get<int>("print-errors-num");
Expand All @@ -42,7 +43,7 @@ void RawDecoderSpec::init(framework::InitContext& ctx)
mOutputLumiInfo.inp2 = inp2;
mMaxInputSize = ctx.options().get<int>("max-input-size");
mMaxInputSizeFatal = ctx.options().get<bool>("max-input-size-fatal");
LOG(info) << "CTP reco init done. Inputs decoding here:" << decodeinps << " DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate << " Lumi inputs:" << lumiinp1 << ":" << inp1 << " " << lumiinp2 << ":" << inp2 << " Max errors:" << maxerrors << " Max input size:" << mMaxInputSize << " MaxInputSizeFatal:" << mMaxInputSizeFatal;
LOG(info) << "CTP reco init done. Inputs decoding here:" << mDecodeinputs << " DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate << " Lumi inputs:" << lumiinp1 << ":" << inp1 << " " << lumiinp2 << ":" << inp2 << " Max errors:" << maxerrors << " Max input size:" << mMaxInputSize << " MaxInputSizeFatal:" << mMaxInputSizeFatal;
// mOutputLumiInfo.printInputs();
}
void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
Expand Down Expand Up @@ -73,6 +74,7 @@ void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
}
void RawDecoderSpec::run(framework::ProcessingContext& ctx)
{
updateTimeDependentParams(ctx);
mOutputDigits.clear();
std::map<o2::InteractionRecord, CTPDigit> digits;
using InputSpec = o2::framework::InputSpec;
Expand Down Expand Up @@ -176,6 +178,7 @@ void RawDecoderSpec::run(framework::ProcessingContext& ctx)
mOutputLumiInfo.orbit = lumiPointsHBF1[0].orbit;
}
mOutputLumiInfo.counts = mCountsT;

mOutputLumiInfo.countsFV0 = mCountsV;
mOutputLumiInfo.nHBFCounted = mNHBIntegratedT;
mOutputLumiInfo.nHBFCountedFV0 = mNHBIntegratedV;
Expand All @@ -199,6 +202,8 @@ o2::framework::DataProcessorSpec o2::ctp::reco_workflow::getRawDecoderSpec(bool

std::vector<o2::framework::OutputSpec> outputs;
if (digits) {
inputs.emplace_back("ctpconfig", "CTP", "CTPCONFIG", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("CTP/Config/Config", 1));
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("CTP/Config/TriggerOffsets"));
outputs.emplace_back("CTP", "DIGITS", 0, o2::framework::Lifetime::Timeframe);
}
if (lumi) {
Expand All @@ -219,3 +224,18 @@ o2::framework::DataProcessorSpec o2::ctp::reco_workflow::getRawDecoderSpec(bool
{"max-input-size-fatal", o2::framework::VariantType::Bool, false, {"If true issue fatal error otherwise error on;y"}},
{"ctpinputs-decoding", o2::framework::VariantType::Bool, false, {"Inputs alignment: true - raw decoder - has to be compatible with CTF decoder: allowed options: 10,01,00"}}}};
}
void RawDecoderSpec::updateTimeDependentParams(framework::ProcessingContext& pc)
{
if (pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged) {
pc.inputs().get<o2::ctp::TriggerOffsetsParam*>("trigoffset");
const auto& trigOffsParam = o2::ctp::TriggerOffsetsParam::Instance();
LOG(info) << "updateing TroggerOffsetsParam: inputs L0_L1:" << trigOffsParam.L0_L1 << " classes L0_L1:" << trigOffsParam.L0_L1_classes;
if (mDecodeinputs) {
const auto ctpcfg = pc.inputs().get<o2::ctp::CTPConfiguration*>("ctpconfig");
if (ctpcfg != nullptr) {
mDecoder.setCTPConfig(*ctpcfg);
LOG(info) << "ctpconfig for run done:" << mDecoder.getCTPConfig().getRunNumber();
}
}
}
}