File indexing completed on 2025-08-03 08:21:01
0001 #include "InttMon.h"
0002
0003 #include <onlmon/OnlMonServer.h>
0004
0005 #include <Event/Event.h>
0006 #include <Event/packet.h>
0007
0008 #include <TH1.h>
0009 #include <TH2.h>
0010
0011 #include <iostream>
0012 #include <limits>
0013
0014 InttMon::InttMon(const std::string &name)
0015 : OnlMon(name)
0016 {
0017
0018 return;
0019 }
0020
0021 InttMon::~InttMon()
0022 {
0023
0024 }
0025
0026 int InttMon::Init()
0027 {
0028 OnlMonServer *se = OnlMonServer::instance();
0029
0030
0031
0032
0033
0034
0035
0036 EvtHist = new TH1I("InttEvtHist", "InttEvtHist", 5, 0.0, 1.0);
0037 HitHist = new TH1D("InttHitHist", "InttHitHist", (NFEES * NCHIPS), 0.0, 1.0);
0038 BcoHist = new TH2D("InttBcoHist", "InttBcoHist", 2, 0.0, 1.0, (NFEES * NBCOS), 0.0, 1.0);
0039
0040
0041 LogHist = new TH1I("InttLogHist", "InttLogHist", m_LOG_DURATION / m_LOG_INTERVAL, 0.0, m_LOG_DURATION);
0042
0043 se->registerHisto(this, EvtHist);
0044 se->registerHisto(this, HitHist);
0045 se->registerHisto(this, BcoHist);
0046 se->registerHisto(this, LogHist);
0047
0048
0049 return 0;
0050 }
0051
0052 int InttMon::BeginRun(const int )
0053 {
0054 EvtHist->Reset();
0055 HitHist->Reset();
0056 BcoHist->Reset();
0057 LogHist->Reset();
0058
0059 m_unique_bcos.clear();
0060 m_unique_bco_count = 0;
0061 m_most_recent_bco = std::numeric_limits<unsigned long long>::max();
0062 m_last_flushed_bco = std::numeric_limits<unsigned long long>::max();
0063
0064 m_log_bin = 0;
0065 m_logged_bcos = 0;
0066
0067 m_start_time = std::chrono::system_clock::now();
0068
0069
0070
0071 std::chrono::time_point<std::chrono::system_clock> const now = std::chrono::system_clock::now();
0072 std::chrono::duration<double> duration = now.time_since_epoch();
0073 double seconds = duration.count();
0074 EvtHist->SetBinContent(4, (int)seconds);
0075
0076 return 0;
0077 }
0078
0079 int InttMon::process_event(Event *evt)
0080 {
0081 for (int pid = 3001; pid < 3009; ++pid)
0082 {
0083 Packet *pkt = evt->getPacket(pid);
0084 if (!pkt)
0085 {
0086 continue;
0087 }
0088
0089
0090 for (int n = 0; n < pkt->iValue(0, "NR_HITS"); ++n)
0091 {
0092 int fee = pkt->iValue(n, "FEE");
0093 int chp = (pkt->iValue(n, "CHIP_ID") + 25) % 26;
0094 int fphx_bco = pkt->iValue(n, "FPHX_BCO");
0095 int bco_diff = ((0x7f & pkt->lValue(n, "BCO")) - fphx_bco + 128) % 128;
0096 HitHist->AddBinContent(fee * NCHIPS + chp + 1);
0097 BcoHist->AddBinContent(BcoHist->GetBin(1, fee * NBCOS + bco_diff + 1));
0098 BcoHist->AddBinContent(BcoHist->GetBin(2, fee * NBCOS + fphx_bco + 1));
0099 }
0100
0101
0102 for (int n = 0; n < pkt->iValue(0, "NR_BCOS"); ++n)
0103 {
0104 unsigned long long bco_full = pkt->lValue(n, "BCOLIST");
0105
0106
0107 if(m_bco_less(m_most_recent_bco, bco_full) || (m_most_recent_bco == std::numeric_limits<unsigned long long>::max()))
0108 {
0109 m_most_recent_bco = bco_full;
0110 }
0111
0112
0113
0114 if(!m_bco_less(m_last_flushed_bco, bco_full) && (m_last_flushed_bco != std::numeric_limits<unsigned long long>::max()))
0115 {
0116 EvtHist->SetBinContent(3, 1);
0117 continue;
0118 }
0119
0120 m_unique_bcos.insert(bco_full);
0121 }
0122
0123 delete pkt;
0124 }
0125
0126
0127 if(100 < m_unique_bcos.size())
0128 {
0129 std::set<unsigned long long, bco_comparator_s>::const_iterator bco_itr = m_unique_bcos.begin();
0130
0131 for(int n = 0; n < 10; ++n)
0132 {
0133 if(bco_itr == m_unique_bcos.end())
0134 {
0135 break;
0136 }
0137
0138
0139 if( m_most_recent_bco == std::numeric_limits<unsigned long long>::max() )
0140 {
0141 break;
0142 }
0143
0144 ++m_unique_bco_count;
0145 m_last_flushed_bco = *bco_itr;
0146 ++bco_itr;
0147 }
0148 m_unique_bcos.erase(m_unique_bcos.begin(), bco_itr);
0149 }
0150
0151 EvtHist->AddBinContent(1);
0152 EvtHist->SetBinContent(2, m_unique_bco_count + m_unique_bcos.size());
0153
0154
0155 std::chrono::time_point<std::chrono::system_clock> const now = std::chrono::system_clock::now();
0156 std::chrono::duration<double> duration = now.time_since_epoch();
0157 double seconds = duration.count();
0158 EvtHist->SetBinContent(5, (int)seconds);
0159
0160 duration = now - m_start_time;
0161 seconds = duration.count();
0162
0163 int N = LogHist->GetNbinsX();
0164 int logged_seconds = m_LOG_INTERVAL * (N * LogHist->GetBinContent(N + 1) + m_log_bin);
0165
0166
0167 while(logged_seconds < seconds)
0168 {
0169 m_logged_bcos = m_unique_bco_count + m_unique_bcos.size();
0170
0171 if(m_log_bin == N - 1)
0172 {
0173 LogHist->AddBinContent(N + 1);
0174 }
0175 m_log_bin = (m_log_bin + 1) % N;
0176
0177 LogHist->SetBinContent(m_log_bin, 0);
0178 LogHist->SetBinContent(N, m_log_bin);
0179
0180 logged_seconds += m_LOG_INTERVAL;
0181 }
0182
0183 LogHist->SetBinContent(m_log_bin, m_unique_bco_count + m_unique_bcos.size() - m_logged_bcos);
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 return 0;
0200 }
0201
0202 int InttMon::Reset()
0203 {
0204 return 0;
0205 }
0206
0207 int InttMon::MiscDebug()
0208 {
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225 return 0;
0226 }
0227
0228 bool InttMon::bco_comparator_s::operator()(unsigned long long const& lhs, unsigned long long const& rhs) const
0229 {
0230 return (rhs - lhs + 2 * MAX) % MAX < (lhs - rhs + 2 *MAX) % MAX;
0231 }
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264