]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerAgent.cxx
propagation of HLT global trigger decision to hltESD
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerAgent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTriggerAgent.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Agent of the libAliHLTTrigger library
23 */
24
25 #include <cassert>
26 #include "AliHLTTriggerAgent.h"
27 #include "AliHLTTriggerDecision.h"
28 #include "AliHLTOUT.h"
29 #include "AliHLTMessage.h"
30 #include "AliESDEvent.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
33 #include "TArrayC.h"
34
35 // header files of library components
36 #include "AliHLTEventSummaryProducerComponent.h"
37 #include "AliHLTRunSummaryProducerComponent.h"
38 #include "AliHLTTriggerBarrelMultiplicity.h"
39 #include "AliHLTTriggerBarrelCosmic.h"
40 #include "AliHLTGlobalTriggerComponent.h"
41
42 /** global instance for agent registration */
43 AliHLTTriggerAgent gAliHLTTriggerAgent;
44
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTTriggerAgent)
47
48 AliHLTTriggerAgent::AliHLTTriggerAgent()
49   : AliHLTModuleAgent("Trigger")
50   , fTriggerDecisionHandler(NULL)
51 {
52   // see header file for class documentation
53   // or
54   // refer to README to build package
55   // or
56   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 }
58
59 AliHLTTriggerAgent::~AliHLTTriggerAgent()
60 {
61   // see header file for class documentation
62 }
63
64 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
65 {
66   // see header file for class documentation
67   assert(pHandler);
68   if (!pHandler) return -EINVAL;
69   pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
70   pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
71   pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
72   return 0;
73 }
74
75 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
76                                             AliRawReader* /*rawReader*/,
77                                             AliRunLoader* /*runloader*/) const
78 {
79   // see header file for class documentation
80   if (!pHandler) return -EINVAL;
81
82   TString triggerInputs;
83   TString triggerOutputs;
84   TString configurationId;
85   /////////////////////////////////////////////////////////////////////////////////////
86   //
87   // a central barrel charged particle multiplicity trigger
88   configurationId="TRIGGER-Barrel-Multiplicity";
89
90   // define the inputsfor the BarrelMultiplicityTrigger
91   triggerInputs="GLOBAL-esd-converter";
92
93   // check for the availibility
94   TObjArray* pTokens=triggerInputs.Tokenize(" ");
95   triggerInputs="";
96   if (pTokens) {
97     for (int n=0; n<pTokens->GetEntriesFast(); n++) {
98       TString module=((TObjString*)pTokens->At(n))->GetString();
99       if (pHandler->FindConfiguration(module.Data())) {
100         triggerInputs+=module;
101         triggerInputs+=" ";
102       }
103     }
104     delete pTokens;
105   }
106
107   if (triggerInputs.Length()>0) {
108     HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
109     pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
110     if (triggerOutputs.Length()>0) triggerOutputs+=" ";
111     triggerOutputs+=configurationId;
112   } else {
113     HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
114   }
115
116   /////////////////////////////////////////////////////////////////////////////////////
117   //
118   // the global trigger component
119   configurationId="GLOBAL-Trigger";
120   HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
121   pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
122   
123   return 0;
124 }
125
126 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
127                                                     AliRunLoader* runloader) const
128 {
129   // see header file for class documentation
130   if (runloader) {
131     // reconstruction chains for AliRoot simulation
132     // Note: run loader is only available while running embedded into
133     // AliRoot simulation
134
135     // currently disabled due to a problem compiling the runtime trigger library
136     return "GLOBAL-Trigger";
137   }
138   return NULL;
139 }
140
141 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
142 {
143   // see header file for class documentation
144
145   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
146 }
147
148 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
149                                            AliHLTUInt32_t /*spec*/,
150                                           AliHLTOUTHandlerDesc& desc) const
151 {
152   // see header file for class documentation
153
154   // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
155   // currently stored as a TObject with the common data type and origin
156   // HLTOUT. However we might need a separate data type in order to
157   // avoid interference with other handlers
158   // the handler produces an ESD object in order to be merged to the
159   // hltEsd afterwards
160   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
161     desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
162     return 1;
163   }
164
165   // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
166   if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
167       dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
168       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
169       return 1;
170   }
171
172   return 0;
173 }
174
175 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
176                                                        AliHLTUInt32_t /*spec*/)
177 {
178   // see header file for class documentation
179
180   // raw data blocks to be fed into offline reconstruction
181   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
182     if (!fTriggerDecisionHandler) {
183       fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
184     }
185     return fTriggerDecisionHandler;
186   }
187
188   // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
189   if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
190       dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
191     return NULL;
192   }
193
194   return NULL;
195 }
196
197 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
198 {
199   // see header file for class documentation
200   if (pInstance==NULL) return -EINVAL;
201
202   if (pInstance==fTriggerDecisionHandler) {
203     delete fTriggerDecisionHandler;
204     fTriggerDecisionHandler=NULL;
205   }
206
207   return 0;
208 }
209
210 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
211   : AliHLTOUTHandler() 
212   , fESD(NULL)
213   , fpData(NULL)
214   , fSize(0)
215 {
216   // see header file for class documentation
217 }
218
219 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
220 {
221   // see header file for class documentation
222   if (fESD) delete fESD;
223   fESD=NULL;
224
225   if (fpData) delete fpData;
226   fpData=NULL;
227   fSize=0;
228 }
229
230 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
231 {
232   // see header file for class documentation
233   if (!pData) return -EINVAL;
234   AliHLTComponentDataType dt=kAliHLTVoidDataType;
235   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
236   int iResult=pData->GetDataBlockDescription(dt, spec);
237   if (iResult>=0) {
238     TObject* pObject=pData->GetDataObject();
239     if (pObject) {
240       AliHLTTriggerDecision* pDecission=dynamic_cast<AliHLTTriggerDecision*>(pObject);
241       if (pDecission) {
242         if (!fESD) {
243           // create the ESD container, but without std content
244           fESD = new AliESDEvent;
245         }
246         if (!fpData) fpData=new TArrayC;
247         if (fESD && fpData) {
248           fESD->Reset();
249           fESD->AddObject(pObject->Clone());
250           AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
251           if (pMsg) {
252             if (!pMsg->CompBuffer()) {
253               fSize=pMsg->Length();
254               fpData->Set(fSize, pMsg->Buffer());
255             } else {
256               fSize=pMsg->CompLength();
257               fpData->Set(fSize, pMsg->CompBuffer());
258             }
259           } else {
260             HLTError("streaming of objects failed");
261           }
262         } else {
263           HLTError("memory allocation failed");
264           iResult=-ENOMEM;
265         }
266       } else {
267         HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
268         iResult=-ENODATA;
269       }
270       pData->ReleaseDataObject(pObject);
271       pObject=NULL;
272     } else {
273       HLTError("can not get TObject from HLTOUT buffer");
274       iResult=-ENODATA;
275     }
276   }
277   if (iResult>=0) return fSize;
278   fSize=0;
279   return iResult;
280 }
281
282 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
283 {
284   // see header file for class documentation
285   if (!fpData) {
286     pData=NULL;
287     return 0;
288   }
289
290   pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
291   return fSize;
292 }
293
294 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
295 {
296   // see header file for class documentation
297   int iResult=0;
298   if (!fpData || size != fSize ||
299       const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
300     HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
301   }
302   fSize=0;
303   return iResult;
304 }