Project
Loading...
Searching...
No Matches
TimeDeadMap.h
Go to the documentation of this file.
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
14#ifndef ALICEO2_ITSMFT_TIMEDEADMAP_H
15#define ALICEO2_ITSMFT_TIMEDEADMAP_H
16
17#include "Rtypes.h"
19#include <iostream>
20#include <vector>
21#include <map>
22
23namespace o2
24{
25
26namespace itsmft
27{
28
30{
31 public:
32 // Constructor
33 TimeDeadMap(std::map<unsigned long, std::vector<uint16_t>>& deadmap)
34 {
35 mEvolvingDeadMap.swap(deadmap);
36 }
37
39 TimeDeadMap() = default;
41 ~TimeDeadMap() = default;
42
43 void fillMap(unsigned long firstOrbit, const std::vector<uint16_t>& deadVect)
44 {
45 mEvolvingDeadMap[firstOrbit] = deadVect;
46 };
47
48 void fillMap(const std::vector<uint16_t>& deadVect)
49 {
50 mStaticDeadMap = deadVect;
51 }
52
53 void clear()
54 {
55 mEvolvingDeadMap.clear();
56 mStaticDeadMap.clear();
57 }
58
60 { // for static part only
61 if (mMAP_VERSION == "3") {
62 LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
63 return;
64 }
65 for (int iel = 0; iel < mStaticDeadMap.size(); iel++) {
66 uint16_t w = mStaticDeadMap[iel];
67 noisemap.maskFullChip(w & 0x7FFF);
68 if (w & 0x8000) {
69 for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) {
70 noisemap.maskFullChip(w2);
71 }
72 }
73 }
74 }
75
76 void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true, long orbitGapAllowed = 330000)
77 { // for time-dependent and (optionally) static part. Use orbitGapAllowed = -1 to ignore check on orbit difference
78
79 if (mMAP_VERSION != "3" && mMAP_VERSION != "4") {
80 LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
81 return;
82 }
83
84 if (mEvolvingDeadMap.empty()) {
85 LOG(warning) << "Time-dependent dead map is empty. Doing nothing.";
86 return;
87 }
88
89 std::vector<uint16_t> closestVec;
90 long dT = getMapAtOrbit(orbit, closestVec);
91
92 if (orbitGapAllowed >= 0 && std::abs(dT) > orbitGapAllowed) {
93 LOG(warning) << "Requested orbit " << orbit << ", found " << orbit - dT << ". Orbit gap is too high, skipping time-dependent map.";
94 closestVec.clear();
95 }
96
97 // add static part if requested. something may be masked twice
98 if (includeStaticMap && mMAP_VERSION != "3") {
99 closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end());
100 }
101
102 // vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector.
103
104 for (int iel = 0; iel < closestVec.size(); iel++) {
105 uint16_t w = closestVec.at(iel);
106 noisemap.maskFullChip(w & 0x7FFF);
107 if (w & 0x8000) {
108 for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) {
109 noisemap.maskFullChip(w2);
110 }
111 }
112 }
113 };
114
115 std::string getMapVersion() const { return mMAP_VERSION; };
116
117 unsigned long getEvolvingMapSize() const { return mEvolvingDeadMap.size(); };
118
119 std::vector<unsigned long> getEvolvingMapKeys()
120 {
121 std::vector<unsigned long> keys;
122 std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys),
123 [](const auto& O) { return O.first; });
124 return keys;
125 }
126
127 void getStaticMap(std::vector<uint16_t>& mmap) { mmap = mStaticDeadMap; };
128
129 long getMapAtOrbit(unsigned long orbit, std::vector<uint16_t>& mmap)
130 { // fills mmap and returns requested_orbit - found_orbit. Found orbit is the highest key lower or equal to the requested one
131 if (mEvolvingDeadMap.empty()) {
132 LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing";
133 return (long)orbit;
134 }
135 auto closest = mEvolvingDeadMap.upper_bound(orbit);
136 if (closest != mEvolvingDeadMap.begin()) {
137 --closest;
138 mmap = closest->second;
139 return (long)orbit - closest->first;
140 } else {
141 mmap = mEvolvingDeadMap.begin()->second;
142 return (long)(orbit)-mEvolvingDeadMap.begin()->first;
143 }
144 }
145
146 void setMapVersion(std::string version) { mMAP_VERSION = version; };
147
148 bool isDefault() { return mIsDefaultObject; };
149 void setAsDefault(bool isdef = true) { mIsDefaultObject = isdef; };
150
151 private:
152 bool mIsDefaultObject = false;
153 std::string mMAP_VERSION = "3";
154 std::map<unsigned long, std::vector<uint16_t>> mEvolvingDeadMap;
155 std::vector<uint16_t> mStaticDeadMap;
156
157 ClassDefNV(TimeDeadMap, 2);
158};
159
160} // namespace itsmft
161} // namespace o2
162
163#endif /* ALICEO2_ITSMFT_TIMEDEADMAP_H */
uint64_t orbit
Definition RawEventData.h:6
uint32_t version
Definition RawData.h:8
NoiseMap class for the ITS and MFT.
Definition NoiseMap.h:39
void maskFullChip(int chip, bool cleanNoisyPixels=false)
Definition NoiseMap.h:178
void fillMap(const std::vector< uint16_t > &deadVect)
Definition TimeDeadMap.h:48
TimeDeadMap(std::map< unsigned long, std::vector< uint16_t > > &deadmap)
Definition TimeDeadMap.h:33
void fillMap(unsigned long firstOrbit, const std::vector< uint16_t > &deadVect)
Definition TimeDeadMap.h:43
void setMapVersion(std::string version)
long getMapAtOrbit(unsigned long orbit, std::vector< uint16_t > &mmap)
unsigned long getEvolvingMapSize() const
void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap &noisemap, bool includeStaticMap=true, long orbitGapAllowed=330000)
Definition TimeDeadMap.h:76
TimeDeadMap()=default
Constructor.
~TimeDeadMap()=default
Destructor.
void setAsDefault(bool isdef=true)
void getStaticMap(std::vector< uint16_t > &mmap)
void decodeMap(o2::itsmft::NoiseMap &noisemap)
Definition TimeDeadMap.h:59
std::string getMapVersion() const
std::vector< unsigned long > getEvolvingMapKeys()
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"