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
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32 #include "AliHLTBlockFilterComponent.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTBlockFilterComponent)
38 AliHLTBlockFilterComponent::AliHLTBlockFilterComponent()
42 // see header file for class documentation
44 // refer to README to build package
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49 AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent()
51 // see header file for class documentation
54 void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
56 // see header file for class documentation
58 list.push_back(kAliHLTAnyDataType);
61 AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType()
63 // see header file for class documentation
64 if (fFilterRules.size()==1) return fFilterRules[0].fDataType;
65 if (fFilterRules.size()==0) return kAliHLTVoidDataType;
66 return kAliHLTMultipleDataType;
69 int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
71 // see header file for class documentation
73 AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
74 while (desc!=fFilterRules.end()) {
75 AliHLTComponentDataTypeList::iterator type=tgtList.begin();
76 while (type!=tgtList.end()) {
77 if (*type==(*desc).fDataType) break;
80 if (type==tgtList.end()) tgtList.push_back((*desc).fDataType);
83 return tgtList.size();
86 void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
88 // see header file for class documentation
90 inputMultiplier=0.0; // there is no new data, just forwarded descriptors
93 int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv )
98 AliHLTComponentBlockData rule;
100 for (int i=0; i<argc && iResult>=0; i++) {
102 if (argument.IsNull()) continue;
105 if (argument.CompareTo("-datatype")==0) {
106 if ((bMissingParam=(i+2>=argc))) break;
108 if (rule.fDataType!=kAliHLTAnyDataType) {
109 // the data type has already been set, add to list
111 fFilterRules.push_back(rule);
115 SetDataType(rule.fDataType, argv[i+1], argv[i+2]);
119 } else if (argument.CompareTo("-dataspec")==0) {
120 if ((bMissingParam=(++i>=argc))) break;
122 if (rule.fSpecification!=kAliHLTVoidDataSpec) {
123 // the specification has already been set, add to list
125 fFilterRules.push_back(rule);
129 TString parameter(argv[i]);
130 parameter.Remove(TString::kLeading, ' '); // remove all blanks
132 rule.fSpecification=strtoul(parameter.Data(), &pRemnant, 0);
133 if (pRemnant!=NULL && pRemnant[0]!=0) {
134 HLTError("invalid parameter/remnant (%s) for argument %s, number expected", pRemnant, argument.Data());
138 HLTError("unknown argument %s", argument.Data());
143 if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || rule.fDataType!=kAliHLTAnyDataType)) {
144 // add the pending rule
145 fFilterRules.push_back(rule);
151 int AliHLTBlockFilterComponent::DoDeinit()
154 fFilterRules.clear();
158 int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& evtData,
159 const AliHLTComponentBlockData* blocks,
160 AliHLTComponentTriggerData& /*trigData*/,
161 AliHLTUInt8_t* /*outputPtr*/,
162 AliHLTUInt32_t& size,
163 AliHLTComponentBlockDataList& outputBlocks )
165 // see header file for class documentation
167 for (int n=0; n<(int)evtData.fBlockCnt; n++ ) {
168 if (IsSelected(blocks[n])) {
169 HLTDebug("block %d type %s %#x (ptr=%p offset=%d size=%d) selected by filter rules",
170 n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification,
171 blocks[n].fPtr, blocks[n].fOffset, blocks[n].fSize);
172 outputBlocks.push_back(blocks[n]);
174 HLTDebug("block %d type %s %#x discarded by filter rules", n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification);
181 int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block)
183 // see header file for class documentation
184 AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
185 //HLTDebug("check block: %s spec %#x", DataType2Text(block.fDataType, 1).c_str(), block.fSpecification);
186 if (desc==fFilterRules.end()) return 1; // no filter rules
189 // 1. data types match or filter data type not set
190 // 2. data spec match or filter data wpec not set
191 // 3. either filter data type or spec is set
192 //HLTDebug("check rule : %s spec %#x", DataType2Text((*desc).fDataType, 2).c_str(), block.fSpecification);
193 if (((*desc).fDataType==block.fDataType || (*desc).fDataType==kAliHLTAnyDataType) &&
194 ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) &&
195 ((*desc).fDataType!=kAliHLTAnyDataType || (*desc).fSpecification!=kAliHLTVoidDataSpec)) {
198 } while (++desc!=fFilterRules.end());