|
| 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 |
0 commit comments