Skip to content

Commit

Permalink
dev: adding counters to bookkeeping (AliceO2Group#13224)
Browse files Browse the repository at this point in the history
  • Loading branch information
lietava authored Jul 25, 2024
1 parent eeca1b0 commit cbf54d0
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 137 deletions.
5 changes: 1 addition & 4 deletions DataFormats/Detectors/CTP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
# 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.

o2_add_library(DataFormatsCTP
SOURCES src/Digits.cxx
src/Configuration.cxx
src/Scalers.cxx
src/CTF.cxx
src/TriggerOffsetsParam.cxx
src/RunManager.cxx
src/LumiInfo.cxx
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat
O2::Headers
Expand All @@ -29,6 +27,5 @@ o2_target_root_dictionary(DataFormatsCTP
include/DataFormatsCTP/Configuration.h
include/DataFormatsCTP/Scalers.h
include/DataFormatsCTP/LumiInfo.h
include/DataFormatsCTP/TriggerOffsetsParam.h
include/DataFormatsCTP/RunManager.h)
include/DataFormatsCTP/TriggerOffsetsParam.h)

Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class CTPConfiguration
const std::vector<CTPClass>& getCTPClasses() const { return mCTPClasses; } // Read-only interface
uint64_t getInputMask(const std::string& name) const;
int getInputIndex(const std::string& name) const;
std::string getClassNameFromIndex(int index) { return mCTPClasses[index].name; };
std::string getClassNameFromHWIndex(int index);
bool isMaskInInputs(const uint64_t& mask) const;
bool isBCMaskInConfig(const std::string maskname) const;
const BCMask* isBCMaskInConfigP(const std::string bcmask) const;
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 @@ -106,7 +106,7 @@ class CTPRunScalers
void setDetectorMask(o2::detectors::DetID::mask_t mask) { mDetectorMask = mask; };
void setRunNumber(uint32_t rnumber) { mRunNumber = rnumber; };
void addScalerRacordRaw(CTPScalerRecordRaw& scalerrecordraw) { mScalerRecordRaw.push_back(scalerrecordraw); };
uint32_t getRunNUmber() { return mRunNumber; };
uint32_t getRunNumber() { return mRunNumber; };
int printRates();
int printIntegrals();
int printInputRateAndIntegral(int inp);
Expand Down
11 changes: 11 additions & 0 deletions DataFormats/Detectors/CTP/src/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,16 @@ int CTPConfiguration::getInputIndex(const std::string& name) const
LOG(info) << "input:" << name << " index:" << index;
return index;
}
std::string CTPConfiguration::getClassNameFromHWIndex(int index)
{
for (auto& cls : mCTPClasses) {
if (cls.classMask == (1ull << index)) {
return cls.name;
}
}
std::string ret = "not found";
return ret;
}
bool CTPConfiguration::isMaskInInputs(const uint64_t& mask) const
{
for (auto const& inp : mInputs) {
Expand Down Expand Up @@ -877,6 +887,7 @@ uint64_t CTPConfiguration::getTriggerClassMask() const
}
return clsmask;
}
// Hardware positions of classes
std::vector<int> CTPConfiguration::getTriggerClassList() const
{
uint64_t clsmask = getTriggerClassMask();
Expand Down
1 change: 0 additions & 1 deletion DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#pragma link C++ class o2::ctp::CTPScalerRecordO2 + ;
#pragma link C++ class vector < o2::ctp::CTPScalerRecordO2> + ;
#pragma link C++ class o2::ctp::CTPRunScalers + ;
#pragma link C++ class o2::ctp::CTPRunManager + ;
#pragma link C++ class o2::ctp::LumiInfo + ;
#pragma link C++ class vector < o2::ctp::LumiInfo> + ;

Expand Down
3 changes: 2 additions & 1 deletion Detectors/CTP/macro/CreateCTPConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CCDB/CcdbApi.h"
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsCTP/Configuration.h"
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include <string>
#include <map>
#include <iostream>
Expand Down Expand Up @@ -79,7 +80,7 @@ ferst 1 \n\
std::cout << "CTP config done" << std::endl;
ctpcfg.checkConfigConsistency();
if (0) {
CTPRunManager* man = new CTPRunManager;
o2::ctp::ctpCCDBManager* man = new ctpCCDBManager;
man->setCCDBHost("http://ccdb-test.cern.ch:8080");
man->saveRunConfigToCCDB(&ctpcfg, 1665784953);
// uint64_t classmask = ctpcfg.getClassMaskForInputMask(0x4);
Expand Down
3 changes: 2 additions & 1 deletion Detectors/CTP/macro/GetAndSave.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsCTP/Scalers.h"
#include "DataFormatsCTP/Configuration.h"
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include "TFile.h"
#include "TString.h"
#include <string>
Expand All @@ -36,7 +37,7 @@ void GetAndSave(std::string ccdbHost = "http://ccdb-test.cern.ch:8080")
// std::vector<string> runs = {"518543"};
// std::vector<long> timestamps = {1655118513690};
int i = 0;
CTPRunManager mng;
ctpCCDBManager mng;
// mng.setCCDBHost(ccdbHost);
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
mgr.setURL(ccdbHost);
Expand Down
4 changes: 3 additions & 1 deletion Detectors/CTP/macro/GetScalers.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsCTP/Scalers.h"
#include "DataFormatsCTP/Configuration.h"
// #include "BookkeepingApi/BkpClientFactory.h"
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include <string>
#include <map>
#include <iostream>
Expand All @@ -34,7 +36,7 @@ void GetScalers(std::string srun, long time, std::string ccdbHost = "http://ccdb
// std::cout << stol(hd["SOR"]) << "\n";
CTPConfiguration ctpcfg;
CTPRunScalers scl;
CTPRunManager mng;
o2::ctp::ctpCCDBManager mng;
mng.setCCDBHost(ccdbHost);
bool ok;
// ctpcfg = mng.getConfigFromCCDB(time, srun);
Expand Down
5 changes: 3 additions & 2 deletions Detectors/CTP/macro/TestConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsCTP/Configuration.h>
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#endif
using namespace o2::ctp;

Expand All @@ -22,9 +23,9 @@ void TestConfig(bool test = 0)
}
uint64_t timestamp = 1660196771632;
std::string run = "523148";
o2::ctp::CTPRunManager::setCCDBHost("https://alice-ccdb.cern.ch");
o2::ctp::ctpCCDBManager::setCCDBHost("https://alice-ccdb.cern.ch");
bool ok;
auto ctpcfg = o2::ctp::CTPRunManager::getConfigFromCCDB(timestamp, run, ok);
auto ctpcfg = o2::ctp::ctpCCDBManager::getConfigFromCCDB(timestamp, run, ok);
if (ok == 0) {
std::cout << "Can not get config for run:" << run << std::endl;
}
Expand Down
12 changes: 11 additions & 1 deletion Detectors/CTP/workflowScalers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
# 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 (NOT APPLE)
o2_add_library(CTPWorkflowScalers
SOURCES src/ctpCCDBManager.cxx
SOURCES src/RunManager.cxx
PUBLIC_LINK_LIBRARIES O2::Framework
O2::DataFormatsCTP
AliceO2::BookkeepingApi)
o2_target_root_dictionary(CTPWorkflowScalers HEADERS
include/CTPWorkflowScalers/ctpCCDBManager.h)
o2_add_executable(
proxy
COMPONENT_NAME ctp
SOURCES src/ctp-proxy.cxx
PUBLIC_LINK_LIBRARIES O2::DCStestWorkflow
O2::DataFormatsCTP)
O2::CTPWorkflowScalers)
endif()
o2_add_executable(
qc-proxy
COMPONENT_NAME ctp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,61 @@
/// \author Roman Lietava
#ifndef _CTP_RUNMANAGER_H_
#define _CTP_RUNMANAGER_H_
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include "DataFormatsCTP/Configuration.h"
#include "BookkeepingApi/BkpClientFactory.h"
#include "BookkeepingApi/BkpClient.h"
using namespace o2::bkp::api;
namespace o2
{
namespace ctp
{
typedef std::map<uint32_t, std::array<uint32_t, 6>> counters_t;
typedef std::map<uint32_t, std::array<uint64_t, 6>> counters64_t;
struct CTPActiveRun {
CTPActiveRun() = default;
long timeStart;
long timeStop;
CTPConfiguration cfg;
CTPRunScalers scalers;
void initBK();
int send2BK(std::unique_ptr<BkpClient>& BKClient, size_t ts, bool start);
//
counters_t cnts0; // first counters in run
counters_t cntslast0; // last minus one read counters needed for overflow correction
counters_t cntslast; // last read counters
counters64_t overflows;
};
class CTPRunManager
class CTPRunManager : public ctpCCDBManager
{
public:
CTPRunManager() = default;
void init();
int loadRun(const std::string& cfg);
int startRun(const std::string& cfg);
int stopRun(uint32_t irun, long timeStamp);
int addScalers(uint32_t irun, std::time_t time);
int addScalers(uint32_t irun, std::time_t time, bool start = 0);
int processMessage(std::string& topic, const std::string& message);
void printActiveRuns() const;
int saveRunScalersToCCDB(int i);
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
int loadScalerNames();
// void setCCDBPathConfig(std::string path) { mCCDBPathCTPConfig = path;};
void setCCDBPathScalers(std::string path) { mCCDBPathCTPScalers = path; };
static void setCCDBHost(std::string host) { mCCDBHost = host; };
int getNRuns();
void setBKHost(std::string host) { mBKHost = host; };
uint64_t checkOverflow(uint32_t lcnt0, uint32_t lcnt1, uint64_t lcntcor);
void printCounters();

private:
/// Database constants
// std::string mCCDBHost = "http://ccdb-test.cern.ch:8080";
static std::string mCCDBHost;
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
std::string mBKHost = "";
std::array<CTPActiveRun*, NRUNS> mActiveRuns;
std::array<std::uint32_t, NRUNS> mActiveRunNumbers;
std::array<uint32_t, CTPRunScalers::NCOUNTERS> mCounters;
std::map<std::string, uint32_t> mScalerName2Position;
std::map<uint32_t, CTPActiveRun*> mRunsLoaded;
std::unique_ptr<BkpClient> mBKClient;
int mEOX = 0; // redundancy check
int mNew = 1; // 1 - no CCDB: used for QC
ClassDefNV(CTPRunManager, 5);

ClassDefNV(CTPRunManager, 6);
};
} // namespace ctp
} // namespace o2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 RunManager.h
/// \brief Managing runs for config and scalers
/// \author Roman Lietava
#ifndef _CTP_CTPCCDB_H_
#define _CTP_CTPCCDB_H_
#include "DataFormatsCTP/Configuration.h"

namespace o2
{
namespace ctp
{
class ctpCCDBManager
{
public:
ctpCCDBManager() = default;
int saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart, long timeStop);
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
void setCCDBPathConfig(std::string path) { mCCDBPathCTPConfig = path; };
void setCCDBPathScalers(std::string path) { mCCDBPathCTPScalers = path; };
static void setCCDBHost(std::string host) { mCCDBHost = host; };

protected:
/// Database constants
// std::string mCCDBHost = "http://ccdb-test.cern.ch:8080";
static std::string mCCDBHost;
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
std::string mCCDBPathCTPConfig = "CTP/Config/Config";

ClassDefNV(ctpCCDBManager, 0);
};
} // namespace ctp
} // namespace o2
#endif //_CTP_CTPCCDB_H_
18 changes: 18 additions & 0 deletions Detectors/CTP/workflowScalers/src/CTPWorkflowScalersLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.
#ifdef __CLING__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class o2::ctp::ctpCCDBManager + ;
#endif
Loading

0 comments on commit cbf54d0

Please sign in to comment.