Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class CTPRateFetcher
double fetchNoPuCorr(o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, int runNumber, const std::string sourceName);
void setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, bool initScalers);
void updateScalers(ctp::CTPRunScalers& scalers);
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
void setOrbit(bool orb) { mOrbit = orb; }
void setOutsideLimits(bool qc) { mOutsideLimits = qc; }

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

double pileUpCorrection(double rate);
int mRunNumber = -1;
bool mOutsideLimits = 0;
bool mOrbit = 0;
o2::ctp::CTPConfiguration mConfig{};
o2::ctp::CTPRunScalers mScalers{};
o2::parameters::GRPLHCIFData mLHCIFdata{};
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CTPRunScalers
void printLMBRateVsT() const; // prints LMB interaction rate vs time for debugging
// returns the pair of global (levelled) interaction rate, as well as interpolated
// rate in Hz at a certain orbit number within the run
std::pair<double, double> getRate(uint32_t orbit, int classindex, int type) const;
std::pair<double, double> getRate(uint32_t orbit, int classindex, int type, bool qc = 0) const;

/// same with absolute timestamp (not orbit) as argument
std::pair<double, double> getRateGivenT(double timestamp, int classindex, int type, bool qc = 0) const;
Expand Down
44 changes: 37 additions & 7 deletions DataFormats/Detectors/CTP/src/CTPRateFetcher.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ void CTPRateFetcher::updateScalers(ctp::CTPRunScalers& scalers)
mScalers.convertRawToO2();
}
//
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
{
setupRun(runNumber, ccdb, 0, 1);
mOrbit = 1;
mOutsideLimits = 1;
auto orbitlimits = mScalers.getOrbitLimit();
// std::cout << "1st orbit:" << orbitlimits.first << " last:" << orbitlimits.second << " Middle:" << (orbitlimits.first + orbitlimits.second)/2 << std::endl;
double rate0 = fetch(ccdb, orbitlimits.first, mRunNumber, sourceName);
double rateLast = fetch(ccdb, orbitlimits.second, mRunNumber, sourceName);
double rateM = fetch(ccdb, (orbitlimits.first + orbitlimits.second) / 2, mRunNumber, sourceName);
// std::cout << rate0 << " " << rateLast << " " << rateM << std::endl;
rates[0] = rate0;
rates[1] = rateLast;
rates[2] = rateM;
return 0;
}
//
double CTPRateFetcher::fetchCTPratesClasses(uint64_t timeStamp, const std::string& className, int inputType)
{
auto triggerRate = fetchCTPratesClassesNoPuCorr(timeStamp, className, inputType);
Expand All @@ -84,14 +101,23 @@ double CTPRateFetcher::fetchCTPratesClassesNoPuCorr(uint64_t timeStamp, const st
LOG(warn) << "Trigger class " << className << " not found in CTPConfiguration";
return -2.;
}
auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, 1)};
return rate.second;
if (mOrbit) {
auto rate{mScalers.getRate((uint32_t)timeStamp, classIndex, inputType, mOutsideLimits)};
return rate.second;
} else {
auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, mOutsideLimits)};
return rate.second;
}
}
double CTPRateFetcher::fetchCTPratesInputs(uint64_t timeStamp, int input)
{
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second);
if (mOrbit) {
return pileUpCorrection(mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second);
} else {
return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second);
}
} else {
LOG(error) << "Inputs not available";
return -1.;
Expand All @@ -101,7 +127,11 @@ double CTPRateFetcher::fetchCTPratesInputsNoPuCorr(uint64_t timeStamp, int input
{
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second;
if (mOrbit) {
return mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second;
} else {
return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second; // qc flag implemented only for time
}
} else {
LOG(error) << "Inputs not available";
return -1.;
Expand All @@ -127,13 +157,13 @@ void CTPRateFetcher::setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, u
return;
}
mRunNumber = runNumber;
LOG(debug) << "Setting up CTP scalers for run " << mRunNumber;
std::map<string, string> metadata;
auto ptrLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
LOG(info) << "Setting up CTP scalers for run " << mRunNumber;
auto ptrLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp);
if (ptrLHCIFdata == nullptr) {
LOG(fatal) << "GRPLHCIFData not in database, timestamp:" << timeStamp;
}
mLHCIFdata = *ptrLHCIFdata;
std::map<string, string> metadata;
metadata["runNumber"] = std::to_string(mRunNumber);
auto ptrConfig = ccdb->getSpecific<ctp::CTPConfiguration>("CTP/Config/Config", timeStamp, metadata);
if (ptrConfig == nullptr) {
Expand Down
13 changes: 10 additions & 3 deletions DataFormats/Detectors/CTP/src/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,16 @@ int CTPConfiguration::processConfigurationLineRun3v2(std::string& line, int& lev
break;
}
case DESCRIPTORS: {
if ((tokens.size() < 2) && (line.find("DTRUE") == std::string::npos)) {
LOG(warning) << "Dsecriptor:" << line;
break;
if ((tokens.size() < 2)) {
if (line.find("TRUE") != std::string::npos) {
CTPDescriptor desc;
desc.name = tokens[0];
mDescriptors.push_back(desc);
break;
} else {
LOG(warning) << "Unexpected Descriptor:" << line;
break;
}
}
CTPDescriptor desc;
desc.name = tokens[0];
Expand Down
23 changes: 18 additions & 5 deletions DataFormats/Detectors/CTP/src/Scalers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ void CTPRunScalers::printLMBRateVsT() const
// rate in Hz at a certain orbit number within the run
// type - 7 : inputs
// type - 1..6 : lmb,lma,l0b,l0a,l1b,l1a
std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex, int type) const
std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex, int type, bool qc) const
{
if (mScalerRecordO2.size() <= 1) {
LOG(error) << "not enough data";
Expand Down Expand Up @@ -709,11 +709,24 @@ std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex,
return -1; // wrong type
}
};

if (nextindex == 0 || nextindex == mScalerRecordO2.size()) {
// qc flag decides what to return if time outside run
if (nextindex == 0) {
// orbit is out of bounds
LOG(info) << "query orbit " << orbit << " out of bounds; Just returning the global rate";
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
if (qc == 0) {
LOG(info) << "query orbit " << orbit << " before first record; Just returning the global rate";
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
} else {
LOG(info) << "query orbit " << orbit << " before first record; Returning the first rate";
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* first rate */ calcRate(0, 1));
}
} else if (nextindex == mScalerRecordO2.size()) {
if (qc == 0) {
LOG(info) << "query orbit " << orbit << " after last record; Just returning the global rate";
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ -1);
} else {
LOG(info) << "query orbit " << orbit << " after last record; Returning the last rate";
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* last rate */ calcRate(mScalerRecordO2.size() - 2, mScalerRecordO2.size() - 1));
}
} else {
return std::make_pair(/*global mean rate*/ calcRate(0, mScalerRecordO2.size() - 1), /* current rate */ calcRate(nextindex - 1, nextindex));
}
Expand Down
13 changes: 12 additions & 1 deletion Detectors/CTP/macro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ o2_add_test_root_macro(CreateBKForRun.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)

o2_add_test_root_macro(CheckCTPConfig.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)
o2_add_test_root_macro(GetRates.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)
o2_add_test_root_macro(TestGetRates.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)
58 changes: 58 additions & 0 deletions Detectors/CTP/macro/CheckCTPConfig.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file CreateCTPConfig.C
/// \brief create CTP config, test it and add to database
/// \author Roman Lietava

#if !defined(__CLING__) || defined(__ROOTCLING__)

#include <fairlogger/Logger.h>
#include "CCDB/CcdbApi.h"
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsCTP/Configuration.h"
#include <string>
#include <map>
#include <iostream>
#endif
using namespace o2::ctp;
int CheckCTPConfig(std::string cfgRun3str = "/home/rl/backup24/runs/559781.rcfg2", int writeToFile = 0)
{
//
// run3 config
//
if (cfgRun3str.find(".rcfg") == std::string::npos) {
std::cout << "No file name:" << cfgRun3str << std::endl;
return 1;
} else {
std::string filename = cfgRun3str;
std::ifstream in;
in.open(filename);
if (!in) {
std::cout << "Can not open file:" << filename << std::endl;
return 2;
}
std::stringstream buffer;
buffer << in.rdbuf();
cfgRun3str = buffer.str();
}
//
CTPConfiguration ctpcfg;
int ret = ctpcfg.loadConfigurationRun3(cfgRun3str);
ctpcfg.printStream(std::cout);
std::cout << "CTP config done" << std::endl;
// ctpcfg.checkConfigConsistency();
auto ctpclasses = ctpcfg.getCTPClasses();
for (auto const& cls : ctpclasses) {
std::cout << cls.descriptor->name << ":" << std::hex << cls.descriptor->getInputsMask() << std::endl;
}
return ret;
}
28 changes: 28 additions & 0 deletions Detectors/CTP/macro/GetRates.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsCTP/Configuration.h>
#include <DataFormatsCTP/CTPRateFetcher.h>
#endif
using namespace o2::ctp;

void TestFetcher(int runNumber = 535087)
{
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
long ts = pp.first + 60;
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
// Opening run
CTPRateFetcher fetcher;
fetcher.setupRun(runNumber, &ccdb, ts, 1);
}
32 changes: 32 additions & 0 deletions Detectors/CTP/macro/TestGetRates.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsCTP/Configuration.h>
#include <DataFormatsCTP/CTPRateFetcher.h>
#endif
using namespace o2::ctp;

void TestGetRates(int runNumber = 557251)
{
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
// Opening run
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
long ts = pp.first + 60;
std::cout << "Run duration:" << pp.first << " " << pp.second << std::endl;
CTPRateFetcher fetcher;
fetcher.setupRun(runNumber, &ccdb, ts, 1);
fetcher.setOrbit(1);
std::array<double, 3> rates;
fetcher.getRates(rates, &ccdb, runNumber, "T0VTX");
std::cout << "Start:" << rates[0] << " End:" << rates[1] << " Middle:" << rates[2] << std::endl;
}
12 changes: 8 additions & 4 deletions Detectors/CTP/workflowScalers/src/ctp-ccdb-orbit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int main(int argc, char** argv)
add_option("run-number,r", bpo::value<int64_t>()->default_value(123), "run number");
add_option("testReset,t", bpo::value<bool>()->default_value(0), "0 = CTP/Calib/OrbitReset; 1 = CTP/Calib/OrbitResetTest");
add_option("sox-orbit,x", bpo::value<int64_t>()->default_value(0), "SOX orbit");
add_option("timestamp,s", bpo::value<uint64_t>()->default_value(0), "timestamp of SOX/orbit reading; if 0 timestamp is calulated inside this code");

//
opt_all.add(opt_general).add(opt_hidden);
Expand All @@ -78,8 +79,11 @@ int main(int argc, char** argv)
std::string action = vm["action"].as<std::string>();
std::vector<int64_t> vect;
std::string ccdbPath;
auto now = std::chrono::system_clock::now();
long tt = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
long tt = vm["timestamp"].as<uint64_t>();
if (tt == 0) {
auto now = std::chrono::system_clock::now();
tt = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
}
vect.push_back(tt);
if (action == "sox") {
// write to CTP/Calib/FirstRunOrbit
Expand Down Expand Up @@ -115,10 +119,10 @@ int main(int argc, char** argv)
if (action == "sox") {
int64_t runnum = vm["run-number"].as<int64_t>();
metadata["runNumber"] = std::to_string(runnum);
std::cout << "Storing:" << ccdbPath << " " << metadata["runNumber"] << " tmin:" << tmin << " tmax:" << tmax << std::endl;
std::cout << "Storing:" << ccdbPath << " " << metadata["runNumber"] << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
} else {
std::cout << "Storing:" << ccdbPath << " tmin:" << tmin << " tmax:" << tmax << std::endl;
std::cout << "Storing:" << ccdbPath << " tmin:" << tmin << " tmax:" << tmax << " ts:" << tt << std::endl;
api.storeAsTFileAny(&(vect), ccdbPath, metadata, tmin, tmax);
}
}
Expand Down
Loading