Fixing warning.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTrigger.cxx
CommitLineData
2974f8dc 1// $Id$
a9670afe 2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
7 * for The ALICE HLT Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
5a806c0e 17
1b9a175e 18/// @file AliHLTTrigger.h
19/// @author Artur Szostak <artursz@iafrica.com>
20/// @date 12 Aug 2008
21/// @brief Implementation of the AliHLTTrigger base component class.
22///
23/// The AliHLTTrigger class is the base class from which all HLT trigger components
24/// should be derived.
25
4aa41877 26#include "AliHLTTrigger.h"
1b9a175e 27#include "AliHLTTriggerDecision.h"
15ede44e 28#include "AliHLTReadoutList.h"
2974f8dc 29#include "AliHLTTriggerDomain.h"
30#include "AliHLTDomainEntry.h"
5a806c0e 31
4aa41877 32ClassImp(AliHLTTrigger)
5a806c0e 33
5a806c0e 34
a9670afe 35AliHLTTrigger::AliHLTTrigger() :
36 AliHLTProcessor(),
37 fEventData(NULL),
38 fTriggerData(NULL),
39 fDecisionMade(false),
acc7214e 40 fClearInfo(true),
4adf50d6 41 fTriggerEventResult(0),
1b9a175e 42 fDescription(),
43 fReadoutList(),
44 fTriggerDomain()
5a806c0e 45{
5d79eb88 46 // Default constructor sets pointers to NULL.
5a806c0e 47}
48
5a806c0e 49
a9670afe 50AliHLTTrigger::~AliHLTTrigger()
5a806c0e 51{
5d79eb88 52 // Default destructor.
4adf50d6 53}
54
55
025443e0 56void AliHLTTrigger::GetInputDataTypes(AliHLTComponentDataTypeList& list) const
57{
58 // Returns the kAliHLTAnyDataType type as input.
59 list.push_back(kAliHLTAnyDataType);
60}
61
62
63void AliHLTTrigger::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
64{
65 // Returns the kAliHLTDataTypeTriggerDecision type as output.
66 list.push_back(kAliHLTDataTypeTriggerDecision);
67}
68
69
4adf50d6 70void AliHLTTrigger::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
71{
5d79eb88 72 // Returns output data size estimate.
73 // See header file for more details.
4adf50d6 74
61074420 75 // Matthias 2009-07-03 this is presumably to small as the streamed object might be
76 // bigger. This is actually the case in root v5-24-00
77 // Just take 2x the size of the object
78 constBase = 2*sizeof(AliHLTTriggerDecision);
4adf50d6 79 inputMultiplier = 1;
5a806c0e 80}
81
5a806c0e 82
a9670afe 83int AliHLTTrigger::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
5a806c0e 84{
5d79eb88 85 // Sets the pointers to the evtData and trigData, then calls the DoTrigger to
86 // execute the actual trigger algorithm.
5a806c0e 87
a9670afe 88 fEventData = &evtData;
89 fTriggerData = &trigData;
90 fDecisionMade = false;
91 fTriggerEventResult = 0;
acc7214e 92 // Reset the description, readout list and trigger domain used by TriggerEvent
93 // if requested to do so.
94 if (fClearInfo)
95 {
96 fDescription = "";
97 fReadoutList.Clear();
98 fTriggerDomain.Clear();
99 }
a9670afe 100
101 int result = DoTrigger();
102 if (result != 0) return result;
103
104 // Fill in a default decision of false if none was made.
105 if (not fDecisionMade)
106 {
107 TriggerEvent(false);
108 }
4adf50d6 109
a9670afe 110 // Cleanup
111 fEventData = NULL;
112 fTriggerData = NULL;
113 return fTriggerEventResult;
5a806c0e 114}
115
5a806c0e 116
4654280e 117int AliHLTTrigger::TriggerEvent(bool value)
5a806c0e 118{
5d79eb88 119 // Sets the trigger decision for the current event.
120 // See header file for more details.
5a806c0e 121
4654280e 122 if (fTriggerEventResult != 0) return fTriggerEventResult; // Do not do anything if a previous call failed.
52f67e50 123 AliHLTTriggerDecision triggerResult(value, GetTriggerName(), fTriggerDomain, fDescription);
8b745301 124 // Append the readout list if it contains anything.
125 triggerResult.TriggerDomain().Add(fReadoutList);
72e31932 126 return TriggerEvent(&triggerResult, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
5d79eb88 127}
128
129
4654280e 130int AliHLTTrigger::TriggerEvent(
5d79eb88 131 AliHLTTriggerDecision* result, const AliHLTComponentDataType& type,
132 AliHLTUInt32_t spec
133 )
134{
135 // Sets a custom trigger decision for the current event.
136 // See header file for more details.
137
4654280e 138 if (fTriggerEventResult != 0) return fTriggerEventResult; // Do not do anything if a previous call failed.
5d79eb88 139 fTriggerEventResult = PushBack(result, type, spec);
f320d378 140 if (fTriggerEventResult == 0) {
025443e0 141 fTriggerEventResult = PushBack(result->ReadoutList().Buffer(), result->ReadoutList().BufferSize(), kAliHLTDataTypeReadoutList);
15ede44e 142 }
143
5d79eb88 144 if (fTriggerEventResult == 0) fDecisionMade = true;
4654280e 145 return fTriggerEventResult;
5d79eb88 146}
147
148
149void AliHLTTrigger::GetInputDataTypes(AliHLTComponentDataTypeList& list)
150{
151 // Calls the const version of this method.
152
153 // Assign to const temporary variable to make sure we call the constant version
154 // of the GetOutputDataTypes method.
155 const AliHLTTrigger* t = this;
4a0b19b6 156 t->GetInputDataTypes(list);
5d79eb88 157}
158
159
160int AliHLTTrigger::GetOutputDataTypes(AliHLTComponentDataTypeList& list)
161{
162 // Calls the const version of this method.
163
164 // Assign to const temporary variable to make sure we call the constant version
165 // of the GetOutputDataTypes method.
166 const AliHLTTrigger* t = this;
167 t->GetOutputDataTypes(list);
025443e0 168 list.push_back(kAliHLTDataTypeReadoutList);
5d79eb88 169 return list.size();
5a806c0e 170}
171
2974f8dc 172int AliHLTTrigger::CreateEventDoneReadoutFilter(const AliHLTTriggerDomain& domain, unsigned type)
173{
174 // add a readout filter to the EventDoneData
175 int iResult=0;
0744f75d 176 unsigned nofEntries=0;
177 switch (type) {
178 /* readout filter */
179 case 3:
180 /* monitoring filter */
181 case 4:
182 nofEntries=domain.GetNofEntries();
183 break;
184 /* monitoring event command */
185 case 5:
186 break;
187 default:
188 HLTError("unknown event done data command code 0x%08x", type);
189 return -EINVAL;
190 }
191
2974f8dc 192 // we need:
0744f75d 193 // 1 word for the filter command: readout filter, monitoring filter, monitoring event
2974f8dc 194 // 1 word for the readout filter size
195 // 4*n words for the filter list
0744f75d 196 if ((iResult=ReserveEventDoneData((nofEntries*4 + 2) * sizeof(AliHLTUInt32_t)))<0) return iResult;
2974f8dc 197 AliHLTUInt32_t eddbuffer[4];
2974f8dc 198
0744f75d 199 // add the specific command
2974f8dc 200 eddbuffer[0]=type;
201 if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
2974f8dc 202
7b638b2a 203 // find the valid entries
204 unsigned block=0;
205 vector<const AliHLTDomainEntry*> entries;
206 for (block=0; block<nofEntries; block++) {
2974f8dc 207 // skip all DAQ readout entries as they are handled by the readout list
44568d8a 208 // 2009-12-03: this turned out to cause a bug, since all blocks with data type
209 // id 'any' will also match this condition. In fact, it is not necessary to
210 // filter the entries, disable this condition. Code can be cleaned up later
211 // if this schema has been established and tested
212 // https://savannah.cern.ch/bugs/index.php?60082
213 //if (domain[block]==AliHLTDomainEntry(kAliHLTDataTypeDAQRDOUT)) continue;
2974f8dc 214 if (domain[block].Exclusive()) {
44568d8a 215 // 2009-12-03 comment out that warning for the moment
216 // there are suddenly exclusive entries in the list
217 // https://savannah.cern.ch/bugs/index.php?60083
218 //HLTWarning("exclusive trigger domain entries are currently not handled, skipping entry %s", domain[block].AsString().Data());
2974f8dc 219 continue;
220 }
7b638b2a 221 entries.push_back(&(domain[block]));
222 }
0744f75d 223
224 // add the number of blocks if not monitoring event command
225 if (type!=5) {
226 eddbuffer[0]=entries.size();
227 if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
228 }
7b638b2a 229
230 for (vector<const AliHLTDomainEntry*>::iterator entry=entries.begin();
231 entry!=entries.end(); entry++) {
232 (*entry)->AsBinary(eddbuffer);
2974f8dc 233 for (int n=0; n<4; n++)
234 if ((iResult=PushEventDoneData(eddbuffer[n]))<0) return iResult;
235 }
236 return iResult;
237}