added new helper components to libAliHLTUtil (EsdCollector and AliHLTOUTPublisher...
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTBlockFilterComponent.cxx
CommitLineData
9bf94558 1// @(#) $Id$
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 */
30ClassImp(AliHLTBlockFilterComponent)
31
32AliHLTBlockFilterComponent::AliHLTBlockFilterComponent()
3bf0e1d7 33 :
34 fFilterRules()
9bf94558 35{
36 // see header file for class documentation
37 // or
38 // refer to README to build package
39 // or
40 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
41}
42
43AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent()
44{
45 // see header file for class documentation
46}
47
48void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
49{
50 // see header file for class documentation
51 list.clear();
52 list.push_back(kAliHLTAnyDataType);
53}
54
55AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType()
56{
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;
61}
62
63int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
64{
65 // see header file for class documentation
66 tgtList.clear();
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;
72 type++;
73 }
74 if (type==tgtList.end()) tgtList.push_back((*desc).fDataType);
75 desc++;
76 }
77 return tgtList.size();
78}
79
80void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
81{
82 // see header file for class documentation
83 constBase=0;
84 inputMultiplier=0.0; // there is no new data, just forwarded descriptors
85}
86
87int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv )
88{
89 int iResult=0;
90 TString argument="";
91 int bMissingParam=0;
92 AliHLTComponentBlockData rule;
93 FillBlockData(rule);
94 for (int i=0; i<argc && iResult>=0; i++) {
95 argument=argv[i];
96 if (argument.IsNull()) continue;
97
98 // -datatype
99 if (argument.CompareTo("-datatype")==0) {
100 if ((bMissingParam=(i+2>=argc))) break;
101
d8f5c9fe 102 if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
9bf94558 103 // the data type has already been set, add to list
104 // and reset
105 fFilterRules.push_back(rule);
106 FillBlockData(rule);
107 }
108
109 SetDataType(rule.fDataType, argv[i+1], argv[i+2]);
110 i+=2;
111
112 // -dataspec
113 } else if (argument.CompareTo("-dataspec")==0) {
114 if ((bMissingParam=(++i>=argc))) break;
115
116 if (rule.fSpecification!=kAliHLTVoidDataSpec) {
117 // the specification has already been set, add to list
118 // and reset
119 fFilterRules.push_back(rule);
120 FillBlockData(rule);
121 }
122
123 TString parameter(argv[i]);
124 parameter.Remove(TString::kLeading, ' '); // remove all blanks
125 char* pRemnant=NULL;
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());
129 iResult=-EINVAL;
130 }
131 } else {
132 HLTError("unknown argument %s", argument.Data());
133 iResult=-EINVAL;
134 break;
135 }
136 }
d8f5c9fe 137 if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType))) {
9bf94558 138 // add the pending rule
139 fFilterRules.push_back(rule);
140 FillBlockData(rule);
141 }
142 return iResult;
143}
144
145int AliHLTBlockFilterComponent::DoDeinit()
146{
147 int iResult=0;
148 fFilterRules.clear();
149 return iResult;
150}
151
b0914d2e 152int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
153 const AliHLTComponentBlockData* /*blocks*/,
9bf94558 154 AliHLTComponentTriggerData& /*trigData*/,
155 AliHLTUInt8_t* /*outputPtr*/,
156 AliHLTUInt32_t& size,
b0914d2e 157 AliHLTComponentBlockDataList& /*outputBlocks*/ )
9bf94558 158{
159 // see header file for class documentation
160 int iResult=0;
c7e9e2f2 161 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
162 pBlock!=NULL;
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);
168 Forward();
9bf94558 169 } else {
c7e9e2f2 170 HLTDebug("block type %s %#x discarded by filter rules", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification);
9bf94558 171 }
172 }
173 size=0;
174 return iResult;
175}
176
177int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block)
178{
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
183 do {
184 // match if
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);
d8f5c9fe 189 if (((*desc).fDataType==block.fDataType) &&
9bf94558 190 ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) &&
d8f5c9fe 191 (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) {
9bf94558 192 return 1;
193 }
194 } while (++desc!=fFilterRules.end());
195
196 return 0;
197}