Trigger for gamma conversions. test macros are added soon.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerAgent.cxx
CommitLineData
89858ccc 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"
18a9a5ad 27#include "AliHLTTriggerDecision.h"
28#include "AliHLTOUT.h"
29#include "AliHLTMessage.h"
30#include "AliESDEvent.h"
c86017ac 31#include "TObjString.h"
32#include "TObjArray.h"
18a9a5ad 33#include "TArrayC.h"
89858ccc 34
35// header files of library components
36#include "AliHLTEventSummaryProducerComponent.h"
37#include "AliHLTRunSummaryProducerComponent.h"
c86017ac 38#include "AliHLTTriggerBarrelMultiplicity.h"
fde46e9e 39#include "AliHLTTriggerBarrelGeomMultiplicity.h"
c86017ac 40#include "AliHLTTriggerBarrelCosmic.h"
5d79eb88 41#include "AliHLTGlobalTriggerComponent.h"
765d85f8 42#include "AliHLTTriggerPhosClusterEnergy.h"
f86ecd3e 43#include "AliHLTTriggerPhosMip.h"
495570cd 44#include "AliHLTTriggerTrdClusterMultiplicity.h"
fc2b0c6d 45#include "AliHLTTriggerGammaConversion.h"
89858ccc 46
47/** global instance for agent registration */
48AliHLTTriggerAgent gAliHLTTriggerAgent;
49
50/** ROOT macro for the implementation of ROOT specific class methods */
51ClassImp(AliHLTTriggerAgent)
52
53AliHLTTriggerAgent::AliHLTTriggerAgent()
18a9a5ad 54 : AliHLTModuleAgent("Trigger")
55 , fTriggerDecisionHandler(NULL)
89858ccc 56{
57 // see header file for class documentation
58 // or
59 // refer to README to build package
60 // or
61 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62}
63
64AliHLTTriggerAgent::~AliHLTTriggerAgent()
65{
66 // see header file for class documentation
67}
68
69int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
70{
71 // see header file for class documentation
72 assert(pHandler);
73 if (!pHandler) return -EINVAL;
5d79eb88 74 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
c86017ac 75 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
fde46e9e 76 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
c86017ac 77 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
765d85f8 78 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
f86ecd3e 79 pHandler->AddComponent(new AliHLTTriggerPhosMip);
fc2b0c6d 80 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
81 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
89858ccc 82 return 0;
83}
84
c86017ac 85int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
86 AliRawReader* /*rawReader*/,
87 AliRunLoader* /*runloader*/) const
88{
89 // see header file for class documentation
90 if (!pHandler) return -EINVAL;
91
92 TString triggerInputs;
93 TString triggerOutputs;
94 TString configurationId;
95 /////////////////////////////////////////////////////////////////////////////////////
96 //
97 // a central barrel charged particle multiplicity trigger
98 configurationId="TRIGGER-Barrel-Multiplicity";
99
100 // define the inputsfor the BarrelMultiplicityTrigger
101 triggerInputs="GLOBAL-esd-converter";
102
103 // check for the availibility
104 TObjArray* pTokens=triggerInputs.Tokenize(" ");
105 triggerInputs="";
106 if (pTokens) {
107 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
108 TString module=((TObjString*)pTokens->At(n))->GetString();
109 if (pHandler->FindConfiguration(module.Data())) {
110 triggerInputs+=module;
111 triggerInputs+=" ";
112 }
113 }
114 delete pTokens;
115 }
116
117 if (triggerInputs.Length()>0) {
118 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
119 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
120 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
121 triggerOutputs+=configurationId;
122 } else {
123 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
124 }
125
126 /////////////////////////////////////////////////////////////////////////////////////
127 //
128 // the global trigger component
129 configurationId="GLOBAL-Trigger";
130 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
131 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
132
133 return 0;
134}
135
136const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
137 AliRunLoader* runloader) const
138{
139 // see header file for class documentation
140 if (runloader) {
141 // reconstruction chains for AliRoot simulation
142 // Note: run loader is only available while running embedded into
143 // AliRoot simulation
144
145 // currently disabled due to a problem compiling the runtime trigger library
18a9a5ad 146 return "GLOBAL-Trigger";
c86017ac 147 }
148 return NULL;
149}
150
151const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
152{
153 // see header file for class documentation
154
155 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
156}
157
89858ccc 158int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
159 AliHLTUInt32_t /*spec*/,
160 AliHLTOUTHandlerDesc& desc) const
161{
162 // see header file for class documentation
163
18a9a5ad 164 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
165 // currently stored as a TObject with the common data type and origin
166 // HLTOUT. However we might need a separate data type in order to
167 // avoid interference with other handlers
168 // the handler produces an ESD object in order to be merged to the
169 // hltEsd afterwards
170 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
171 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
172 return 1;
173 }
174
89858ccc 175 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
176 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
177 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
178 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
179 return 1;
180 }
181
182 return 0;
183}
184
185AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
18a9a5ad 186 AliHLTUInt32_t /*spec*/)
89858ccc 187{
188 // see header file for class documentation
189
18a9a5ad 190 // raw data blocks to be fed into offline reconstruction
191 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
192 if (!fTriggerDecisionHandler) {
193 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
194 }
195 return fTriggerDecisionHandler;
196 }
197
89858ccc 198 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
199 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
200 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
201 return NULL;
202 }
203
204 return NULL;
205}
206
207int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
208{
209 // see header file for class documentation
210 if (pInstance==NULL) return -EINVAL;
211
18a9a5ad 212 if (pInstance==fTriggerDecisionHandler) {
213 delete fTriggerDecisionHandler;
214 fTriggerDecisionHandler=NULL;
215 }
216
89858ccc 217 return 0;
218}
18a9a5ad 219
220AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
221 : AliHLTOUTHandler()
222 , fESD(NULL)
223 , fpData(NULL)
224 , fSize(0)
225{
226 // see header file for class documentation
227}
228
229AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
230{
231 // see header file for class documentation
232 if (fESD) delete fESD;
233 fESD=NULL;
234
235 if (fpData) delete fpData;
236 fpData=NULL;
237 fSize=0;
238}
239
240int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
241{
242 // see header file for class documentation
243 if (!pData) return -EINVAL;
e13512e4 244 pData->SelectFirstDataBlock();
18a9a5ad 245 AliHLTComponentDataType dt=kAliHLTVoidDataType;
246 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
247 int iResult=pData->GetDataBlockDescription(dt, spec);
248 if (iResult>=0) {
249 TObject* pObject=pData->GetDataObject();
250 if (pObject) {
30d84601 251 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
252 if (pDecision) {
e13512e4 253 //pDecision->Print();
30d84601 254 HLTDebug("extracted %s", pDecision->GetName());
18a9a5ad 255 if (!fESD) {
256 // create the ESD container, but without std content
257 fESD = new AliESDEvent;
258 }
259 if (!fpData) fpData=new TArrayC;
260 if (fESD && fpData) {
261 fESD->Reset();
30d84601 262 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
263 if (pESDObject) {
264 // copy the content to the already existing object
265 pObject->Copy(*pESDObject);
266 } else {
267 // add a new object
268 fESD->AddObject(pObject->Clone());
269 }
18a9a5ad 270 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
271 if (pMsg) {
272 if (!pMsg->CompBuffer()) {
273 fSize=pMsg->Length();
274 fpData->Set(fSize, pMsg->Buffer());
275 } else {
276 fSize=pMsg->CompLength();
277 fpData->Set(fSize, pMsg->CompBuffer());
278 }
279 } else {
280 HLTError("streaming of objects failed");
281 }
282 } else {
283 HLTError("memory allocation failed");
284 iResult=-ENOMEM;
285 }
286 } else {
287 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
288 iResult=-ENODATA;
289 }
290 pData->ReleaseDataObject(pObject);
291 pObject=NULL;
292 } else {
293 HLTError("can not get TObject from HLTOUT buffer");
294 iResult=-ENODATA;
295 }
296 }
e13512e4 297 if (iResult>=0) {
298 if (pData->SelectNextDataBlock()>=0) {
299 HLTWarning("current implementation of trigger decision handler can only handle one block");
300 }
301 return fSize;
302 }
18a9a5ad 303 fSize=0;
304 return iResult;
305}
306
307int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
308{
309 // see header file for class documentation
310 if (!fpData) {
311 pData=NULL;
312 return 0;
313 }
314
315 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
316 return fSize;
317}
318
319int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
320{
321 // see header file for class documentation
322 int iResult=0;
323 if (!fpData || size != fSize ||
324 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
325 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
326 }
327 fSize=0;
328 return iResult;
329}