Belle II Software development
Styling.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/display/ColorMapping.h>
11#include <tracking/trackFindingCDC/display/Mapping.h>
12#include <tracking/trackFindingCDC/display/AttributeMap.h>
13
14
15#include <map>
16#include <sstream>
17#include <memory>
18
19namespace Belle2 {
24 class RecoTrack;
25 class CDCHit;
26
27 namespace TrackingUtilities {
28 class CDCSegment2D;
29 }
30 namespace TrackFindingCDC {
31
33 template <class AObject>
34 class Styling {
35
36 public:
38 virtual ~Styling() = default;
39
41 virtual AttributeMap map(int index __attribute__((unused)),
42 AObject& object __attribute__((unused)))
43 {
44 return {};
45 }
46
48 virtual std::string info()
49 {
50 return "(no info available)\n";
51 }
52 };
53
55 template <class AObject>
56 class FixedStyling : public Styling<AObject> {
57
58 public:
60 AttributeMap map(int index __attribute__((unused)),
61 AObject& object __attribute__((unused))) override
62 {
63 return m_attributeMap;
64 }
65
67 std::string info() override
68 {
69 std::ostringstream oss;
70 for (const auto& keyValue : m_attributeMap) {
71 oss << keyValue.first << ": " << keyValue.second << '\n';
72 }
73 return oss.str();
74 }
75
77 void set(const std::string& key, const std::string& value)
78 {
79 m_attributeMap.emplace(key, value);
80 }
81
83 void setStroke(const std::string& value)
84 {
85 set("stroke", value);
86 }
87
89 void setStrokeWidth(const std::string& value)
90 {
91 set("stroke-width", value);
92 }
93
94 private:
96 AttributeMap m_attributeMap;
97 };
98
100 template <class AObject>
101 class ChooseableStyling : public Styling<AObject> {
102
103 public:
106
107 public:
109 AttributeMap map(int index, AObject& object) override
110 {
111 AttributeMap attributeMap;
112 for (const auto& keyMapping : m_mappingsByKey) {
113 const std::string& key = keyMapping.first;
114 const std::unique_ptr<ObjectMapping>& mapping = keyMapping.second;
115 attributeMap[key] = mapping->map(index, object);
116 }
117 return attributeMap;
118 }
119
121 std::string info() override
122 {
123 std::ostringstream oss;
124 for (const auto& keyMapping : m_mappingsByKey) {
125 const std::string& key = keyMapping.first;
126 const std::unique_ptr<ObjectMapping>& mapping = keyMapping.second;
127 oss << key << ": " << mapping->info();
128 }
129 return oss.str();
130 }
131
138 virtual std::unique_ptr<ObjectMapping> createMapping(const std::string& mappingName)
139 {
140 return std::make_unique<ConstantMapping<AObject>>(mappingName);
141 }
142
144 void set(const std::string& key, std::unique_ptr<ObjectMapping> mapping)
145 {
146 if (mapping) {
147 m_mappingsByKey[key] = std::move(mapping);
148 }
149 }
150
152 void set(const std::string& key, const std::string& mappingName)
153 {
154 std::unique_ptr<ObjectMapping> objectMapping = this->createMapping(mappingName);
155 if (objectMapping) {
156 set(key, std::move(objectMapping));
157 }
158 }
159
165 void setStroke(const std::string& mappingName)
166 {
167 set("stroke", mappingName);
168 }
169
175 void setStrokeWidth(const std::string& mappingName)
176 {
177 set("stroke-width", mappingName);
178 }
179
180 protected:
182 std::map<std::string, std::unique_ptr<ObjectMapping> > m_mappingsByKey;
183 };
184
186 template <class AObject>
188 public:
191 {
192 this->set("stroke", std::make_unique<DefaultColorCycleMapping<AObject>>());
193 }
194 };
195
200 class ChooseableRecoTrackStyling : public ChooseableStyling<const RecoTrack> {
201
202 private:
205
208
209 public:
211 std::unique_ptr<ObjectMapping> createMapping(const std::string& mappingName) override;
212 };
213
218 class ChooseableSegmentStyling : public ChooseableStyling<const TrackingUtilities::CDCSegment2D> {
219
220 private:
223
226
227 public:
229 std::unique_ptr<ObjectMapping> createMapping(const std::string& mappingName) override;
230 };
231
236 class ChooseableHitStyling : public ChooseableStyling<const CDCHit> {
237
238 private:
241
244
245 public:
247 std::unique_ptr<ObjectMapping> createMapping(const std::string& mappingName) override;
248 };
249 }
251}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition CDCHit.h:40
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition Styling.h:236
std::unique_ptr< ObjectMapping > createMapping(const std::string &mappingName) override
Method defining the available mapping names.
Definition Styling.cc:53
ChooseableStyling< const CDCHit > Super
Type of the base class.
Definition Styling.h:240
This Class handles the mapping from the colormapping-method name given as a string to the actual colo...
Definition Styling.h:200
std::unique_ptr< ObjectMapping > createMapping(const std::string &mappingName) override
Method defining the available mapping names.
Definition Styling.cc:17
ChooseableStyling< const RecoTrack > Super
Type of the base class.
Definition Styling.h:204
This Class handles the mapping from the colormapping-method name given as a string to the actual ACol...
Definition Styling.h:218
ChooseableStyling< const TrackingUtilities::CDCSegment2D > Super
Type of the base class.
Definition Styling.h:222
std::unique_ptr< ObjectMapping > createMapping(const std::string &mappingName) override
Method defining the available mapping names.
Definition Styling.cc:31
Implementation of a styling composed from several predefined mappings chooseable by their name.
Definition Styling.h:101
virtual std::unique_ptr< ObjectMapping > createMapping(const std::string &mappingName)
Create a mapping for the object from a name.
Definition Styling.h:138
void set(const std::string &key, const std::string &mappingName)
Sets the given attribute to the fixed value.
Definition Styling.h:152
AttributeMap map(int index, AObject &object) override
Create a map of attributes from the stored attribute maps.
Definition Styling.h:109
Mapping< AObject > ObjectMapping
Mapping for the object type.
Definition Styling.h:105
std::map< std::string, std::unique_ptr< ObjectMapping > > m_mappingsByKey
Definition Styling.h:182
void set(const std::string &key, std::unique_ptr< ObjectMapping > mapping)
Sets the given attribute to the attribute mapping.
Definition Styling.h:144
void setStrokeWidth(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke width.
Definition Styling.h:175
void setStroke(const std::string &mappingName)
Legacy method to set the mapping on how to match a object to the stroke color.
Definition Styling.h:165
std::string info() override
Returns informal string about the currently set mappings.
Definition Styling.h:121
Class template for coloring objects in different Colors.
DefaultColorCycleStyling()
Constructor. Sets the stroke mapping the the default color cycle.
Definition Styling.h:190
Implementation of a styling from fixed attribute map.
Definition Styling.h:56
void setStrokeWidth(const std::string &value)
Legacy - Sets the stroke width to the fixed value.
Definition Styling.h:89
AttributeMap map(int index, AObject &object) override
Return the fixed attributes on each invocation.
Definition Styling.h:60
AttributeMap m_attributeMap
Memory for the fixed attribute values.
Definition Styling.h:96
void set(const std::string &key, const std::string &value)
Sets the given attribute to the fixed value.
Definition Styling.h:77
void setStroke(const std::string &value)
Legacy - Sets the stroke color to the fixed value.
Definition Styling.h:83
std::string info() override
Informal string summarizing the translation from the object to the styling attributes.
Definition Styling.h:67
Interface defining a mapping of objects to attribute values e.g. a color.
Definition Mapping.h:23
Interface for a mapping of object and an index to styling attributes.
Definition Styling.h:34
virtual AttributeMap map(int index, AObject &object)
Maps the object at the given index to attribute values.
Definition Styling.h:41
virtual ~Styling()=default
Make destructor of interface virtual.
virtual std::string info()
Informal string summarizing the translation from the object to the styling attributes.
Definition Styling.h:48
A reconstructed sequence of two dimensional hits in one super layer.
Abstract base class for different kinds of events.