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