]>
Commit | Line | Data |
---|---|---|
4b31e06b | 1 | // $Id$ |
9bf94558 | 2 | |
c1292031 | 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 | //************************************************************************** | |
9bf94558 | 18 | |
19 | /** @file AliHLTBlockFilterComponent.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief A simple data block filter and merger, merges block descriptors | |
c1292031 | 23 | */ |
9bf94558 | 24 | |
25 | #include <cstdlib> | |
26 | #include "AliHLTBlockFilterComponent.h" | |
27 | #include "TString.h" | |
28 | ||
29 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
30 | ClassImp(AliHLTBlockFilterComponent) | |
31 | ||
32 | AliHLTBlockFilterComponent::AliHLTBlockFilterComponent() | |
6dc62e29 | 33 | : AliHLTProcessor() |
34 | , fFilterRules() | |
35 | , fPrescalar(0) | |
36 | , fFirstEvent(0) | |
9bf94558 | 37 | { |
38 | // see header file for class documentation | |
39 | // or | |
40 | // refer to README to build package | |
41 | // or | |
42 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
43 | } | |
44 | ||
45 | AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent() | |
46 | { | |
47 | // see header file for class documentation | |
48 | } | |
49 | ||
50 | void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) | |
51 | { | |
52 | // see header file for class documentation | |
53 | list.clear(); | |
54 | list.push_back(kAliHLTAnyDataType); | |
55 | } | |
56 | ||
57 | AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType() | |
58 | { | |
59 | // see header file for class documentation | |
60 | if (fFilterRules.size()==1) return fFilterRules[0].fDataType; | |
c57201be | 61 | if (fFilterRules.size()==0) return kAliHLTAnyDataType; |
9bf94558 | 62 | return kAliHLTMultipleDataType; |
63 | } | |
64 | ||
65 | int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
66 | { | |
67 | // see header file for class documentation | |
68 | tgtList.clear(); | |
69 | AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin(); | |
70 | while (desc!=fFilterRules.end()) { | |
71 | AliHLTComponentDataTypeList::iterator type=tgtList.begin(); | |
72 | while (type!=tgtList.end()) { | |
73 | if (*type==(*desc).fDataType) break; | |
74 | type++; | |
75 | } | |
76 | if (type==tgtList.end()) tgtList.push_back((*desc).fDataType); | |
77 | desc++; | |
78 | } | |
79 | return tgtList.size(); | |
80 | } | |
81 | ||
82 | void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
83 | { | |
84 | // see header file for class documentation | |
85 | constBase=0; | |
86 | inputMultiplier=0.0; // there is no new data, just forwarded descriptors | |
87 | } | |
88 | ||
89 | int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv ) | |
90 | { | |
91 | int iResult=0; | |
92 | TString argument=""; | |
93 | int bMissingParam=0; | |
94 | AliHLTComponentBlockData rule; | |
95 | FillBlockData(rule); | |
96 | for (int i=0; i<argc && iResult>=0; i++) { | |
97 | argument=argv[i]; | |
98 | if (argument.IsNull()) continue; | |
99 | ||
100 | // -datatype | |
101 | if (argument.CompareTo("-datatype")==0) { | |
102 | if ((bMissingParam=(i+2>=argc))) break; | |
103 | ||
d8f5c9fe | 104 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { |
9bf94558 | 105 | // the data type has already been set, add to list |
106 | // and reset | |
107 | fFilterRules.push_back(rule); | |
108 | FillBlockData(rule); | |
109 | } | |
110 | ||
111 | SetDataType(rule.fDataType, argv[i+1], argv[i+2]); | |
112 | i+=2; | |
113 | ||
a7ad9794 | 114 | // -origin |
115 | } else if (argument.CompareTo("-origin")==0) { | |
116 | if ((bMissingParam=(i+1>=argc))) break; | |
117 | ||
118 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
119 | // the data type has already been set, add to list | |
120 | // and reset | |
121 | fFilterRules.push_back(rule); | |
122 | FillBlockData(rule); | |
123 | } | |
124 | ||
125 | SetDataType(rule.fDataType, NULL, argv[i+1]); | |
126 | i+=1; | |
127 | ||
128 | // -typeid | |
129 | } else if (argument.CompareTo("-typeid")==0) { | |
130 | if ((bMissingParam=(i+1>=argc))) break; | |
131 | ||
132 | if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) { | |
133 | // the data type has already been set, add to list | |
134 | // and reset | |
135 | fFilterRules.push_back(rule); | |
136 | FillBlockData(rule); | |
137 | } | |
138 | ||
139 | SetDataType(rule.fDataType, argv[i+1], NULL); | |
140 | i+=1; | |
141 | ||
9bf94558 | 142 | // -dataspec |
143 | } else if (argument.CompareTo("-dataspec")==0) { | |
144 | if ((bMissingParam=(++i>=argc))) break; | |
145 | ||
146 | if (rule.fSpecification!=kAliHLTVoidDataSpec) { | |
147 | // the specification has already been set, add to list | |
148 | // and reset | |
149 | fFilterRules.push_back(rule); | |
150 | FillBlockData(rule); | |
151 | } | |
152 | ||
153 | TString parameter(argv[i]); | |
154 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
155 | char* pRemnant=NULL; | |
156 | rule.fSpecification=strtoul(parameter.Data(), &pRemnant, 0); | |
157 | if (pRemnant!=NULL && pRemnant[0]!=0) { | |
158 | HLTError("invalid parameter/remnant (%s) for argument %s, number expected", pRemnant, argument.Data()); | |
159 | iResult=-EINVAL; | |
160 | } | |
6dc62e29 | 161 | // -prescalar |
162 | } else if (argument.CompareTo("-prescalar")==0) { | |
163 | if ((bMissingParam=(++i>=argc))) break; | |
164 | TString parameter(argv[i]); | |
165 | fPrescalar=parameter.Atoi(); | |
166 | // -skip-events | |
167 | } else if (argument.CompareTo("-skip-events")==0) { | |
168 | if ((bMissingParam=(++i>=argc))) break; | |
169 | TString parameter(argv[i]); | |
170 | fFirstEvent=parameter.Atoi(); | |
9bf94558 | 171 | } else { |
172 | HLTError("unknown argument %s", argument.Data()); | |
173 | iResult=-EINVAL; | |
174 | break; | |
175 | } | |
176 | } | |
d8f5c9fe | 177 | if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType))) { |
9bf94558 | 178 | // add the pending rule |
179 | fFilterRules.push_back(rule); | |
180 | FillBlockData(rule); | |
181 | } | |
182 | return iResult; | |
183 | } | |
184 | ||
185 | int AliHLTBlockFilterComponent::DoDeinit() | |
186 | { | |
187 | int iResult=0; | |
188 | fFilterRules.clear(); | |
189 | return iResult; | |
190 | } | |
191 | ||
b0914d2e | 192 | int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, |
193 | const AliHLTComponentBlockData* /*blocks*/, | |
9bf94558 | 194 | AliHLTComponentTriggerData& /*trigData*/, |
195 | AliHLTUInt8_t* /*outputPtr*/, | |
196 | AliHLTUInt32_t& size, | |
b0914d2e | 197 | AliHLTComponentBlockDataList& /*outputBlocks*/ ) |
9bf94558 | 198 | { |
199 | // see header file for class documentation | |
200 | int iResult=0; | |
6dc62e29 | 201 | if ((fPrescalar==0 || ((GetEventCount())%fPrescalar)==0) && |
f0c71181 | 202 | GetEventCount()>=(int)fFirstEvent) { |
c7e9e2f2 | 203 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(); |
204 | pBlock!=NULL; | |
205 | pBlock=GetNextInputBlock()) { | |
206 | if (IsSelected(*pBlock)) { | |
207 | HLTDebug("block type %s %#x (ptr=%p offset=%d size=%d) selected by filter rules", | |
208 | DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, | |
209 | pBlock->fPtr, pBlock->fOffset, pBlock->fSize); | |
210 | Forward(); | |
9bf94558 | 211 | } else { |
c7e9e2f2 | 212 | HLTDebug("block type %s %#x discarded by filter rules", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification); |
9bf94558 | 213 | } |
6dc62e29 | 214 | } |
9bf94558 | 215 | } |
216 | size=0; | |
217 | return iResult; | |
218 | } | |
219 | ||
220 | int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block) | |
221 | { | |
222 | // see header file for class documentation | |
223 | AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin(); | |
224 | //HLTDebug("check block: %s spec %#x", DataType2Text(block.fDataType, 1).c_str(), block.fSpecification); | |
225 | if (desc==fFilterRules.end()) return 1; // no filter rules | |
226 | do { | |
227 | // match if | |
228 | // 1. data types match or filter data type not set | |
229 | // 2. data spec match or filter data wpec not set | |
230 | // 3. either filter data type or spec is set | |
231 | //HLTDebug("check rule : %s spec %#x", DataType2Text((*desc).fDataType, 2).c_str(), block.fSpecification); | |
d8f5c9fe | 232 | if (((*desc).fDataType==block.fDataType) && |
9bf94558 | 233 | ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) && |
d8f5c9fe | 234 | (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) { |
9bf94558 | 235 | return 1; |
236 | } | |
237 | } while (++desc!=fFilterRules.end()); | |
238 | ||
239 | return 0; | |
240 | } |