Line data Source code
1 : /**************************************************************************
2 : * This file is property of and copyright by the ALICE HLT Project *
3 : * All rights reserved. *
4 : * *
5 : * Primary Authors: *
6 : * Artur Szostak <artursz@iafrica.com> *
7 : * *
8 : * Permission to use, copy, modify and distribute this software and its *
9 : * documentation strictly for non-commercial purposes is hereby granted *
10 : * without fee, provided that the above copyright notice appears in all *
11 : * copies and that both the copyright notice and this permission notice *
12 : * appear in the supporting documentation. The authors make no claims *
13 : * about the suitability of this software for any purpose. It is *
14 : * provided "as is" without express or implied warranty. *
15 : **************************************************************************/
16 :
17 : // $Id$
18 :
19 : ///
20 : /// @file AliHLTMUONEmptyEventFilterComponent.cxx
21 : /// @author Artur Szostak <artursz@iafrica.com>
22 : /// @date 2007-12-12
23 : /// @brief Implementation of the empty event filter component.
24 : ///
25 : /// This component is used to forward events for where there is at least one
26 : /// non-empty dHLT data block.
27 : ///
28 :
29 : #include "AliHLTMUONEmptyEventFilterComponent.h"
30 : #include "AliHLTMUONConstants.h"
31 : #include "AliHLTLogging.h"
32 : #include "AliHLTSystem.h"
33 : #include "AliHLTDefinitions.h"
34 : #include <cstdlib>
35 : #include <cerrno>
36 : #include <cassert>
37 :
38 6 : ClassImp(AliHLTMUONEmptyEventFilterComponent)
39 :
40 :
41 : AliHLTMUONEmptyEventFilterComponent::AliHLTMUONEmptyEventFilterComponent() :
42 3 : AliHLTMUONProcessor(),
43 3 : fSendOnEmpty(false)
44 15 : {
45 : ///
46 : /// Default constructor.
47 : ///
48 6 : }
49 :
50 :
51 : AliHLTMUONEmptyEventFilterComponent::~AliHLTMUONEmptyEventFilterComponent()
52 12 : {
53 : ///
54 : /// Default destructor.
55 : ///
56 12 : }
57 :
58 : const char* AliHLTMUONEmptyEventFilterComponent::GetComponentID()
59 : {
60 : ///
61 : /// Inherited from AliHLTComponent. Returns the component ID.
62 : ///
63 :
64 192 : return AliHLTMUONConstants::EmptyEventFilterComponentId();
65 : }
66 :
67 :
68 : void AliHLTMUONEmptyEventFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
69 : {
70 : ///
71 : /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
72 : /// At the moment this list is "any data type" since it is not known before
73 : /// hand what kind of input blocks we will get.
74 :
75 0 : assert( list.empty() );
76 0 : list.push_back( kAliHLTAnyDataType );
77 0 : }
78 :
79 :
80 : AliHLTComponentDataType AliHLTMUONEmptyEventFilterComponent::GetOutputDataType()
81 : {
82 : ///
83 : /// Inherited from AliHLTComponent. Returns the output data type of
84 : /// "any data type" with MUON origin.
85 :
86 0 : return kAliHLTAnyDataType | kAliHLTDataOriginMUON;
87 : }
88 :
89 :
90 : void AliHLTMUONEmptyEventFilterComponent::GetOutputDataSize(
91 : unsigned long& constBase, double& inputMultiplier
92 : )
93 : {
94 : ///
95 : /// Inherited from AliHLTComponent.
96 : /// Returns an estimate of the expected output data size.
97 :
98 : // Both of these are zero because we will only ever pass on input data blocks
99 : // and never generate data in this component.
100 0 : constBase = 0;
101 0 : inputMultiplier = 0;
102 0 : }
103 :
104 :
105 : AliHLTComponent* AliHLTMUONEmptyEventFilterComponent::Spawn()
106 : {
107 : ///
108 : /// Inherited from AliHLTComponent. Creates a new object instance.
109 : ///
110 :
111 0 : return new AliHLTMUONEmptyEventFilterComponent;
112 0 : }
113 :
114 :
115 : bool AliHLTMUONEmptyEventFilterComponent::IgnoreArgument(const char* arg) const
116 : {
117 : /// Return true if the argument is one of -cdbpath -run or -delaysetup
118 : /// to prevent the parent class from parsing these arguments in DoInit.
119 :
120 0 : if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
121 0 : strcmp(arg, "-delaysetup") == 0)
122 : {
123 0 : return true;
124 : }
125 : else
126 : {
127 0 : return false;
128 : }
129 0 : }
130 :
131 :
132 : int AliHLTMUONEmptyEventFilterComponent::DoInit(int argc, const char** argv)
133 : {
134 : ///
135 : /// Inherited from AliHLTComponent.
136 : /// Parses the command line parameters and initialises the component.
137 : ///
138 :
139 0 : HLTInfo("Initialising dHLT event filter component.");
140 :
141 : // Inherit the parents functionality.
142 0 : int result = AliHLTMUONProcessor::DoInit(argc, argv);
143 0 : if (result != 0) return result;
144 :
145 0 : fSendOnEmpty = false; // Set to the default value.
146 :
147 0 : for (int i = 0; i < argc; i++)
148 : {
149 0 : if (ArgumentAlreadyHandled(i, argv[i])) continue;
150 :
151 0 : if (strcmp(argv[i], "-sendempty") == 0)
152 : {
153 0 : fSendOnEmpty = true;
154 0 : HLTInfo("Turning on anti-filtering. Will be passing all data on empty dHLT results.");
155 : continue;
156 : }
157 :
158 0 : HLTError("Unknown option '%s'.", argv[i]);
159 0 : return -EINVAL;
160 : }
161 :
162 0 : return 0;
163 0 : }
164 :
165 :
166 : int AliHLTMUONEmptyEventFilterComponent::DoDeinit()
167 : {
168 : ///
169 : /// Inherited from AliHLTComponent. Performs a cleanup of the component.
170 : ///
171 :
172 0 : HLTInfo("Deinitialising dHLT event filter component.");
173 :
174 0 : return 0;
175 : }
176 :
177 :
178 : int AliHLTMUONEmptyEventFilterComponent::DoEvent(
179 : const AliHLTComponentEventData& evtData,
180 : const AliHLTComponentBlockData* blocks,
181 : AliHLTComponentTriggerData& trigData,
182 : AliHLTUInt8_t* outputPtr,
183 : AliHLTUInt32_t& size,
184 : AliHLTComponentBlockDataList& outputBlocks
185 : )
186 : {
187 : /// Inherited from AliHLTProcessor. Processes the new event data.
188 : /// Here we go through the list of input data blocks looking for blocks
189 : /// containing dHLT results. If all of these blocks are empty then we
190 : /// mark the event for filtering.
191 : /// What we actually do with the whole event will depend on the fSendOnEmpty
192 : /// flag. If it is set to false (the default) then we will copy all the
193 : /// input data blocks to output if the dHLT results were NOT empty.
194 : /// If fSendOnEmpty is true then we will copy all the input data blocks
195 : /// to the output if the dHLT results ARE empty.
196 :
197 : HLTDebug("Processing event %llu with %u input data blocks.",
198 : evtData.fEventID, evtData.fBlockCnt
199 : );
200 :
201 : bool emptyEvent = true;
202 :
203 0 : for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
204 : {
205 : HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
206 : n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
207 : );
208 :
209 0 : if (blocks[n].fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
210 : {
211 0 : AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
212 0 : if (not BlockStructureOk(inblock))
213 : {
214 0 : if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
215 0 : continue;
216 : }
217 0 : if (inblock.Nentries() != 0) emptyEvent = false;
218 0 : }
219 0 : else if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
220 : {
221 0 : AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
222 0 : if (not BlockStructureOk(inblock))
223 : {
224 0 : if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
225 0 : continue;
226 : }
227 0 : if (inblock.Nentries() != 0) emptyEvent = false;
228 0 : }
229 0 : else if (blocks[n].fDataType == AliHLTMUONConstants::MansoTracksBlockDataType())
230 : {
231 0 : AliHLTMUONMansoTracksBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
232 0 : if (not BlockStructureOk(inblock))
233 : {
234 0 : if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
235 0 : continue;
236 : }
237 0 : if (inblock.Nentries() != 0) emptyEvent = false;
238 0 : }
239 0 : else if (blocks[n].fDataType == AliHLTMUONConstants::SinglesDecisionBlockDataType())
240 : {
241 0 : AliHLTMUONSinglesDecisionBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
242 0 : if (not BlockStructureOk(inblock))
243 : {
244 0 : if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
245 0 : continue;
246 : }
247 0 : if (inblock.Nentries() != 0) emptyEvent = false;
248 0 : }
249 0 : else if (blocks[n].fDataType == AliHLTMUONConstants::PairsDecisionBlockDataType())
250 : {
251 0 : AliHLTMUONPairsDecisionBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
252 0 : if (not BlockStructureOk(inblock))
253 : {
254 0 : if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
255 0 : continue;
256 : }
257 0 : if (inblock.Nentries() != 0) emptyEvent = false;
258 0 : }
259 : }
260 :
261 : // If we are filtering or required to send only empty events then
262 : // copy all the input blocks to the output.
263 0 : if ((emptyEvent and fSendOnEmpty) or (not emptyEvent and not fSendOnEmpty))
264 : {
265 0 : for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
266 : {
267 0 : outputBlocks.push_back(blocks[n]);
268 : }
269 0 : }
270 :
271 : // Finally we set the total size of output memory we consumed which is
272 : // zero since we just copied the input descriptors to output if anything.
273 0 : size = 0;
274 0 : return 0;
275 : }
276 :
|