2020#include " DataFormatsCTP/Digits.h"
2121#include " DataFormatsCTP/LumiInfo.h"
2222#include " CTPReconstruction/RawDataDecoder.h"
23+ #include " DataFormatsParameters/AggregatedRunInfo.h"
2324
2425namespace o2
2526{
@@ -55,10 +56,16 @@ class RawDecoderSpec : public framework::Task
5556 // / \brief Compute per BC luminosity from the interaction counts from CTP digits
5657 // / \param ctpdigits Vector of CTP digits to be processed
5758 // / \return Array of luminosity values for each BC
58- std::pair<std::array<double , o2::constants::lhc::LHCMaxBunches>, std::array<double , o2::constants::lhc::LHCMaxBunches>> computeLumiPerBC (const o2::pmr::vector<CTPDigit>& ctpdigits);
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);
5961 // / \brief Integrate luminosity per BC over multiple time frames
60- // / \param perTF Array of luminosity values for each BC from a single time frame
61- void integrateLumi (const std::array<double , o2::constants::lhc::LHCMaxBunches>& perTFInp1, const std::array<double , o2::constants::lhc::LHCMaxBunches>& perTFInp2);
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);
6269 protected:
6370 private:
6471 // for digits
@@ -74,8 +81,14 @@ class RawDecoderSpec : public framework::Task
7481 uint64_t mCountsT = 0 ;
7582 uint64_t mCountsV = 0 ;
7683 uint32_t mNTFToIntegrate = 1 ;
84+ uint32_t mNHBIntegrated = 0 ;
7785 uint32_t mNHBIntegratedT = 0 ;
7886 uint32_t mNHBIntegratedV = 0 ;
87+ uint32_t mNHBToIntegrate = 1 ;
88+ uint32_t mFirstOrbit = 0 ;
89+ uint32_t mOrbitsInCurrentWindow = 0 ;
90+ uint32_t mTFsInCurrentWindow = 0 ;
91+ double mWindowStartTime = 0.0 ;
7992 bool mDecodeinputs = 0 ;
8093 std::deque<size_t > mHistoryT ;
8194 std::deque<size_t > mHistoryV ;
@@ -94,10 +107,38 @@ class RawDecoderSpec : public framework::Task
94107 std::array<double , o2::constants::lhc::LHCMaxBunches> mCountsPerBC1 {};
95108 std::array<double , o2::constants::lhc::LHCMaxBunches> mCountsPerBC2 {};
96109 double totalTime = 0.0 ;
97- const double orbitsPerTF = 32 ;
98- const double tfTime = orbitsPerTF * o2::constants::lhc::LHCOrbitMUS * 1e-6 ; // total time in seconds for one timeframe
110+ uint32_t mOrbitsPerTF = 0 ;
111+ const double tfTime = mOrbitsPerTF * o2::constants::lhc::LHCOrbitMUS * 1e-6 ; // total time in seconds for one timeframe
99112 std::bitset<3564 > mLHCBCs ;
100- const double timeInterval = o2::constants::lhc::LHCOrbitMUS * 1e-6 ; // one HBF
113+ static constexpr double orbitTime = o2::constants::lhc::LHCOrbitMUS * 1e-6 ; // one HBF
114+ std::array<double , o2::constants::lhc::LHCMaxBunches> mTotalCountsPerBC1 {};
115+ std::array<double , o2::constants::lhc::LHCMaxBunches> mTotalCountsPerBC2 {};
116+ double mTotalElapsedTime = 0.0 ;
117+ // Massi file output
118+ std::string mFillNumber = " unknown" ;
119+ std::string mMassiOutDir ;
120+ int mMassiYear = 0 ;
121+ double mOrbitResetTimeSec = 0.0 ;
122+ bool mStableBeams = false ;
123+ std::map<int , std::ofstream> mMassiFiles ; // one open file per RF bucket
124+ o2::parameters::AggregatedRunInfo mRunInfo ;
125+ double mCrossSection = 1.0 ;
126+ double mTFsInMin = 0.0 ;
127+ uint32_t mPrevTFLastOrbit = 0 ;
128+ bool mHavePrevTF = false ;
129+ int mRunStartTime = 0 ;
130+ int mRunEndTime = 0 ;
131+ struct PendingTF {
132+ std::array<double , o2::constants::lhc::LHCMaxBunches> countsPerBC1{};
133+ std::array<double , o2::constants::lhc::LHCMaxBunches> countsPerBC2{};
134+ int64_t unixTimeStart;
135+ uint32_t nOrbitsThisTF;
136+ };
137+ std::map<uint32_t , PendingTF> mPendingTFs ;
138+ uint32_t mReorderDepth = 5 ;
139+ void flushReadyTFs ();
140+ void flushAllPendingTFs ();
141+ std::pair<double , double > pileupCorrection (double rate) const ;
101142};
102143
103144// / \brief Creating DataProcessorSpec for the CTP
0 commit comments