]>
Commit | Line | Data |
---|---|---|
2974f8dc | 1 | // $Id$ |
dce3e5ce | 2 | /************************************************************************** |
3 | * This file is property of and copyright by the ALICE HLT Project * | |
4 | * ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Primary Authors: Artur Szostak <artursz@iafrica.com> * | |
7 | * for The ALICE HLT Project. * | |
8 | * * | |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
14 | * about the suitability of this software for any purpose. It is * | |
15 | * provided "as is" without express or implied warranty. * | |
16 | **************************************************************************/ | |
17 | ||
18 | /// @file AliHLTDomainEntry.cxx | |
19 | /// @author Artur Szostak <artursz@iafrica.com> | |
20 | /// @date 20 Nov 2008 | |
21 | /// @brief Implementation of the AliHLTDomainEntry class. | |
22 | /// | |
23 | /// The AliHLTDomainEntry class is used to store information identifying a particular | |
24 | /// HLT internal data block, or set of data blocks using wild card values. This | |
25 | /// class is used by AliHLTTriggerDomain to store a list of data block classes | |
26 | /// that should be readout by the HLT. The information identifying a data block is | |
27 | /// the following: | |
28 | /// - the data block type | |
29 | /// - the data block's origin (detector name) | |
30 | /// - the data block's specification (detector specific bits) | |
31 | /// Several useful operators and methods are defined to help manipulate this | |
32 | /// information in the AliHLTTriggerDomain class. | |
33 | ||
34 | #include "AliHLTDomainEntry.h" | |
35 | #include "Riostream.h" | |
36 | #include "TString.h" | |
37 | #include <cstring> | |
2974f8dc | 38 | #include <cerrno> |
dce3e5ce | 39 | |
40 | ClassImp(AliHLTDomainEntry) | |
41 | ||
42 | ||
43 | AliHLTDomainEntry::AliHLTDomainEntry() : | |
44 | TObject(), | |
45 | fExclude(kFALSE), | |
46 | fUseSpec(kFALSE), | |
47 | fType(kAliHLTVoidDataType), | |
2959db22 | 48 | fSpecification(kAliHLTVoidDataSpec) |
dce3e5ce | 49 | { |
50 | // Default constructor. | |
51 | } | |
52 | ||
53 | AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTDomainEntry& domain) : | |
54 | TObject(domain), | |
55 | fExclude(domain.fExclude), | |
56 | fUseSpec(domain.fUseSpec), | |
57 | fType(domain.fType), | |
58 | fSpecification(domain.fSpecification) | |
59 | { | |
60 | // Copy constructor performs a deep copy. | |
61 | } | |
62 | ||
63 | ||
64 | AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTComponentDataType& type) : | |
65 | TObject(), | |
66 | fExclude(kFALSE), | |
67 | fUseSpec(kFALSE), | |
68 | fType(type), | |
2959db22 | 69 | fSpecification(kAliHLTVoidDataSpec) |
dce3e5ce | 70 | { |
71 | // Constructs a domain entry with a particular data type and any specification. | |
72 | // See header file for more information. | |
73 | } | |
74 | ||
75 | ||
76 | AliHLTDomainEntry::AliHLTDomainEntry(const char* blocktype, const char* origin) : | |
77 | TObject(), | |
78 | fExclude(kFALSE), | |
79 | fUseSpec(kFALSE), | |
80 | fType(), | |
2959db22 | 81 | fSpecification(kAliHLTVoidDataSpec) |
dce3e5ce | 82 | { |
83 | // Constructs a domain entry with a particular data type and any specification. | |
84 | // See header file for more information. | |
85 | ||
86 | char id[kAliHLTComponentDataTypefIDsize]; | |
87 | memset(&id, 0x0, sizeof(id)); | |
88 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++) | |
89 | { | |
90 | id[i] = blocktype[i]; | |
91 | } | |
92 | fType = AliHLTComponentDataTypeInitializer(id, origin); | |
93 | } | |
94 | ||
95 | ||
96 | AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTComponentDataType& type, UInt_t spec) : | |
97 | TObject(), | |
98 | fExclude(kFALSE), | |
99 | fUseSpec(kTRUE), | |
100 | fType(type), | |
101 | fSpecification(spec) | |
102 | { | |
103 | // Constructs a domain entry with a particular data type and specification. | |
104 | // See header file for more information. | |
105 | } | |
106 | ||
107 | ||
108 | AliHLTDomainEntry::AliHLTDomainEntry(const char* blocktype, const char* origin, UInt_t spec) : | |
109 | TObject(), | |
110 | fExclude(kFALSE), | |
111 | fUseSpec(kTRUE), | |
112 | fType(), | |
113 | fSpecification(spec) | |
114 | { | |
115 | // Constructs a domain entry with a particular data type and specification. | |
116 | // See header file for more information. | |
117 | ||
118 | char id[kAliHLTComponentDataTypefIDsize]; | |
119 | memset(&id, 0x0, sizeof(id)); | |
120 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++) | |
121 | { | |
122 | id[i] = blocktype[i]; | |
123 | } | |
124 | fType = AliHLTComponentDataTypeInitializer(id, origin); | |
125 | } | |
126 | ||
127 | ||
128 | AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTDomainEntry& domain) : | |
129 | TObject(domain), | |
130 | fExclude(exclude), | |
131 | fUseSpec(domain.fUseSpec), | |
132 | fType(domain.fType), | |
133 | fSpecification(domain.fSpecification) | |
134 | { | |
135 | // Constructs a domain entry from an existing one but with the exclude flag set. | |
136 | // See header file for more information. | |
137 | } | |
138 | ||
139 | ||
140 | AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTComponentDataType& type) : | |
141 | TObject(), | |
142 | fExclude(exclude), | |
143 | fUseSpec(kFALSE), | |
144 | fType(type), | |
2959db22 | 145 | fSpecification(kAliHLTVoidDataSpec) |
dce3e5ce | 146 | { |
147 | // Constructs a domain entry with the given data type, any specification | |
148 | // and the exclude flag set. | |
149 | // See header file for more information. | |
150 | } | |
151 | ||
152 | ||
153 | AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const char* blocktype, const char* origin) : | |
154 | TObject(), | |
155 | fExclude(exclude), | |
156 | fUseSpec(kFALSE), | |
157 | fType(), | |
2959db22 | 158 | fSpecification(kAliHLTVoidDataSpec) |
dce3e5ce | 159 | { |
160 | // Constructs a domain entry with a particular data type, any specification | |
161 | // and the exclude flag set. | |
162 | // See header file for more information. | |
163 | ||
164 | char id[kAliHLTComponentDataTypefIDsize]; | |
165 | memset(&id, 0x0, sizeof(id)); | |
166 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++) | |
167 | { | |
168 | id[i] = blocktype[i]; | |
169 | } | |
170 | fType = AliHLTComponentDataTypeInitializer(id, origin); | |
171 | } | |
172 | ||
173 | ||
174 | AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTComponentDataType& type, UInt_t spec) : | |
175 | TObject(), | |
176 | fExclude(exclude), | |
177 | fUseSpec(kTRUE), | |
178 | fType(type), | |
179 | fSpecification(spec) | |
180 | { | |
181 | // Constructs a domain entry with a particular data type and specification, | |
182 | // and the exclude flag is set. | |
183 | // See header file for more information. | |
184 | } | |
185 | ||
186 | ||
187 | AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const char* blocktype, const char* origin, UInt_t spec) : | |
188 | TObject(), | |
189 | fExclude(exclude), | |
190 | fUseSpec(kTRUE), | |
191 | fType(), | |
192 | fSpecification(spec) | |
193 | { | |
194 | // Constructs a domain entry with a particular data type and specification, | |
195 | // and the exclude flag is set. | |
196 | // See header file for more information. | |
197 | ||
198 | char id[kAliHLTComponentDataTypefIDsize]; | |
199 | memset(&id, 0x0, sizeof(id)); | |
200 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++) | |
201 | { | |
202 | id[i] = blocktype[i]; | |
203 | } | |
204 | fType = AliHLTComponentDataTypeInitializer(id, origin); | |
205 | } | |
206 | ||
207 | ||
208 | AliHLTDomainEntry::~AliHLTDomainEntry() | |
209 | { | |
210 | // Default destructor. | |
211 | } | |
212 | ||
213 | ||
214 | AliHLTDomainEntry& AliHLTDomainEntry::operator = (const AliHLTDomainEntry& domain) | |
215 | { | |
216 | // The copy operator performs a deep copy. | |
217 | ||
218 | TObject::operator = (domain); | |
219 | fType = domain.fType; | |
220 | fUseSpec = domain.fUseSpec; | |
221 | fSpecification = domain.fSpecification; | |
222 | return *this; | |
223 | } | |
224 | ||
225 | ||
226 | bool AliHLTDomainEntry::IdenticalTo(const AliHLTDomainEntry& rhs) const | |
227 | { | |
228 | // Checks if this domain entry is identical to 'rhs' and do not just have a | |
229 | // set intersection. | |
230 | // See header file for more information. | |
231 | ||
232 | if (not MatchExactly(fType, rhs.fType)) return false; | |
233 | return (fUseSpec == rhs.fUseSpec) and (fSpecification == rhs.fSpecification); | |
234 | } | |
235 | ||
236 | ||
237 | bool AliHLTDomainEntry::SubsetOf(const AliHLTDomainEntry& rhs) const | |
238 | { | |
239 | // Checks if this domain entry is a subset of 'rhs'. | |
240 | // See header file for more information. | |
241 | ||
242 | if (*this != rhs) return false; | |
243 | bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0; | |
dce3e5ce | 244 | bool rhsTypeIsAny = strncmp(&rhs.fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0; |
dce3e5ce | 245 | if (thisTypeIsAny and not rhsTypeIsAny) return false; |
2f251ae6 | 246 | bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0; |
247 | bool rhsOriginIsAny = strncmp(&rhs.fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0; | |
dce3e5ce | 248 | if (thisOriginIsAny and not rhsOriginIsAny) return false; |
2f251ae6 | 249 | bool thisSpecIsAny = not fUseSpec; |
250 | bool rhsSpecIsAny = not rhs.fUseSpec; | |
dce3e5ce | 251 | if (thisSpecIsAny and not rhsSpecIsAny) return false; |
252 | return true; | |
253 | } | |
254 | ||
255 | ||
256 | bool AliHLTDomainEntry::IntersectWith(const AliHLTDomainEntry& rhs, AliHLTDomainEntry& result) const | |
257 | { | |
258 | // Finds the set intersection between this domain entry and 'rhs'. | |
259 | // See header file for more information. | |
260 | ||
261 | if (*this != rhs) return false; | |
262 | bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0; | |
263 | bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0; | |
264 | bool thisSpecIsAny = not fUseSpec; | |
265 | const AliHLTComponentDataType& type = (not thisTypeIsAny) ? fType : rhs.fType; | |
266 | const AliHLTComponentDataType& origin = (not thisOriginIsAny) ? fType : rhs.fType; | |
267 | Bool_t useSpec; | |
268 | UInt_t spec; | |
269 | if (not thisSpecIsAny) | |
270 | { | |
271 | useSpec = fUseSpec; | |
272 | spec = fSpecification; | |
273 | } | |
274 | else | |
275 | { | |
276 | useSpec = rhs.fUseSpec; | |
277 | spec = rhs.fSpecification; | |
278 | } | |
279 | if (useSpec) | |
280 | { | |
281 | result = AliHLTDomainEntry(type | origin.fOrigin, spec); | |
282 | } | |
283 | else | |
284 | { | |
285 | result = AliHLTDomainEntry(type | origin.fOrigin); | |
286 | } | |
287 | return true; | |
288 | } | |
289 | ||
290 | ||
291 | void AliHLTDomainEntry::Print(Option_t* option) const | |
292 | { | |
293 | // Inherited from TObject. Prints the domain entry contents. | |
294 | // See header file for more information. | |
295 | ||
52f67e50 | 296 | cout << AsString().Data(); |
297 | TString opt(option); | |
298 | if (opt.Contains("noendl")) return; | |
299 | cout << endl; | |
300 | } | |
301 | ||
302 | ||
303 | TString AliHLTDomainEntry::AsString() const | |
304 | { | |
305 | // Returns a string representation of the domain entry. | |
306 | // See header file for more information. | |
307 | ||
308 | TString str; | |
dce3e5ce | 309 | if (strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0) |
310 | { | |
52f67e50 | 311 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) str += "*"; |
dce3e5ce | 312 | } |
313 | else | |
314 | { | |
315 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) | |
316 | { | |
317 | if (fType.fID[i] != '\0') | |
52f67e50 | 318 | str += fType.fID[i]; |
dce3e5ce | 319 | else |
52f67e50 | 320 | str += "\\0"; |
dce3e5ce | 321 | } |
322 | } | |
52f67e50 | 323 | str += ":"; |
dce3e5ce | 324 | if (strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0) |
325 | { | |
52f67e50 | 326 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) str += "*"; |
dce3e5ce | 327 | } |
328 | else | |
329 | { | |
330 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) | |
331 | { | |
332 | if (fType.fOrigin[i] != '\0') | |
52f67e50 | 333 | str += fType.fOrigin[i]; |
dce3e5ce | 334 | else |
52f67e50 | 335 | str += "\\0"; |
dce3e5ce | 336 | } |
337 | } | |
52f67e50 | 338 | str += ":"; |
dce3e5ce | 339 | if (fUseSpec) |
340 | { | |
52f67e50 | 341 | char num[16]; |
342 | sprintf(num, "0x%8.8X", fSpecification); | |
343 | str += num; | |
dce3e5ce | 344 | } |
345 | else | |
346 | { | |
52f67e50 | 347 | str += "**********"; |
dce3e5ce | 348 | } |
52f67e50 | 349 | return str; |
dce3e5ce | 350 | } |
351 | ||
2974f8dc | 352 | int AliHLTDomainEntry::AsBinary(AliHLTUInt32_t buffer[4]) const |
353 | { | |
354 | // convert the data type and specification to a 32 byte buffer | |
355 | if (!buffer) return -EINVAL; | |
356 | ||
357 | AliHLTUInt32_t* tgt=buffer; | |
358 | unsigned ii=0; | |
359 | ||
360 | // lower part of the data type id | |
361 | *tgt=0; | |
362 | for ( ii=0; ii<4; ii++ ) { | |
363 | *tgt |= ((AliHLTUInt32_t)(fType.fID[8-1-ii])) << (ii*8); | |
364 | } | |
365 | tgt++; | |
366 | ||
367 | // upper part of the data type id | |
368 | *tgt=0; | |
369 | for ( ii=0; ii<4; ii++ ) { | |
370 | *tgt |= ((AliHLTUInt32_t)(fType.fID[8-5-ii])) << (ii*8); | |
371 | } | |
372 | tgt++; | |
373 | ||
374 | // data type origin | |
375 | *tgt=0; | |
376 | for ( ii=0; ii<4; ii++ ) { | |
377 | *tgt |= ((AliHLTUInt32_t)(fType.fOrigin[4-1-ii])) << (ii*8); | |
378 | } | |
379 | tgt++; | |
380 | ||
381 | // specification | |
2959db22 | 382 | if (fUseSpec) |
383 | *tgt = fSpecification; | |
384 | else | |
385 | *tgt = kAliHLTVoidDataSpec; | |
2974f8dc | 386 | |
387 | return 0; | |
388 | } |