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 "AliHLTOUT.h"
29 #include "AliHLTMessage.h"
30 #include "AliESDEvent.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
35 // header files of library components
36 #include "AliHLTEventSummaryProducerComponent.h"
37 #include "AliHLTRunSummaryProducerComponent.h"
38 #include "AliHLTTriggerBarrelMultiplicity.h"
39 #include "AliHLTTriggerBarrelCosmic.h"
40 #include "AliHLTGlobalTriggerComponent.h"
41 #include "AliHLTTriggerPhosClusterEnergy.h"
42 #include "AliHLTTriggerPhosMip.h"
43 #include "AliHLTTriggerTrdClusterMultiplicity.h"
45 /** global instance for agent registration */
46 AliHLTTriggerAgent gAliHLTTriggerAgent;
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTTriggerAgent)
51 AliHLTTriggerAgent::AliHLTTriggerAgent()
52 : AliHLTModuleAgent("Trigger")
53 , fTriggerDecisionHandler(NULL)
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 AliHLTTriggerAgent::~AliHLTTriggerAgent()
64 // see header file for class documentation
67 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
69 // see header file for class documentation
71 if (!pHandler) return -EINVAL;
72 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
73 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
74 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
75 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
76 pHandler->AddComponent(new AliHLTTriggerPhosMip);
77 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
81 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
82 AliRawReader* /*rawReader*/,
83 AliRunLoader* /*runloader*/) const
85 // see header file for class documentation
86 if (!pHandler) return -EINVAL;
88 TString triggerInputs;
89 TString triggerOutputs;
90 TString configurationId;
91 /////////////////////////////////////////////////////////////////////////////////////
93 // a central barrel charged particle multiplicity trigger
94 configurationId="TRIGGER-Barrel-Multiplicity";
96 // define the inputsfor the BarrelMultiplicityTrigger
97 triggerInputs="GLOBAL-esd-converter";
99 // check for the availibility
100 TObjArray* pTokens=triggerInputs.Tokenize(" ");
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;
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;
119 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
122 /////////////////////////////////////////////////////////////////////////////////////
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(), "");
132 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
133 AliRunLoader* runloader) const
135 // see header file for class documentation
137 // reconstruction chains for AliRoot simulation
138 // Note: run loader is only available while running embedded into
139 // AliRoot simulation
141 // currently disabled due to a problem compiling the runtime trigger library
142 return "GLOBAL-Trigger";
147 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
149 // see header file for class documentation
151 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
154 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
155 AliHLTUInt32_t /*spec*/,
156 AliHLTOUTHandlerDesc& desc) const
158 // see header file for class documentation
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
166 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
167 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
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());
181 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
182 AliHLTUInt32_t /*spec*/)
184 // see header file for class documentation
186 // raw data blocks to be fed into offline reconstruction
187 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
188 if (!fTriggerDecisionHandler) {
189 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
191 return fTriggerDecisionHandler;
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)) {
203 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
205 // see header file for class documentation
206 if (pInstance==NULL) return -EINVAL;
208 if (pInstance==fTriggerDecisionHandler) {
209 delete fTriggerDecisionHandler;
210 fTriggerDecisionHandler=NULL;
216 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
222 // see header file for class documentation
225 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
227 // see header file for class documentation
228 if (fESD) delete fESD;
231 if (fpData) delete fpData;
236 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
238 // see header file for class documentation
239 if (!pData) return -EINVAL;
240 pData->SelectFirstDataBlock();
241 AliHLTComponentDataType dt=kAliHLTVoidDataType;
242 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
243 int iResult=pData->GetDataBlockDescription(dt, spec);
245 TObject* pObject=pData->GetDataObject();
247 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
249 //pDecision->Print();
250 HLTDebug("extracted %s", pDecision->GetName());
252 // create the ESD container, but without std content
253 fESD = new AliESDEvent;
255 if (!fpData) fpData=new TArrayC;
256 if (fESD && fpData) {
258 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
260 // copy the content to the already existing object
261 pObject->Copy(*pESDObject);
264 fESD->AddObject(pObject->Clone());
266 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
268 if (!pMsg->CompBuffer()) {
269 fSize=pMsg->Length();
270 fpData->Set(fSize, pMsg->Buffer());
272 fSize=pMsg->CompLength();
273 fpData->Set(fSize, pMsg->CompBuffer());
276 HLTError("streaming of objects failed");
279 HLTError("memory allocation failed");
283 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
286 pData->ReleaseDataObject(pObject);
289 HLTError("can not get TObject from HLTOUT buffer");
294 if (pData->SelectNextDataBlock()>=0) {
295 HLTWarning("current implementation of trigger decision handler can only handle one block");
303 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
305 // see header file for class documentation
311 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
315 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
317 // see header file for class documentation
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);