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