Skip to content

Commit 08303cc

Browse files
wiechuladavidrohr
authored andcommitted
Prepare dead channel map for tracking, misc updates
1 parent 27d5f68 commit 08303cc

29 files changed

Lines changed: 802 additions & 41 deletions

File tree

DataFormats/Detectors/TPC/include/DataFormatsTPC/Defs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ enum class StatisticsType {
9797
MeanStdDev ///< Use mean and standard deviation
9898
};
9999

100+
enum class PadFlags : unsigned short {
101+
flagGoodPad = 1 << 0, ///< flag for a good pad binary 0001
102+
flagDeadPad = 1 << 1, ///< flag for a dead pad binary 0010
103+
flagUnknownPad = 1 << 2, ///< flag for unknown status binary 0100
104+
flagSaturatedPad = 1 << 3, ///< flag for saturated status binary 0100
105+
flagHighPad = 1 << 4, ///< flag for pad with extremly high IDC value
106+
flagLowPad = 1 << 5, ///< flag for pad with extremly low IDC value
107+
flagSkip = 1 << 6, ///< flag for defining a pad which is just ignored during the calculation of I1 and IDCDelta
108+
flagFEC = 1 << 7, ///< flag for a whole masked FEC
109+
flagNeighbour = 1 << 8, ///< flag if n neighbouring pads are outlier
110+
flagAllNoneGood = flagDeadPad | flagUnknownPad | flagSaturatedPad | flagHighPad | flagLowPad | flagSkip | flagFEC | flagNeighbour,
111+
};
112+
113+
inline PadFlags operator&(PadFlags a, PadFlags b) { return static_cast<PadFlags>(static_cast<int>(a) & static_cast<int>(b)); }
114+
inline PadFlags operator~(PadFlags a) { return static_cast<PadFlags>(~static_cast<int>(a)); }
115+
inline PadFlags operator|(PadFlags a, PadFlags b) { return static_cast<PadFlags>(static_cast<int>(a) | static_cast<int>(b)); }
116+
100117
// default point definitions for PointND, PointNDlocal, PointNDglobal are in
101118
// MathUtils/CartesianND.h
102119

Detectors/TPC/base/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ o2_add_library(TPCBase
3737
src/CRUCalibHelpers.cxx
3838
src/IonTailSettings.cxx
3939
src/FEEConfig.cxx
40+
src/DeadChannelMapCreator.cxx
4041
PUBLIC_LINK_LIBRARIES Vc::Vc Boost::boost O2::DataFormatsTPC
4142
O2::DetectorsRaw O2::CCDB FairRoot::Base)
4243

@@ -67,7 +68,8 @@ o2_target_root_dictionary(TPCBase
6768
include/TPCBase/Utils.h
6869
include/TPCBase/CRUCalibHelpers.h
6970
include/TPCBase/IonTailSettings.h
70-
include/TPCBase/FEEConfig.h)
71+
include/TPCBase/FEEConfig.h
72+
include/TPCBase/DeadChannelMapCreator.h)
7173
o2_add_test(Base
7274
COMPONENT_NAME tpc
7375
PUBLIC_LINK_LIBRARIES O2::TPCBase

Detectors/TPC/base/include/TPCBase/CDBInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ class CDBStorage
460460

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

463+
std::string getMetaDataString() const;
464+
463465
void setSimulate(bool sim = true) { mSimulate = sim; }
464466

465467
bool getSimulate() const { return mSimulate; }

Detectors/TPC/base/include/TPCBase/CRUCalibHelpers.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <cassert>
2020
#include <gsl/span>
2121
#include <filesystem>
22+
#include <type_traits>
2223
namespace fs = std::filesystem;
2324

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

119+
template <class T>
120+
struct is_map {
121+
static constexpr bool value = false;
122+
};
123+
124+
template <class Key, class Value>
125+
struct is_map<std::map<Key, Value>> {
126+
static constexpr bool value = true;
127+
};
128+
/// fill cal pad object from HV data map
129+
/// TODO: Function to be tested
130+
template <typename DataMap, uint32_t SignificantBitsT = 0>
131+
typename std::enable_if_t<is_map<DataMap>::value, void>
132+
fillCalPad(CalDet<float>& calPad, const DataMap& map)
133+
{
134+
using namespace o2::tpc;
135+
const auto& mapper = Mapper::instance();
136+
137+
for (const auto& [linkInfo, data] : map) {
138+
const CRU cru(linkInfo.cru);
139+
const PartitionInfo& partInfo = mapper.getMapPartitionInfo()[cru.partition()];
140+
const int nFECs = partInfo.getNumberOfFECs();
141+
const int fecOffset = (nFECs + 1) / 2;
142+
const int fecInPartition = (linkInfo.globalLinkID < fecOffset) ? linkInfo.globalLinkID : fecOffset + linkInfo.globalLinkID % 12;
143+
144+
int hwChannel{0};
145+
for (const auto& val : data) {
146+
const auto& [sampaOnFEC, channelOnSAMPA] = getSampaInfo(hwChannel, cru);
147+
const PadROCPos padROCPos = mapper.padROCPos(cru, fecInPartition, sampaOnFEC, channelOnSAMPA);
148+
if constexpr (SignificantBitsT == 0) {
149+
const float set = std::stof(val);
150+
calPad.getCalArray(padROCPos.getROC()).setValue(padROCPos.getRow(), padROCPos.getPad(), set);
151+
} else {
152+
const float set = fixedSizeToFloat<SignificantBitsT>(uint32_t(std::stoi(val)));
153+
calPad.getCalArray(padROCPos.getROC()).setValue(padROCPos.getRow(), padROCPos.getPad(), set);
154+
}
155+
++hwChannel;
156+
}
157+
}
158+
}
159+
118160
/// fill cal pad object from HW value stream
119161
template <uint32_t SignificantBitsT = 2>
120162
int fillCalPad(CalDet<float>& calPad, std::istream& infile)

Detectors/TPC/base/include/TPCBase/CalArray.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ class CalArray
105105
std::vector<T>& getData() { return mData; }
106106

107107
/// calculate the sum of all elements
108-
const T getSum() const { return std::accumulate(mData.begin(), mData.end(), T(0)); }
108+
template <typename U = T>
109+
const U getSum() const
110+
{
111+
return std::accumulate(mData.begin(), mData.end(), U{});
112+
}
109113

110114
/// Multiply all val to all channels
111115
const CalArray<T>& multiply(const T& val) { return *this *= val; }
@@ -228,7 +232,11 @@ inline const CalArray<T>& CalArray<T>::operator+=(const CalArray<T>& other)
228232
return *this;
229233
}
230234
for (size_t i = 0; i < mData.size(); ++i) {
231-
mData[i] += other.getValue(i);
235+
if constexpr (std::is_same_v<T, bool>) {
236+
mData[i] = mData[i] | other.getValue(i);
237+
} else {
238+
mData[i] += other.getValue(i);
239+
}
232240
}
233241
return *this;
234242
}
@@ -256,7 +264,11 @@ inline const CalArray<T>& CalArray<T>::operator*=(const CalArray<T>& other)
256264
return *this;
257265
}
258266
for (size_t i = 0; i < mData.size(); ++i) {
259-
mData[i] *= other.getValue(i);
267+
if constexpr (std::is_same_v<T, bool>) {
268+
mData[i] = mData[i] & other.getValue(i);
269+
} else {
270+
mData[i] *= other.getValue(i);
271+
}
260272
}
261273
return *this;
262274
}

Detectors/TPC/base/include/TPCBase/CalDet.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define ALICEO2_TPC_CALDET_H_
1414

1515
#include <memory>
16+
#include <numeric>
1617
#include <vector>
1718
#include <string>
1819
#include <cassert>
@@ -114,13 +115,29 @@ class CalDet
114115
U sum = 0;
115116
for (const auto& data : mData) {
116117
const auto& vals = data.getData();
117-
sum += std::accumulate(vals.begin(), vals.end(), 0.f);
118+
sum += std::accumulate(vals.begin(), vals.end(), U{0});
118119
nVal += static_cast<U>(vals.size());
119120
}
120121

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

125+
template <typename U = T>
126+
U getSum() const
127+
{
128+
if (mData.size() == 0) {
129+
return U{};
130+
}
131+
132+
U sum{};
133+
for (const auto& data : mData) {
134+
const auto& vals = data.getData();
135+
sum += data.template getSum<U>();
136+
}
137+
138+
return sum;
139+
}
140+
124141
private:
125142
std::string mName; ///< name of the object
126143
std::vector<CalType> mData; ///< internal CalArrays
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
#ifndef ALICEO2_TPC_DeadChannelMapCreator_H_
13+
#define ALICEO2_TPC_DeadChannelMapCreator_H_
14+
15+
#include <unordered_map>
16+
#include <memory>
17+
18+
#include "Rtypes.h"
19+
20+
#include "CCDB/CcdbApi.h"
21+
22+
#include "DataFormatsTPC/Defs.h"
23+
#include "TPCBase/CDBInterface.h"
24+
#include "TPCBase/FEEConfig.h"
25+
26+
namespace o2::tpc
27+
{
28+
29+
enum class SourcesDeadMap : unsigned short {
30+
None = 0, ///< no inputs
31+
IDCPadStatus = 1 << 0, ///< use idc pad status map
32+
FEEConfig = 1 << 1, ///< use fee config
33+
All = IDCPadStatus | FEEConfig, ///< all sources
34+
};
35+
inline SourcesDeadMap operator&(SourcesDeadMap a, SourcesDeadMap b) { return static_cast<SourcesDeadMap>(static_cast<unsigned short>(a) & static_cast<unsigned short>(b)); }
36+
inline SourcesDeadMap operator~(SourcesDeadMap a) { return static_cast<SourcesDeadMap>(~static_cast<unsigned short>(a)); }
37+
inline SourcesDeadMap operator|(SourcesDeadMap a, SourcesDeadMap b) { return static_cast<SourcesDeadMap>(static_cast<unsigned short>(a) | static_cast<unsigned short>(b)); }
38+
39+
struct FEEConfig;
40+
41+
class DeadChannelMapCreator
42+
{
43+
struct ValidityRange {
44+
long startvalidity = 0;
45+
long endvalidity = -1;
46+
bool isValid(long ts) const { return ts < endvalidity && ts > startvalidity; }
47+
};
48+
49+
public:
50+
using CalDetFlag_t = o2::tpc::CalDet<o2::tpc::PadFlags>;
51+
52+
void reset();
53+
54+
void init();
55+
void load(long timeStampOrRun);
56+
void loadFEEConfigViaRunInfoTS(long timeStamp);
57+
void loadFEEConfigViaRunInfo(long timeStampOrRun);
58+
void loadFEEConfig(long tag, long createdNotAfter = -1);
59+
void loadIDCPadFlags(long timeStampOrRun);
60+
61+
void setDeadChannelMapIDCPadStatus(const CalDetFlag_t& padStatusMap, PadFlags mask = PadFlags::flagAllNoneGood);
62+
63+
const CalDet<bool>& getDeadChannelMapIDC() const { return mDeadChannelMapIDC; }
64+
const CalDet<bool>& getDeadChannelMapFEE() const { return mDeadChannelMapFEE; }
65+
const CalDet<bool>& getDeadChannelMap() const { return mDeadChannelMap; }
66+
67+
void drawDeadChannelMapIDC();
68+
void drawDeadChannelMapFEE();
69+
void drawDeadChannelMap();
70+
71+
long getTimeStamp(long timeStampOrRun) const;
72+
73+
void finalizeDeadChannelMap();
74+
void resetDeadChannelMap() { mDeadChannelMap = false; }
75+
76+
void setSource(SourcesDeadMap s) { mSources = s; }
77+
void addSource(SourcesDeadMap s) { mSources = s | mSources; }
78+
bool useSource(SourcesDeadMap s) const { return (mSources & s) == s; }
79+
SourcesDeadMap getSources() const { return mSources; }
80+
81+
private:
82+
std::unique_ptr<FEEConfig> mFEEConfig; ///< Electronics configuration, manually loaded
83+
std::unique_ptr<CalDetFlag_t> mPadStatusMap; ///< Pad status map from IDCs, manually loaded
84+
// FEEConfig::CalPadMapType* mPulserData; ///< Pulser information
85+
// FEEConfig::CalPadMapType* mCEData; ///< CE information
86+
87+
std::unordered_map<CDBType, ValidityRange> mObjectValidity; ///< validity range of internal objects
88+
SourcesDeadMap mSources = SourcesDeadMap::All; ///< Inputs to use to create the map
89+
ccdb::CcdbApi mCCDBApi; ///< CCDB Api
90+
CalDet<bool> mDeadChannelMapIDC{"DeadChannelMapIDC"}; ///< Combined dead channel map
91+
CalDet<bool> mDeadChannelMapFEE{"DeadChannelMapFEE"}; ///< Dead Channel map from FEE configuration
92+
CalDet<bool> mDeadChannelMap{"DeadChannelMap"}; ///< Combined dead channel map
93+
94+
ClassDefNV(DeadChannelMapCreator, 0);
95+
};
96+
97+
inline long DeadChannelMapCreator::getTimeStamp(long timeStampOrRun) const
98+
{
99+
if (timeStampOrRun < 1000000) {
100+
// assume run number
101+
const auto c = mCCDBApi.retrieveHeaders("RCT/Info/RunInformation", {}, timeStampOrRun);
102+
timeStampOrRun = (std::stol(c.at("SOR")) + std::stol(c.at("EOR"))) / 2;
103+
}
104+
105+
return timeStampOrRun;
106+
}
107+
108+
} // namespace o2::tpc
109+
110+
#endif

Detectors/TPC/base/include/TPCBase/FEEConfig.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <unordered_map>
2222
#include <vector>
2323
#include <cstdint>
24+
#include <numeric>
2425

2526
#include "Rtypes.h"
2627

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

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

64+
enum class PadConfig {
65+
ITfraction = 0,
66+
ITexpLambda = 1,
67+
CMkValues = 2,
68+
ThresholdMap = 3,
69+
Pedestals = 4,
70+
};
71+
72+
static constexpr size_t MaxLinks = 91 * 36;
73+
static const std::unordered_map<Tags, const std::string> TagNames;
74+
static const std::unordered_map<PadConfig, const std::string> PadConfigNames;
75+
6276
using CalPadMapType = std::unordered_map<std::string, CalPad>;
6377
FEEConfig() { cruConfig.resize(CRU::MaxCRU); }
6478
// FEEConfig& operator=(const FEEConfig& config)
@@ -82,6 +96,17 @@ struct FEEConfig {
8296
}
8397
}
8498

99+
size_t getNumberActiveLinks() const;
100+
bool isCMCEnabled() const;
101+
bool isITFEnabled() const;
102+
bool isZSEnabled() const;
103+
bool isResyncEnabled() const;
104+
105+
void print() const;
106+
107+
/// Dead channel map including deactivated links and single channels
108+
CalDet<bool> getDeadChannelMap() const;
109+
85110
ClassDefNV(FEEConfig, 2);
86111
};
87112

Detectors/TPC/base/src/CDBInterface.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,13 @@ bool CDBStorage::checkMetaData(MetaData_t metaData) const
519519
return counts[0] == 0;
520520
}
521521

522+
//______________________________________________________________________________
523+
std::string CDBStorage::getMetaDataString() const
524+
{
525+
std::string metaDataString;
526+
return metaDataString;
527+
}
528+
522529
//______________________________________________________________________________
523530
void CDBStorage::uploadNoiseAndPedestal(std::string_view fileName, long first, long last)
524531
{

0 commit comments

Comments
 (0)