tmf.core: Changed printStackTrace() for logError()
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / statesystem / mipmap / AbstractTmfMipmapStateProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Jean-Christian Kouamé - Initial API and implementation
11 * Patrick Tasse - Updates to mipmap feature
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18 import java.util.HashMap;
19 import java.util.LinkedHashSet;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.internal.tmf.core.Activator;
25 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
26 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
27 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
28 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
29 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
30 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
31 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
32 import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
33 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
34
35 /**
36 * This is an abstract state provider that allows attributes to be mipmapped
37 * for one or more of the supported mipmap features (min, max, average).
38 *
39 * Extend this class for a specific implementation
40 */
41 public abstract class AbstractTmfMipmapStateProvider extends AbstractTmfStateProvider {
42
43 /**
44 * Feature bit for the maximum mipmap feature (value is 1<<1).
45 */
46 public static final int MAX = 1 << 1;
47
48 /**
49 * Feature bit for the minimum mipmap feature (value is 1&lt;&lt;2).
50 */
51 public static final int MIN = 1 << 2;
52
53 /**
54 * Feature bit for the average mipmap feature (value is 1&lt;&lt;3).
55 */
56 public static final int AVG = 1 << 3;
57
58 /**
59 * The string for maximum mipmap feature sub-attribute.
60 * This attribute value is the mipmap number of levels.
61 * It has sub-attributes for every level ("1", "2", etc.)
62 */
63 public static final String MAX_STRING = "max"; //$NON-NLS-1$
64
65 /**
66 * The string for minimum mipmap feature sub-attribute.
67 * This attribute value is the mipmap number of levels.
68 * It has sub-attributes for every level ("1", "2", etc.)
69 */
70 public static final String MIN_STRING = "min"; //$NON-NLS-1$
71
72 /**
73 * The string for average mipmap feature sub-attribute.
74 * This attribute value is the mipmap number of levels.
75 * It has sub-attributes for every level ("1", "2", etc.)
76 */
77 public static final String AVG_STRING = "avg"; //$NON-NLS-1$
78
79 /**
80 * Map of mipmap features per attribute. The map's key is the base attribute quark.
81 */
82 private Map<Integer, Set<ITmfMipmapFeature>> featureMap = new HashMap<>();
83
84 // ------------------------------------------------------------------------
85 // Constructor
86 // ------------------------------------------------------------------------
87
88 /**
89 * Constructor
90 *
91 * @param trace
92 * The trace directory
93 * @param id
94 * The name given to this state change input. Only used
95 * internally.
96 */
97 public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace,
98 @NonNull String id) {
99 super(trace, id);
100 }
101
102 // ------------------------------------------------------------------------
103 // Public methods
104 // ------------------------------------------------------------------------
105
106 @Override
107 public void dispose() {
108 waitForEmptyQueue();
109 for (Set<ITmfMipmapFeature> features : featureMap.values()) {
110 for (ITmfMipmapFeature feature : features) {
111 feature.updateAndCloseMipmap();
112 }
113 }
114 super.dispose();
115 }
116
117 /**
118 * Modify a mipmap attribute. The base attribute is modified and the mipmap
119 * attributes for the feature(s) specified in the mipmap feature bitmap are
120 * created and/or updated.<br>
121 * Note: The mipmapFeatureBits and resolution are only used on the first
122 * call of this method for a particular attribute, and the mipmap features
123 * for this attribute are then activated until the end of the trace.<br>
124 * Note: The base attribute should only be modified by calling this method.
125 *
126 * @param ts
127 * The timestamp of the event
128 * @param value
129 * The value of the base attribute
130 * @param baseQuark
131 * The quark of the base attribute
132 * @param mipmapFeatureBits
133 * The mipmap feature bit(s)
134 * @param resolution
135 * The mipmap resolution (must be greater than 1)
136 * @throws TimeRangeException
137 * If the requested time is outside of the trace's range
138 * @throws AttributeNotFoundException
139 * If the requested attribute quark is invalid
140 * @throws StateValueTypeException
141 * If the inserted state value's type does not match what is
142 * already assigned to this attribute.
143 * @see #MAX
144 * @see #MIN
145 * @see #AVG
146 */
147 public void modifyMipmapAttribute(long ts, ITmfStateValue value, int baseQuark, int mipmapFeatureBits, int resolution)
148 throws TimeRangeException, AttributeNotFoundException, StateValueTypeException {
149 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
150 ss.modifyAttribute(ts, value, baseQuark);
151 if (value.getType() == Type.LONG || value.getType() == Type.INTEGER || value.getType() == Type.DOUBLE || value.isNull()) {
152 Set<ITmfMipmapFeature> features = getFeatureSet(baseQuark, ts, value, mipmapFeatureBits, resolution);
153 for (ITmfMipmapFeature mf : features) {
154 mf.updateMipmap(value, ts);
155 }
156 }
157 }
158
159 // ------------------------------------------------------------------------
160 // Private methods
161 // ------------------------------------------------------------------------
162
163 private Set<ITmfMipmapFeature> getFeatureSet(int baseQuark, long ts, ITmfStateValue value, int mipmapFeatureBits, int resolution) {
164 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
165
166 Set<ITmfMipmapFeature> features = featureMap.get(baseQuark);
167 if (features != null) {
168 return features;
169 }
170 features = new LinkedHashSet<>();
171 if (value.isNull()) {
172 return features;
173 }
174 featureMap.put(baseQuark, features);
175 if (resolution > 1) {
176 try {
177 if ((mipmapFeatureBits & MAX) != 0) {
178 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MAX_STRING);
179 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
180 MaxMipmapFeature mf = new MaxMipmapFeature(baseQuark, featureQuark, resolution, ss);
181 features.add(mf);
182 }
183 if ((mipmapFeatureBits & MIN) != 0) {
184 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MIN_STRING);
185 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
186 MinMipmapFeature mf = new MinMipmapFeature(baseQuark, featureQuark, resolution, ss);
187 features.add(mf);
188 }
189 if ((mipmapFeatureBits & AVG) != 0) {
190 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, AVG_STRING);
191 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
192 AvgMipmapFeature mf = new AvgMipmapFeature(baseQuark, featureQuark, resolution, ss);
193 features.add(mf);
194 }
195 } catch (TimeRangeException e) {
196 Activator.logError("MipMapProvider : Time stamp outside of time range of state system", e); //$NON-NLS-1$
197 } catch (AttributeNotFoundException e) {
198 Activator.logError("MipMapProvider : Attribute not found", e); //$NON-NLS-1$
199 } catch (StateValueTypeException e) {
200 Activator.logError("MipMapProvider : Wrong state value type", e); //$NON-NLS-1$
201 }
202 }
203 return features;
204 }
205 }
This page took 0.03803 seconds and 6 git commands to generate.