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()
36 // see header file for class documentation
38 // refer to README to build package
40 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43 AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent()
45 // see header file for class documentation
48 void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
50 // see header file for class documentation
52 list.push_back(kAliHLTAnyDataType);
55 AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType()
57 // see header file for class documentation
58 if (fFilterRules.size()==1) return fFilterRules[0].fDataType;
59 if (fFilterRules.size()==0) return kAliHLTVoidDataType;
60 return kAliHLTMultipleDataType;
63 int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
65 // see header file for class documentation
67 AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
68 while (desc!=fFilterRules.end()) {
69 AliHLTComponentDataTypeList::iterator type=tgtList.begin();
70 while (type!=tgtList.end()) {
71 if (*type==(*desc).fDataType) break;
74 if (type==tgtList.end()) tgtList.push_back((*desc).fDataType);
77 return tgtList.size();
80 void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
82 // see header file for class documentation
84 inputMultiplier=0.0; // there is no new data, just forwarded descriptors
87 int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv )
92 AliHLTComponentBlockData rule;
94 for (int i=0; i<argc && iResult>=0; i++) {
96 if (argument.IsNull()) continue;
99 if (argument.CompareTo("-datatype")==0) {
100 if ((bMissingParam=(i+2>=argc))) break;
102 if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
103 // the data type has already been set, add to list
105 fFilterRules.push_back(rule);
109 SetDataType(rule.fDataType, argv[i+1], argv[i+2]);
113 } else if (argument.CompareTo("-dataspec")==0) {
114 if ((bMissingParam=(++i>=argc))) break;
116 if (rule.fSpecification!=kAliHLTVoidDataSpec) {
117 // the specification has already been set, add to list
119 fFilterRules.push_back(rule);
123 TString parameter(argv[i]);
124 parameter.Remove(TString::kLeading, ' '); // remove all blanks
126 rule.fSpecification=strtoul(parameter.Data(), &pRemnant, 0);
127 if (pRemnant!=NULL && pRemnant[0]!=0) {
128 HLTError("invalid parameter/remnant (%s) for argument %s, number expected", pRemnant, argument.Data());
132 HLTError("unknown argument %s", argument.Data());
137 if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType))) {
138 // add the pending rule
139 fFilterRules.push_back(rule);
145 int AliHLTBlockFilterComponent::DoDeinit()
148 fFilterRules.clear();
152 int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
153 const AliHLTComponentBlockData* /*blocks*/,
154 AliHLTComponentTriggerData& /*trigData*/,
155 AliHLTUInt8_t* /*outputPtr*/,
156 AliHLTUInt32_t& size,
157 AliHLTComponentBlockDataList& /*outputBlocks*/ )
159 // see header file for class documentation
161 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
163 pBlock=GetNextInputBlock()) {
164 if (IsSelected(*pBlock)) {
165 HLTDebug("block type %s %#x (ptr=%p offset=%d size=%d) selected by filter rules",
166 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
167 pBlock->fPtr, pBlock->fOffset, pBlock->fSize);
170 HLTDebug("block type %s %#x discarded by filter rules", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification);
177 int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block)
179 // see header file for class documentation
180 AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
181 //HLTDebug("check block: %s spec %#x", DataType2Text(block.fDataType, 1).c_str(), block.fSpecification);
182 if (desc==fFilterRules.end()) return 1; // no filter rules
185 // 1. data types match or filter data type not set
186 // 2. data spec match or filter data wpec not set
187 // 3. either filter data type or spec is set
188 //HLTDebug("check rule : %s spec %#x", DataType2Text((*desc).fDataType, 2).c_str(), block.fSpecification);
189 if (((*desc).fDataType==block.fDataType) &&
190 ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) &&
191 (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) {
194 } while (++desc!=fFilterRules.end());