]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTrigger.cxx
flat friends update
[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 #include "AliHLTCTPData.h"
32
33 ClassImp(AliHLTTrigger)
34
35
36 AliHLTTrigger::AliHLTTrigger() :
37         AliHLTProcessor(),
38         fEventData(NULL),
39         fTriggerData(NULL),
40         fDecisionMade(false),
41         fClearInfo(true),
42         fTriggerEventResult(0),
43         fDescription(),
44         fReadoutList(),
45         fTriggerDomain(),
46         fReadoutListSpecBits(kAliHLTVoidDataSpec)
47 {
48   // Default constructor sets pointers to NULL.
49 }
50
51
52 AliHLTTrigger::~AliHLTTrigger()
53 {
54   // Default destructor.
55 }
56
57
58 void AliHLTTrigger::GetInputDataTypes(AliHLTComponentDataTypeList& list) const
59 {
60   // Returns the kAliHLTAnyDataType type as input.
61   list.push_back(kAliHLTAnyDataType);
62 }
63
64
65 void AliHLTTrigger::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
66 {
67   // Returns the kAliHLTDataTypeTriggerDecision type as output.
68   list.push_back(kAliHLTDataTypeTriggerDecision);
69 }
70
71
72 void AliHLTTrigger::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
73 {
74   // Returns output data size estimate.
75   // See header file for more details.
76
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);
81   inputMultiplier = 1;
82 }
83
84
85 int AliHLTTrigger::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
86 {
87   // Sets the pointers to the evtData and trigData, then calls the DoTrigger to
88   // execute the actual trigger algorithm.
89
90   fEventData = &evtData;
91   fTriggerData = &trigData;
92   fDecisionMade = false;
93   fTriggerEventResult = 0;
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   }
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   }
111
112   // Cleanup
113   fEventData = NULL;
114   fTriggerData = NULL;
115   return fTriggerEventResult;
116 }
117
118
119 int AliHLTTrigger::TriggerEvent(bool value)
120 {
121   // Sets the trigger decision for the current event.
122   // See header file for more details.
123   
124   if (fTriggerEventResult != 0) return fTriggerEventResult;  // Do not do anything if a previous call failed.
125   AliHLTTriggerDecision triggerResult(value, GetTriggerName(), fTriggerDomain, fDescription);
126   // Append the readout list if it contains anything.
127   triggerResult.TriggerDomain().Add(fReadoutList);
128   return TriggerEvent(&triggerResult, kAliHLTDataTypeTriggerDecision);
129 }
130
131
132 int AliHLTTrigger::TriggerEvent(
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   
140   if (fTriggerEventResult != 0) return fTriggerEventResult;  // Do not do anything if a previous call failed.
141   
142   AliHLTReadoutList readoutlist = result->ReadoutList();
143   
144   fTriggerEventResult = PushBack(result, type, spec);
145   if (fTriggerEventResult == 0) {
146     fTriggerEventResult = PushBack(readoutlist.Buffer(), readoutlist.BufferSize(), kAliHLTDataTypeReadoutList, fReadoutListSpecBits);
147   }
148   
149   if (fTriggerEventResult == 0) fDecisionMade = true;
150   return fTriggerEventResult;
151 }
152
153
154 void 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;
161   t->GetInputDataTypes(list);
162 }
163
164
165 int 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);
173   list.push_back(kAliHLTDataTypeReadoutList);
174   return list.size();
175 }
176
177 int AliHLTTrigger::CreateEventDoneReadoutFilter(const AliHLTTriggerDomain& domain, unsigned type)
178 {
179   // add a readout filter to the EventDoneData
180   int iResult=0;
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
197   // we need:
198   //   1 word for the filter command: readout filter, monitoring filter, monitoring event
199   //   1 word for the readout filter size
200   // 4*n words for the filter list
201   if ((iResult=ReserveEventDoneData((nofEntries*4 + 2) * sizeof(AliHLTUInt32_t)))<0) return iResult;
202   AliHLTUInt32_t eddbuffer[4];
203
204   // add the specific command
205   eddbuffer[0]=type;
206   if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
207
208   // find the valid entries
209   unsigned block=0;
210   vector<const AliHLTDomainEntry*> entries;
211   for (block=0; block<nofEntries; block++) {
212     // skip all DAQ readout entries as they are handled by the readout list
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;
219     if (domain[block].Exclusive()) {
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());
224       continue;
225     }
226     entries.push_back(&(domain[block]));
227   }
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   }
234
235   for (vector<const AliHLTDomainEntry*>::iterator entry=entries.begin();
236        entry!=entries.end(); entry++) {
237     (*entry)->AsBinary(eddbuffer);
238     for (int n=0; n<4; n++)
239       if ((iResult=PushEventDoneData(eddbuffer[n]))<0) return iResult;
240   }
241   return iResult;
242 }