Project
Loading...
Searching...
No Matches
TPCDistributeSACSpec.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef O2_TPCDISTRIBUTESACSPEC_H
18#define O2_TPCDISTRIBUTESACSPEC_H
19
20#include <vector>
21#include "Framework/Task.h"
23#include "Framework/Logger.h"
25#include "Headers/DataHeader.h"
27#include "DataFormatsTPC/Defs.h"
29
30using namespace o2::framework;
32using namespace o2::tpc;
33
34namespace o2::tpc
35{
36
38{
39 public:
40 TPCDistributeSACSpec(const unsigned int timeframes, const unsigned int outlanes)
41 : mTimeFrames{timeframes}, mOutLanes{outlanes}
42 {
43 // pre calculate data description for output
44 mDataDescrOut.reserve(mOutLanes);
45 for (int i = 0; i < mOutLanes; ++i) {
46 mDataDescrOut.emplace_back(getDataDescriptionSACVec(i));
47 }
48 };
49
51 {
52 const auto& sacPoint = pc.inputs().get<std::vector<o2::tpc::sac::DataPoint>>("sac");
53 for (const auto& val : sacPoint) {
54 for (int stack = 0; stack < o2::tpc::GEMSTACKS; ++stack) {
55 const auto sac = val.currents[stack];
56 mSACs[stack].emplace_back(sac);
57 }
58 }
59
60 if (mCCDBTimeStamp == 0 && !sacPoint.empty()) {
61 const auto reftime = pc.inputs().get<double>("reftime");
62 mCCDBTimeStamp = static_cast<uint64_t>(reftime + sacPoint.front().time * o2::tpc::sac::Decoder::SampleDistanceTimeMS);
63 }
64
65 ++mProcessedTFs;
66 if (mProcessedTFs == mTimeFrames) {
67 sendOutput(pc);
68 mProcessedTFs = 0;
69 mCurrentOutLane = ++mCurrentOutLane % mOutLanes;
70 mCCDBTimeStamp = 0;
71 for (auto& sac : mSACs) {
72 sac.clear();
73 }
74 }
75 }
76
78 {
79 ec.services().get<ControlService>().readyToQuit(QuitRequest::Me);
80 }
81
83
86 {
87 const std::string name = fmt::format("SACVEC{}", lane).data();
88 header::DataDescription description;
89 description.runtimeInit(name.substr(0, 16).c_str());
90 return description;
91 }
92
93 private:
94 const unsigned int mTimeFrames{};
95 const unsigned int mOutLanes{};
96 int mProcessedTFs{0};
97 std::array<std::vector<int32_t>, o2::tpc::GEMSTACKS> mSACs{};
98 unsigned int mCurrentOutLane{0};
99 uint64_t mCCDBTimeStamp{0};
100 std::vector<header::DataDescription> mDataDescrOut{};
101
102 void sendOutput(o2::framework::ProcessingContext& pc)
103 {
104 LOGP(info, "Sending SACs on lane: {} for {} TFs", mCurrentOutLane, mProcessedTFs);
106 for (unsigned int i = 0; i < o2::tpc::GEMSTACKS; ++i) {
107 pc.outputs().snapshot(Output{gDataOriginTPC, mDataDescrOut[mCurrentOutLane], header::DataHeader::SubSpecificationType{i}}, mSACs[i]);
108 }
109 }
110};
111
112DataProcessorSpec getTPCDistributeSACSpec(const unsigned int timeframes, const unsigned int outlanes)
113{
114 std::vector<InputSpec> inputSpecs;
115 inputSpecs.emplace_back(InputSpec{"sac", gDataOriginTPC, "DECODEDSAC", 0, Lifetime::Sporadic});
116 inputSpecs.emplace_back(InputSpec{"reftime", gDataOriginTPC, "REFTIMESAC", 0, Lifetime::Sporadic});
117
118 std::vector<OutputSpec> outputSpecs;
119 for (unsigned int lane = 0; lane < outlanes; ++lane) {
120 outputSpecs.emplace_back(ConcreteDataTypeMatcher{gDataOriginTPC, TPCDistributeSACSpec::getDataDescriptionSACVec(lane)}, Lifetime::Sporadic);
121 }
122 outputSpecs.emplace_back(gDataOriginTPC, TPCDistributeSACSpec::getDataDescriptionSACCCDB(), 0, Lifetime::Sporadic);
123
124 return DataProcessorSpec{
125 "tpc-distribute-sac",
126 inputSpecs,
127 outputSpecs,
128 AlgorithmSpec{adaptFromTask<TPCDistributeSACSpec>(timeframes, outlanes)}};
129}
130
131} // namespace o2::tpc
132
133#endif
int32_t i
uint32_t stack
Definition RawData.h:1
Decoding of integrated analogue currents.
void snapshot(const Output &spec, T const &object)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
TPCDistributeSACSpec(const unsigned int timeframes, const unsigned int outlanes)
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
static header::DataDescription getDataDescriptionSACVec(const int lane)
return data description for aggregated SACs for given lane
void run(o2::framework::ProcessingContext &pc) final
static constexpr header::DataDescription getDataDescriptionSACCCDB()
static constexpr double SampleDistanceTimeMS
Time distance in MS between samples.
Definition SACDecoder.h:137
GLuint const GLchar * name
Definition glcorearb.h:781
GLuint GLfloat * val
Definition glcorearb.h:1582
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
Global TPC definitions and constants.
Definition SimTraits.h:167
DataProcessorSpec getTPCDistributeSACSpec(const unsigned int timeframes, const unsigned int outlanes)
constexpr unsigned short GEMSTACKS
Definition Defs.h:60
uint32_t SubSpecificationType
Definition DataHeader.h:620
void runtimeInit(const char *string, short length=-1)
Definition DataHeader.h:261