Skip to content

Commit

Permalink
Prepare dead channel map for tracking, misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wiechula authored and davidrohr committed Nov 9, 2023
1 parent 27d5f68 commit 08303cc
Show file tree
Hide file tree
Showing 29 changed files with 802 additions and 41 deletions.
17 changes: 17 additions & 0 deletions DataFormats/Detectors/TPC/include/DataFormatsTPC/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ enum class StatisticsType {
MeanStdDev ///< Use mean and standard deviation
};

enum class PadFlags : unsigned short {
flagGoodPad = 1 << 0, ///< flag for a good pad binary 0001
flagDeadPad = 1 << 1, ///< flag for a dead pad binary 0010
flagUnknownPad = 1 << 2, ///< flag for unknown status binary 0100
flagSaturatedPad = 1 << 3, ///< flag for saturated status binary 0100
flagHighPad = 1 << 4, ///< flag for pad with extremly high IDC value
flagLowPad = 1 << 5, ///< flag for pad with extremly low IDC value
flagSkip = 1 << 6, ///< flag for defining a pad which is just ignored during the calculation of I1 and IDCDelta
flagFEC = 1 << 7, ///< flag for a whole masked FEC
flagNeighbour = 1 << 8, ///< flag if n neighbouring pads are outlier
flagAllNoneGood = flagDeadPad | flagUnknownPad | flagSaturatedPad | flagHighPad | flagLowPad | flagSkip | flagFEC | flagNeighbour,
};

inline PadFlags operator&(PadFlags a, PadFlags b) { return static_cast<PadFlags>(static_cast<int>(a) & static_cast<int>(b)); }
inline PadFlags operator~(PadFlags a) { return static_cast<PadFlags>(~static_cast<int>(a)); }
inline PadFlags operator|(PadFlags a, PadFlags b) { return static_cast<PadFlags>(static_cast<int>(a) | static_cast<int>(b)); }

// default point definitions for PointND, PointNDlocal, PointNDglobal are in
// MathUtils/CartesianND.h

Expand Down
4 changes: 3 additions & 1 deletion Detectors/TPC/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ o2_add_library(TPCBase
src/CRUCalibHelpers.cxx
src/IonTailSettings.cxx
src/FEEConfig.cxx
src/DeadChannelMapCreator.cxx
PUBLIC_LINK_LIBRARIES Vc::Vc Boost::boost O2::DataFormatsTPC
O2::DetectorsRaw O2::CCDB FairRoot::Base)

Expand Down Expand Up @@ -67,7 +68,8 @@ o2_target_root_dictionary(TPCBase
include/TPCBase/Utils.h
include/TPCBase/CRUCalibHelpers.h
include/TPCBase/IonTailSettings.h
include/TPCBase/FEEConfig.h)
include/TPCBase/FEEConfig.h
include/TPCBase/DeadChannelMapCreator.h)
o2_add_test(Base
COMPONENT_NAME tpc
PUBLIC_LINK_LIBRARIES O2::TPCBase
Expand Down
2 changes: 2 additions & 0 deletions Detectors/TPC/base/include/TPCBase/CDBInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ class CDBStorage

const auto& getMetaData() const { return mMetaData; }

std::string getMetaDataString() const;

void setSimulate(bool sim = true) { mSimulate = sim; }

bool getSimulate() const { return mSimulate; }
Expand Down
42 changes: 42 additions & 0 deletions Detectors/TPC/base/include/TPCBase/CRUCalibHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cassert>
#include <gsl/span>
#include <filesystem>
#include <type_traits>
namespace fs = std::filesystem;

#include "Rtypes.h"
Expand Down Expand Up @@ -115,6 +116,47 @@ void writeValues(const std::string_view fileName, const DataMap& map, bool onlyF
}
}

template <class T>
struct is_map {
static constexpr bool value = false;
};

template <class Key, class Value>
struct is_map<std::map<Key, Value>> {
static constexpr bool value = true;
};
/// fill cal pad object from HV data map
/// TODO: Function to be tested
template <typename DataMap, uint32_t SignificantBitsT = 0>
typename std::enable_if_t<is_map<DataMap>::value, void>
fillCalPad(CalDet<float>& calPad, const DataMap& map)
{
using namespace o2::tpc;
const auto& mapper = Mapper::instance();

for (const auto& [linkInfo, data] : map) {
const CRU cru(linkInfo.cru);
const PartitionInfo& partInfo = mapper.getMapPartitionInfo()[cru.partition()];
const int nFECs = partInfo.getNumberOfFECs();
const int fecOffset = (nFECs + 1) / 2;
const int fecInPartition = (linkInfo.globalLinkID < fecOffset) ? linkInfo.globalLinkID : fecOffset + linkInfo.globalLinkID % 12;

int hwChannel{0};
for (const auto& val : data) {
const auto& [sampaOnFEC, channelOnSAMPA] = getSampaInfo(hwChannel, cru);
const PadROCPos padROCPos = mapper.padROCPos(cru, fecInPartition, sampaOnFEC, channelOnSAMPA);
if constexpr (SignificantBitsT == 0) {
const float set = std::stof(val);
calPad.getCalArray(padROCPos.getROC()).setValue(padROCPos.getRow(), padROCPos.getPad(), set);
} else {
const float set = fixedSizeToFloat<SignificantBitsT>(uint32_t(std::stoi(val)));
calPad.getCalArray(padROCPos.getROC()).setValue(padROCPos.getRow(), padROCPos.getPad(), set);
}
++hwChannel;
}
}
}

/// fill cal pad object from HW value stream
template <uint32_t SignificantBitsT = 2>
int fillCalPad(CalDet<float>& calPad, std::istream& infile)
Expand Down
18 changes: 15 additions & 3 deletions Detectors/TPC/base/include/TPCBase/CalArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ class CalArray
std::vector<T>& getData() { return mData; }

/// calculate the sum of all elements
const T getSum() const { return std::accumulate(mData.begin(), mData.end(), T(0)); }
template <typename U = T>
const U getSum() const
{
return std::accumulate(mData.begin(), mData.end(), U{});
}

/// Multiply all val to all channels
const CalArray<T>& multiply(const T& val) { return *this *= val; }
Expand Down Expand Up @@ -228,7 +232,11 @@ inline const CalArray<T>& CalArray<T>::operator+=(const CalArray<T>& other)
return *this;
}
for (size_t i = 0; i < mData.size(); ++i) {
mData[i] += other.getValue(i);
if constexpr (std::is_same_v<T, bool>) {
mData[i] = mData[i] | other.getValue(i);
} else {
mData[i] += other.getValue(i);
}
}
return *this;
}
Expand Down Expand Up @@ -256,7 +264,11 @@ inline const CalArray<T>& CalArray<T>::operator*=(const CalArray<T>& other)
return *this;
}
for (size_t i = 0; i < mData.size(); ++i) {
mData[i] *= other.getValue(i);
if constexpr (std::is_same_v<T, bool>) {
mData[i] = mData[i] & other.getValue(i);
} else {
mData[i] *= other.getValue(i);
}
}
return *this;
}
Expand Down
19 changes: 18 additions & 1 deletion Detectors/TPC/base/include/TPCBase/CalDet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define ALICEO2_TPC_CALDET_H_

#include <memory>
#include <numeric>
#include <vector>
#include <string>
#include <cassert>
Expand Down Expand Up @@ -114,13 +115,29 @@ class CalDet
U sum = 0;
for (const auto& data : mData) {
const auto& vals = data.getData();
sum += std::accumulate(vals.begin(), vals.end(), 0.f);
sum += std::accumulate(vals.begin(), vals.end(), U{0});
nVal += static_cast<U>(vals.size());
}

return (nVal > 0) ? sum / nVal : U{0};
}

template <typename U = T>
U getSum() const
{
if (mData.size() == 0) {
return U{};
}

U sum{};
for (const auto& data : mData) {
const auto& vals = data.getData();
sum += data.template getSum<U>();
}

return sum;
}

private:
std::string mName; ///< name of the object
std::vector<CalType> mData; ///< internal CalArrays
Expand Down
110 changes: 110 additions & 0 deletions Detectors/TPC/base/include/TPCBase/DeadChannelMapCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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.

#ifndef ALICEO2_TPC_DeadChannelMapCreator_H_
#define ALICEO2_TPC_DeadChannelMapCreator_H_

#include <unordered_map>
#include <memory>

#include "Rtypes.h"

#include "CCDB/CcdbApi.h"

#include "DataFormatsTPC/Defs.h"
#include "TPCBase/CDBInterface.h"
#include "TPCBase/FEEConfig.h"

namespace o2::tpc
{

enum class SourcesDeadMap : unsigned short {
None = 0, ///< no inputs
IDCPadStatus = 1 << 0, ///< use idc pad status map
FEEConfig = 1 << 1, ///< use fee config
All = IDCPadStatus | FEEConfig, ///< all sources
};
inline SourcesDeadMap operator&(SourcesDeadMap a, SourcesDeadMap b) { return static_cast<SourcesDeadMap>(static_cast<unsigned short>(a) & static_cast<unsigned short>(b)); }
inline SourcesDeadMap operator~(SourcesDeadMap a) { return static_cast<SourcesDeadMap>(~static_cast<unsigned short>(a)); }
inline SourcesDeadMap operator|(SourcesDeadMap a, SourcesDeadMap b) { return static_cast<SourcesDeadMap>(static_cast<unsigned short>(a) | static_cast<unsigned short>(b)); }

struct FEEConfig;

class DeadChannelMapCreator
{
struct ValidityRange {
long startvalidity = 0;
long endvalidity = -1;
bool isValid(long ts) const { return ts < endvalidity && ts > startvalidity; }
};

public:
using CalDetFlag_t = o2::tpc::CalDet<o2::tpc::PadFlags>;

void reset();

void init();
void load(long timeStampOrRun);
void loadFEEConfigViaRunInfoTS(long timeStamp);
void loadFEEConfigViaRunInfo(long timeStampOrRun);
void loadFEEConfig(long tag, long createdNotAfter = -1);
void loadIDCPadFlags(long timeStampOrRun);

void setDeadChannelMapIDCPadStatus(const CalDetFlag_t& padStatusMap, PadFlags mask = PadFlags::flagAllNoneGood);

const CalDet<bool>& getDeadChannelMapIDC() const { return mDeadChannelMapIDC; }
const CalDet<bool>& getDeadChannelMapFEE() const { return mDeadChannelMapFEE; }
const CalDet<bool>& getDeadChannelMap() const { return mDeadChannelMap; }

void drawDeadChannelMapIDC();
void drawDeadChannelMapFEE();
void drawDeadChannelMap();

long getTimeStamp(long timeStampOrRun) const;

void finalizeDeadChannelMap();
void resetDeadChannelMap() { mDeadChannelMap = false; }

void setSource(SourcesDeadMap s) { mSources = s; }
void addSource(SourcesDeadMap s) { mSources = s | mSources; }
bool useSource(SourcesDeadMap s) const { return (mSources & s) == s; }
SourcesDeadMap getSources() const { return mSources; }

private:
std::unique_ptr<FEEConfig> mFEEConfig; ///< Electronics configuration, manually loaded
std::unique_ptr<CalDetFlag_t> mPadStatusMap; ///< Pad status map from IDCs, manually loaded
// FEEConfig::CalPadMapType* mPulserData; ///< Pulser information
// FEEConfig::CalPadMapType* mCEData; ///< CE information

std::unordered_map<CDBType, ValidityRange> mObjectValidity; ///< validity range of internal objects
SourcesDeadMap mSources = SourcesDeadMap::All; ///< Inputs to use to create the map
ccdb::CcdbApi mCCDBApi; ///< CCDB Api
CalDet<bool> mDeadChannelMapIDC{"DeadChannelMapIDC"}; ///< Combined dead channel map
CalDet<bool> mDeadChannelMapFEE{"DeadChannelMapFEE"}; ///< Dead Channel map from FEE configuration
CalDet<bool> mDeadChannelMap{"DeadChannelMap"}; ///< Combined dead channel map

ClassDefNV(DeadChannelMapCreator, 0);
};

inline long DeadChannelMapCreator::getTimeStamp(long timeStampOrRun) const
{
if (timeStampOrRun < 1000000) {
// assume run number
const auto c = mCCDBApi.retrieveHeaders("RCT/Info/RunInformation", {}, timeStampOrRun);
timeStampOrRun = (std::stol(c.at("SOR")) + std::stol(c.at("EOR"))) / 2;
}

return timeStampOrRun;
}

} // namespace o2::tpc

#endif
27 changes: 26 additions & 1 deletion Detectors/TPC/base/include/TPCBase/FEEConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>
#include <vector>
#include <cstdint>
#include <numeric>

#include "Rtypes.h"

Expand All @@ -32,7 +33,7 @@ namespace o2::tpc
struct CRUConfig {
static constexpr int NConfigValues = 7; ///< number of configuration values

uint32_t linkOn{0}; ///< if the link is active
uint32_t linkOn{0}; ///< bitmask of active links
uint32_t cmcEnabled{0}; ///< if common mode correction is enabled
uint32_t zsOffset{0}; ///< zero suppression offset value used in ITF
float itCorr0{1.f}; ///< ion tail scaling parameter
Expand All @@ -57,8 +58,21 @@ struct FEEConfig {
Physics35sigma = 6, ///< Physics configuration with 3.5 sigma thresholds
Physics30sigma = 7, ///< Physics configuration with 3.0 sigma thresholds
Physics25sigma = 8, ///< Physics configuration with 2.5 sigma thresholds
Laser10ADCoff = 9, ///< Configuration for Laser data taking with 10ADC offset for special studies
};

enum class PadConfig {
ITfraction = 0,
ITexpLambda = 1,
CMkValues = 2,
ThresholdMap = 3,
Pedestals = 4,
};

static constexpr size_t MaxLinks = 91 * 36;
static const std::unordered_map<Tags, const std::string> TagNames;
static const std::unordered_map<PadConfig, const std::string> PadConfigNames;

using CalPadMapType = std::unordered_map<std::string, CalPad>;
FEEConfig() { cruConfig.resize(CRU::MaxCRU); }
// FEEConfig& operator=(const FEEConfig& config)
Expand All @@ -82,6 +96,17 @@ struct FEEConfig {
}
}

size_t getNumberActiveLinks() const;
bool isCMCEnabled() const;
bool isITFEnabled() const;
bool isZSEnabled() const;
bool isResyncEnabled() const;

void print() const;

/// Dead channel map including deactivated links and single channels
CalDet<bool> getDeadChannelMap() const;

ClassDefNV(FEEConfig, 2);
};

Expand Down
7 changes: 7 additions & 0 deletions Detectors/TPC/base/src/CDBInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ bool CDBStorage::checkMetaData(MetaData_t metaData) const
return counts[0] == 0;
}

//______________________________________________________________________________
std::string CDBStorage::getMetaDataString() const
{
std::string metaDataString;
return metaDataString;
}

//______________________________________________________________________________
void CDBStorage::uploadNoiseAndPedestal(std::string_view fileName, long first, long last)
{
Expand Down
Loading

0 comments on commit 08303cc

Please sign in to comment.