Project
Loading...
Searching...
No Matches
RawDecoderSpec.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
12#ifndef O2_CTP_RAWDECODER_H
13#define O2_CTP_RAWDECODER_H
14
15#include <vector>
16#include <deque>
18#include "Framework/Task.h"
24
25namespace o2
26{
27namespace ctp
28{
29namespace reco_workflow
30{
31
36class RawDecoderSpec : public framework::Task
37{
38 public:
41 RawDecoderSpec(bool digits, bool lumi) : mDoDigits(digits), mDoLumi(lumi) {}
43 ~RawDecoderSpec() override = default;
46 void init(framework::InitContext& ctx) final;
59 // std::pair<std::array<double, o2::constants::lhc::LHCMaxBunches>, std::array<double, o2::constants::lhc::LHCMaxBunches>>
60 void computeLumiPerBC(const o2::pmr::vector<CTPDigit>& ctpdigits, uint32_t firstOrbit, uint32_t orbitsPerTF);
63 void integrateLumi(const std::array<double, o2::constants::lhc::LHCMaxBunches>& tfCounts1, const std::array<double, o2::constants::lhc::LHCMaxBunches>& tfCounts2, int64_t unixTime, uint32_t nOrbitsThisTF);
64 void writeMassiLinePerBC(int bc, int64_t unixTime, double lumi, double lumiErr, double correctedRate, double correctedLumi, double mu);
65 void writeMassiLineLumi(int64_t unixTime, double lumi, double lumiErr);
66 int64_t unixTimeForOrbitStart(uint32_t orbit) const;
67 int yearFromUnixTime(int64_t unixTime) const;
68 void fetchRunInfo(int runNumber);
69
70 protected:
71 private:
72 // for digits
73 bool mDoDigits = true;
74 o2::pmr::vector<CTPDigit> mOutputDigits;
75 int mMaxInputSize = 0;
76 bool mMaxInputSizeFatal = 0;
77 // for lumi
78 bool mDoLumi = true;
79 //
80 LumiInfo mOutputLumiInfo;
81 bool mVerbose = false;
82 uint64_t mCountsT = 0;
83 uint64_t mCountsV = 0;
84 uint32_t mNTFToIntegrate = 1;
85 uint32_t mNHBIntegrated = 0;
86 uint32_t mNHBIntegratedT = 0;
87 uint32_t mNHBIntegratedV = 0;
88 uint32_t mNHBToIntegrate = 1;
89 uint32_t mFirstOrbit = 0;
90 uint32_t mOrbitsInCurrentWindow = 0;
91 uint32_t mTFsInCurrentWindow = 0;
92 double mWindowStartTime = 0.0;
93 bool mDecodeinputs = 0;
94 std::deque<size_t> mHistoryT;
95 std::deque<size_t> mHistoryV;
96 RawDataDecoder mDecoder;
97 // Errors
98 int mLostDueToShiftInps = 0;
99 int mErrorIR = 0;
100 int mErrorTCR = 0;
101 int mIRRejected = 0;
102 int mTCRRejected = 0;
103 std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClsEA{};
104 std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClsEB{}; // from inputs
105 std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClsA{};
106 std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClsB{}; // from inputs
107 bool mCheckConsistency = false;
108 std::array<double, o2::constants::lhc::LHCMaxBunches> mCountsPerBC1{};
109 std::array<double, o2::constants::lhc::LHCMaxBunches> mCountsPerBC2{};
110 double totalTime = 0.0;
111 uint32_t mOrbitsPerTF = 0;
112 const double tfTime = mOrbitsPerTF * o2::constants::lhc::LHCOrbitMUS * 1e-6; // total time in seconds for one timeframe
113 std::bitset<3564> mLHCBCs;
114 static constexpr double orbitTime = o2::constants::lhc::LHCOrbitMUS * 1e-6; // one HBF
115 std::array<double, o2::constants::lhc::LHCMaxBunches> mTotalCountsPerBC1{};
116 std::array<double, o2::constants::lhc::LHCMaxBunches> mTotalCountsPerBC2{};
117 double mTotalElapsedTime = 0.0;
118 // Massi file output
119 std::string mFillNumber = "unknown";
120 std::string mMassiOutDir;
121 int mMassiYear = 0;
122 double mOrbitResetTimeSec = 0.0;
123 bool mStableBeams = false;
124 std::map<int, std::ofstream> mMassiFiles; // one open file per RF bucket
126 double mCrossSection = 1.0;
127 double mTFsInMin = 0.0;
128 uint32_t mPrevTFLastOrbit = 0;
129 bool mHavePrevTF = false;
130 int mRunStartTime = 0;
131 int mRunEndTime = 0;
132 struct PendingTF {
133 std::array<double, o2::constants::lhc::LHCMaxBunches> countsPerBC1{};
134 std::array<double, o2::constants::lhc::LHCMaxBunches> countsPerBC2{};
135 int64_t unixTimeStart;
136 uint32_t nOrbitsThisTF;
137 };
138 std::map<uint32_t, PendingTF> mPendingTFs;
139 uint32_t mReorderDepth = 5;
140 void flushReadyTFs();
141 void flushAllPendingTFs();
142 std::pair<double, double> pileupCorrection(double rate) const;
143};
144
148
149} // namespace reco_workflow
150
151} // namespace ctp
152
153} // namespace o2
154
155#endif
definition of CTPDigit, CTPInputDigit
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
Digits tw Raw translation.
void run(framework::ProcessingContext &ctx) final
Run conversion of raw data to cells.
void computeLumiPerBC(const o2::pmr::vector< CTPDigit > &ctpdigits, uint32_t firstOrbit, uint32_t orbitsPerTF)
Compute per BC luminosity from the interaction counts from CTP digits.
void writeMassiLinePerBC(int bc, int64_t unixTime, double lumi, double lumiErr, double correctedRate, double correctedLumi, double mu)
~RawDecoderSpec() override=default
Destructor.
void writeMassiLineLumi(int64_t unixTime, double lumi, double lumiErr)
void integrateLumi(const std::array< double, o2::constants::lhc::LHCMaxBunches > &tfCounts1, const std::array< double, o2::constants::lhc::LHCMaxBunches > &tfCounts2, int64_t unixTime, uint32_t nOrbitsThisTF)
Integrate luminosity per BC over multiple time frames.
void init(framework::InitContext &ctx) final
Initializing the RawDecoderSpec.
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
RawDecoderSpec(bool digits, bool lumi)
Constructor.
void updateTimeDependentParams(framework::ProcessingContext &pc)
int yearFromUnixTime(int64_t unixTime) const
int64_t unixTimeForOrbitStart(uint32_t orbit) const
GLuint GLenum * rate
Definition glcorearb.h:5735
constexpr double LHCOrbitMUS
o2::framework::DataProcessorSpec getRawDecoderSpec(bool askSTFDist, bool digits, bool lumi)
Creating DataProcessorSpec for the CTP.
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LumiInfo lumi
std::vector< Digit > digits