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
41 changes: 33 additions & 8 deletions DataFormats/Detectors/CTP/include/DataFormatsCTP/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@
#include <vector>
#include <bitset>
#include <map>
#include <set>
namespace o2
{
namespace ctp
{
/// Database constants
const std::string CCDBPathCTPConfig = "CTP/Config/Config";
///
bool isDetector(o2::detectors::DetID& det);
/// CTP Config items
struct BCMask {
BCMask() = default;
std::string name;
std::bitset<o2::constants::lhc::LHCMaxBunches> BCmask;
void printStream(std::ostream& strem) const;
void printStream(std::ostream& stream) const;
ClassDefNV(BCMask, 1);
};
struct CTPGenerator {
static const std::set<std::string> Generators;
std::string name;
std::string frequency;
void printStream(std::ostream& stream) const;
ClassDefNV(CTPGenerator, 1);
};
struct CTPInput {
CTPInput() = default;
std::string name;
Expand All @@ -61,30 +68,45 @@ struct CTPDetector {
o2::detectors::DetID::ID detID;
const char* getName() const { return o2::detectors::DetID::getName(detID); }
uint32_t HBaccepted; /// Number of HB frames in TF to be accepted
void printStream(std::ostream& strem) const;
std::string mode;
uint32_t ferst;
void printStream(std::ostream& stream) const;
ClassDefNV(CTPDetector, 1)
};
struct CTPCluster {
CTPCluster() = default;
std::string name;
uint32_t hwMask;
o2::detectors::DetID::mask_t maskCluster;
std::string getClusterDetNames() const { return o2::detectors::DetID::getNames(maskCluster, ' '); }
void printStream(std::ostream& strem) const;
ClassDefNV(CTPCluster, 2)
ClassDefNV(CTPCluster, 3)
};
struct CTPClass {
CTPClass() = default;
std::string name;
std::uint64_t classMask;
CTPDescriptor const* descriptor;
CTPCluster const* cluster;
CTPDescriptor const* descriptor = nullptr;
CTPCluster const* cluster = nullptr;
int clusterIndex;
;
void printStream(std::ostream& strem) const;
ClassDefNV(CTPClass, 1);
ClassDefNV(CTPClass, 2);
};
class CTPConfiguration
{
public:
CTPConfiguration() = default;
bool isDetector(const o2::detectors::DetID& det);
void capitaliseString(std::string& str);
enum ConfigPart { MASKS,
GENS,
INPUT,
LTG,
LTGitems,
CLUSTER,
CLASS };
int loadConfigurationRun3(const std::string& ctpconfiguartion);
int loadConfiguration(const std::string& ctpconfiguartion);
void addBCMask(const BCMask& bcmask);
void addCTPInput(const CTPInput& input);
Expand All @@ -97,6 +119,7 @@ class CTPConfiguration
std::vector<CTPClass>& getCTPClasses() { return mCTPClasses; }
uint64_t getInputMask(const std::string& name);
bool isMaskInInputs(const uint64_t& mask) const;
bool isBCMaskInConfig(const std::string maskname) const;
CTPInput* isInputInConfig(const std::string inpname);
uint64_t getDecrtiptorInputsMask(const std::string& name) const;
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> getDet2InputMap();
Expand All @@ -107,13 +130,15 @@ class CTPConfiguration
std::string mName;
std::string mVersion;
std::vector<BCMask> mBCMasks;
std::vector<CTPGenerator> mGenerators;
std::vector<CTPInput> mInputs;
std::vector<CTPDescriptor> mDescriptors;
std::vector<CTPDetector> mDetectors;
std::vector<CTPCluster> mClusters;
std::vector<CTPClass> mCTPClasses;
int processConfigurationLineRun3(std::string& line, int& level);
int processConfigurationLine(std::string& line, int& level);
ClassDefNV(CTPConfiguration, 2);
ClassDefNV(CTPConfiguration, 3);
};
} // namespace ctp
} // namespace o2
Expand Down
206 changes: 196 additions & 10 deletions DataFormats/Detectors/CTP/src/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,42 @@
#include "DataFormatsCTP/Configuration.h"
#include <iostream>
#include <sstream>
#include <regex>
#include "CommonUtils/StringUtils.h"
#include "FairLogger.h"

using namespace o2::ctp;
//
//
bool CTPConfiguration::isDetector(const o2::detectors::DetID& det)
{
bool isdet = det.getID() >= det.getNDetectors();
isdet |= det.getID() < 0;
if (isdet) {
LOG(error) << " Detector does not exist: " << det.getID();
return false;
}
return true;
}
void CTPConfiguration::capitaliseString(std::string& str)
{
for (auto& c : str) {
c = std::toupper(c);
}
}
//
void BCMask::printStream(std::ostream& stream) const
{
stream << "CTP BC mask:" << name << std::endl;
/// << ":" << BCmask << std::endl;
}
//
const std::set<std::string> CTPGenerator::Generators = {"bcd1m", "bcd2m", "bcd10", "bcd20", "rnd1m", "rnd2m", "rnd10", "rnd20"};
void CTPGenerator::printStream(std::ostream& stream) const
{
stream << "CTP generator:" << name << " frequency:" << frequency << std::endl;
}
//
void CTPInput::printStream(std::ostream& stream) const
{
stream << "CTP Input:" << name << " Detector:" << getInputDetName() << " Level:" << level << " Hardware mask:0x" << std::hex << inputMask << std::dec << std::endl;
Expand All @@ -50,30 +75,45 @@ void CTPDescriptor::printStream(std::ostream& stream) const
//
void CTPDetector::printStream(std::ostream& stream) const
{
stream << "CTP Detector:" << getName() << " HBaccepted:" << HBaccepted << std::endl;
stream << "CTP Detector:" << getName() << " HBaccepted:" << HBaccepted;
stream << " Mode:" << mode << " FErst:" << ferst << std::endl;
}

void CTPCluster::printStream(std::ostream& stream) const
{
stream << "CTP Cluster:" << name << getClusterDetNames();
stream << "CTP Cluster:" << name << " " << getClusterDetNames();
stream << " mask:0b" << std::hex << maskCluster << " " << std::dec;
stream << std::endl;
}
//
void CTPClass::printStream(std::ostream& stream) const
{
stream << "CTP Class:" << name << " Hardware mask:" << classMask << " Descriptor:" << descriptor->name << " Cluster:" << cluster->name << std::endl;
stream << "CTP Class:" << name << " Hardware mask:" << classMask;
if (descriptor != nullptr) {
stream << " Descriptor:" << descriptor->name;
}
if (cluster != nullptr) {
stream << " Cluster:" << cluster->name;
}
stream << std::endl;
}
/// CTP configuration
/// Assuming Run2 format + LTG
//
bool CTPConfiguration::isDetector(const o2::detectors::DetID& det)
int CTPConfiguration::loadConfigurationRun3(const std::string& ctpconfiguration)
{
if (det.getID() >= det.getNDetectors()) {
LOG(fatal) << " Detector does not exist: " << det.getName();
return false;
LOG(info) << "Loading CTP configuration.";
std::istringstream iss(ctpconfiguration);
int ret = 0;
int level = MASKS;
std::string line;
while (std::getline(iss, line)) {
o2::utils::Str::trim(line);
if ((ret = processConfigurationLineRun3(line, level)) != 0) {
return ret;
}
}
return true;
return ret;
return 0;
}
int CTPConfiguration::loadConfiguration(const std::string& ctpconfiguration)
{
Expand All @@ -90,6 +130,143 @@ int CTPConfiguration::loadConfiguration(const std::string& ctpconfiguration)
}
return ret;
}
int CTPConfiguration::processConfigurationLineRun3(std::string& line, int& level)
{
// LOG(debug) << "line:" << line;
if (line.size() == 0) {
return 0;
}
if (line.at(0) == '#') {
return 0;
}
//
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
size_t ntokens = tokens.size();
if (ntokens == 0) {
LOG(warning) << "# of tokens zero in line:" << line;
return 0;
}
size_t first;
if (CTPGenerator::Generators.count(tokens[0])) {
if (level != CLASS) {
level = GENS;
}
level = GENS;
} else if ((first = line.find("bcm")) != std::string::npos) {
if (level == MASKS) {
level = MASKS;
}
} else if ((first = line.find("LTG")) != std::string::npos) {
level = LTG;
} else if ((first = line.find("cluster")) != std::string::npos) {
level = CLUSTER;
} else {
}
switch (level) {
case MASKS: {
BCMask bcmask;
bcmask.name = tokens[1];
std::regex LHdelimiters("[LH]");
if (std::regex_search(tokens[2], LHdelimiters)) {
// jusko notation
} else {
// list of integers
for (int i = 2; i < ntokens; i++) {
uint32_t bc;
try {
bc = std::stoull(tokens[i]);
} catch (...) {
LOG(info) << "mask syntax:" << tokens[i];
continue;
}
bcmask.BCmask.set(bc, 1);
}
}
mBCMasks.push_back(bcmask);
LOG(info) << "BC mask added:" << bcmask.name;
break;
}
case GENS: {
CTPGenerator gen;
gen.name = tokens[0];
gen.frequency = tokens[1];
LOG(info) << "Gen added:" << line;
break;
}
case LTG: {
CTPDetector ctpdet;
std::string detname = tokens[1];
capitaliseString(detname);
o2::detectors::DetID det(detname.c_str());
if (isDetector(det)) {
ctpdet.detID = det.getID();
LOG(info) << "Detector found:" << det.getID() << " " << detname;
} else {
LOG(info) << "Unknown detectors:" << line;
}
mDetectors.push_back(ctpdet);
level = LTGitems;
break;
}
case LTGitems: {
if (ntokens == 1) {
mDetectors.back().mode = tokens[0];
}
LOG(info) << "LTGitem:" << line;
break;
}
case CLUSTER: {
CTPCluster cluster;
try {
cluster.hwMask = std::stoull(tokens[0]);
} catch (...) {
LOG(info) << "Cluster syntax error:" << line;
return level;
}
LOG(info) << "Cluster:" << line;
cluster.name = tokens[2];
o2::detectors::DetID::mask_t mask;
for (int item = 3; item < ntokens; item++) {
std::string detname = tokens[item];
capitaliseString(detname);
// LOG(info) << "Detector:" << detname;
o2::detectors::DetID det(detname.c_str());
isDetector(det);
mask |= det.getMask();
}
cluster.maskCluster = mask;
mClusters.push_back(cluster);
level = CLASS;
// LOG(info) << "Cluster done:" << cluster.name << std::endl;
break;
}
case CLASS: {
// add to the last cluster
uint64_t index;
try {
index = std::stoull(tokens[0]);
} catch (...) {
LOG(info) << "Class syntax error:" << line;
return level;
}
LOG(info) << "Class:" << line;
CTPClass cls;
cls.classMask = 1ull << index;
cls.name = tokens[1];
cls.clusterIndex = mClusters.size() - 1;
// LOG(info) << "point:" << cls.cluster << " " << &mClusters.front();
mCTPClasses.push_back(cls);
break;
}
default: {
LOG(info) << "unknown line:" << line;
}
}
for (auto& cls : mCTPClasses) {
cls.cluster = &mClusters[cls.clusterIndex];
}
return 0;
}
int CTPConfiguration::processConfigurationLine(std::string& line, int& level)
{
if (line.size() == 0) {
Expand Down Expand Up @@ -269,7 +446,7 @@ void CTPConfiguration::printStream(std::ostream& stream) const
for (const auto& i : mDescriptors) {
i.printStream(stream);
}
stream << "CTP detectors:" << std::endl;
stream << "CTP detectors:" << mDetectors.size() << std::endl;
for (const auto& i : mDetectors) {
i.printStream(stream);
}
Expand Down Expand Up @@ -300,6 +477,15 @@ bool CTPConfiguration::isMaskInInputs(const uint64_t& mask) const
}
return false;
}
bool CTPConfiguration::isBCMaskInConfig(const std::string maskname) const
{
for (auto& bcm : mBCMasks) {
if (bcm.name == maskname) {
return true;
}
}
return false;
}
CTPInput* CTPConfiguration::isInputInConfig(const std::string inpname)
{
for (auto& inp : mInputs) {
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#pragma link C++ class vector < o2::ctp::CTPInputDigit> + ;
#pragma link C++ class o2::ctp::BCMask + ;
#pragma link C++ class vector < o2::ctp::BCMask> + ;
#pragma link C++ class o2::ctp::CTPGenerator + ;
#pragma link C++ class vector < o2::ctp::CTPGenerator> + ;
#pragma link C++ class o2::ctp::CTPInput + ;
#pragma link C++ class vector < o2::ctp::CTPInput> + ;
#pragma link C++ class o2::ctp::CTPDescriptor + ;
Expand Down
Loading