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