Project
Loading...
Searching...
No Matches
DetMatrixCache.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#ifndef ALICEO2_BASE_DETMATRIXCACHE_H
12#define ALICEO2_BASE_DETMATRIXCACHE_H
13
14//Forward to standard headers with protection for GPU compilation
15#include "GPUCommonLogger.h"
16#include "GPUCommonRtypes.h"
17
18#include <array>
19#include <vector>
20
21#include "MathUtils/Cartesian.h"
23
24class TGeoHMatrix;
25
26namespace o2
27{
28namespace detectors
29{
31
32template <typename T = o2::math_utils::Transform3D>
34{
35 // matrices (per sensor) for specific transformation type
36
37 public:
38 MatrixCache() = default;
39 ~MatrixCache() = default;
40 MatrixCache(const MatrixCache& src) = delete;
42
44 void setSize(int s)
45 {
46 if (!mCache.size()) {
47 mCache.resize(s);
48 }
49 }
50
52 int getSize() const { return mCache.size(); }
54 void setMatrix(const T& mat, int sensID)
55 {
56 // assign matrix for given sensor. The cache must be booked in advance
57 if ((unsigned int)sensID >= mCache.size()) {
58 LOG(fatal) << "SensID " << sensID << " exceeds cache size of " << mCache.size();
59 }
60 mCache[sensID] = mat;
61 }
62
63 const T& getMatrix(int sensID) const { return mCache[sensID]; }
64 bool isFilled() const { return !mCache.empty(); }
65
66 private:
67 std::vector<T> mCache;
68 ClassDefNV(MatrixCache, 1);
69};
70
73
75{
76 public:
79
80 DetMatrixCache() = default;
83 virtual ~DetMatrixCache() = default;
84
86 DetMatrixCache& operator=(const DetMatrixCache& geom) = delete;
87
88 const o2::detectors::DetID& getDetID() const { return mDetID; }
89 const char* getName() const { return mDetID.getName(); }
90 const MatrixCache<Mat3D>& getCacheT2L() const { return mT2L; }
91 const MatrixCache<Mat3D>& getCacheT2G() const { return mT2G; }
92 const MatrixCache<Mat3D>& getCacheL2G() const { return mL2G; }
93 const MatrixCache<Rot2D>& getCacheT2GRot() const { return mT2GRot; }
94 const Mat3D& getMatrixT2L(int sensID) const { return mT2L.getMatrix(sensID); }
95 const Mat3D& getMatrixT2G(int sensID) const { return mT2G.getMatrix(sensID); }
96 const Mat3D& getMatrixL2G(int sensID) const { return mL2G.getMatrix(sensID); }
97 const Rot2D& getMatrixT2GRot(int sensID) const { return mT2GRot.getMatrix(sensID); }
98 bool isBuilt() const { return mSize != 0; }
99 int getSize() const { return mSize; }
100 // protected:
101
102 // detector derived class must define its implementation for the method to populate the matrix cache, as an
103 // example, see ITS implementation GeometryTGeo.
104 // The method can be called multiple times to init caches for different transformations, i.e.
105 // with differen mask as o2::math_utils::bit2Mask(T2L), or bit2Mask(L2G,T2L), but for the consistency
106 // check the nsens must be always the same.
107 virtual void fillMatrixCache(int mask) = 0;
108
109 // before calling fillMatrixCache, detector implementation should set the size of the matrix cache
110 void setSize(int s);
111
112 // acces to non-const caches for filling in the base classes only
118 int mSize = 0;
119
124
126};
127
129
131{
132 public:
135
138 ~DetMatrixCacheIndirect() override = default;
139
142
143 const Mat3D& getMatrixT2L(int sensID) const { return mT2L.getMatrix(mIndirection[sensID]); }
144 const Mat3D& getMatrixT2G(int sensID) const { return mT2G.getMatrix(mIndirection[sensID]); }
145 const Mat3D& getMatrixL2G(int sensID) const { return mL2G.getMatrix(mIndirection[sensID]); }
146 const Rot2D& getMatrixT2GRot(int sensID) const { return mT2GRot.getMatrix(mIndirection[sensID]); }
147
148 bool isBuilt() const { return DetMatrixCache::isBuilt(); }
149 int getSize() const { return DetMatrixCache::getSize(); }
150 int getIndirectSize() const { return mIndirectSize; }
151 bool isMatrixAvailable(int sensID) const { return mIndirection[sensID] >= 0; }
152
153 protected:
154 // before calling fillMatrixCache, detector implementation should set the size of the matrix cache
155 void setSize(int s) = delete;
156 void setSize(int size, int sizeIndirect);
157
158 void setMatrixT2L(const Mat3D& matrix, int sensID) { mT2L.setMatrix(matrix, getCacheHelper(sensID)); }
159 void setMatrixT2G(const Mat3D& matrix, int sensID) { mT2G.setMatrix(matrix, getCacheHelper(sensID)); }
160 void setMatrixL2G(const Mat3D& matrix, int sensID) { mL2G.setMatrix(matrix, getCacheHelper(sensID)); }
161 void setMatrixT2GRot(const Rot2D& matrix, int sensID) { mT2GRot.setMatrix(matrix, getCacheHelper(sensID)); }
162 void useT2LCache() { mT2L.setSize(mSize); }
163 void useT2GCache() { mT2G.setSize(mSize); }
164 void useL2GCache() { mL2G.setSize(mSize); }
165 void useT2GRotCache() { mT2GRot.setSize(mSize); }
166
167 private:
168 int getCacheHelper(int sensID)
169 {
170 if (sensID >= mIndirectSize) {
171 LOG(fatal) << "SendID " << sensID << " exceeds indirect cache size of " << mIndirectSize;
172 }
173 if (mIndirection[sensID] >= 0) {
174 return mIndirection[sensID];
175 }
176 return (mIndirection[sensID] = mNextEntry++);
177 }
178
179 int mIndirectSize = 0;
180 int mNextEntry = 0;
181 std::vector<short> mIndirection;
182
183 ClassDefOverride(DetMatrixCacheIndirect, 1);
184};
185} // namespace detectors
186} // namespace o2
187
188#endif
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:145
Variant of DetMatrixCache for non consecutive indexing.
const Mat3D & getMatrixT2L(int sensID) const
void setMatrixT2L(const Mat3D &matrix, int sensID)
DetMatrixCacheIndirect(const o2::detectors::DetID &id)
DetMatrixCacheIndirect & operator=(const DetMatrixCacheIndirect &geom)=delete
o2::math_utils::Rotation2Df_t Rot2D
void setMatrixT2GRot(const Rot2D &matrix, int sensID)
o2::math_utils::Transform3D Mat3D
void setMatrixL2G(const Mat3D &matrix, int sensID)
void setMatrixT2G(const Mat3D &matrix, int sensID)
const Rot2D & getMatrixT2GRot(int sensID) const
const Mat3D & getMatrixL2G(int sensID) const
~DetMatrixCacheIndirect() override=default
bool isMatrixAvailable(int sensID) const
DetMatrixCacheIndirect(const DetMatrixCacheIndirect &src)=delete
const Mat3D & getMatrixT2G(int sensID) const
MatrixCache< Rot2D > & getCacheT2GRot()
virtual void fillMatrixCache(int mask)=0
o2::detectors::DetID mDetID
detector ID
const Mat3D & getMatrixT2L(int sensID) const
const MatrixCache< Mat3D > & getCacheT2L() const
const char * getName() const
const Rot2D & getMatrixT2GRot(int sensID) const
virtual ~DetMatrixCache()=default
this may serve as a base class for detector interface to geometry, make it virtual
MatrixCache< Mat3D > & getCacheL2G()
MatrixCache< Mat3D > & getCacheT2L()
MatrixCache< Rot2D > mT2GRot
Tracking to Global matrices in case of barrel (simple rotation)
MatrixCache< Mat3D > mL2G
Local to Global matrices.
DetMatrixCache(const DetMatrixCache &src)=delete
const o2::detectors::DetID & getDetID() const
DetMatrixCache & operator=(const DetMatrixCache &geom)=delete
o2::math_utils::Rotation2Df_t Rot2D
MatrixCache< Mat3D > mT2G
Tracking to Global matrices (general case)
const Mat3D & getMatrixL2G(int sensID) const
ClassDef(DetMatrixCache, 1)
const MatrixCache< Mat3D > & getCacheT2G() const
int mSize
prebooked number of sensors
MatrixCache< Mat3D > & getCacheT2G()
o2::math_utils::Transform3D Mat3D
DetMatrixCache(const o2::detectors::DetID &id)
const MatrixCache< Rot2D > & getCacheT2GRot() const
const MatrixCache< Mat3D > & getCacheL2G() const
const Mat3D & getMatrixT2G(int sensID) const
MatrixCache< Mat3D > mT2L
Tracking to Local matrices.
MatrixCache is a vector of cached transform matrices (per sensor) for specific Transformation type.
int getSize() const
get the size of the cache
void setMatrix(const T &mat, int sensID)
assign matrix to a slot
const T & getMatrix(int sensID) const
void setSize(int s)
set the size of the cache
MatrixCache(const MatrixCache &src)=delete
MatrixCache & operator=(const MatrixCache &src)=delete
transformation types
Definition Cartesian.h:62
GLenum src
Definition glcorearb.h:1767
GLsizeiptr size
Definition glcorearb.h:659
GLint GLuint mask
Definition glcorearb.h:291
GLuint id
Definition glcorearb.h:650
std::string detectors(const std::vector< std::string > &det, unsigned mask)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"