Skip to content

Commit

Permalink
ctpdevL input scalers (#11970)
Browse files Browse the repository at this point in the history
* dev: scaler inputs dinished and tools

* clang
  • Loading branch information
lietava authored Sep 28, 2023
1 parent c29befc commit e22bf1a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
6 changes: 4 additions & 2 deletions DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class CTPRunScalers
uint32_t getRunNUmber() { return mRunNumber; };
int printRates();
int printIntegrals();
int printInputRateAndIntegral(int inp);
int printClassBRateAndIntegral(int icls);
//
// static constexpr uint32_t NCOUNTERS = 1052;
// v1
Expand Down Expand Up @@ -146,10 +148,10 @@ class CTPRunScalers
std::vector<CTPScalerRecordRaw> mScalerRecordRaw;
std::vector<CTPScalerRecordO2> mScalerRecordO2;
int processScalerLine(const std::string& line, int& level, int& nclasses);
int copyRawToO2ScalerRecord(const CTPScalerRecordRaw& rawrec, CTPScalerRecordO2& o2rec, overflows_t& classesoverflows);
int copyRawToO2ScalerRecord(const CTPScalerRecordRaw& rawrec, CTPScalerRecordO2& o2rec, overflows_t& classesoverflows, std::array<uint32_t, 48>& overflows);
int updateOverflows(const CTPScalerRecordRaw& rec0, const CTPScalerRecordRaw& rec1, overflows_t& classesoverflows) const;
int updateOverflows(const CTPScalerRaw& scal0, const CTPScalerRaw& scal1, std::array<uint32_t, 6>& overflow) const;

int updateOverflowsInps(const CTPScalerRecordRaw& rec0, const CTPScalerRecordRaw& rec1, std::array<uint32_t, 48>& overflow) const;
ClassDefNV(CTPRunScalers, 2);
};
} // namespace ctp
Expand Down
72 changes: 68 additions & 4 deletions DataFormats/Detectors/CTP/src/Scalers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void CTPScalerRecordRaw::printStream(std::ostream& stream) const
for (auto const& cnts : scalers) {
cnts.printStream(stream);
}
std::cout << "Inputs:" << scalersInps.size() << std::endl;
for (auto const& dets : scalersInps) {
stream << dets << " ";
}
Expand All @@ -77,6 +78,7 @@ void CTPScalerRecordO2::printStream(std::ostream& stream) const
for (auto const& cnts : scalers) {
cnts.printStream(stream);
}
std::cout << "Inputs:" << scalersInps.size() << std::endl;
for (auto const& dets : scalersInps) {
stream << dets << " ";
}
Expand Down Expand Up @@ -273,10 +275,12 @@ int CTPRunScalers::convertRawToO2()
overflows[i] = {0, 0, 0, 0, 0, 0};
}
}
// Input overflows
std::array<uint32_t, 48> overflowsInputs = {48 * 0};
errorCounters eCnts;
// 1st o2 rec is just copy
CTPScalerRecordO2 o2rec;
copyRawToO2ScalerRecord(mScalerRecordRaw[0], o2rec, overflows);
copyRawToO2ScalerRecord(mScalerRecordRaw[0], o2rec, overflows, overflowsInputs);
mScalerRecordO2.push_back(o2rec);
int j = 1;
for (uint32_t i = 1; i < mScalerRecordRaw.size(); i++) {
Expand All @@ -285,7 +289,8 @@ int CTPRunScalers::convertRawToO2()
//
if (ret == 0) {
CTPScalerRecordO2 o2rec;
copyRawToO2ScalerRecord(mScalerRecordRaw[i], o2rec, overflows);
ret = updateOverflowsInps(mScalerRecordRaw[i - 1], mScalerRecordRaw[i], overflowsInputs);
copyRawToO2ScalerRecord(mScalerRecordRaw[i], o2rec, overflows, overflowsInputs);
mScalerRecordO2.push_back(o2rec);
// Check consistency
checkConsistency(mScalerRecordO2[j - 1], mScalerRecordO2[j], eCnts);
Expand All @@ -295,7 +300,7 @@ int CTPRunScalers::convertRawToO2()
eCnts.printStream(std::cout);
return 0;
}
int CTPRunScalers::copyRawToO2ScalerRecord(const CTPScalerRecordRaw& rawrec, CTPScalerRecordO2& o2rec, overflows_t& classesoverflows)
int CTPRunScalers::copyRawToO2ScalerRecord(const CTPScalerRecordRaw& rawrec, CTPScalerRecordO2& o2rec, overflows_t& classesoverflows, std::array<uint32_t, 48>& overflows)
{
if (rawrec.scalers.size() != (mClassMask.count())) {
LOG(error) << "Inconsistent scaler record size:" << rawrec.scalers.size() << " Expected:" << mClassMask.count();
Expand All @@ -313,6 +318,10 @@ int CTPRunScalers::copyRawToO2ScalerRecord(const CTPScalerRecordRaw& rawrec, CTP
o2scal.createCTPScalerO2FromRaw(rawscal, classesoverflows[k]);
o2rec.scalers.push_back(o2scal);
}
for (int i = 0; i < rawrec.scalersInps.size(); i++) {
uint64_t inpo2 = (uint64_t)(rawrec.scalersInps[i]) + 0xffffffffull * (uint64_t)(overflows[i]);
o2rec.scalersInps.push_back(inpo2);
}
return 0;
}
int CTPRunScalers::checkConsistency(const CTPScalerO2& scal0, const CTPScalerO2& scal1, errorCounters& eCnts) const
Expand Down Expand Up @@ -452,6 +461,26 @@ int CTPRunScalers::updateOverflows(const CTPScalerRaw& scal0, const CTPScalerRaw
//std::cout << std::endl;
return 0;
}
//
int CTPRunScalers::updateOverflowsInps(const CTPScalerRecordRaw& rec0, const CTPScalerRecordRaw& rec1, std::array<uint32_t, 48>& overflow) const
{
int NINPS = 48;
if (rec0.scalersInps.size() < NINPS) {
LOG(error) << "updateOverflowsInps.size < 48:" << rec0.scalersInps.size();
return 1;
}
if (rec1.scalersInps.size() < NINPS) {
LOG(error) << "updateOverflowsInps.size < 48:" << rec1.scalersInps.size();
return 2;
}
for (int i = 0; i < NINPS; i++) {
if (rec0.scalersInps[i] > rec1.scalersInps[i]) {
overflow[i] += 1;
}
}
return 0;
}
//
int CTPRunScalers::printRates()
{
if (mScalerRecordO2.size() == 0) {
Expand Down Expand Up @@ -507,7 +536,42 @@ int CTPRunScalers::printIntegrals()
}
return 0;
}

//
// Input counting 1..48
int CTPRunScalers::printInputRateAndIntegral(int inp)
{
if (mScalerRecordO2.size() == 0) {
LOG(info) << "ScalerRecord is empty, doing nothing";
return 1;
}
double_t time0 = mScalerRecordO2[0].epochTime;
double_t timeL = mScalerRecordO2[mScalerRecordO2.size() - 1].epochTime;
int integral = mScalerRecordO2[mScalerRecordO2.size() - 1].scalersInps[inp - 1] - mScalerRecordO2[0].scalersInps[inp - 1];
std::cout << "Scaler Integrals for run:" << mRunNumber << " duration:" << timeL - time0;
std::cout << " Input " << inp << " integral:" << integral << " rate:" << integral / (timeL - time0) << std::endl;
return 0;
}
// Prints class before counters for lumi
// Class counting 1..64
int CTPRunScalers::printClassBRateAndIntegral(int icls)
{
if (mScalerRecordO2.size() == 0) {
LOG(info) << "ScalerRecord is empty, doing nothing";
return 1;
}
double_t time0 = mScalerRecordO2[0].epochTime;
double_t timeL = mScalerRecordO2[mScalerRecordO2.size() - 1].epochTime;
if (mScalerRecordO2[0].scalers.size() < icls) {
LOG(error) << "class number bigger than expected for this run:" << icls << "expexted smaller than:" << mScalerRecordO2[0].scalers.size();
return 1;
} else {
int integral = mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[icls - 1].lmBefore - mScalerRecordO2[0].scalers[icls - 1].lmBefore;
std::cout << "Scaler Integrals for run:" << mRunNumber << " duration:" << timeL - time0;
std::cout << " Class " << icls << " integral:" << integral << " rate:" << integral / (timeL - time0) << std::endl;
}
return 0;
}
//
void CTPRunScalers::printLMBRateVsT() const
{
for (int i = 1; i < mScalerRecordO2.size(); i++) { // loop over time
Expand Down
23 changes: 15 additions & 8 deletions Detectors/CTP/macro/GetScalers.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ void GetScalers(std::string srun, long time, std::string ccdbHost = "http://ccdb
// return;
scl = mng.getScalersFromCCDB(time, srun, ok);
if (ok == 1) {
scl.printStream(std::cout);
scl.convertRawToO2();
scl.printO2(std::cout);
scl.printFromZero(std::cout);
scl.printIntegrals();
scl.printRates();
// std::vector<int> clsses;
// clsses = ctpcfg.getTriggerClassList();
// std::cout << clsses.size() << std::endl;
// for(auto const& i : clsses) std::cout << i << std::endl;
// scl.printO2(std::cout);
// scl.printFromZero(std::cout);
// scl.printIntegrals();
// scl.printRates();
std::cout << "TVX,TSC,TCE,ZNC:" << std::endl;
scl.printInputRateAndIntegral(3);
scl.printInputRateAndIntegral(4);
scl.printInputRateAndIntegral(5);
scl.printInputRateAndIntegral(26);
std::cout << " TVX,TVX&TCE,TVX&TSC,TVX&VCH:" << std::endl;
scl.printClassBRateAndIntegral(3);
scl.printClassBRateAndIntegral(4);
scl.printClassBRateAndIntegral(5);
scl.printClassBRateAndIntegral(6);
} else {
std::cout << "Can not find run, please, check parameters" << std::endl;
}
Expand Down

0 comments on commit e22bf1a

Please sign in to comment.