Skip to content

Commit 41919ac

Browse files
authored
Ctpdev: 3 things (#13875)
* dev: 3 things * clang
1 parent a0bd8e9 commit 41919ac

File tree

10 files changed

+209
-21
lines changed

10 files changed

+209
-21
lines changed

DataFormats/Detectors/CTP/include/DataFormatsCTP/CTPRateFetcher.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class CTPRateFetcher
3232
double fetchNoPuCorr(o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, int runNumber, const std::string sourceName);
3333
void setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, bool initScalers);
3434
void updateScalers(ctp::CTPRunScalers& scalers);
35+
int getRates(std::array<double, 3>& rates, o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName); // rates at start,stop and middle of the run
36+
void setOrbit(bool orb) { mOrbit = orb; }
37+
void setOutsideLimits(bool qc) { mOutsideLimits = qc; }
3538

3639
private:
3740
double fetchCTPratesInputs(uint64_t timeStamp, int input);
@@ -41,6 +44,8 @@ class CTPRateFetcher
4144

4245
double pileUpCorrection(double rate);
4346
int mRunNumber = -1;
47+
bool mOutsideLimits = 0;
48+
bool mOrbit = 0;
4449
o2::ctp::CTPConfiguration mConfig{};
4550
o2::ctp::CTPRunScalers mScalers{};
4651
o2::parameters::GRPLHCIFData mLHCIFdata{};

DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class CTPRunScalers
125125
void printLMBRateVsT() const; // prints LMB interaction rate vs time for debugging
126126
// returns the pair of global (levelled) interaction rate, as well as interpolated
127127
// rate in Hz at a certain orbit number within the run
128-
std::pair<double, double> getRate(uint32_t orbit, int classindex, int type) const;
128+
std::pair<double, double> getRate(uint32_t orbit, int classindex, int type, bool qc = 0) const;
129129

130130
/// same with absolute timestamp (not orbit) as argument
131131
std::pair<double, double> getRateGivenT(double timestamp, int classindex, int type, bool qc = 0) const;

DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ void CTPRateFetcher::updateScalers(ctp::CTPRunScalers& scalers)
6161
mScalers.convertRawToO2();
6262
}
6363
//
64+
int CTPRateFetcher::getRates(std::array<double, 3>& rates, o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName) // rates at start,stop and middle of the run
65+
{
66+
setupRun(runNumber, ccdb, 0, 1);
67+
mOrbit = 1;
68+
mOutsideLimits = 1;
69+
auto orbitlimits = mScalers.getOrbitLimit();
70+
// std::cout << "1st orbit:" << orbitlimits.first << " last:" << orbitlimits.second << " Middle:" << (orbitlimits.first + orbitlimits.second)/2 << std::endl;
71+
double rate0 = fetch(ccdb, orbitlimits.first, mRunNumber, sourceName);
72+
double rateLast = fetch(ccdb, orbitlimits.second, mRunNumber, sourceName);
73+
double rateM = fetch(ccdb, (orbitlimits.first + orbitlimits.second) / 2, mRunNumber, sourceName);
74+
// std::cout << rate0 << " " << rateLast << " " << rateM << std::endl;
75+
rates[0] = rate0;
76+
rates[1] = rateLast;
77+
rates[2] = rateM;
78+
return 0;
79+
}
80+
//
6481
double CTPRateFetcher::fetchCTPratesClasses(uint64_t timeStamp, const std::string& className, int inputType)
6582
{
6683
auto triggerRate = fetchCTPratesClassesNoPuCorr(timeStamp, className, inputType);
@@ -84,14 +101,23 @@ double CTPRateFetcher::fetchCTPratesClassesNoPuCorr(uint64_t timeStamp, const st
84101
LOG(warn) << "Trigger class " << className << " not found in CTPConfiguration";
85102
return -2.;
86103
}
87-
auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, 1)};
88-
return rate.second;
104+
if (mOrbit) {
105+
auto rate{mScalers.getRate((uint32_t)timeStamp, classIndex, inputType, mOutsideLimits)};
106+
return rate.second;
107+
} else {
108+
auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, mOutsideLimits)};
109+
return rate.second;
110+
}
89111
}
90112
double CTPRateFetcher::fetchCTPratesInputs(uint64_t timeStamp, int input)
91113
{
92114
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
93115
if (recs[0].scalersInps.size() == 48) {
94-
return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second);
116+
if (mOrbit) {
117+
return pileUpCorrection(mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second);
118+
} else {
119+
return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second);
120+
}
95121
} else {
96122
LOG(error) << "Inputs not available";
97123
return -1.;
@@ -101,7 +127,11 @@ double CTPRateFetcher::fetchCTPratesInputsNoPuCorr(uint64_t timeStamp, int input
101127
{
102128
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
103129
if (recs[0].scalersInps.size() == 48) {
104-
return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second;
130+
if (mOrbit) {
131+
return mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second;
132+
} else {
133+
return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second; // qc flag implemented only for time
134+
}
105135
} else {
106136
LOG(error) << "Inputs not available";
107137
return -1.;
@@ -127,13 +157,13 @@ void CTPRateFetcher::setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, u
127157
return;
128158
}
129159
mRunNumber = runNumber;
130-
LOG(debug) << "Setting up CTP scalers for run " << mRunNumber;
131-
std::map<string, string> metadata;
132-
auto ptrLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
160+
LOG(info) << "Setting up CTP scalers for run " << mRunNumber;
161+
auto ptrLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp);
133162
if (ptrLHCIFdata == nullptr) {
134163
LOG(fatal) << "GRPLHCIFData not in database, timestamp:" << timeStamp;
135164
}
136165
mLHCIFdata = *ptrLHCIFdata;
166+
std::map<string, string> metadata;
137167
metadata["runNumber"] = std::to_string(mRunNumber);
138168
auto ptrConfig = ccdb->getSpecific<ctp::CTPConfiguration>("CTP/Config/Config", timeStamp, metadata);
139169
if (ptrConfig == nullptr) {

DataFormats/Detectors/CTP/src/Configuration.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,16 @@ int CTPConfiguration::processConfigurationLineRun3v2(std::string& line, int& lev
608608
break;
609609
}
610610
case DESCRIPTORS: {
611-
if ((tokens.size() < 2) && (line.find("DTRUE") == std::string::npos)) {
612-
LOG(warning) << "Dsecriptor:" << line;
613-
break;
611+
if ((tokens.size() < 2)) {
612+
if (line.find("TRUE") != std::string::npos) {
613+
CTPDescriptor desc;
614+
desc.name = tokens[0];
615+
mDescriptors.push_back(desc);
616+
break;
617+
} else {
618+
LOG(warning) << "Unexpected Descriptor:" << line;
619+
break;
620+
}
614621
}
615622
CTPDescriptor desc;
616623
desc.name = tokens[0];

DataFormats/Detectors/CTP/src/Scalers.cxx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void CTPRunScalers::printLMBRateVsT() const
662662
// rate in Hz at a certain orbit number within the run
663663
// type - 7 : inputs
664664
// type - 1..6 : lmb,lma,l0b,l0a,l1b,l1a
665-
std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex, int type) const
665+
std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex, int type, bool qc) const
666666
{
667667
if (mScalerRecordO2.size() <= 1) {
668668
LOG(error) << "not enough data";
@@ -709,11 +709,24 @@ std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex,
709709
return -1; // wrong type
710710
}
711711
};
712-
713-
if (nextindex == 0 || nextindex == mScalerRecordO2.size()) {
712+
// qc flag decides what to return if time outside run
713+
if (nextindex == 0) {
714714
// orbit is out of bounds
715-
LOG(info) << "query orbit " << orbit << " out of bounds; Just returning the global rate";
716-
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
715+
if (qc == 0) {
716+
LOG(info) << "query orbit " << orbit << " before first record; Just returning the global rate";
717+
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
718+
} else {
719+
LOG(info) << "query orbit " << orbit << " before first record; Returning the first rate";
720+
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* first rate */ calcRate(0, 1));
721+
}
722+
} else if (nextindex == mScalerRecordO2.size()) {
723+
if (qc == 0) {
724+
LOG(info) << "query orbit " << orbit << " after last record; Just returning the global rate";
725+
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
726+
} else {
727+
LOG(info) << "query orbit " << orbit << " after last record; Returning the last rate";
728+
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* last rate */ calcRate(mScalerRecordO2.size() - 2, mScalerRecordO2.size() - 1));
729+
}
717730
} else {
718731
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ calcRate(nextindex - 1, nextindex));
719732
}

Detectors/CTP/macro/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,15 @@ o2_add_test_root_macro(CreateBKForRun.C
7373
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
7474
O2::CCDB
7575
LABELS ctp)
76-
76+
o2_add_test_root_macro(CheckCTPConfig.C
77+
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
78+
O2::CCDB
79+
LABELS ctp)
80+
o2_add_test_root_macro(GetRates.C
81+
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
82+
O2::CCDB
83+
LABELS ctp)
84+
o2_add_test_root_macro(TestGetRates.C
85+
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
86+
O2::CCDB
87+
LABELS ctp)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
/// \file CreateCTPConfig.C
13+
/// \brief create CTP config, test it and add to database
14+
/// \author Roman Lietava
15+
16+
#if !defined(__CLING__) || defined(__ROOTCLING__)
17+
18+
#include <fairlogger/Logger.h>
19+
#include "CCDB/CcdbApi.h"
20+
#include "CCDB/BasicCCDBManager.h"
21+
#include "DataFormatsCTP/Configuration.h"
22+
#include <string>
23+
#include <map>
24+
#include <iostream>
25+
#endif
26+
using namespace o2::ctp;
27+
int CheckCTPConfig(std::string cfgRun3str = "/home/rl/backup24/runs/559781.rcfg2", int writeToFile = 0)
28+
{
29+
//
30+
// run3 config
31+
//
32+
if (cfgRun3str.find(".rcfg") == std::string::npos) {
33+
std::cout << "No file name:" << cfgRun3str << std::endl;
34+
return 1;
35+
} else {
36+
std::string filename = cfgRun3str;
37+
std::ifstream in;
38+
in.open(filename);
39+
if (!in) {
40+
std::cout << "Can not open file:" << filename << std::endl;
41+
return 2;
42+
}
43+
std::stringstream buffer;
44+
buffer << in.rdbuf();
45+
cfgRun3str = buffer.str();
46+
}
47+
//
48+
CTPConfiguration ctpcfg;
49+
int ret = ctpcfg.loadConfigurationRun3(cfgRun3str);
50+
ctpcfg.printStream(std::cout);
51+
std::cout << "CTP config done" << std::endl;
52+
// ctpcfg.checkConfigConsistency();
53+
auto ctpclasses = ctpcfg.getCTPClasses();
54+
for (auto const& cls : ctpclasses) {
55+
std::cout << cls.descriptor->name << ":" << std::hex << cls.descriptor->getInputsMask() << std::endl;
56+
}
57+
return ret;
58+
}

Detectors/CTP/macro/GetRates.C

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include <CCDB/BasicCCDBManager.h>
14+
#include <DataFormatsCTP/Configuration.h>
15+
#include <DataFormatsCTP/CTPRateFetcher.h>
16+
#endif
17+
using namespace o2::ctp;
18+
19+
void TestFetcher(int runNumber = 535087)
20+
{
21+
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
22+
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
23+
long ts = pp.first + 60;
24+
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
25+
// Opening run
26+
CTPRateFetcher fetcher;
27+
fetcher.setupRun(runNumber, &ccdb, ts, 1);
28+
}

Detectors/CTP/macro/TestGetRates.C

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include <CCDB/BasicCCDBManager.h>
14+
#include <DataFormatsCTP/Configuration.h>
15+
#include <DataFormatsCTP/CTPRateFetcher.h>
16+
#endif
17+
using namespace o2::ctp;
18+
19+
void TestGetRates(int runNumber = 557251)
20+
{
21+
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
22+
// Opening run
23+
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
24+
long ts = pp.first + 60;
25+
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
26+
CTPRateFetcher fetcher;
27+
fetcher.setupRun(runNumber, &ccdb, ts, 1);
28+
fetcher.setOrbit(1);
29+
std::array<double, 3> rates;
30+
fetcher.getRates(rates, &ccdb, runNumber, "T0VTX");
31+
std::cout << "Start:" << rates[0] << " End:" << rates[1] << " Middle:" << rates[2] << std::endl;
32+
}

Detectors/CTP/workflowScalers/src/ctp-ccdb-orbit.cxx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int main(int argc, char** argv)
5757
add_option("run-number,r", bpo::value<int64_t>()->default_value(123), "run number");
5858
add_option("testReset,t", bpo::value<bool>()->default_value(0), "0 = CTP/Calib/OrbitReset; 1 = CTP/Calib/OrbitResetTest");
5959
add_option("sox-orbit,x", bpo::value<int64_t>()->default_value(0), "SOX orbit");
60+
add_option("timestamp,s", bpo::value<uint64_t>()->default_value(0), "timestamp of SOX/orbit reading; if 0 timestamp is calulated inside this code");
6061

6162
//
6263
opt_all.add(opt_general).add(opt_hidden);
@@ -78,8 +79,11 @@ int main(int argc, char** argv)
7879
std::string action = vm["action"].as<std::string>();
7980
std::vector<int64_t> vect;
8081
std::string ccdbPath;
81-
auto now = std::chrono::system_clock::now();
82-
long tt = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
82+
long tt = vm["timestamp"].as<uint64_t>();
83+
if (tt == 0) {
84+
auto now = std::chrono::system_clock::now();
85+
tt = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
86+
}
8387
vect.push_back(tt);
8488
if (action == "sox") {
8589
// write to CTP/Calib/FirstRunOrbit
@@ -115,10 +119,10 @@ int main(int argc, char** argv)
115119
if (action == "sox") {
116120
int64_t runnum = vm["run-number"].as<int64_t>();
117121
metadata["runNumber"] = std::to_string(runnum);
118-
std::cout << "Storing:" << ccdbPath << " " << metadata["runNumber"] << " tmin:" << tmin << " tmax:" << tmax << std::endl;
122+
std::cout << "Storing:" << ccdbPath << " " << metadata["runNumber"] << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
119123
api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
120124
} else {
121-
std::cout << "Storing:" << ccdbPath << " tmin:" << tmin << " tmax:" << tmax << std::endl;
125+
std::cout << "Storing:" << ccdbPath << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
122126
api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
123127
}
124128
}

0 commit comments

Comments
 (0)