]>
Commit | Line | Data |
---|---|---|
4b31e06b | 1 | // $Id$ |
2 | ||
3 | //************************************************************************** | |
4 | //* This file is property of and copyright by the ALICE HLT Project * | |
5 | //* ALICE Experiment at CERN, All rights reserved. * | |
6 | //* * | |
7 | //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
8 | //* for The ALICE HLT Project. * | |
9 | //* * | |
10 | //* Permission to use, copy, modify and distribute this software and its * | |
11 | //* documentation strictly for non-commercial purposes is hereby granted * | |
12 | //* without fee, provided that the above copyright notice appears in all * | |
13 | //* copies and that both the copyright notice and this permission notice * | |
14 | //* appear in the supporting documentation. The authors make no claims * | |
15 | //* about the suitability of this software for any purpose. It is * | |
16 | //* provided "as is" without express or implied warranty. * | |
17 | //************************************************************************** | |
18 | ||
19 | /** @file AliHLTBlockDataCollection.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief A collection of AliHLTComponentBlockData descriptors providing | |
23 | argument parsing and basic selection. | |
24 | */ | |
25 | ||
26 | #include <cstdlib> | |
27 | #include "AliHLTBlockDataCollection.h" | |
28 | #include "AliHLTComponent.h" | |
29 | #include "TString.h" | |
30 | ||
31 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
32 | ClassImp(AliHLTBlockDataCollection) | |
33 | ||
34 | AliHLTBlockDataCollection::AliHLTBlockDataCollection() | |
35 | : TObject() | |
36 | , AliHLTLogging() | |
37 | , fFilterRules() | |
38 | { | |
39 | // see header file for class documentation | |
40 | // or | |
41 | // refer to README to build package | |
42 | // or | |
43 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
44 | } | |
45 | ||
46 | AliHLTBlockDataCollection::~AliHLTBlockDataCollection() | |
47 | { | |
48 | // see header file for class documentation | |
49 | } | |
50 | ||
51 | int AliHLTBlockDataCollection::Add(const AliHLTComponentBlockData& block) | |
52 | { | |
53 | // see header file for class documentation | |
54 | fFilterRules.push_back(block); | |
55 | return fFilterRules.size(); | |
56 | } | |
57 | ||
58 | int AliHLTBlockDataCollection::ScanArgument( int argc, const char** argv ) | |
59 | { | |
60 | // see header file for class documentation | |
61 | int iResult=0; | |
62 | TString argument=""; | |
63 | int bMissingParam=0; | |
64 | AliHLTComponentBlockData rule; | |
65 | AliHLTComponent::FillBlockData(rule); | |
66 | int i=0; | |
67 | for (; i<argc && iResult>=0; i++) { | |
68 | argument=argv[i]; | |
69 | if (argument.IsNull()) continue; | |
70 | ||
71 | // -datatype | |
72 | if (argument.CompareTo("-datatype")==0) { | |
73 | if ((bMissingParam=(i+2>=argc))) break; | |
74 | ||
75 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
76 | // the data type has already been set, add to list | |
77 | // and reset | |
78 | fFilterRules.push_back(rule); | |
79 | AliHLTComponent::FillBlockData(rule); | |
80 | } | |
81 | ||
82 | AliHLTComponent::SetDataType(rule.fDataType, argv[i+1], argv[i+2]); | |
83 | i+=2; | |
84 | ||
85 | // -origin | |
86 | } else if (argument.CompareTo("-origin")==0) { | |
87 | if ((bMissingParam=(i+1>=argc))) break; | |
88 | ||
89 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
90 | // the data type has already been set, add to list | |
91 | // and reset | |
92 | fFilterRules.push_back(rule); | |
93 | AliHLTComponent::FillBlockData(rule); | |
94 | } | |
95 | ||
96 | AliHLTComponent::SetDataType(rule.fDataType, NULL, argv[i+1]); | |
97 | i+=1; | |
98 | ||
99 | // -typeid | |
100 | } else if (argument.CompareTo("-typeid")==0) { | |
101 | if ((bMissingParam=(i+1>=argc))) break; | |
102 | ||
103 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
104 | // the data type has already been set, add to list | |
105 | // and reset | |
106 | fFilterRules.push_back(rule); | |
107 | AliHLTComponent::FillBlockData(rule); | |
108 | } | |
109 | ||
110 | AliHLTComponent::SetDataType(rule.fDataType, argv[i+1], NULL); | |
111 | i+=1; | |
112 | ||
113 | // -dataspec | |
114 | } else if (argument.CompareTo("-dataspec")==0) { | |
115 | if ((bMissingParam=(++i>=argc))) break; | |
116 | ||
117 | if (rule.fSpecification!=kAliHLTVoidDataSpec) { | |
118 | // the specification has already been set, add to list | |
119 | // and reset | |
120 | fFilterRules.push_back(rule); | |
121 | AliHLTComponent::FillBlockData(rule); | |
122 | } | |
123 | ||
124 | TString parameter(argv[i]); | |
125 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
126 | char* pRemnant=NULL; | |
127 | rule.fSpecification=strtoul(parameter.Data(), &pRemnant, 0); | |
128 | if (pRemnant!=NULL && pRemnant[0]!=0) { | |
129 | HLTError("invalid parameter/remnant (%s) for argument %s, number expected", pRemnant, argument.Data()); | |
130 | iResult=-EINVAL; | |
131 | } | |
132 | } else { | |
133 | // terminate at the first unknown argument | |
134 | break; | |
135 | } | |
136 | } | |
137 | ||
138 | if (bMissingParam) { | |
139 | HLTError("missing parameter for argument %s", argument.Data()); | |
140 | iResult=-EPROTO; | |
141 | } | |
142 | if (iResult>=0) { | |
143 | if (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
144 | // add the pending rule | |
145 | fFilterRules.push_back(rule); | |
146 | AliHLTComponent::FillBlockData(rule); | |
147 | } | |
148 | iResult=i; | |
149 | } | |
150 | ||
151 | return iResult; | |
152 | } | |
153 | ||
154 | int AliHLTBlockDataCollection::IsSelected(const AliHLTComponentBlockData& block) | |
155 | { | |
156 | // see header file for class documentation | |
157 | AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin(); | |
158 | //HLTDebug("check block: %s spec %#x", DataType2Text(block.fDataType, 1).c_str(), block.fSpecification); | |
159 | if (desc==fFilterRules.end()) return 1; // no filter rules | |
160 | do { | |
161 | // match if | |
162 | // 1. data types match or filter data type not set | |
163 | // 2. data spec match or filter data wpec not set | |
164 | // 3. either filter data type or spec is set | |
165 | //HLTDebug("check rule : %s spec %#x", DataType2Text((*desc).fDataType, 2).c_str(), block.fSpecification); | |
166 | if (((*desc).fDataType==block.fDataType) && | |
167 | ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) && | |
168 | (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) { | |
169 | return 1; | |
170 | } | |
171 | } while (++desc!=fFilterRules.end()); | |
172 | ||
173 | return 0; | |
174 | } | |
175 | ||
176 | int AliHLTBlockDataCollection::IsEmpty() | |
177 | { | |
178 | // see header file for class documentation | |
179 | if (fFilterRules.size()==0) return 1; | |
180 | return 0; | |
181 | } |