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 "AliHLTD0Trigger.h"
40 #include "AliHLTTriggerITSMultiplicity.h"
41 #include "AliHLTTriggerBarrelGeomMultiplicity.h"
42 #include "AliHLTTriggerBarrelCosmic.h"
43 #include "AliHLTGlobalTriggerComponent.h"
44 #include "AliHLTTriggerPhosClusterEnergy.h"
45 #include "AliHLTTriggerPhosMip.h"
46 #include "AliHLTTriggerTrdClusterMultiplicity.h"
47 #include "AliHLTTriggerGammaConversion.h"
48 #include "AliHLTMuonSpectroTriggerComponent.h"
50 /** global instance for agent registration */
51 AliHLTTriggerAgent gAliHLTTriggerAgent;
53 /** ROOT macro for the implementation of ROOT specific class methods */
54 ClassImp(AliHLTTriggerAgent)
56 AliHLTTriggerAgent::AliHLTTriggerAgent()
57 : AliHLTModuleAgent("Trigger")
58 , fTriggerDecisionHandler(NULL)
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTTriggerAgent::~AliHLTTriggerAgent()
69 // see header file for class documentation
72 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
74 // see header file for class documentation
76 if (!pHandler) return -EINVAL;
77 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
78 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
79 pHandler->AddComponent(new AliHLTTriggerITSMultiplicity);
80 pHandler->AddComponent(new AliHLTD0Trigger);
81 pHandler->AddComponent(new AliHLTTriggerBarrelGeomMultiplicity);
82 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
83 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
84 pHandler->AddComponent(new AliHLTTriggerPhosMip);
85 pHandler->AddComponent(new AliHLTTriggerTrdClusterMultiplicity);
86 pHandler->AddComponent(new AliHLTTriggerGammaConversion);
87 pHandler->AddComponent(new AliHLTMuonSpectroTriggerComponent);
91 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
92 AliRawReader* /*rawReader*/,
93 AliRunLoader* /*runloader*/) const
95 // see header file for class documentation
96 if (!pHandler) return -EINVAL;
98 TString triggerInputs;
99 TString triggerOutputs;
100 TString configurationId;
101 /////////////////////////////////////////////////////////////////////////////////////
103 // a central barrel charged particle multiplicity trigger
104 configurationId="TRIGGER-Barrel-Multiplicity";
106 // define the inputsfor the BarrelMultiplicityTrigger
107 triggerInputs="GLOBAL-esd-converter";
109 // check for the availibility
110 TObjArray* pTokens=triggerInputs.Tokenize(" ");
113 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
114 TString module=((TObjString*)pTokens->At(n))->GetString();
115 if (pHandler->FindConfiguration(module.Data())) {
116 triggerInputs+=module;
123 if (triggerInputs.Length()>0) {
124 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
125 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
126 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
127 triggerOutputs+=configurationId;
129 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
132 /////////////////////////////////////////////////////////////////////////////////////
133 // The muon spectrometer trigger
134 configurationId = "TRIGGER-Muon-Spectrometer";
136 // define the inputsfor the muon spectrometer trigger.
137 if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
138 triggerInputs = "dHLT-sim-fromRaw";
140 else if (pHandler->FindConfiguration("dHLT-sim")) {
141 triggerInputs = "dHLT-sim";
143 else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
144 triggerInputs = "dHLT-sim-fromMC";
147 if (triggerInputs.Length() > 0) {
148 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
149 pHandler->CreateConfiguration(configurationId.Data(), "MuonSpectroTrigger", triggerInputs.Data(), "-makestats");
150 if (triggerOutputs.Length() > 0) triggerOutputs += " ";
151 triggerOutputs += configurationId;
153 HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
156 /////////////////////////////////////////////////////////////////////////////////////
158 // the global trigger component
159 configurationId="GLOBAL-Trigger";
160 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
161 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
166 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
167 AliRunLoader* runloader) const
169 // see header file for class documentation
171 // reconstruction chains for AliRoot simulation
172 // Note: run loader is only available while running embedded into
173 // AliRoot simulation
175 // currently disabled due to a problem compiling the runtime trigger library
176 return "GLOBAL-Trigger";
181 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
183 // see header file for class documentation
185 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so libAliHLTMUON.so";
188 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
189 AliHLTUInt32_t /*spec*/,
190 AliHLTOUTHandlerDesc& desc) const
192 // see header file for class documentation
194 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
195 // currently stored as a TObject with the common data type and origin
196 // HLTOUT. However we might need a separate data type in order to
197 // avoid interference with other handlers
198 // the handler produces an ESD object in order to be merged to the
200 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
201 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
205 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
206 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
207 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
208 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
215 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
216 AliHLTUInt32_t /*spec*/)
218 // see header file for class documentation
220 // raw data blocks to be fed into offline reconstruction
221 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
222 if (!fTriggerDecisionHandler) {
223 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
225 return fTriggerDecisionHandler;
228 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
229 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
230 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
237 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
239 // see header file for class documentation
240 if (pInstance==NULL) return -EINVAL;
242 if (pInstance==fTriggerDecisionHandler) {
243 delete fTriggerDecisionHandler;
244 fTriggerDecisionHandler=NULL;
250 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
256 // see header file for class documentation
259 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
261 // see header file for class documentation
262 if (fESD) delete fESD;
265 if (fpData) delete fpData;
270 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
272 // see header file for class documentation
273 if (!pData) return -EINVAL;
274 pData->SelectFirstDataBlock();
275 AliHLTComponentDataType dt=kAliHLTVoidDataType;
276 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
277 int iResult=pData->GetDataBlockDescription(dt, spec);
279 TObject* pObject=pData->GetDataObject();
281 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
283 //pDecision->Print();
284 HLTDebug("extracted %s", pDecision->GetName());
286 // create the ESD container, but without std content
287 fESD = new AliESDEvent;
289 if (!fpData) fpData=new TArrayC;
290 if (fESD && fpData) {
292 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
294 // copy the content to the already existing object
295 pObject->Copy(*pESDObject);
298 fESD->AddObject(pObject->Clone());
300 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
302 if (!pMsg->CompBuffer()) {
303 fSize=pMsg->Length();
304 fpData->Set(fSize, pMsg->Buffer());
306 fSize=pMsg->CompLength();
307 fpData->Set(fSize, pMsg->CompBuffer());
310 HLTError("streaming of objects failed");
313 HLTError("memory allocation failed");
317 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
320 pData->ReleaseDataObject(pObject);
323 HLTError("can not get TObject from HLTOUT buffer");
328 if (pData->SelectNextDataBlock()>=0) {
329 HLTWarning("current implementation of trigger decision handler can only handle one block");
337 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
339 // see header file for class documentation
345 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
349 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
351 // see header file for class documentation
353 if (!fpData || size != fSize ||
354 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
355 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);