]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTDomainEntry.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDomainEntry.cxx
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 ClassImp(AliHLTDomainEntry)
41
42
43 AliHLTDomainEntry::AliHLTDomainEntry() :
44   TObject(),
45   fExclude(kFALSE),
46   fUseSpec(kFALSE),
47   fType(kAliHLTVoidDataType),
48   fSpecification(kAliHLTVoidDataSpec)
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),
69   fSpecification(kAliHLTVoidDataSpec)
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(),
81   fSpecification(kAliHLTVoidDataSpec)
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),
145   fSpecification(kAliHLTVoidDataSpec)
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(),
158   fSpecification(kAliHLTVoidDataSpec)
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   if (this==&domain) return *this;
219   TObject::operator = (domain);
220   fType = domain.fType;
221   fUseSpec = domain.fUseSpec;
222   fSpecification = domain.fSpecification;
223   return *this;
224 }
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   if (not MatchExactly(fType, rhs.fType)) return false;
234   return (fUseSpec == rhs.fUseSpec) and (fSpecification == rhs.fSpecification);
235 }
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   if (*this != rhs) return false;
244   bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
245   bool rhsTypeIsAny = strncmp(&rhs.fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
246   if (thisTypeIsAny and not rhsTypeIsAny) return false;
247   bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
248   bool rhsOriginIsAny = strncmp(&rhs.fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
249   if (thisOriginIsAny and not rhsOriginIsAny) return false;
250   bool thisSpecIsAny = not fUseSpec;
251   bool rhsSpecIsAny = not rhs.fUseSpec;
252   if (thisSpecIsAny and not rhsSpecIsAny) return false;
253   return true;
254 }
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   if (*this != rhs) return false;
263   bool thisTypeIsAny = strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0;
264   bool thisOriginIsAny = strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0;
265   bool thisSpecIsAny = not fUseSpec;
266   const AliHLTComponentDataType& type = (not thisTypeIsAny) ? fType : rhs.fType;
267   const AliHLTComponentDataType& origin = (not thisOriginIsAny) ? fType : rhs.fType;
268   Bool_t useSpec;
269   UInt_t spec;
270   if (not thisSpecIsAny)
271   {
272     useSpec = fUseSpec;
273     spec = fSpecification;
274   }
275   else
276   {
277     useSpec = rhs.fUseSpec;
278     spec = rhs.fSpecification;
279   }
280   if (useSpec)
281   {
282     result = AliHLTDomainEntry(type | origin.fOrigin, spec);
283   }
284   else
285   {
286     result = AliHLTDomainEntry(type | origin.fOrigin);
287   }
288   return true;
289 }
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   cout << AsString().Data();
298   TString opt(option);
299   if (opt.Contains("noendl")) return;
300   cout << endl;
301 }
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   TString str;
310   if (strncmp(&fType.fID[0], kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize) == 0)
311   {
312     for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) str += "*";
313   }
314   else
315   {
316     for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
317     {
318       if (fType.fID[i] != '\0')
319         str += fType.fID[i];
320       else
321         str += "\\0";
322     }
323   }
324   str += ":";
325   if (strncmp(&fType.fOrigin[0], kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize) == 0)
326   {
327     for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) str += "*";
328   }
329   else
330   {
331     for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
332     {
333       if (fType.fOrigin[i] != '\0')
334         str += fType.fOrigin[i];
335       else
336         str += "\\0";
337     }
338   }
339   str += ":";
340   if (fUseSpec)
341   {
342     char num[16];
343     sprintf(num, "0x%8.8X", fSpecification);
344     str += num;
345   }
346   else
347   {
348     str += "**********";
349   }
350   return str;
351 }
352
353 int AliHLTDomainEntry::AsBinary(AliHLTUInt32_t buffer[4]) const
354 {
355   // convert the data type and specification to a 32 byte buffer
356   if (!buffer) return -EINVAL;
357
358   AliHLTUInt32_t* tgt=buffer; 
359   unsigned ii=0;
360
361   // lower part of the data type id
362   *tgt=0;
363   for ( ii=0; ii<4; ii++ ) {
364     *tgt |= ((AliHLTUInt32_t)(fType.fID[8-1-ii])) << (ii*8);
365   }
366   tgt++;
367           
368   // upper part of the data type id
369   *tgt=0;
370   for ( ii=0; ii<4; ii++ ) {
371     *tgt |= ((AliHLTUInt32_t)(fType.fID[8-5-ii])) << (ii*8);
372   }
373   tgt++;
374   
375   // data type origin
376   *tgt=0;
377   for ( ii=0; ii<4; ii++ ) {
378     *tgt |= ((AliHLTUInt32_t)(fType.fOrigin[4-1-ii])) << (ii*8);
379   }
380   tgt++;
381   
382   // specification
383   if (fUseSpec)
384     *tgt = fSpecification;
385   else
386     *tgt = kAliHLTVoidDataSpec;
387
388   return 0;
389 }