]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTrigger.cxx
including the CTPData to the input objects of the HLTGlobalTriggerDecision
[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::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
57 {
58   // Returns output data size estimate.
59   // See header file for more details.
60
61   // Matthias 2009-07-03 this is presumably to small as the streamed object might be
62   // bigger. This is actually the case in root v5-24-00
63   // Just take 2x the size of the object
64   constBase = 2*sizeof(AliHLTTriggerDecision);
65   inputMultiplier = 1;
66 }
67
68
69 int AliHLTTrigger::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
70 {
71   // Sets the pointers to the evtData and trigData, then calls the DoTrigger to
72   // execute the actual trigger algorithm.
73
74   fEventData = &evtData;
75   fTriggerData = &trigData;
76   fDecisionMade = false;
77   fTriggerEventResult = 0;
78   // Reset the description, readout list and trigger domain used by TriggerEvent
79   // if requested to do so.
80   if (fClearInfo)
81   {
82     fDescription = "";
83     fReadoutList.Clear();
84     fTriggerDomain.Clear();
85   }
86   
87   int result = DoTrigger();
88   if (result != 0) return result;
89   
90   // Fill in a default decision of false if none was made.
91   if (not fDecisionMade)
92   {
93     TriggerEvent(false);
94   }
95
96   // Cleanup
97   fEventData = NULL;
98   fTriggerData = NULL;
99   return fTriggerEventResult;
100 }
101
102
103 int AliHLTTrigger::TriggerEvent(bool value)
104 {
105   // Sets the trigger decision for the current event.
106   // See header file for more details.
107   
108   if (fTriggerEventResult != 0) return fTriggerEventResult;  // Do not do anything if a previous call failed.
109   AliHLTTriggerDecision triggerResult(value, GetTriggerName(), fTriggerDomain, fDescription);
110   // Append the readout list if it contains anything.
111   triggerResult.TriggerDomain().Add(fReadoutList);
112   return TriggerEvent(&triggerResult, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
113 }
114
115
116 int AliHLTTrigger::TriggerEvent(
117     AliHLTTriggerDecision* result, const AliHLTComponentDataType& type,
118     AliHLTUInt32_t spec
119   )
120 {
121   // Sets a custom 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   fTriggerEventResult = PushBack(result, type, spec);
126   if (fTriggerEventResult == 0) {
127     fTriggerEventResult = PushBack(result->ReadoutList().Buffer(), result->ReadoutList().BufferSize(), "HLTRDLST", "HLT "/*kAliHLTDataTypeDAQRDOUT|kAliHLTDataOriginOut*/);
128   }
129   
130   if (fTriggerEventResult == 0) fDecisionMade = true;
131   return fTriggerEventResult;
132 }
133
134
135 void AliHLTTrigger::GetInputDataTypes(AliHLTComponentDataTypeList& list)
136 {
137   // Calls the const version of this method.
138   
139   // Assign to const temporary variable to make sure we call the constant version
140   // of the GetOutputDataTypes method.
141   const AliHLTTrigger* t = this;
142   t->GetInputDataTypes(list);
143 }
144
145
146 int AliHLTTrigger::GetOutputDataTypes(AliHLTComponentDataTypeList& list)
147 {
148   // Calls the const version of this method.
149   
150   // Assign to const temporary variable to make sure we call the constant version
151   // of the GetOutputDataTypes method.
152   const AliHLTTrigger* t = this;
153   t->GetOutputDataTypes(list);
154   list.push_back(kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
155   return list.size();
156 }
157
158 int AliHLTTrigger::CreateEventDoneReadoutFilter(const AliHLTTriggerDomain& domain, unsigned type)
159 {
160   // add a readout filter to the EventDoneData
161   int iResult=0;
162   unsigned nofEntries=domain.GetNofEntries();
163   // we need:
164   //   1 word eventually for the monitor event command
165   //   1 word for the readout filter command
166   //   1 word for the readout filter size
167   // 4*n words for the filter list
168   if ((iResult=ReserveEventDoneData((nofEntries*4 + 3) * sizeof(AliHLTUInt32_t)))<0) return iResult;
169   AliHLTUInt32_t eddbuffer[4];
170   if (type==4) {
171     // in the case of the monitoring filter we also add the monitor event command
172     eddbuffer[0]=5;
173     if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
174   }
175
176   // now the readout list command and the block count
177   eddbuffer[0]=type;
178   if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
179
180   // find the valid entries
181   unsigned block=0;
182   vector<const AliHLTDomainEntry*> entries;
183   for (block=0; block<nofEntries; block++) {
184     // skip all DAQ readout entries as they are handled by the readout list
185     if (domain[block]==AliHLTDomainEntry(kAliHLTDataTypeDAQRDOUT)) continue;
186     if (domain[block].Exclusive()) {
187       HLTWarning("exclusive trigger domain entries are currently not handled, skipping entry %s", domain[block].AsString().Data());
188       continue;
189     }
190     entries.push_back(&(domain[block]));
191   }
192   eddbuffer[0]=entries.size();
193   if ((iResult=PushEventDoneData(eddbuffer[0]))<0) return iResult;
194
195   for (vector<const AliHLTDomainEntry*>::iterator entry=entries.begin();
196        entry!=entries.end(); entry++) {
197     (*entry)->AsBinary(eddbuffer);
198     for (int n=0; n<4; n++)
199       if ((iResult=PushEventDoneData(eddbuffer[n]))<0) return iResult;
200   }
201   return iResult;
202 }