|
| 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> |
| 17 | +#include "Framework/DataProcessorSpec.h" |
| 18 | +#include "Framework/Task.h" |
| 19 | +#include "Framework/WorkflowSpec.h" |
| 20 | +#include "DataFormatsCTP/Digits.h" |
| 21 | +#include "DataFormatsCTP/LumiInfo.h" |
| 22 | +#include "CTPReconstruction/RawDataDecoder.h" |
| 23 | +#include "DataFormatsParameters/AggregatedRunInfo.h" |
| 24 | + |
| 25 | +namespace o2 |
| 26 | +{ |
| 27 | +namespace ctp |
| 28 | +{ |
| 29 | +namespace reco_workflow |
| 30 | +{ |
| 31 | + |
| 32 | +/// \class RawDecoderSpec |
| 33 | +/// \brief Coverter task for Raw data to CTP digits |
| 34 | +/// \author Roman Lietava from CPV example |
| 35 | +/// |
| 36 | +class RawDecoderSpec : public framework::Task |
| 37 | +{ |
| 38 | + public: |
| 39 | + /// \brief Constructor |
| 40 | + /// \param propagateMC If true the MCTruthContainer is propagated to the output |
| 41 | + RawDecoderSpec(bool digits, bool lumi) : mDoDigits(digits), mDoLumi(lumi) {} |
| 42 | + /// \brief Destructor |
| 43 | + ~RawDecoderSpec() override = default; |
| 44 | + /// \brief Initializing the RawDecoderSpec |
| 45 | + /// \param ctx Init context |
| 46 | + void init(framework::InitContext& ctx) final; |
| 47 | + void endOfStream(o2::framework::EndOfStreamContext& ec) final; |
| 48 | + /// \brief Run conversion of raw data to cells |
| 49 | + /// \param ctx Processing context |
| 50 | + /// |
| 51 | + /// The following branches are linked: |
| 52 | + /// Input RawData: {"ROUT", "RAWDATA", 0, Lifetime::Timeframe} |
| 53 | + /// Output HW errors: {"CTP", "RAWHWERRORS", 0, Lifetime::Timeframe} -later |
| 54 | + void run(framework::ProcessingContext& ctx) final; |
| 55 | + void updateTimeDependentParams(framework::ProcessingContext& pc); |
| 56 | + /// \brief Compute per BC luminosity from the interaction counts from CTP digits |
| 57 | + /// \param ctpdigits Vector of CTP digits to be processed |
| 58 | + /// \return Array of luminosity values for each BC |
| 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); |
| 61 | + /// \brief Integrate luminosity per BC over multiple time frames |
| 62 | + /// \param perInterval Array of luminosity values for each BC for a given time interval |
| 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 |
| 125 | + o2::parameters::AggregatedRunInfo mRunInfo; |
| 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 | + |
| 145 | +/// \brief Creating DataProcessorSpec for the CTP |
| 146 | +/// |
| 147 | +o2::framework::DataProcessorSpec getRawDecoderSpec(bool askSTFDist, bool digits, bool lumi); |
| 148 | + |
| 149 | +} // namespace reco_workflow |
| 150 | + |
| 151 | +} // namespace ctp |
| 152 | + |
| 153 | +} // namespace o2 |
| 154 | + |
| 155 | +#endif |
0 commit comments