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

Use tfCounter in time-slot calib, provide real time. #8639

Merged
merged 4 commits into from
Apr 26, 2022
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
9 changes: 9 additions & 0 deletions CCDB/include/CCDB/CcdbObjectInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ namespace o2::ccdb
class CcdbObjectInfo
{
public:
// time intervals in milliseconds
static constexpr long SECOND = 1000;
static constexpr long MINUTE = 60 * SECOND;
static constexpr long HOUR = 60 * MINUTE;
static constexpr long DAY = 24 * HOUR;
static constexpr long MONTH = 30 * DAY;
static constexpr long YEAR = 364 * DAY;
static constexpr long INFINITE_TIMESTAMP = 9999999999999;

CcdbObjectInfo() = default;
CcdbObjectInfo(std::string path, std::string objType, std::string flName,
std::map<std::string, std::string> metadata,
Expand Down
13 changes: 8 additions & 5 deletions Detectors/Base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ and the method `GRPGeomRequest::instance()->checkUpdates(pc)` is called in the b
```cpp
class MyTask {
public:
MyTask(std::shared_ptr<GRPGeomRequest> req, ...)
{
GRPGeomRequest::instance()->setRequest(req);
MyTask(std::shared_ptr<GRPGeomRequest> req, ...) : mCCDBReq(req) {
}
void init(o2::framework::InitContext& ic) {
GRPGeomHelper::instance()->setRequest(req);
...
}
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
GRPGeomRequest::instance()->finaliseCCDB(matcher, obj);
GRPGeomHelper::instance()->finaliseCCDB(matcher, obj);
...
}
void run(ProcessingContext& pc)
{
GRPGeomRequest::instance()->checkUpdates(pc);
GRPGeomHelper::instance()->checkUpdates(pc);
...
}
protected:
std::shared_ptr<GRPGeomRequest> mCCDBReq;
};
```

Expand Down
16 changes: 12 additions & 4 deletions Detectors/Base/include/DetectorsBase/GRPGeomHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ALICEO2_GRPGEOM_HELPER

#include <vector>
#include <memory>
#include "DetectorsCommonDataFormats/DetID.h"

namespace o2::framework
Expand Down Expand Up @@ -60,18 +61,23 @@ class MatLayerCylSet;
I.e the task should look like:
class MyTask {
public:
MyTask(std::shared_ptr<GRPGeomRequest> req, ...) {
GRPGeomRequest::instance()->setRequest(req);
MyTask(std::shared_ptr<GRPGeomRequest> req, ...) : mCCDBReq(req) {
...
}
void init(o2::framework::InitContext& ic) {
GRPGeomHelper::instance()->setRequest(mCCDBReq);
...
}
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) {
GRPGeomRequest::instance()->finaliseCCDB(matcher, obj);
GRPGeomHelper::instance()->finaliseCCDB(matcher, obj);
...
}
void run(ProcessingContext& pc) {
GRPGeomRequest::instance()->checkUpdates(pc);
GRPGeomHelper::instance()->checkUpdates(pc);
...
}
protected:
std::shared_ptr<GRPGeomRequest> mCCDBReq;
}
*/

Expand Down Expand Up @@ -117,6 +123,8 @@ class GRPGeomHelper
auto getGRPMagField() const { return mGRPMagField; }
auto getOrbitResetTimeMS() const { return mOrbitResetTimeMS; }

static int getNHBFPerTF();

private:
GRPGeomHelper() = default;

Expand Down
5 changes: 5 additions & 0 deletions Detectors/Base/src/GRPGeomHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,8 @@ void GRPGeomHelper::checkUpdates(ProcessingContext& pc) const
}
}
}

int GRPGeomHelper::getNHBFPerTF()
{
return instance().mGRPECS ? instance().mGRPECS->getNHBFPerTF() : 128;
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void CPVBadMapCalibDevice::sendOutput(DataAllocator& output)
// TODO: should be changed to time of the run
time_t now = time(nullptr);
info.setStartValidityTimestamp(now);
info.setEndValidityTimestamp(99999999999999);
info.setEndValidityTimestamp(o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP);
std::map<std::string, std::string> md;
info.setMetaData(md);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void CPVGainCalibDevice::sendOutput(DataAllocator& output)
// TODO: should be changed to time of the run
time_t now = time(nullptr);
info.setStartValidityTimestamp(now);
info.setEndValidityTimestamp(99999999999999);
info.setEndValidityTimestamp(o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP);
std::map<std::string, std::string> md;
info.setMetaData(md);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CPVPedestalCalibDevice::sendOutput(DataAllocator& output)
const auto now = std::chrono::system_clock::now();
long timeStart = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
info.setStartValidityTimestamp(timeStart);
info.setEndValidityTimestamp(99999999999999);
info.setEndValidityTimestamp(o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP);
std::map<std::string, std::string> md;
info.setMetaData(md);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class NoiseCalibrator final : public o2::calibration::TimeSlotCalibration<o2::cp
}
void initOutput() final;
void finalizeSlot(NoiseTimeSlot& slot) final;
NoiseTimeSlot& emplaceNewSlot(bool front, uint64_t tstart, uint64_t tend) final;
NoiseTimeSlot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;

private:
std::unique_ptr<std::vector<float>> mPedEfficiencies = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PedestalCalibrator final : public o2::calibration::TimeSlotCalibration<o2:
}
void initOutput() final;
void finalizeSlot(PedestalTimeSlot& slot) final;
PedestalTimeSlot& emplaceNewSlot(bool front, uint64_t tstart, uint64_t tend) final;
PedestalTimeSlot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;

private:
int mMinEvents = 100;
Expand All @@ -113,4 +113,4 @@ class PedestalCalibrator final : public o2::calibration::TimeSlotCalibration<o2:
} //end namespace cpv
} //end namespace o2

#endif /* CPV_PEDESTAL_CALIBRATIOR_H_ */
#endif /* CPV_PEDESTAL_CALIBRATIOR_H_ */
2 changes: 1 addition & 1 deletion Detectors/CPV/calib/src/NoiseCalibrator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void NoiseCalibrator::finalizeSlot(NoiseTimeSlot& slot)
mCcdbInfoBadChannelMapVec.emplace_back("CPV/Calib/BadChannelMap", className, fileName, metaData, timeStamp, timeStamp + 31536000000); // one year validity time (in milliseconds!)
}
//_____________________________________________________________________________
NoiseTimeSlot& NoiseCalibrator::emplaceNewSlot(bool front, uint64_t tstart, uint64_t tend)
NoiseTimeSlot& NoiseCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend)
{
LOG(info) << "NoiseCalibrator::emplaceNewSlot() : emplacing new Slot from tstart = " << tstart << " to " << tend;
auto& cont = getSlots();
Expand Down
2 changes: 1 addition & 1 deletion Detectors/CPV/calib/src/PedestalCalibrator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void PedestalCalibrator::finalizeSlot(PedestalTimeSlot& slot)
mCcdbInfoHighPedChannelsVec.emplace_back("CPV/PedestalRun/HighPedChannels", className, fileName, metaData, timeStamp, timeStamp + 31536000000); // one year validity time (in milliseconds!)
}
//___________________________________________________________________
PedestalTimeSlot& PedestalCalibrator::emplaceNewSlot(bool front, uint64_t tstart, uint64_t tend)
PedestalTimeSlot& PedestalCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend)
{
auto& cont = getSlots();
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
Expand Down
34 changes: 26 additions & 8 deletions Detectors/CPV/calib/testWorkflow/NoiseCalibratorSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "CPVCalibration/NoiseCalibrator.h"
#include "DataFormatsCPV/Digit.h"
#include "DataFormatsCPV/TriggerRecord.h"
#include "DetectorsBase/GRPGeomHelper.h"

using namespace o2::framework;

Expand All @@ -30,12 +31,15 @@ namespace calibration
class CPVNoiseCalibratorSpec : public o2::framework::Task
{
public:
CPVNoiseCalibratorSpec(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req) {}

//_________________________________________________________________
void init(o2::framework::InitContext& ic) final
{
uint64_t slotL = ic.options().get<uint64_t>("tf-per-slot");
uint64_t delay = ic.options().get<uint64_t>("max-delay");
uint64_t updateInterval = ic.options().get<uint64_t>("updateInterval");
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
auto slotL = ic.options().get<uint32_t>("tf-per-slot");
auto delay = ic.options().get<uint32_t>("max-delay");
auto updateInterval = ic.options().get<uint32_t>("updateInterval");
bool updateAtTheEndOfRunOnly = ic.options().get<bool>("updateAtTheEndOfRunOnly");
mCalibrator = std::make_unique<o2::cpv::NoiseCalibrator>();
mCalibrator->setSlotLength(slotL);
Expand All @@ -50,9 +54,16 @@ class CPVNoiseCalibratorSpec : public o2::framework::Task
LOG(info) << "updateInterval = " << updateInterval;
LOG(info) << "updateAtTheEndOfRunOnly = " << updateAtTheEndOfRunOnly;
}

void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
{
o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj);
}

//_________________________________________________________________
void run(o2::framework::ProcessingContext& pc) final
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
TFType tfcounter = mCalibrator->getCurrentTFInfo().startTime;
auto&& digits = pc.inputs().get<gsl::span<o2::cpv::Digit>>("digits");
Expand Down Expand Up @@ -107,6 +118,7 @@ class CPVNoiseCalibratorSpec : public o2::framework::Task
//_________________________________________________________________
private:
std::unique_ptr<o2::cpv::NoiseCalibrator> mCalibrator;
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;

void sendOutput(DataAllocator& output)
{
Expand Down Expand Up @@ -145,7 +157,13 @@ DataProcessorSpec getCPVNoiseCalibratorSpec()
inputs.emplace_back("pedeffs", "CPV", "CPV_PedEffs", 0, Lifetime::Condition, ccdbParamSpec("CPV/PedestalRun/ChannelEfficiencies"));
inputs.emplace_back("deadchs", "CPV", "CPV_DeadChnls", 0, Lifetime::Condition, ccdbParamSpec("CPV/PedestalRun/DeadChannels"));
inputs.emplace_back("highpeds", "CPV", "CPV_HighThrs", 0, Lifetime::Condition, ccdbParamSpec("CPV/PedestalRun/HighPedChannels"));

auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);
std::vector<OutputSpec> outputs;
// Length of data description ("CPV_Pedestals") must be < 16 characters.
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "CPV_BadMap"}, Lifetime::Sporadic);
Expand All @@ -155,12 +173,12 @@ DataProcessorSpec getCPVNoiseCalibratorSpec()
"cpv-noise-calibration",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<device>()},
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
Options{
{"tf-per-slot", VariantType::UInt64, (uint64_t)std::numeric_limits<long>::max(), {"number of TFs per calibration time slot"}},
{"max-delay", VariantType::UInt64, uint64_t(1000), {"number of slots in past to consider"}},
{"tf-per-slot", VariantType::UInt32, o2::calibration::INFINITE_TF, {"number of TFs per calibration time slot, if 0: finalize once statistics is reached"}},
{"max-delay", VariantType::UInt32, 1000u, {"number of slots in past to consider"}},
{"updateAtTheEndOfRunOnly", VariantType::Bool, false, {"finalize the slots and prepare the CCDB entries only at the end of the run."}},
{"updateInterval", VariantType::UInt64, (uint64_t)10, {"try to finalize the slot (and produce calibration) when the updateInterval has passed.\n To be used together with tf-per-slot = std::numeric_limits<long>::max()"}}}};
{"updateInterval", VariantType::UInt32, 10u, {"try to finalize the slot (and produce calibration) when the updateInterval has passed.\n To be used together with tf-per-slot = 0"}}}};
}
} // namespace framework
} // namespace o2
35 changes: 27 additions & 8 deletions Detectors/CPV/calib/testWorkflow/PedestalCalibratorSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CPVCalibration/PedestalCalibrator.h"
#include "DataFormatsCPV/Digit.h"
#include "DataFormatsCPV/TriggerRecord.h"
#include "DetectorsBase/GRPGeomHelper.h"

using namespace o2::framework;

Expand All @@ -29,9 +30,11 @@ namespace calibration
class CPVPedestalCalibratorSpec : public o2::framework::Task
{
public:
CPVPedestalCalibratorSpec(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req) {}
//_________________________________________________________________
void init(o2::framework::InitContext& ic) final
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
uint64_t slotL = ic.options().get<uint64_t>("tf-per-slot");
uint64_t delay = ic.options().get<uint64_t>("max-delay");
uint64_t updateInterval = ic.options().get<uint64_t>("updateInterval");
Expand All @@ -49,9 +52,17 @@ class CPVPedestalCalibratorSpec : public o2::framework::Task
LOG(info) << "updateInterval = " << updateInterval;
LOG(info) << "updateAtTheEndOfRunOnly = " << updateAtTheEndOfRunOnly;
}

//_________________________________________________________________
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
{
o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj);
}

//_________________________________________________________________
void run(o2::framework::ProcessingContext& pc) final
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
TFType tfcounter = mCalibrator->getCurrentTFInfo().startTime;
auto&& digits = pc.inputs().get<gsl::span<o2::cpv::Digit>>("digits");
Expand Down Expand Up @@ -82,6 +93,7 @@ class CPVPedestalCalibratorSpec : public o2::framework::Task

private:
std::unique_ptr<o2::cpv::PedestalCalibrator> mCalibrator;
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;

void sendOutput(DataAllocator& output)
{
Expand Down Expand Up @@ -136,6 +148,7 @@ class CPVPedestalCalibratorSpec : public o2::framework::Task
}
}; // class CPVPedestalCalibratorSpec
} // namespace calibration

namespace framework
{
DataProcessorSpec getCPVPedestalCalibratorSpec()
Expand All @@ -154,19 +167,25 @@ DataProcessorSpec getCPVPedestalCalibratorSpec()
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "CPV_DeadChnls"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "CPV_HighThrs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "CPV_HighThrs"}, Lifetime::Sporadic);

std::vector<InputSpec> inputs{{"digits", "CPV", "DIGITS"},
{"trigrecs", "CPV", "DIGITTRIGREC"}};
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);
return DataProcessorSpec{
"cpv-pedestal-calibration",
Inputs{
{"digits", "CPV", "DIGITS"},
{"trigrecs", "CPV", "DIGITTRIGREC"}},
inputs,
outputs,
AlgorithmSpec{adaptFromTask<device>()},
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
Options{
{"tf-per-slot", VariantType::UInt64, (uint64_t)std::numeric_limits<long>::max(), {"number of TFs per calibration time slot"}},
{"max-delay", VariantType::UInt64, uint64_t(1000), {"number of slots in past to consider"}},
{"tf-per-slot", VariantType::UInt32, o2::calibration::INFINITE_TF, {"number of TFs per calibration time slot, if 0: finalize once statistics is reached"}},
{"max-delay", VariantType::UInt32, 1000u, {"number of slots in past to consider"}},
{"updateAtTheEndOfRunOnly", VariantType::Bool, false, {"finalize the slots and prepare the CCDB entries only at the end of the run."}},
{"updateInterval", VariantType::UInt64, (uint64_t)10, {"try to finalize the slot (and produce calibration) when the updateInterval has passed.\n To be used together with tf-per-slot = std::numeric_limits<long>::max()"}}}};
{"updateInterval", VariantType::UInt32, 10u, {"try to finalize the slot (and produce calibration) when the updateInterval has passed.\n To be used together with tf-per-slot = 0"}}}};
}
} // namespace framework
} // namespace o2
Loading