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 "AliHLTEventSummaryProducerComponent.h"
40 #include "AliHLTRunSummaryProducerComponent.h"
41 #include "AliHLTTriggerBarrelMultiplicity.h"
42 #include "AliHLTD0Trigger.h"
43 #include "AliHLTTriggerITSMultiplicity.h"
44 #include "AliHLTTriggerBarrelGeomMultiplicity.h"
45 #include "AliHLTTriggerBarrelCosmic.h"
46 #include "AliHLTGlobalTriggerComponent.h"
47 #include "AliHLTTriggerPhosClusterEnergy.h"
48 #include "AliHLTTriggerEmcalClusterEnergy.h"
49 #include "AliHLTTriggerPhosMip.h"
50 #include "AliHLTTriggerTrdClusterMultiplicity.h"
51 #include "AliHLTTriggerGammaConversion.h"
52 #include "AliHLTMuonSpectroTriggerComponent.h"
54 /** global instance for agent registration */
55 AliHLTTriggerAgent gAliHLTTriggerAgent;
57 /** ROOT macro for the implementation of ROOT specific class methods */
58 ClassImp(AliHLTTriggerAgent)
60 AliHLTTriggerAgent::AliHLTTriggerAgent()
61 : AliHLTModuleAgent("Trigger")
62 , fTriggerDecisionHandler(NULL)
64 // see header file for class documentation
66 // refer to README to build package
68 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
71 AliHLTTriggerAgent::~AliHLTTriggerAgent()
73 // see header file for class documentation
76 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
78 // see header file for class documentation
80 if (!pHandler) return -EINVAL;
81 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
82 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
83 pHandler->AddComponent(new AliHLTTriggerITSMultiplicity);
84 pHandler->AddComponent(new AliHLTD0Trigger);
85 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
86 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
87 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
88 pHandler->AddComponent(new AliHLTTriggerEmcalClusterEnergy);
89 pHandler->AddComponent(new AliHLTTriggerPhosMip);
90 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
91 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
92 pHandler->AddComponent(new AliHLTMuonSpectroTriggerComponent);
96 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
97 AliRawReader* /*rawReader*/,
98 AliRunLoader* /*runloader*/) const
100 // see header file for class documentation
101 if (!pHandler) return -EINVAL;
103 TString triggerInputs;
104 TString triggerOutputs;
105 TString configurationId;
106 /////////////////////////////////////////////////////////////////////////////////////
108 // a central barrel charged particle multiplicity trigger
109 configurationId="TRIGGER-Barrel-Multiplicity";
111 // define the inputs for the BarrelMultiplicityTrigger
112 triggerInputs="GLOBAL-esd-converter";
114 // check for the availibility
115 TObjArray* pTokens=triggerInputs.Tokenize(" ");
118 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
119 TString module=((TObjString*)pTokens->At(n))->GetString();
120 if (pHandler->FindConfiguration(module.Data())) {
121 triggerInputs+=module;
129 if (triggerInputs.Length()>0) {
130 // define multiple instances of the BarrelMultiplicityTrigger with different settings
131 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
132 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
133 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
134 triggerOutputs+=configurationId;
136 configurationId="TRIGGER-Barrel-HighMultiplicity";
137 arg="-triggername BarrelHighMultiplicity";
138 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
139 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
140 triggerOutputs+=configurationId;
142 configurationId="TRIGGER-Barrel-Pt_v01";
143 arg="-triggername BarrelPt_v01";
144 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
145 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
146 triggerOutputs+=configurationId;
148 configurationId="TRIGGER-Barrel-Pt_v02";
149 arg="-triggername BarrelPt_v02";
150 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
151 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
152 triggerOutputs+=configurationId;
154 configurationId="TRIGGER-Barrel-Pt_v03";
155 arg="-triggername BarrelPt_v03";
156 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), arg.Data());
157 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
158 triggerOutputs+=configurationId;
160 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
163 /////////////////////////////////////////////////////////////////////////////////////
164 // The muon spectrometer trigger
165 configurationId = "TRIGGER-Muon-Spectrometer";
167 // define the inputsfor the muon spectrometer trigger.
168 if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
169 triggerInputs = "dHLT-sim-fromRaw";
171 else if (pHandler->FindConfiguration("dHLT-sim")) {
172 triggerInputs = "dHLT-sim";
174 else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
175 triggerInputs = "dHLT-sim-fromMC";
178 if (triggerInputs.Length() > 0) {
179 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
180 pHandler->CreateConfiguration(configurationId.Data(), "MuonSpectroTrigger", triggerInputs.Data(), "-makestats");
181 if (triggerOutputs.Length() > 0) triggerOutputs += " ";
182 triggerOutputs += configurationId;
184 HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
187 /////////////////////////////////////////////////////////////////////////////////////
189 // the global trigger component
190 configurationId="GLOBAL-Trigger";
191 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
192 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
197 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
198 AliRunLoader* runloader) const
200 // see header file for class documentation
202 // reconstruction chains for AliRoot simulation
203 // Note: run loader is only available while running embedded into
204 // AliRoot simulation
206 // currently disabled due to a problem compiling the runtime trigger library
207 return "GLOBAL-Trigger";
212 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
214 // see header file for class documentation
216 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so libAliHLTMUON.so";
219 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
220 AliHLTUInt32_t /*spec*/,
221 AliHLTOUTHandlerDesc& desc) const
223 // see header file for class documentation
225 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
226 // currently stored as a TObject with the common data type and origin
227 // HLTOUT. However we might need a separate data type in order to
228 // avoid interference with other handlers
229 // the handler produces an ESD object in order to be merged to the
231 // 2009-11-17 adding the data tyepes for (global) trigger decisions
232 // the TObject data types stays for a while in order to preserve
233 // backward compatibility
234 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
235 dt==kAliHLTDataTypeTriggerDecision ||
236 dt==kAliHLTDataTypeGlobalTrigger) {
237 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
241 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
242 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
243 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
244 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
251 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
252 AliHLTUInt32_t /*spec*/)
254 // see header file for class documentation
256 // raw data blocks to be fed into offline reconstruction
257 if ((dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
258 (dt==kAliHLTDataTypeTriggerDecision) ||
259 (dt==kAliHLTDataTypeGlobalTrigger))) {
260 if (!fTriggerDecisionHandler) {
261 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
263 return fTriggerDecisionHandler;
266 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
267 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
268 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
275 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
277 // see header file for class documentation
278 if (pInstance==NULL) return -EINVAL;
280 if (pInstance==fTriggerDecisionHandler) {
281 delete fTriggerDecisionHandler;
282 fTriggerDecisionHandler=NULL;
288 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
296 // see header file for class documentation
299 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
301 // see header file for class documentation
303 fpESDtree->GetUserInfo()->Clear();
314 if (fESD) delete fESD;
317 if (fpData) delete fpData;
322 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
324 // see header file for class documentation
325 if (!pData) return -EINVAL;
327 AliHLTGlobalTriggerDecision* pGlobalDecision=NULL;
328 TObjArray triggerDecisions;
329 triggerDecisions.SetOwner(kTRUE);
330 for (iResult=pData->SelectFirstDataBlock(); iResult>=0; iResult=pData->SelectNextDataBlock()) {
331 AliHLTComponentDataType dt=kAliHLTVoidDataType;
332 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
333 if ((iResult=pData->GetDataBlockDescription(dt, spec))<0) break;
334 TObject* pObject=pData->GetDataObject();
336 if(dt==kAliHLTDataTypeGlobalTrigger) {
337 if (!pGlobalDecision) {
338 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
339 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
340 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
343 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
345 } else if (dt==kAliHLTDataTypeTriggerDecision) {
346 if (pObject->IsA() == AliHLTTriggerDecision::Class() &&
347 !(pObject->IsA() == AliHLTGlobalTriggerDecision::Class())) {
348 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
350 if (pGlobalDecision) {
352 pGlobalDecision->AddTriggerInput(*pDecision);
355 triggerDecisions.Add(pDecision->Clone());
358 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
361 } else if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)){
362 // this is the branch for keeping compatibility
363 // the first version of the trigger framework was using the kAliHLTDataTypeTObject
364 // data type instead of the specific data types for HLT triggers
365 // this effects the cosmic data taken Sep to Oct 2009
366 if (pObject->IsA() == AliHLTGlobalTriggerDecision::Class()) {
367 if (!pGlobalDecision) {
368 if ((pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pObject))==NULL ||
369 (pGlobalDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(pGlobalDecision->Clone()))==NULL) {
370 HLTFatal("can not convert object of name %s (%s) to HLTGlobalTriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
373 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
375 } else if (pObject->IsA() == AliHLTTriggerDecision::Class()) {
376 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
378 if (pGlobalDecision) {
380 pGlobalDecision->AddTriggerInput(*pDecision);
383 triggerDecisions.Add(pDecision->Clone());
386 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
390 pData->ReleaseDataObject(pObject);
393 HLTError("can not get TObject from HLTOUT buffer");
397 // -ENOENT just signals that there are no more entries
398 if (iResult==-ENOENT) iResult=0;
400 if (pGlobalDecision) {
401 for (int i=0; i<triggerDecisions.GetEntriesFast(); i++) {
402 if (triggerDecisions[i]) {
403 pGlobalDecision->AddTriggerInput(*((AliHLTTriggerDecision*)triggerDecisions[i]));
406 triggerDecisions.Delete();
407 AliHLTTriggerDecision* pDecision=pGlobalDecision;
410 //pDecision->Print();
411 HLTDebug("extracted %s", pDecision->GetName());
413 // create the ESD container, but without std content
414 fESD = new AliESDEvent;
416 if (!fpData) fpData=new TArrayC;
417 if (fESD && fpData) {
419 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
421 // copy the content to the already existing object
422 pDecision->Copy(*pESDObject);
425 fESD->AddObject(pDecision->Clone());
428 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
430 if (!pMsg->CompBuffer()) {
431 fSize=pMsg->Length();
432 fpData->Set(fSize, pMsg->Buffer());
434 fSize=pMsg->CompLength();
435 fpData->Set(fSize, pMsg->CompBuffer());
438 HLTError("streaming of objects failed");
441 HLTError("memory allocation failed");
446 delete pGlobalDecision;
447 pGlobalDecision=NULL;
449 HLTError("no global trigger found in data collection");
459 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
461 // see header file for class documentation
467 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
471 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
473 // see header file for class documentation
475 if (!fpData || size != fSize ||
476 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
477 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
483 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::WriteESD()
485 // see header file for class documentation
489 fpESDfile=new TFile("HLTdecision.root", "RECREATE");
492 fpESDtree=new TTree("HLTesdTree", "Tree with HLT ESD containing HLT decision");
494 fESD->WriteToTree(fpESDtree);
495 fpESDtree->GetUserInfo()->Add(fESD);
498 if (!fpESDfile || !fpESDtree) return -ENOMEM;
502 fpESDtree->Write(fpESDtree->GetName(),TObject::kOverwrite);