]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/trigger/AliHLTTriggerAgent.cxx
Update of the SSD on-line clusterfinder:
[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"
8a8ea98b 28#include "AliHLTGlobalTriggerDecision.h"
18a9a5ad 29#include "AliHLTOUT.h"
30#include "AliHLTMessage.h"
31#include "AliESDEvent.h"
c86017ac 32#include "TObjString.h"
33#include "TObjArray.h"
18a9a5ad 34#include "TArrayC.h"
8a8ea98b 35#include "TFile.h"
36#include "TTree.h"
89858ccc 37
38// header files of library components
39#include "AliHLTEventSummaryProducerComponent.h"
40#include "AliHLTRunSummaryProducerComponent.h"
c86017ac 41#include "AliHLTTriggerBarrelMultiplicity.h"
5f4502cc 42#include "AliHLTD0Trigger.h"
43#include "AliHLTTriggerITSMultiplicity.h"
fde46e9e 44#include "AliHLTTriggerBarrelGeomMultiplicity.h"
c86017ac 45#include "AliHLTTriggerBarrelCosmic.h"
5d79eb88 46#include "AliHLTGlobalTriggerComponent.h"
765d85f8 47#include "AliHLTTriggerPhosClusterEnergy.h"
f86ecd3e 48#include "AliHLTTriggerPhosMip.h"
495570cd 49#include "AliHLTTriggerTrdClusterMultiplicity.h"
fc2b0c6d 50#include "AliHLTTriggerGammaConversion.h"
c1550d2c 51#include "AliHLTMuonSpectroTriggerComponent.h"
89858ccc 52
53/** global instance for agent registration */
54AliHLTTriggerAgent gAliHLTTriggerAgent;
55
56/** ROOT macro for the implementation of ROOT specific class methods */
57ClassImp(AliHLTTriggerAgent)
58
59AliHLTTriggerAgent::AliHLTTriggerAgent()
18a9a5ad 60 : AliHLTModuleAgent("Trigger")
61 , fTriggerDecisionHandler(NULL)
89858ccc 62{
63 // see header file for class documentation
64 // or
65 // refer to README to build package
66 // or
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68}
69
70AliHLTTriggerAgent::~AliHLTTriggerAgent()
71{
72 // see header file for class documentation
73}
74
75int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
76{
77 // see header file for class documentation
78 assert(pHandler);
79 if (!pHandler) return -EINVAL;
5d79eb88 80 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
c86017ac 81 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
5f4502cc 82 pHandler->AddComponent(new AliHLTTriggerITSMultiplicity);
83 pHandler->AddComponent(new AliHLTD0Trigger);
fde46e9e 84 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
c86017ac 85 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
765d85f8 86 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
f86ecd3e 87 pHandler->AddComponent(new AliHLTTriggerPhosMip);
fc2b0c6d 88 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
89 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
c1550d2c 90 pHandler->AddComponent(new AliHLTMuonSpectroTriggerComponent);
89858ccc 91 return 0;
92}
93
c86017ac 94int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
95 AliRawReader* /*rawReader*/,
96 AliRunLoader* /*runloader*/) const
97{
98 // see header file for class documentation
99 if (!pHandler) return -EINVAL;
100
101 TString triggerInputs;
102 TString triggerOutputs;
103 TString configurationId;
104 /////////////////////////////////////////////////////////////////////////////////////
105 //
106 // a central barrel charged particle multiplicity trigger
107 configurationId="TRIGGER-Barrel-Multiplicity";
108
feb0a3ff 109 // define the inputs for the BarrelMultiplicityTrigger
c86017ac 110 triggerInputs="GLOBAL-esd-converter";
111
112 // check for the availibility
113 TObjArray* pTokens=triggerInputs.Tokenize(" ");
114 triggerInputs="";
115 if (pTokens) {
116 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
117 TString module=((TObjString*)pTokens->At(n))->GetString();
118 if (pHandler->FindConfiguration(module.Data())) {
119 triggerInputs+=module;
120 triggerInputs+=" ";
121 }
122 }
123 delete pTokens;
124 }
125
feb0a3ff 126 TString arg;
c86017ac 127 if (triggerInputs.Length()>0) {
feb0a3ff 128 // define multiple instances of the BarrelMultiplicityTrigger with different settings
c86017ac 129 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
130 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
131 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
132 triggerOutputs+=configurationId;
feb0a3ff 133
134 configurationId="TRIGGER-Barrel-HighMultiplicity";
135 arg="-triggername BarrelHighMultiplicity";
136 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
137 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
138 triggerOutputs+=configurationId;
139
140 configurationId="TRIGGER-Barrel-Pt_v01";
141 arg="-triggername BarrelPt_v01";
142 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
143 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
144 triggerOutputs+=configurationId;
145
146 configurationId="TRIGGER-Barrel-Pt_v02";
147 arg="-triggername BarrelPt_v02";
148 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
149 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
150 triggerOutputs+=configurationId;
151
152 configurationId="TRIGGER-Barrel-Pt_v03";
153 arg="-triggername BarrelPt_v03";
154 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
155 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
156 triggerOutputs+=configurationId;
c86017ac 157 } else {
158 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
159 }
c1550d2c 160
161 /////////////////////////////////////////////////////////////////////////////////////
162 // The muon spectrometer trigger
163 configurationId = "TRIGGER-Muon-Spectrometer";
164
165 // define the inputsfor the muon spectrometer trigger.
166 if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
167 triggerInputs = "dHLT-sim-fromRaw";
168 }
169 else if (pHandler->FindConfiguration("dHLT-sim")) {
170 triggerInputs = "dHLT-sim";
171 }
172 else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
173 triggerInputs = "dHLT-sim-fromMC";
174 }
175
176 if (triggerInputs.Length() > 0) {
177 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
178 pHandler->CreateConfiguration(configurationId.Data(), "MuonSpectroTrigger", triggerInputs.Data(), "-makestats");
179 if (triggerOutputs.Length() > 0) triggerOutputs += " ";
180 triggerOutputs += configurationId;
181 } else {
182 HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
183 }
c86017ac 184
185 /////////////////////////////////////////////////////////////////////////////////////
186 //
187 // the global trigger component
188 configurationId="GLOBAL-Trigger";
189 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
190 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
191
192 return 0;
193}
194
195const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
196 AliRunLoader* runloader) const
197{
198 // see header file for class documentation
199 if (runloader) {
200 // reconstruction chains for AliRoot simulation
201 // Note: run loader is only available while running embedded into
202 // AliRoot simulation
203
204 // currently disabled due to a problem compiling the runtime trigger library
18a9a5ad 205 return "GLOBAL-Trigger";
c86017ac 206 }
207 return NULL;
208}
209
210const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
211{
212 // see header file for class documentation
213
c1550d2c 214 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so libAliHLTMUON.so";
c86017ac 215}
216
89858ccc 217int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
218 AliHLTUInt32_t /*spec*/,
219 AliHLTOUTHandlerDesc& desc) const
220{
221 // see header file for class documentation
222
18a9a5ad 223 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
224 // currently stored as a TObject with the common data type and origin
225 // HLTOUT. However we might need a separate data type in order to
226 // avoid interference with other handlers
227 // the handler produces an ESD object in order to be merged to the
228 // hltEsd afterwards
8a8ea98b 229 // 2009-11-17 adding the data tyepes for (global) trigger decisions
230 // the TObject data types stays for a while in order to preserve
231 // backward compatibility
232 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
233 dt==kAliHLTDataTypeTriggerDecision ||
234 dt==kAliHLTDataTypeGlobalTrigger) {
18a9a5ad 235 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
236 return 1;
237 }
238
89858ccc 239 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
240 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
241 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
242 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
243 return 1;
244 }
245
246 return 0;
247}
248
249AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
18a9a5ad 250 AliHLTUInt32_t /*spec*/)
89858ccc 251{
252 // see header file for class documentation
253
18a9a5ad 254 // raw data blocks to be fed into offline reconstruction
8a8ea98b 255 if ((dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
256 (dt==kAliHLTDataTypeTriggerDecision) ||
257 (dt==kAliHLTDataTypeGlobalTrigger))) {
18a9a5ad 258 if (!fTriggerDecisionHandler) {
259 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
260 }
261 return fTriggerDecisionHandler;
262 }
263
89858ccc 264 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
265 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
266 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
267 return NULL;
268 }
269
270 return NULL;
271}
272
273int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
274{
275 // see header file for class documentation
276 if (pInstance==NULL) return -EINVAL;
277
18a9a5ad 278 if (pInstance==fTriggerDecisionHandler) {
279 delete fTriggerDecisionHandler;
280 fTriggerDecisionHandler=NULL;
281 }
282
89858ccc 283 return 0;
284}
18a9a5ad 285
286AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
287 : AliHLTOUTHandler()
288 , fESD(NULL)
289 , fpData(NULL)
290 , fSize(0)
8a8ea98b 291 , fpESDfile(NULL)
292 , fpESDtree(NULL)
18a9a5ad 293{
294 // see header file for class documentation
295}
296
297AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
298{
299 // see header file for class documentation
8a8ea98b 300 if (fpESDtree) {
301 fpESDtree->GetUserInfo()->Clear();
302 delete fpESDtree;
303 }
304 fpESDtree=NULL;
305
306 if (fpESDfile) {
307 fpESDfile->Close();
308 delete fpESDfile;
309 }
310 fpESDfile=NULL;
311
18a9a5ad 312 if (fESD) delete fESD;
313 fESD=NULL;
314
315 if (fpData) delete fpData;
316 fpData=NULL;
317 fSize=0;
318}
319
320int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
321{
322 // see header file for class documentation
323 if (!pData) return -EINVAL;
8a8ea98b 324 int iResult=0;
325 AliHLTGlobalTriggerDecision* pGlobalDecision=NULL;
326 TObjArray triggerDecisions;
327 triggerDecisions.SetOwner(kTRUE);
328 for (iResult=pData->SelectFirstDataBlock(); iResult>=0; iResult=pData->SelectNextDataBlock()) {
329 AliHLTComponentDataType dt=kAliHLTVoidDataType;
330 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
331 if ((iResult=pData->GetDataBlockDescription(dt, spec))<0) break;
18a9a5ad 332 TObject* pObject=pData->GetDataObject();
333 if (pObject) {
8a8ea98b 334 if(dt==kAliHLTDataTypeGlobalTrigger) {
335 if (!pGlobalDecision) {
336 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
337 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
338 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
339 }
340 } else {
341 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
342 }
343 } else if (dt==kAliHLTDataTypeTriggerDecision) {
344 if (pObject->IsA() == AliHLTTriggerDecision::Class() &&
345 !(pObject->IsA() == AliHLTGlobalTriggerDecision::Class())) {
346 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
347 if (pDecision) {
348 if (pGlobalDecision) {
349 // add directly
350 pGlobalDecision->AddTriggerInput(*pDecision);
351 } else {
352 // schedule
353 triggerDecisions.Add(pDecision->Clone());
354 }
355 } else {
356 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
357 }
358 }
359 } else if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)){
360 // this is the branch for keeping compatibility
361 // the first version of the trigger framework was using the kAliHLTDataTypeTObject
362 // data type instead of the specific data types for HLT triggers
363 // this effects the cosmic data taken Sep to Oct 2009
364 if (pObject->IsA() == AliHLTGlobalTriggerDecision::Class()) {
365 if (!pGlobalDecision) {
366 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
367 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
368 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
369 }
370 } else {
371 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
372 }
373 } else if (pObject->IsA() == AliHLTTriggerDecision::Class()) {
374 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
375 if (pDecision) {
376 if (pGlobalDecision) {
377 // add directly
378 pGlobalDecision->AddTriggerInput(*pDecision);
379 } else {
380 // schedule
381 triggerDecisions.Add(pDecision->Clone());
382 }
383 } else {
384 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
385 }
386 }
387 }
388 pData->ReleaseDataObject(pObject);
389 pObject=NULL;
390 } else {
391 HLTError("can not get TObject from HLTOUT buffer");
392 iResult=-ENODATA;
393 }
394 }
395 // -ENOENT just signals that there are no more entries
396 if (iResult==-ENOENT) iResult=0;
397
398 if (pGlobalDecision) {
399 for (int i=0; i<triggerDecisions.GetEntriesFast(); i++) {
400 if (triggerDecisions[i]) {
401 pGlobalDecision->AddTriggerInput(*((AliHLTTriggerDecision*)triggerDecisions[i]));
402 }
403 }
404 triggerDecisions.Delete();
405 AliHLTTriggerDecision* pDecision=pGlobalDecision;
406 {
30d84601 407 if (pDecision) {
e13512e4 408 //pDecision->Print();
30d84601 409 HLTDebug("extracted %s", pDecision->GetName());
18a9a5ad 410 if (!fESD) {
411 // create the ESD container, but without std content
412 fESD = new AliESDEvent;
413 }
414 if (!fpData) fpData=new TArrayC;
415 if (fESD && fpData) {
416 fESD->Reset();
30d84601 417 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
418 if (pESDObject) {
419 // copy the content to the already existing object
8a8ea98b 420 pDecision->Copy(*pESDObject);
30d84601 421 } else {
422 // add a new object
8a8ea98b 423 fESD->AddObject(pDecision->Clone());
30d84601 424 }
8a8ea98b 425 WriteESD();
18a9a5ad 426 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
427 if (pMsg) {
428 if (!pMsg->CompBuffer()) {
429 fSize=pMsg->Length();
430 fpData->Set(fSize, pMsg->Buffer());
431 } else {
432 fSize=pMsg->CompLength();
433 fpData->Set(fSize, pMsg->CompBuffer());
434 }
435 } else {
436 HLTError("streaming of objects failed");
437 }
438 } else {
439 HLTError("memory allocation failed");
440 iResult=-ENOMEM;
441 }
18a9a5ad 442 }
18a9a5ad 443 }
8a8ea98b 444 delete pGlobalDecision;
445 pGlobalDecision=NULL;
446 } else {
447 HLTError("no global trigger found in data collection");
18a9a5ad 448 }
8a8ea98b 449
e13512e4 450 if (iResult>=0) {
e13512e4 451 return fSize;
452 }
18a9a5ad 453 fSize=0;
454 return iResult;
455}
456
457int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
458{
459 // see header file for class documentation
460 if (!fpData) {
461 pData=NULL;
462 return 0;
463 }
464
465 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
466 return fSize;
467}
468
469int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
470{
471 // see header file for class documentation
472 int iResult=0;
473 if (!fpData || size != fSize ||
474 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
475 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
476 }
477 fSize=0;
478 return iResult;
479}
8a8ea98b 480
481int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::WriteESD()
482{
483 // see header file for class documentation
484 int iResult=0;
485 if (!fESD) return 0;
486 if (!fpESDfile) {
487 fpESDfile=new TFile("HLTdecision.root", "RECREATE");
488 }
489 if (!fpESDtree) {
490 fpESDtree=new TTree("HLTesdTree", "Tree with HLT ESD containing HLT decision");
491 if (fpESDtree) {
492 fESD->WriteToTree(fpESDtree);
493 fpESDtree->GetUserInfo()->Add(fESD);
494 }
495 }
496 if (!fpESDfile || !fpESDtree) return -ENOMEM;
497
498 fpESDtree->Fill();
499 fpESDfile->cd();
500 fpESDtree->Write(fpESDtree->GetName(),TObject::kOverwrite);
501
502 return iResult;
503}