]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTrigger.cxx
temporarily reverting part of r36598
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTrigger.cxx
1 // $Id$
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  **************************************************************************/
17
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
26 #include "AliHLTTrigger.h"
27 #include "AliHLTTriggerDecision.h"
28 #include "AliHLTReadoutList.h"
29 #include "AliHLTTriggerDomain.h"
30 #include "AliHLTDomainEntry.h"
31
32 ClassImp(AliHLTTrigger)
33
34
35 AliHLTTrigger::AliHLTTrigger() :
36         AliHLTProcessor(),
37         fEventData(NULL),
38         fTriggerData(NULL),
39         fDecisionMade(false),
40         fClearInfo(true),
41         fTriggerEventResult(0),
42         fDescription(),
43         fReadoutList(),
44         fTriggerDomain()
45 {
46   // Default constructor sets pointers to NULL.
47 }
48
49
50 AliHLTTrigger::~AliHLTTrigger()
51 {
52   // Default destructor.
53 }
54
55
56 void AliHLTTrigger::GetInputDataTypes(AliHLTComponentDataTypeList& list) const
57 {
58   // Returns the kAliHLTAnyDataType type as input.
59   list.push_back(kAliHLTAnyDataType);
60 }
61
62
63 void AliHLTTrigger::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
64 {
65   // Returns the kAliHLTDataTypeTriggerDecision type as output.
66   list.push_back(kAliHLTDataTypeTriggerDecision);
67 }
68
69
70 void AliHLTTrigger::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
71 {
72   // Returns output data size estimate.
73   // See header file for more details.
74
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);
79   inputMultiplier = 1;
80 }
81
82
83 int AliHLTTrigger::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
84 {
85   // Sets the pointers to the evtData and trigData, then calls the DoTrigger to
86   // execute the actual trigger algorithm.
87
88   fEventData = &evtData;
89   fTriggerData = &trigData;
90   fDecisionMade = false;
91   fTriggerEventResult = 0;
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   }
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   }
109
110   // Cleanup
111   fEventData = NULL;
112   fTriggerData = NULL;
113   return fTriggerEventResult;
114 }
115
116
117 int AliHLTTrigger::TriggerEvent(bool value)
118 {
119   // Sets the trigger decision for the current event.
120   // See header file for more details.
121   
122   if (fTriggerEventResult != 0) return fTriggerEventResult;  // Do not do anything if a previous call failed.
123   AliHLTTriggerDecision triggerResult(value, GetTriggerName(), fTriggerDomain, fDescription);
124   // Append the readout list if it contains anything.
125   triggerResult.TriggerDomain().Add(fReadoutList);
126   return TriggerEvent(&triggerResult, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
127 }
128
129
130 int AliHLTTrigger::TriggerEvent(
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   
138   if (fTriggerEventResult != 0) return fTriggerEventResult;  // Do not do anything if a previous call failed.
139   fTriggerEventResult = PushBack(result, type, spec);
140   if (fTriggerEventResult == 0) {
141     fTriggerEventResult = PushBack(result->ReadoutList().Buffer(), result->ReadoutList().BufferSize(), kAliHLTDataTypeReadoutList);
142   }
143   
144   if (fTriggerEventResult == 0) fDecisionMade = true;
145   return fTriggerEventResult;
146 }
147
148
149 void 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;
156   t->GetInputDataTypes(list);
157 }
158
159
160 int 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);
168   list.push_back(kAliHLTDataTypeReadoutList);
169   return list.size();
170 }
171
172 int AliHLTTrigger::CreateEventDoneReadoutFilter(const AliHLTTriggerDomain& domain, unsigned type)
173 {
174   // add a readout filter to the EventDoneData
175   int iResult=0;
176   unsigned nofEntries=domain.GetNofEntries();
177   // we need:
178   //   1 word eventually for the monitor event command
179   //   1 word for the readout filter command
180   //   1 word for the readout filter size
181   // 4*n words for the filter list
182   if ((iResult=ReserveEventDoneData((nofEntries*4 + 3) * sizeof(AliHLTUInt32_t)))<0) return iResult;
183   AliHLTUInt32_t eddbuffer[4];
184   if (type==4) {
185     // in the case of the monitoring filter we also add the monitor event command
186     eddbuffer[0]=5;
187     if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
188   }
189
190   // now the readout list command and the block count
191   eddbuffer[0]=type;
192   if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
193
194   // find the valid entries
195   unsigned block=0;
196   vector<const AliHLTDomainEntry*> entries;
197   for (block=0; block<nofEntries; block++) {
198     // skip all DAQ readout entries as they are handled by the readout list
199     if (domain[block]==AliHLTDomainEntry(kAliHLTDataTypeDAQRDOUT)) continue;
200     if (domain[block].Exclusive()) {
201       HLTWarning("exclusive trigger domain entries are currently not handled, skipping entry %s", domain[block].AsString().Data());
202       continue;
203     }
204     entries.push_back(&(domain[block]));
205   }
206   eddbuffer[0]=entries.size();
207   if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
208
209   for (vector<const AliHLTDomainEntry*>::iterator entry=entries.begin();
210        entry!=entries.end(); entry++) {
211     (*entry)->AsBinary(eddbuffer);
212     for (int n=0; n<4; n++)
213       if ((iResult=PushEventDoneData(eddbuffer[n]))<0) return iResult;
214   }
215   return iResult;
216 }