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"
42 /** global instance for agent registration */
43 AliHLTTriggerAgent gAliHLTTriggerAgent;
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTTriggerAgent)
48 AliHLTTriggerAgent::AliHLTTriggerAgent()
49 : AliHLTModuleAgent("Trigger")
50 , fTriggerDecisionHandler(NULL)
52 // see header file for class documentation
54 // refer to README to build package
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliHLTTriggerAgent::~AliHLTTriggerAgent()
61 // see header file for class documentation
64 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
66 // see header file for class documentation
68 if (!pHandler) return -EINVAL;
69 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
70 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
71 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
75 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
76 AliRawReader* /*rawReader*/,
77 AliRunLoader* /*runloader*/) const
79 // see header file for class documentation
80 if (!pHandler) return -EINVAL;
82 TString triggerInputs;
83 TString triggerOutputs;
84 TString configurationId;
85 /////////////////////////////////////////////////////////////////////////////////////
87 // a central barrel charged particle multiplicity trigger
88 configurationId="TRIGGER-Barrel-Multiplicity";
90 // define the inputsfor the BarrelMultiplicityTrigger
91 triggerInputs="GLOBAL-esd-converter";
93 // check for the availibility
94 TObjArray* pTokens=triggerInputs.Tokenize(" ");
97 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
98 TString module=((TObjString*)pTokens->At(n))->GetString();
99 if (pHandler->FindConfiguration(module.Data())) {
100 triggerInputs+=module;
107 if (triggerInputs.Length()>0) {
108 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
109 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
110 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
111 triggerOutputs+=configurationId;
113 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
116 /////////////////////////////////////////////////////////////////////////////////////
118 // the global trigger component
119 configurationId="GLOBAL-Trigger";
120 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
121 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
126 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
127 AliRunLoader* runloader) const
129 // see header file for class documentation
131 // reconstruction chains for AliRoot simulation
132 // Note: run loader is only available while running embedded into
133 // AliRoot simulation
135 // currently disabled due to a problem compiling the runtime trigger library
136 return "GLOBAL-Trigger";
141 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
143 // see header file for class documentation
145 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
148 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
149 AliHLTUInt32_t /*spec*/,
150 AliHLTOUTHandlerDesc& desc) const
152 // see header file for class documentation
154 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
155 // currently stored as a TObject with the common data type and origin
156 // HLTOUT. However we might need a separate data type in order to
157 // avoid interference with other handlers
158 // the handler produces an ESD object in order to be merged to the
160 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
161 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
165 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
166 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
167 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
168 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
175 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
176 AliHLTUInt32_t /*spec*/)
178 // see header file for class documentation
180 // raw data blocks to be fed into offline reconstruction
181 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
182 if (!fTriggerDecisionHandler) {
183 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
185 return fTriggerDecisionHandler;
188 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
189 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
190 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
197 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
199 // see header file for class documentation
200 if (pInstance==NULL) return -EINVAL;
202 if (pInstance==fTriggerDecisionHandler) {
203 delete fTriggerDecisionHandler;
204 fTriggerDecisionHandler=NULL;
210 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
216 // see header file for class documentation
219 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
221 // see header file for class documentation
222 if (fESD) delete fESD;
225 if (fpData) delete fpData;
230 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
232 // see header file for class documentation
233 if (!pData) return -EINVAL;
234 pData->SelectFirstDataBlock();
235 AliHLTComponentDataType dt=kAliHLTVoidDataType;
236 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
237 int iResult=pData->GetDataBlockDescription(dt, spec);
239 TObject* pObject=pData->GetDataObject();
241 AliHLTTriggerDecision* pDecission=dynamic_cast<AliHLTTriggerDecision*>(pObject);
243 //pDecision->Print();
245 // create the ESD container, but without std content
246 fESD = new AliESDEvent;
248 if (!fpData) fpData=new TArrayC;
249 if (fESD && fpData) {
251 fESD->AddObject(pObject->Clone());
252 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
254 if (!pMsg->CompBuffer()) {
255 fSize=pMsg->Length();
256 fpData->Set(fSize, pMsg->Buffer());
258 fSize=pMsg->CompLength();
259 fpData->Set(fSize, pMsg->CompBuffer());
262 HLTError("streaming of objects failed");
265 HLTError("memory allocation failed");
269 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
272 pData->ReleaseDataObject(pObject);
275 HLTError("can not get TObject from HLTOUT buffer");
280 if (pData->SelectNextDataBlock()>=0) {
281 HLTWarning("current implementation of trigger decision handler can only handle one block");
289 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
291 // see header file for class documentation
297 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
301 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
303 // see header file for class documentation
305 if (!fpData || size != fSize ||
306 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
307 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);