3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTriggerAgent.cxx
20 @author Matthias Richter
22 @brief Agent of the libAliHLTTrigger library
26 #include "AliHLTTriggerAgent.h"
27 #include "AliHLTTriggerDecision.h"
28 #include "AliHLTGlobalTriggerDecision.h"
29 #include "AliHLTOUT.h"
30 #include "AliHLTMessage.h"
31 #include "AliESDEvent.h"
32 #include "TObjString.h"
33 #include "TObjArray.h"
38 // header files of library components
39 #include "AliHLTTriggerBarrelMultiplicity.h"
40 #include "AliHLTD0Trigger.h"
41 #include "AliHLTTriggerITSMultiplicity.h"
42 #include "AliHLTTriggerBarrelGeomMultiplicity.h"
43 #include "AliHLTGlobalTriggerComponent.h"
44 #include "AliHLTTriggerPhosClusterEnergy.h"
45 #include "AliHLTTriggerEmcalClusterEnergy.h"
46 #include "AliHLTTriggerPhosMip.h"
47 #include "AliHLTTriggerTrdClusterMultiplicity.h"
48 #include "AliHLTTriggerGammaConversion.h"
49 #include "AliHLTMuonSpectroTriggerComponent.h"
50 #include "AliHLTUpcTriggerComponent.h"
51 #include "AliHLTTriggerCosmics.h"
52 #include "AliHLTTriggerCounterComponent.h"
53 #include "AliHLTTriggerEmcalElectron.h"
54 //#include "AliHLTTriggerFastJet.h"
55 #include "AliHLTFastJetMonitorComponent.h"
56 #include "AliHLTEmcalElectronMonitorComponent.h"
57 #include "AliHLTTRDTriggerComponent.h"
59 /** global instance for agent registration */
60 AliHLTTriggerAgent gAliHLTTriggerAgent;
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTTriggerAgent)
65 AliHLTTriggerAgent::AliHLTTriggerAgent()
66 : AliHLTModuleAgent("Trigger")
67 , fTriggerDecisionHandler(NULL)
69 // see header file for class documentation
71 // refer to README to build package
73 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
76 AliHLTTriggerAgent::~AliHLTTriggerAgent()
78 // see header file for class documentation
81 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
83 // see header file for class documentation
85 if (!pHandler) return -EINVAL;
86 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
87 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
88 pHandler->AddComponent(new AliHLTTriggerITSMultiplicity);
89 pHandler->AddComponent(new AliHLTD0Trigger);
90 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
91 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
92 pHandler->AddComponent(new AliHLTTriggerEmcalClusterEnergy);
93 pHandler->AddComponent(new AliHLTTriggerPhosMip);
94 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
95 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
96 pHandler->AddComponent(new AliHLTMuonSpectroTriggerComponent);
97 pHandler->AddComponent(new AliHLTUpcTriggerComponent);
98 pHandler->AddComponent(new AliHLTTriggerCosmics);
99 pHandler->AddComponent(new AliHLTTriggerCounterComponent);
100 pHandler->AddComponent(new AliHLTTriggerEmcalElectron);
101 //pHandler->AddComponent(new AliHLTTriggerFastJet);
102 pHandler->AddComponent(new AliHLTFastJetMonitorComponent);
103 pHandler->AddComponent(new AliHLTEmcalElectronMonitorComponent);
104 pHandler->AddComponent(new AliHLTTRDTriggerComponent);
108 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
109 AliRawReader* rawReader,
110 AliRunLoader* runloader) const
112 // see header file for class documentation
113 if (!pHandler) return -EINVAL;
115 TString triggerInputs;
116 TString triggerOutputs;
117 TString configurationId;
118 /////////////////////////////////////////////////////////////////////////////////////
120 // a central barrel charged particle multiplicity trigger
121 configurationId="TRIGGER-Barrel-Multiplicity";
123 // define the inputs for the BarrelMultiplicityTrigger
124 triggerInputs="GLOBAL-esd-converter";
126 // check for the availibility
127 TObjArray* pTokens=triggerInputs.Tokenize(" ");
130 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
131 if (!pTokens->At(n)) continue;
132 TString module=pTokens->At(n)->GetName();
133 if (pHandler->FindConfiguration(module.Data())) {
134 triggerInputs+=module;
142 if (triggerInputs.Length()>0) {
143 // define multiple instances of the BarrelMultiplicityTrigger with different settings
144 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
145 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
146 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
147 triggerOutputs+=configurationId;
149 configurationId="TRIGGER-Barrel-HighMultiplicity";
150 arg="-triggername BarrelHighMultiplicity";
151 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
152 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
153 triggerOutputs+=configurationId;
155 configurationId="TRIGGER-Barrel-Pt_v01";
156 arg="-triggername BarrelPt_v01";
157 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
158 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
159 triggerOutputs+=configurationId;
161 configurationId="TRIGGER-Barrel-Pt_v02";
162 arg="-triggername BarrelPt_v02";
163 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
164 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
165 triggerOutputs+=configurationId;
167 configurationId="TRIGGER-Barrel-Pt_v03";
168 arg="-triggername BarrelPt_v03";
169 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
170 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
171 triggerOutputs+=configurationId;
173 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
176 /////////////////////////////////////////////////////////////////////////////////////
177 // The muon spectrometer trigger
178 configurationId = "TRIGGER-Muon-Spectrometer";
180 // define the inputsfor the muon spectrometer trigger.
181 if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
182 triggerInputs = "dHLT-sim-fromRaw";
184 else if (pHandler->FindConfiguration("dHLT-sim")) {
185 triggerInputs = "dHLT-sim";
187 else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
188 triggerInputs = "dHLT-sim-fromMC";
191 if (triggerInputs.Length() > 0) {
192 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
193 pHandler->CreateConfiguration(configurationId.Data(), "MuonSpectroTrigger", triggerInputs.Data(), "-makestats");
194 if (triggerOutputs.Length() > 0) triggerOutputs += " ";
195 triggerOutputs += configurationId;
197 HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
200 /////////////////////////////////////////////////////////////////////////////////////
202 configurationId = "TRIGGER-D0";
203 if(runloader && !rawReader){
204 // simulation without simulated raw data
206 triggerInputs="GLOBAL-esd-converter ";
209 // simulation with simulated raw data, or raw data reconstruction
210 // use input from ITS tracker and vertexer directly
211 triggerInputs="ITS-tracker GLOBAL-vertexer";
214 // check for the availibility of inputs
215 pTokens=triggerInputs.Tokenize(" ");
218 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
219 if (!pTokens->At(n)) continue;
220 TString module=pTokens->At(n)->GetName();
221 if (pHandler->FindConfiguration(module.Data())) {
222 triggerInputs+=module;
230 if (triggerInputs.Length()>0) {
231 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
232 pHandler->CreateConfiguration(configurationId.Data(), "D0Trigger", triggerInputs.Data(), argD0.Data());
233 // FIXME: due to a rare segfault for reconstruction of PbPb data the
234 // component is temporarily excluded
235 // https://savannah.cern.ch/bugs/?72590
236 //if (triggerOutputs.Length()>0) triggerOutputs+=" ";
237 //triggerOutputs+=configurationId;
239 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
242 /////////////////////////////////////////////////////////////////////////////////////
244 // the global trigger component
245 configurationId="GLOBAL-Trigger";
246 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
247 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "-skipctp");
252 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
253 AliRunLoader* runloader) const
255 // see header file for class documentation
257 // reconstruction chains for AliRoot simulation
258 // Note: run loader is only available while running embedded into
259 // AliRoot simulation
261 // currently disabled due to a problem compiling the runtime trigger library
262 return "GLOBAL-Trigger";
267 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
269 // see header file for class documentation
274 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
275 AliHLTUInt32_t /*spec*/,
276 AliHLTOUTHandlerDesc& desc) const
278 // get description of HLTOUT data blocks handled by this agent
280 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
281 // currently stored as a TObject with the common data type and origin
282 // HLTOUT. However we might need a separate data type in order to
283 // avoid interference with other handlers
284 // the handler produces an ESD object in order to be merged to the
286 // 2009-11-17 adding the data types for (global) trigger decisions
287 // {GLOBTRIG:HLT } and {TRIG_DEC:HLT }
288 // the TObject data types stays for a while in order to preserve
289 // backward compatibility
290 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
291 dt==kAliHLTDataTypeTriggerDecision ||
292 dt==kAliHLTDataTypeGlobalTrigger) {
293 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
297 // handler for the HLT readout list and trigger data data blocks {'HLTRDLST':'HLT '}
298 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
299 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
300 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
307 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
308 AliHLTUInt32_t /*spec*/)
310 // see header file for class documentation
312 // raw data blocks to be fed into offline reconstruction
313 if ((dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
314 (dt==kAliHLTDataTypeTriggerDecision) ||
315 (dt==kAliHLTDataTypeGlobalTrigger))) {
316 if (!fTriggerDecisionHandler) {
317 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
319 return fTriggerDecisionHandler;
322 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
323 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
324 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
331 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
333 // see header file for class documentation
334 if (pInstance==NULL) return -EINVAL;
336 if (pInstance==fTriggerDecisionHandler) {
337 delete fTriggerDecisionHandler;
338 fTriggerDecisionHandler=NULL;
344 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
352 // see header file for class documentation
355 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
357 // see header file for class documentation
359 fpESDtree->GetUserInfo()->Clear();
370 if (fESD) delete fESD;
373 if (fpData) delete fpData;
378 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
380 // see header file for class documentation
381 if (!pData) return -EINVAL;
383 AliHLTGlobalTriggerDecision* pGlobalDecision=NULL;
384 TObjArray triggerDecisions;
385 triggerDecisions.SetOwner(kTRUE);
386 for (iResult=pData->SelectFirstDataBlock(); iResult>=0; iResult=pData->SelectNextDataBlock()) {
387 AliHLTComponentDataType dt=kAliHLTVoidDataType;
388 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
389 if ((iResult=pData->GetDataBlockDescription(dt, spec))<0) break;
390 TObject* pObject=pData->GetDataObject();
392 if(dt==kAliHLTDataTypeGlobalTrigger) {
393 if (!pGlobalDecision) {
394 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
395 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
396 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
399 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
401 } else if (dt==kAliHLTDataTypeTriggerDecision) {
402 if (pObject->IsA() == AliHLTTriggerDecision::Class() &&
403 !(pObject->IsA() == AliHLTGlobalTriggerDecision::Class())) {
404 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
406 if (pGlobalDecision) {
408 pGlobalDecision->AddTriggerInput(*pDecision);
411 triggerDecisions.Add(pDecision->Clone());
414 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
417 } else if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)){
418 // this is the branch for keeping compatibility
419 // the first version of the trigger framework was using the kAliHLTDataTypeTObject
420 // data type instead of the specific data types for HLT triggers
421 // this effects the cosmic data taken Sep to Oct 2009
422 if (pObject->IsA() == AliHLTGlobalTriggerDecision::Class()) {
423 if (!pGlobalDecision) {
424 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
425 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
426 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
429 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
431 } else if (pObject->IsA() == AliHLTTriggerDecision::Class()) {
432 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
434 if (pGlobalDecision) {
436 pGlobalDecision->AddTriggerInput(*pDecision);
439 triggerDecisions.Add(pDecision->Clone());
442 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
446 pData->ReleaseDataObject(pObject);
449 HLTError("can not get TObject from HLTOUT buffer");
453 // -ENOENT just signals that there are no more entries
454 if (iResult==-ENOENT) iResult=0;
456 if (pGlobalDecision) {
457 for (int i=0; i<triggerDecisions.GetEntriesFast(); i++) {
458 if (triggerDecisions[i]) {
459 pGlobalDecision->AddTriggerInput(*((AliHLTTriggerDecision*)triggerDecisions[i]));
462 triggerDecisions.Delete();
463 AliHLTTriggerDecision* pDecision=pGlobalDecision;
466 //pDecision->Print();
467 HLTDebug("extracted %s", pDecision->GetName());
469 // create the ESD container, but without std content
470 fESD = new AliESDEvent;
472 if (!fpData) fpData=new TArrayC;
473 if (fESD && fpData) {
475 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
477 // copy the content to the already existing object
478 pDecision->Copy(*pESDObject);
481 fESD->AddObject(pDecision->Clone());
484 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
486 if (!pMsg->CompBuffer()) {
487 fSize=pMsg->Length();
488 fpData->Set(fSize, pMsg->Buffer());
490 fSize=pMsg->CompLength();
491 fpData->Set(fSize, pMsg->CompBuffer());
496 HLTError("streaming of objects failed");
499 HLTError("memory allocation failed");
504 delete pGlobalDecision;
505 pGlobalDecision=NULL;
507 HLTError("no global trigger found in data collection");
517 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
519 // see header file for class documentation
525 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
529 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
531 // see header file for class documentation
533 if (!fpData || size != fSize ||
534 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
535 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
541 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::WriteESD()
543 // see header file for class documentation
547 fpESDfile=new TFile("HLTdecision.root", "RECREATE");
550 fpESDtree=new TTree("HLTesdTree", "Tree with HLT ESD containing HLT decision");
552 fESD->WriteToTree(fpESDtree);
553 fpESDtree->GetUserInfo()->Add(fESD);
556 if (!fpESDfile || !fpESDtree) return -ENOMEM;
560 fpESDtree->Write(fpESDtree->GetName(),TObject::kOverwrite);