3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTBlockFilterComponent.cxx
20 @author Matthias Richter
22 @brief A simple data block filter and merger, merges block descriptors
26 #include "AliHLTBlockFilterComponent.h"
29 /** ROOT macro for the implementation of ROOT specific class methods */
30 ClassImp(AliHLTBlockFilterComponent)
32 AliHLTBlockFilterComponent::AliHLTBlockFilterComponent()
38 // see header file for class documentation
40 // refer to README to build package
42 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45 AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent()
47 // see header file for class documentation
50 void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
52 // see header file for class documentation
54 list.push_back(kAliHLTAnyDataType);
57 AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType()
59 // see header file for class documentation
60 if (fFilterRules.size()==1) return fFilterRules[0].fDataType;
61 if (fFilterRules.size()==0) return kAliHLTAnyDataType;
62 return kAliHLTMultipleDataType;
65 int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
67 // see header file for class documentation
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;
76 if (type==tgtList.end()) tgtList.push_back((*desc).fDataType);
79 return tgtList.size();
82 void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
84 // see header file for class documentation
86 inputMultiplier=0.0; // there is no new data, just forwarded descriptors
89 int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv )
94 AliHLTComponentBlockData rule;
96 for (int i=0; i<argc && iResult>=0; i++) {
98 if (argument.IsNull()) continue;
101 if (argument.CompareTo("-datatype")==0) {
102 if ((bMissingParam=(i+2>=argc))) break;
104 if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
105 // the data type has already been set, add to list
107 fFilterRules.push_back(rule);
111 SetDataType(rule.fDataType, argv[i+1], argv[i+2]);
115 } else if (argument.CompareTo("-origin")==0) {
116 if ((bMissingParam=(i+1>=argc))) break;
118 if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
119 // the data type has already been set, add to list
121 fFilterRules.push_back(rule);
125 SetDataType(rule.fDataType, NULL, argv[i+1]);
129 } else if (argument.CompareTo("-typeid")==0) {
130 if ((bMissingParam=(i+1>=argc))) break;
132 if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
133 // the data type has already been set, add to list
135 fFilterRules.push_back(rule);
139 SetDataType(rule.fDataType, argv[i+1], NULL);
143 } else if (argument.CompareTo("-dataspec")==0) {
144 if ((bMissingParam=(++i>=argc))) break;
146 if (rule.fSpecification!=kAliHLTVoidDataSpec) {
147 // the specification has already been set, add to list
149 fFilterRules.push_back(rule);
153 TString parameter(argv[i]);
154 parameter.Remove(TString::kLeading, ' '); // remove all blanks
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());
162 } else if (argument.CompareTo("-prescalar")==0) {
163 if ((bMissingParam=(++i>=argc))) break;
164 TString parameter(argv[i]);
165 fPrescalar=parameter.Atoi();
167 } else if (argument.CompareTo("-skip-events")==0) {
168 if ((bMissingParam=(++i>=argc))) break;
169 TString parameter(argv[i]);
170 fFirstEvent=parameter.Atoi();
172 HLTError("unknown argument %s", argument.Data());
177 if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType))) {
178 // add the pending rule
179 fFilterRules.push_back(rule);
185 int AliHLTBlockFilterComponent::DoDeinit()
188 fFilterRules.clear();
192 int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
193 const AliHLTComponentBlockData* /*blocks*/,
194 AliHLTComponentTriggerData& /*trigData*/,
195 AliHLTUInt8_t* /*outputPtr*/,
196 AliHLTUInt32_t& size,
197 AliHLTComponentBlockDataList& /*outputBlocks*/ )
199 // see header file for class documentation
201 if ((fPrescalar==0 || ((GetEventCount())%fPrescalar)==0) &&
202 GetEventCount()>=fFirstEvent) {
203 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
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);
212 HLTDebug("block type %s %#x discarded by filter rules", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification);
220 int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block)
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
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);
232 if (((*desc).fDataType==block.fDataType) &&
233 ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) &&
234 (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) {
237 } while (++desc!=fFilterRules.end());