]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerAgent.cxx
Adding HLT trigger component for the muon spectrometer to fit within the HLT trigger...
[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 #include "AliHLTMuonSpectroTriggerComponent.h"
49
50 /** global instance for agent registration */
51 AliHLTTriggerAgent gAliHLTTriggerAgent;
52
53 /** ROOT macro for the implementation of ROOT specific class methods */
54 ClassImp(AliHLTTriggerAgent)
55
56 AliHLTTriggerAgent::AliHLTTriggerAgent()
57   : AliHLTModuleAgent("Trigger")
58   , fTriggerDecisionHandler(NULL)
59 {
60   // see header file for class documentation
61   // or
62   // refer to README to build package
63   // or
64   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 }
66
67 AliHLTTriggerAgent::~AliHLTTriggerAgent()
68 {
69   // see header file for class documentation
70 }
71
72 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
73 {
74   // see header file for class documentation
75   assert(pHandler);
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);
88   return 0;
89 }
90
91 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
92                                             AliRawReader* /*rawReader*/,
93                                             AliRunLoader* /*runloader*/) const
94 {
95   // see header file for class documentation
96   if (!pHandler) return -EINVAL;
97
98   TString triggerInputs;
99   TString triggerOutputs;
100   TString configurationId;
101   /////////////////////////////////////////////////////////////////////////////////////
102   //
103   // a central barrel charged particle multiplicity trigger
104   configurationId="TRIGGER-Barrel-Multiplicity";
105
106   // define the inputsfor the BarrelMultiplicityTrigger
107   triggerInputs="GLOBAL-esd-converter";
108
109   // check for the availibility
110   TObjArray* pTokens=triggerInputs.Tokenize(" ");
111   triggerInputs="";
112   if (pTokens) {
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;
117         triggerInputs+=" ";
118       }
119     }
120     delete pTokens;
121   }
122
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;
128   } else {
129     HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
130   }
131   
132   /////////////////////////////////////////////////////////////////////////////////////
133   // The muon spectrometer trigger
134   configurationId = "TRIGGER-Muon-Spectrometer";
135
136   // define the inputsfor the muon spectrometer trigger.
137   if (pHandler->FindConfiguration("dHLT-sim-fromRaw")) {
138     triggerInputs = "dHLT-sim-fromRaw";
139   }
140   else if (pHandler->FindConfiguration("dHLT-sim")) {
141     triggerInputs = "dHLT-sim";
142   }
143   else if (pHandler->FindConfiguration("dHLT-sim-fromMC")) {
144     triggerInputs = "dHLT-sim-fromMC";
145   }
146
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;
152   } else {
153     HLTWarning("No inputs for %s found, skipping component.", configurationId.Data());
154   }
155
156   /////////////////////////////////////////////////////////////////////////////////////
157   //
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(), "");
162   
163   return 0;
164 }
165
166 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
167                                                     AliRunLoader* runloader) const
168 {
169   // see header file for class documentation
170   if (runloader) {
171     // reconstruction chains for AliRoot simulation
172     // Note: run loader is only available while running embedded into
173     // AliRoot simulation
174
175     // currently disabled due to a problem compiling the runtime trigger library
176     return "GLOBAL-Trigger";
177   }
178   return NULL;
179 }
180
181 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
182 {
183   // see header file for class documentation
184
185   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so libAliHLTMUON.so";
186 }
187
188 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
189                                            AliHLTUInt32_t /*spec*/,
190                                           AliHLTOUTHandlerDesc& desc) const
191 {
192   // see header file for class documentation
193
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
199   // hltEsd afterwards
200   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
201     desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
202     return 1;
203   }
204
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());
209       return 1;
210   }
211
212   return 0;
213 }
214
215 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
216                                                        AliHLTUInt32_t /*spec*/)
217 {
218   // see header file for class documentation
219
220   // raw data blocks to be fed into offline reconstruction
221   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
222     if (!fTriggerDecisionHandler) {
223       fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
224     }
225     return fTriggerDecisionHandler;
226   }
227
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)) {
231     return NULL;
232   }
233
234   return NULL;
235 }
236
237 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
238 {
239   // see header file for class documentation
240   if (pInstance==NULL) return -EINVAL;
241
242   if (pInstance==fTriggerDecisionHandler) {
243     delete fTriggerDecisionHandler;
244     fTriggerDecisionHandler=NULL;
245   }
246
247   return 0;
248 }
249
250 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
251   : AliHLTOUTHandler() 
252   , fESD(NULL)
253   , fpData(NULL)
254   , fSize(0)
255 {
256   // see header file for class documentation
257 }
258
259 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
260 {
261   // see header file for class documentation
262   if (fESD) delete fESD;
263   fESD=NULL;
264
265   if (fpData) delete fpData;
266   fpData=NULL;
267   fSize=0;
268 }
269
270 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
271 {
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);
278   if (iResult>=0) {
279     TObject* pObject=pData->GetDataObject();
280     if (pObject) {
281       AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
282       if (pDecision) {
283         //pDecision->Print();
284         HLTDebug("extracted %s", pDecision->GetName());
285         if (!fESD) {
286           // create the ESD container, but without std content
287           fESD = new AliESDEvent;
288         }
289         if (!fpData) fpData=new TArrayC;
290         if (fESD && fpData) {
291           fESD->Reset();
292           TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
293           if (pESDObject) {
294             // copy the content to the already existing object
295             pObject->Copy(*pESDObject);
296           } else {
297             // add a new object
298             fESD->AddObject(pObject->Clone());
299           }
300           AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
301           if (pMsg) {
302             if (!pMsg->CompBuffer()) {
303               fSize=pMsg->Length();
304               fpData->Set(fSize, pMsg->Buffer());
305             } else {
306               fSize=pMsg->CompLength();
307               fpData->Set(fSize, pMsg->CompBuffer());
308             }
309           } else {
310             HLTError("streaming of objects failed");
311           }
312         } else {
313           HLTError("memory allocation failed");
314           iResult=-ENOMEM;
315         }
316       } else {
317         HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
318         iResult=-ENODATA;
319       }
320       pData->ReleaseDataObject(pObject);
321       pObject=NULL;
322     } else {
323       HLTError("can not get TObject from HLTOUT buffer");
324       iResult=-ENODATA;
325     }
326   }
327   if (iResult>=0) {
328     if (pData->SelectNextDataBlock()>=0) {
329       HLTWarning("current implementation of trigger decision handler can only handle one block");
330     }
331     return fSize;
332   }
333   fSize=0;
334   return iResult;
335 }
336
337 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
338 {
339   // see header file for class documentation
340   if (!fpData) {
341     pData=NULL;
342     return 0;
343   }
344
345   pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
346   return fSize;
347 }
348
349 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
350 {
351   // see header file for class documentation
352   int iResult=0;
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);
356   }
357   fSize=0;
358   return iResult;
359 }