55#include " Framework/DeviceSpec.h"
66#include " Framework/WorkflowSpec.h"
77#include " Framework/Task.h"
8+ #include " DetectorsCalibration/Utils.h"
89
910#include " DataFormatsFT0/Digit.h"
10- #include " DataFormatsFT0/BcEvents.h"
1111#include " FT0Calibration/EventsPerBcCalibrator.h"
1212
13- namespace o2 ::ft0
13+
14+ namespace o2 ::calibration
1415{
1516 class FT0EventsPerBcProcessor final : public o2::framework::Task
1617 {
18+ public:
1719 void init (o2::framework::InitContext& ic) final
1820 {
19- mCalibrator = std::make_unique<EventsPerBcCalibrator>();
21+ mCalibrator = std::make_unique<o2::ft0::EventsPerBcCalibrator>();
22+ if (ic.options ().hasOption (" slot-len-sec" )) {
23+ mSlotLenSec = ic.options ().get <uint32_t >(" slot-len-sec" );
24+ }
25+ if (ic.options ().hasOption (" one-object-per-run" )) {
26+ mOneObjectPerRun = ic.options ().get <bool >(" one-object-per-run" );
27+ }
28+
29+ if (mOneObjectPerRun ) {
30+ mCalibrator ->setUpdateAtTheEndOfRunOnly ();
31+ } else {
32+ mCalibrator ->setSlotLengthInSeconds (mSlotLenSec );
33+ }
2034 }
2135
22- void run (o2::framework::ProcessContext & pc) final
36+ void run (o2::framework::ProcessingContext & pc) final
2337 {
2438 auto digits = pc.inputs ().get <gsl::span<o2::ft0::Digit>>(" digits" );
2539 mCalibrator ->process (digits);
40+ if (mOneObjectPerRun == false ) {
41+ sendOutput (pc.outputs ());
42+ }
2643 }
2744
2845 void endOfStream (o2::framework::EndOfStreamContext& ec) final
2946 {
30- mCalibrator ->chekSlotToFinalize ();
47+ mCalibrator ->checkSlotsToFinalize ();
3148 sendOutput (ec.outputs ());
3249 mCalibrator ->initOutput ();
3350 }
3451
35- void sendOutput (DataAllocator& output)
52+ void sendOutput (o2::framework:: DataAllocator& output)
3653 {
37- TH1F* tvxHist = mCalibrator ->getTvxPerBc ();
38- CcdbObjectInfo* info = mCalibrator ->getTvxPerBcCcdbInfo ();
39- auto image = o2::ccdb::CcdbApi::createObjectImage (tvxHist, info);
40- LOG (info) << " Sending object to CCDB" ;
41- output.snapshot (Output{o2::calibration::Utils::gDataOriginCDBPayload , " EVENTS_PER_BC_INFO" , 0 }, *image.get ());
42- output.snapshot (Output{o2::calibration::Utils::gDataOriginCDBWrapper , " EVENTS_PER_BC_INFO" , 0 }, info);
54+ using o2::framework::Output;
55+
56+ const auto & tvxHists = mCalibrator ->getTvxPerBc ();
57+ auto & infos = mCalibrator ->getTvxPerBcCcdbInfo ();
58+ for (int idx = 0 ; idx < tvxHists.size (); idx++){
59+ auto & info = infos[idx];
60+ const auto & payload = tvxHists[idx];
61+
62+ auto image = o2::ccdb::CcdbApi::createObjectImage (payload.get (), info.get ());
63+ LOG (info) << " Sending object " << info->getPath () << " /" << info->getFileName () << " of size " << image->size ()
64+ << " bytes, valid for " << info->getStartValidityTimestamp () << " : " << info->getEndValidityTimestamp ();
65+ output.snapshot (Output (o2::calibration::Utils::gDataOriginCDBPayload , " EVENTS_PER_BC_INFO" , 0 ), *image.get ());
66+ output.snapshot (Output (o2::calibration::Utils::gDataOriginCDBWrapper , " EVENTS_PER_BC_INFO" , 0 ), *info.get ());
67+ }
4368 }
4469
4570 private:
46- std::unique_ptr<EventsPerBcCalibrator> mCalibrator ;
71+ std::unique_ptr<o2::ft0::EventsPerBcCalibrator> mCalibrator ;
72+ bool mOneObjectPerRun ;
73+ uint32_t mSlotLenSec ;
4774 };
4875}
4976
50- WorkflowSpec defineDataProcessing (ConfigContext& const & cfgc)
77+ namespace o2 ::framework
78+ {
79+ WorkflowSpec defineDataProcessing (ConfigContext const & cfgc)
5180{
5281 using namespace o2 ::framework;
82+ using o2::calibration::FT0EventsPerBcProcessor;
5383 std::vector<InputSpec> inputs;
5484 inputs.emplace_back (" digits" , " FT0" , " DIGITSBC" );
5585 std::vector<OutputSpec> outputs;
56- outputs.emplace_back (" eventsPerBcInfo" , " FT0" , " EVENTS_PER_BC_INFO" )
86+ outputs.emplace_back (" eventsPerBcInfo" , " FT0" , " EVENTS_PER_BC_INFO" );
5787 DataProcessorSpec dataProcessorSpec{
5888 " FT0EventsPerBcProcessor" ,
5989 inputs,
6090 outputs,
61- AlgorithmSpec (adaptFromTask<o2::ft0::FT0EventsPerBcProcessor>()),
62- Options{}
91+ AlgorithmSpec (adaptFromTask<FT0EventsPerBcProcessor>()),
92+ Options{
93+ {" slot-len-sec" , VariantType::UInt32, 3600u , " Time lenght of slot in seconds" },
94+ {" one-object-per-run" , VariantType::Bool, false , " If true, then one calibration object is created per run" }
95+ }
6396 };
6497
6598 WorkflowSpec workflow;
6699 workflow.emplace_back (dataProcessorSpec);
67100 return workflow;
101+ }
68102}
0 commit comments