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"
44 /** global instance for agent registration */
45 AliHLTTriggerAgent gAliHLTTriggerAgent;
47 /** ROOT macro for the implementation of ROOT specific class methods */
48 ClassImp(AliHLTTriggerAgent)
50 AliHLTTriggerAgent::AliHLTTriggerAgent()
51 : AliHLTModuleAgent("Trigger")
52 , fTriggerDecisionHandler(NULL)
54 // see header file for class documentation
56 // refer to README to build package
58 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
61 AliHLTTriggerAgent::~AliHLTTriggerAgent()
63 // see header file for class documentation
66 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
68 // see header file for class documentation
70 if (!pHandler) return -EINVAL;
71 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
72 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
73 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
74 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
75 pHandler->AddComponent(new AliHLTTriggerPhosMip);
79 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
80 AliRawReader* /*rawReader*/,
81 AliRunLoader* /*runloader*/) const
83 // see header file for class documentation
84 if (!pHandler) return -EINVAL;
86 TString triggerInputs;
87 TString triggerOutputs;
88 TString configurationId;
89 /////////////////////////////////////////////////////////////////////////////////////
91 // a central barrel charged particle multiplicity trigger
92 configurationId="TRIGGER-Barrel-Multiplicity";
94 // define the inputsfor the BarrelMultiplicityTrigger
95 triggerInputs="GLOBAL-esd-converter";
97 // check for the availibility
98 TObjArray* pTokens=triggerInputs.Tokenize(" ");
101 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
102 TString module=((TObjString*)pTokens->At(n))->GetString();
103 if (pHandler->FindConfiguration(module.Data())) {
104 triggerInputs+=module;
111 if (triggerInputs.Length()>0) {
112 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
113 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
114 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
115 triggerOutputs+=configurationId;
117 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
120 /////////////////////////////////////////////////////////////////////////////////////
122 // the global trigger component
123 configurationId="GLOBAL-Trigger";
124 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
125 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
130 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
131 AliRunLoader* runloader) const
133 // see header file for class documentation
135 // reconstruction chains for AliRoot simulation
136 // Note: run loader is only available while running embedded into
137 // AliRoot simulation
139 // currently disabled due to a problem compiling the runtime trigger library
140 return "GLOBAL-Trigger";
145 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
147 // see header file for class documentation
149 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
152 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
153 AliHLTUInt32_t /*spec*/,
154 AliHLTOUTHandlerDesc& desc) const
156 // see header file for class documentation
158 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
159 // currently stored as a TObject with the common data type and origin
160 // HLTOUT. However we might need a separate data type in order to
161 // avoid interference with other handlers
162 // the handler produces an ESD object in order to be merged to the
164 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
165 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
169 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
170 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
171 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
172 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
179 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
180 AliHLTUInt32_t /*spec*/)
182 // see header file for class documentation
184 // raw data blocks to be fed into offline reconstruction
185 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
186 if (!fTriggerDecisionHandler) {
187 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
189 return fTriggerDecisionHandler;
192 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
193 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
194 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
201 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
203 // see header file for class documentation
204 if (pInstance==NULL) return -EINVAL;
206 if (pInstance==fTriggerDecisionHandler) {
207 delete fTriggerDecisionHandler;
208 fTriggerDecisionHandler=NULL;
214 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
220 // see header file for class documentation
223 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
225 // see header file for class documentation
226 if (fESD) delete fESD;
229 if (fpData) delete fpData;
234 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
236 // see header file for class documentation
237 if (!pData) return -EINVAL;
238 pData->SelectFirstDataBlock();
239 AliHLTComponentDataType dt=kAliHLTVoidDataType;
240 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
241 int iResult=pData->GetDataBlockDescription(dt, spec);
243 TObject* pObject=pData->GetDataObject();
245 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
247 //pDecision->Print();
248 HLTDebug("extracted %s", pDecision->GetName());
250 // create the ESD container, but without std content
251 fESD = new AliESDEvent;
253 if (!fpData) fpData=new TArrayC;
254 if (fESD && fpData) {
256 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
258 // copy the content to the already existing object
259 pObject->Copy(*pESDObject);
262 fESD->AddObject(pObject->Clone());
264 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
266 if (!pMsg->CompBuffer()) {
267 fSize=pMsg->Length();
268 fpData->Set(fSize, pMsg->Buffer());
270 fSize=pMsg->CompLength();
271 fpData->Set(fSize, pMsg->CompBuffer());
274 HLTError("streaming of objects failed");
277 HLTError("memory allocation failed");
281 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
284 pData->ReleaseDataObject(pObject);
287 HLTError("can not get TObject from HLTOUT buffer");
292 if (pData->SelectNextDataBlock()>=0) {
293 HLTWarning("current implementation of trigger decision handler can only handle one block");
301 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
303 // see header file for class documentation
309 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
313 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
315 // see header file for class documentation
317 if (!fpData || size != fSize ||
318 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
319 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);