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 "AliHLTTriggerPhosMip.h"
49 #include "AliHLTTriggerTrdClusterMultiplicity.h"
50 #include "AliHLTTriggerGammaConversion.h"
51 #include "AliHLTMuonSpectroTriggerComponent.h"
53 /** global instance for agent registration */
54 AliHLTTriggerAgent gAliHLTTriggerAgent;
56 /** ROOT macro for the implementation of ROOT specific class methods */
57 ClassImp(AliHLTTriggerAgent)
59 AliHLTTriggerAgent::AliHLTTriggerAgent()
60 : AliHLTModuleAgent("Trigger")
61 , fTriggerDecisionHandler(NULL)
63 // see header file for class documentation
65 // refer to README to build package
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 AliHLTTriggerAgent::~AliHLTTriggerAgent()
72 // see header file for class documentation
75 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
77 // see header file for class documentation
79 if (!pHandler) return -EINVAL;
80 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
81 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
82 pHandler->AddComponent(new AliHLTTriggerITSMultiplicity);
83 pHandler->AddComponent(new AliHLTD0Trigger);
84 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
85 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
86 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
87 pHandler->AddComponent(new AliHLTTriggerPhosMip);
88 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
89 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
90 pHandler->AddComponent(new AliHLTMuonSpectroTriggerComponent);
94 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
95 AliRawReader* /*rawReader*/,
96 AliRunLoader* /*runloader*/) const
98 // see header file for class documentation
99 if (!pHandler) return -EINVAL;
101 TString triggerInputs;
102 TString triggerOutputs;
103 TString configurationId;
104 /////////////////////////////////////////////////////////////////////////////////////
106 // a central barrel charged particle multiplicity trigger
107 configurationId="TRIGGER-Barrel-Multiplicity";
109 // define the inputs for the BarrelMultiplicityTrigger
110 triggerInputs="GLOBAL-esd-converter";
112 // check for the availibility
113 TObjArray* pTokens=triggerInputs.Tokenize(" ");
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;
127 if (triggerInputs.Length()>0) {
128 // define multiple instances of the BarrelMultiplicityTrigger with different settings
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;
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;
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;
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;
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;
158 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
161 /////////////////////////////////////////////////////////////////////////////////////
162 // The muon spectrometer trigger
163 configurationId = "TRIGGER-Muon-Spectrometer";
165 // define the inputsfor the muon spectrometer trigger.
166 if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
167 triggerInputs = "dHLT-sim-fromRaw";
169 else if (pHandler->FindConfiguration("dHLT-sim")) {
170 triggerInputs = "dHLT-sim";
172 else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
173 triggerInputs = "dHLT-sim-fromMC";
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;
182 HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
185 /////////////////////////////////////////////////////////////////////////////////////
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(), "");
195 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
196 AliRunLoader* runloader) const
198 // see header file for class documentation
200 // reconstruction chains for AliRoot simulation
201 // Note: run loader is only available while running embedded into
202 // AliRoot simulation
204 // currently disabled due to a problem compiling the runtime trigger library
205 return "GLOBAL-Trigger";
210 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
212 // see header file for class documentation
214 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so libAliHLTMUON.so";
217 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
218 AliHLTUInt32_t /*spec*/,
219 AliHLTOUTHandlerDesc& desc) const
221 // see header file for class documentation
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
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) {
235 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
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());
249 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
250 AliHLTUInt32_t /*spec*/)
252 // see header file for class documentation
254 // raw data blocks to be fed into offline reconstruction
255 if ((dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut) ||
256 (dt==kAliHLTDataTypeTriggerDecision) ||
257 (dt==kAliHLTDataTypeGlobalTrigger))) {
258 if (!fTriggerDecisionHandler) {
259 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
261 return fTriggerDecisionHandler;
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)) {
273 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
275 // see header file for class documentation
276 if (pInstance==NULL) return -EINVAL;
278 if (pInstance==fTriggerDecisionHandler) {
279 delete fTriggerDecisionHandler;
280 fTriggerDecisionHandler=NULL;
286 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
294 // see header file for class documentation
297 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
299 // see header file for class documentation
301 fpESDtree->GetUserInfo()->Clear();
312 if (fESD) delete fESD;
315 if (fpData) delete fpData;
320 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
322 // see header file for class documentation
323 if (!pData) return -EINVAL;
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;
332 TObject* pObject=pData->GetDataObject();
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());
341 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
343 } else if (dt==kAliHLTDataTypeTriggerDecision) {
344 if (pObject->IsA() == AliHLTTriggerDecision::Class() &&
345 !(pObject->IsA() == AliHLTGlobalTriggerDecision::Class())) {
346 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
348 if (pGlobalDecision) {
350 pGlobalDecision->AddTriggerInput(*pDecision);
353 triggerDecisions.Add(pDecision->Clone());
356 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
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());
371 HLTWarning("multiple HLT GlobalTrigger decision objects, ignoring all but the first one");
373 } else if (pObject->IsA() == AliHLTTriggerDecision::Class()) {
374 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
376 if (pGlobalDecision) {
378 pGlobalDecision->AddTriggerInput(*pDecision);
381 triggerDecisions.Add(pDecision->Clone());
384 HLTFatal("can not convert object of name %s (%s) to HLT TriggerDecsion according to data type", pObject->GetName(), pObject->Class()->GetName());
388 pData->ReleaseDataObject(pObject);
391 HLTError("can not get TObject from HLTOUT buffer");
395 // -ENOENT just signals that there are no more entries
396 if (iResult==-ENOENT) iResult=0;
398 if (pGlobalDecision) {
399 for (int i=0; i<triggerDecisions.GetEntriesFast(); i++) {
400 if (triggerDecisions[i]) {
401 pGlobalDecision->AddTriggerInput(*((AliHLTTriggerDecision*)triggerDecisions[i]));
404 triggerDecisions.Delete();
405 AliHLTTriggerDecision* pDecision=pGlobalDecision;
408 //pDecision->Print();
409 HLTDebug("extracted %s", pDecision->GetName());
411 // create the ESD container, but without std content
412 fESD = new AliESDEvent;
414 if (!fpData) fpData=new TArrayC;
415 if (fESD && fpData) {
417 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
419 // copy the content to the already existing object
420 pDecision->Copy(*pESDObject);
423 fESD->AddObject(pDecision->Clone());
426 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
428 if (!pMsg->CompBuffer()) {
429 fSize=pMsg->Length();
430 fpData->Set(fSize, pMsg->Buffer());
432 fSize=pMsg->CompLength();
433 fpData->Set(fSize, pMsg->CompBuffer());
436 HLTError("streaming of objects failed");
439 HLTError("memory allocation failed");
444 delete pGlobalDecision;
445 pGlobalDecision=NULL;
447 HLTError("no global trigger found in data collection");
457 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
459 // see header file for class documentation
465 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
469 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
471 // see header file for class documentation
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);
481 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::WriteESD()
483 // see header file for class documentation
487 fpESDfile=new TFile("HLTdecision.root", "RECREATE");
490 fpESDtree=new TTree("HLTesdTree", "Tree with HLT ESD containing HLT decision");
492 fESD->WriteToTree(fpESDtree);
493 fpESDtree->GetUserInfo()->Add(fESD);
496 if (!fpESDfile || !fpESDtree) return -ENOMEM;
500 fpESDtree->Write(fpESDtree->GetName(),TObject::kOverwrite);