Line data Source code
1 : // $Id$
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>
38 : #include <cerrno>
39 :
40 126 : ClassImp(AliHLTDomainEntry)
41 :
42 :
43 : AliHLTDomainEntry::AliHLTDomainEntry() :
44 6 : TObject(),
45 6 : fExclude(kFALSE),
46 6 : fUseSpec(kFALSE),
47 6 : fType(kAliHLTVoidDataType),
48 6 : fSpecification(kAliHLTVoidDataSpec)
49 30 : {
50 : // Default constructor.
51 12 : }
52 :
53 : AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTDomainEntry& domain) :
54 0 : TObject(domain),
55 0 : fExclude(domain.fExclude),
56 0 : fUseSpec(domain.fUseSpec),
57 0 : fType(domain.fType),
58 0 : fSpecification(domain.fSpecification)
59 0 : {
60 : // Copy constructor performs a deep copy.
61 0 : }
62 :
63 :
64 : AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTComponentDataType& type) :
65 48 : TObject(),
66 48 : fExclude(kFALSE),
67 48 : fUseSpec(kFALSE),
68 48 : fType(type),
69 48 : fSpecification(kAliHLTVoidDataSpec)
70 240 : {
71 : // Constructs a domain entry with a particular data type and any specification.
72 : // See header file for more information.
73 96 : }
74 :
75 :
76 : AliHLTDomainEntry::AliHLTDomainEntry(const char* blocktype, const char* origin) :
77 0 : TObject(),
78 0 : fExclude(kFALSE),
79 0 : fUseSpec(kFALSE),
80 0 : fType(),
81 0 : fSpecification(kAliHLTVoidDataSpec)
82 0 : {
83 : // Constructs a domain entry with a particular data type and any specification.
84 : // See header file for more information.
85 :
86 0 : char id[kAliHLTComponentDataTypefIDsize];
87 0 : memset(&id, 0x0, sizeof(id));
88 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++)
89 : {
90 0 : id[i] = blocktype[i];
91 : }
92 0 : fType = AliHLTComponentDataTypeInitializer(id, origin);
93 0 : }
94 :
95 :
96 : AliHLTDomainEntry::AliHLTDomainEntry(const AliHLTComponentDataType& type, UInt_t spec) :
97 0 : TObject(),
98 0 : fExclude(kFALSE),
99 0 : fUseSpec(kTRUE),
100 0 : fType(type),
101 0 : fSpecification(spec)
102 0 : {
103 : // Constructs a domain entry with a particular data type and specification.
104 : // See header file for more information.
105 0 : }
106 :
107 :
108 : AliHLTDomainEntry::AliHLTDomainEntry(const char* blocktype, const char* origin, UInt_t spec) :
109 0 : TObject(),
110 0 : fExclude(kFALSE),
111 0 : fUseSpec(kTRUE),
112 0 : fType(),
113 0 : fSpecification(spec)
114 0 : {
115 : // Constructs a domain entry with a particular data type and specification.
116 : // See header file for more information.
117 :
118 0 : char id[kAliHLTComponentDataTypefIDsize];
119 0 : memset(&id, 0x0, sizeof(id));
120 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++)
121 : {
122 0 : id[i] = blocktype[i];
123 : }
124 0 : fType = AliHLTComponentDataTypeInitializer(id, origin);
125 0 : }
126 :
127 :
128 : AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTDomainEntry& domain) :
129 0 : TObject(domain),
130 0 : fExclude(exclude),
131 0 : fUseSpec(domain.fUseSpec),
132 0 : fType(domain.fType),
133 0 : fSpecification(domain.fSpecification)
134 0 : {
135 : // Constructs a domain entry from an existing one but with the exclude flag set.
136 : // See header file for more information.
137 0 : }
138 :
139 :
140 : AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTComponentDataType& type) :
141 0 : TObject(),
142 0 : fExclude(exclude),
143 0 : fUseSpec(kFALSE),
144 0 : fType(type),
145 0 : fSpecification(kAliHLTVoidDataSpec)
146 0 : {
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 0 : }
151 :
152 :
153 : AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const char* blocktype, const char* origin) :
154 0 : TObject(),
155 0 : fExclude(exclude),
156 0 : fUseSpec(kFALSE),
157 0 : fType(),
158 0 : fSpecification(kAliHLTVoidDataSpec)
159 0 : {
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 0 : char id[kAliHLTComponentDataTypefIDsize];
165 0 : memset(&id, 0x0, sizeof(id));
166 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++)
167 : {
168 0 : id[i] = blocktype[i];
169 : }
170 0 : fType = AliHLTComponentDataTypeInitializer(id, origin);
171 0 : }
172 :
173 :
174 : AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const AliHLTComponentDataType& type, UInt_t spec) :
175 0 : TObject(),
176 0 : fExclude(exclude),
177 0 : fUseSpec(kTRUE),
178 0 : fType(type),
179 0 : fSpecification(spec)
180 0 : {
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 0 : }
185 :
186 :
187 : AliHLTDomainEntry::AliHLTDomainEntry(Bool_t exclude, const char* blocktype, const char* origin, UInt_t spec) :
188 0 : TObject(),
189 0 : fExclude(exclude),
190 0 : fUseSpec(kTRUE),
191 0 : fType(),
192 0 : fSpecification(spec)
193 0 : {
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 0 : char id[kAliHLTComponentDataTypefIDsize];
199 0 : memset(&id, 0x0, sizeof(id));
200 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize && blocktype[i] != '\0'; i++)
201 : {
202 0 : id[i] = blocktype[i];
203 : }
204 0 : fType = AliHLTComponentDataTypeInitializer(id, origin);
205 0 : }
206 :
207 :
208 : AliHLTDomainEntry::~AliHLTDomainEntry()
209 12 : {
210 : // Default destructor.
211 14 : }
212 :
213 :
214 : AliHLTDomainEntry& AliHLTDomainEntry::operator = (const AliHLTDomainEntry& domain)
215 : {
216 : // The copy operator performs a deep copy.
217 :
218 0 : if (this==&domain) return *this;
219 0 : TObject::operator = (domain);
220 0 : fType = domain.fType;
221 0 : fUseSpec = domain.fUseSpec;
222 0 : fSpecification = domain.fSpecification;
223 0 : return *this;
224 0 : }
225 :
226 :
227 : bool AliHLTDomainEntry::IdenticalTo(const AliHLTDomainEntry& rhs) const
228 : {
229 : // Checks if this domain entry is identical to 'rhs' and do not just have a
230 : // set intersection.
231 : // See header file for more information.
232 :
233 0 : if (not MatchExactly(fType, rhs.fType)) return false;
234 0 : return (fUseSpec == rhs.fUseSpec) and (fSpecification == rhs.fSpecification);
235 0 : }
236 :
237 :
238 : bool AliHLTDomainEntry::SubsetOf(const AliHLTDomainEntry& rhs) const
239 : {
240 : // Checks if this domain entry is a subset of 'rhs'.
241 : // See header file for more information.
242 :
243 0 : if (*this != rhs) return false;
244 0 : bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
245 0 : bool rhsTypeIsAny = strncmp(&rhs.fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
246 0 : if (thisTypeIsAny and not rhsTypeIsAny) return false;
247 0 : bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
248 0 : bool rhsOriginIsAny = strncmp(&rhs.fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
249 0 : if (thisOriginIsAny and not rhsOriginIsAny) return false;
250 0 : bool thisSpecIsAny = not fUseSpec;
251 0 : bool rhsSpecIsAny = not rhs.fUseSpec;
252 0 : if (thisSpecIsAny and not rhsSpecIsAny) return false;
253 0 : return true;
254 0 : }
255 :
256 :
257 : bool AliHLTDomainEntry::IntersectWith(const AliHLTDomainEntry& rhs, AliHLTDomainEntry& result) const
258 : {
259 : // Finds the set intersection between this domain entry and 'rhs'.
260 : // See header file for more information.
261 :
262 0 : if (*this != rhs) return false;
263 0 : bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
264 0 : bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
265 0 : bool thisSpecIsAny = not fUseSpec;
266 0 : const AliHLTComponentDataType& type = (not thisTypeIsAny) ? fType : rhs.fType;
267 0 : const AliHLTComponentDataType& origin = (not thisOriginIsAny) ? fType : rhs.fType;
268 : Bool_t useSpec;
269 : UInt_t spec;
270 0 : if (not thisSpecIsAny)
271 : {
272 0 : useSpec = fUseSpec;
273 0 : spec = fSpecification;
274 0 : }
275 : else
276 : {
277 0 : useSpec = rhs.fUseSpec;
278 0 : spec = rhs.fSpecification;
279 : }
280 0 : if (useSpec)
281 : {
282 0 : result = AliHLTDomainEntry(type | origin.fOrigin, spec);
283 0 : }
284 : else
285 : {
286 0 : result = AliHLTDomainEntry(type | origin.fOrigin);
287 : }
288 : return true;
289 0 : }
290 :
291 :
292 : void AliHLTDomainEntry::Print(Option_t* option) const
293 : {
294 : // Inherited from TObject. Prints the domain entry contents.
295 : // See header file for more information.
296 :
297 0 : cout << AsString().Data();
298 0 : TString opt(option);
299 0 : if (opt.Contains("noendl")) return;
300 0 : cout << endl;
301 0 : }
302 :
303 :
304 : TString AliHLTDomainEntry::AsString() const
305 : {
306 : // Returns a string representation of the domain entry.
307 : // See header file for more information.
308 :
309 0 : TString str;
310 0 : if (strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0)
311 : {
312 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) str += "*";
313 0 : }
314 : else
315 : {
316 0 : for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
317 : {
318 0 : if (fType.fID[i] != '\0')
319 0 : str += fType.fID[i];
320 : else
321 0 : str += "\\0";
322 : }
323 : }
324 0 : str += ":";
325 0 : if (strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0)
326 : {
327 0 : for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) str += "*";
328 0 : }
329 : else
330 : {
331 0 : for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
332 : {
333 0 : if (fType.fOrigin[i] != '\0')
334 0 : str += fType.fOrigin[i];
335 : else
336 0 : str += "\\0";
337 : }
338 : }
339 0 : str += ":";
340 0 : if (fUseSpec)
341 : {
342 0 : char num[16];
343 0 : sprintf(num, "0x%8.8X", fSpecification);
344 0 : str += num;
345 0 : }
346 : else
347 : {
348 0 : str += "**********";
349 : }
350 : return str;
351 0 : }
352 :
353 : int AliHLTDomainEntry::AsBinary(AliHLTUInt32_t buffer[4]) const
354 : {
355 : // convert the data type and specification to a 32 byte buffer
356 0 : if (!buffer) return -EINVAL;
357 :
358 : AliHLTUInt32_t* tgt=buffer;
359 : unsigned ii=0;
360 :
361 : // lower part of the data type id
362 0 : *tgt=0;
363 0 : for ( ii=0; ii<4; ii++ ) {
364 0 : *tgt |= ((AliHLTUInt32_t)(fType.fID[8-1-ii])) << (ii*8);
365 : }
366 0 : tgt++;
367 :
368 : // upper part of the data type id
369 0 : *tgt=0;
370 0 : for ( ii=0; ii<4; ii++ ) {
371 0 : *tgt |= ((AliHLTUInt32_t)(fType.fID[8-5-ii])) << (ii*8);
372 : }
373 0 : tgt++;
374 :
375 : // data type origin
376 0 : *tgt=0;
377 0 : for ( ii=0; ii<4; ii++ ) {
378 0 : *tgt |= ((AliHLTUInt32_t)(fType.fOrigin[4-1-ii])) << (ii*8);
379 : }
380 0 : tgt++;
381 :
382 : // specification
383 0 : if (fUseSpec)
384 0 : *tgt = fSpecification;
385 : else
386 0 : *tgt = kAliHLTVoidDataSpec;
387 :
388 : return 0;
389 0 : }
|