]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerAgent.cxx
adding Mimimum Ionizing Particle trigger for PHOS inclduing configuration object...
[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 "AliHLTTriggerBarrelCosmic.h"
40 #include "AliHLTGlobalTriggerComponent.h"
41 #include "AliHLTTriggerPhosClusterEnergy.h"
42 #include "AliHLTTriggerPhosMip.h"
43
44 /** global instance for agent registration */
45 AliHLTTriggerAgent gAliHLTTriggerAgent;
46
47 /** ROOT macro for the implementation of ROOT specific class methods */
48 ClassImp(AliHLTTriggerAgent)
49
50 AliHLTTriggerAgent::AliHLTTriggerAgent()
51   : AliHLTModuleAgent("Trigger")
52   , fTriggerDecisionHandler(NULL)
53 {
54   // see header file for class documentation
55   // or
56   // refer to README to build package
57   // or
58   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 }
60
61 AliHLTTriggerAgent::~AliHLTTriggerAgent()
62 {
63   // see header file for class documentation
64 }
65
66 int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
67 {
68   // see header file for class documentation
69   assert(pHandler);
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); 
76   return 0;
77 }
78
79 int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
80                                             AliRawReader* /*rawReader*/,
81                                             AliRunLoader* /*runloader*/) const
82 {
83   // see header file for class documentation
84   if (!pHandler) return -EINVAL;
85
86   TString triggerInputs;
87   TString triggerOutputs;
88   TString configurationId;
89   /////////////////////////////////////////////////////////////////////////////////////
90   //
91   // a central barrel charged particle multiplicity trigger
92   configurationId="TRIGGER-Barrel-Multiplicity";
93
94   // define the inputsfor the BarrelMultiplicityTrigger
95   triggerInputs="GLOBAL-esd-converter";
96
97   // check for the availibility
98   TObjArray* pTokens=triggerInputs.Tokenize(" ");
99   triggerInputs="";
100   if (pTokens) {
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;
105         triggerInputs+=" ";
106       }
107     }
108     delete pTokens;
109   }
110
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;
116   } else {
117     HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
118   }
119
120   /////////////////////////////////////////////////////////////////////////////////////
121   //
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(), "");
126   
127   return 0;
128 }
129
130 const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
131                                                     AliRunLoader* runloader) const
132 {
133   // see header file for class documentation
134   if (runloader) {
135     // reconstruction chains for AliRoot simulation
136     // Note: run loader is only available while running embedded into
137     // AliRoot simulation
138
139     // currently disabled due to a problem compiling the runtime trigger library
140     return "GLOBAL-Trigger";
141   }
142   return NULL;
143 }
144
145 const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
146 {
147   // see header file for class documentation
148
149   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
150 }
151
152 int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
153                                            AliHLTUInt32_t /*spec*/,
154                                           AliHLTOUTHandlerDesc& desc) const
155 {
156   // see header file for class documentation
157
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
163   // hltEsd afterwards
164   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
165     desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
166     return 1;
167   }
168
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());
173       return 1;
174   }
175
176   return 0;
177 }
178
179 AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
180                                                        AliHLTUInt32_t /*spec*/)
181 {
182   // see header file for class documentation
183
184   // raw data blocks to be fed into offline reconstruction
185   if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
186     if (!fTriggerDecisionHandler) {
187       fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
188     }
189     return fTriggerDecisionHandler;
190   }
191
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)) {
195     return NULL;
196   }
197
198   return NULL;
199 }
200
201 int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
202 {
203   // see header file for class documentation
204   if (pInstance==NULL) return -EINVAL;
205
206   if (pInstance==fTriggerDecisionHandler) {
207     delete fTriggerDecisionHandler;
208     fTriggerDecisionHandler=NULL;
209   }
210
211   return 0;
212 }
213
214 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
215   : AliHLTOUTHandler() 
216   , fESD(NULL)
217   , fpData(NULL)
218   , fSize(0)
219 {
220   // see header file for class documentation
221 }
222
223 AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
224 {
225   // see header file for class documentation
226   if (fESD) delete fESD;
227   fESD=NULL;
228
229   if (fpData) delete fpData;
230   fpData=NULL;
231   fSize=0;
232 }
233
234 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
235 {
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);
242   if (iResult>=0) {
243     TObject* pObject=pData->GetDataObject();
244     if (pObject) {
245       AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
246       if (pDecision) {
247         //pDecision->Print();
248         HLTDebug("extracted %s", pDecision->GetName());
249         if (!fESD) {
250           // create the ESD container, but without std content
251           fESD = new AliESDEvent;
252         }
253         if (!fpData) fpData=new TArrayC;
254         if (fESD && fpData) {
255           fESD->Reset();
256           TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
257           if (pESDObject) {
258             // copy the content to the already existing object
259             pObject->Copy(*pESDObject);
260           } else {
261             // add a new object
262             fESD->AddObject(pObject->Clone());
263           }
264           AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
265           if (pMsg) {
266             if (!pMsg->CompBuffer()) {
267               fSize=pMsg->Length();
268               fpData->Set(fSize, pMsg->Buffer());
269             } else {
270               fSize=pMsg->CompLength();
271               fpData->Set(fSize, pMsg->CompBuffer());
272             }
273           } else {
274             HLTError("streaming of objects failed");
275           }
276         } else {
277           HLTError("memory allocation failed");
278           iResult=-ENOMEM;
279         }
280       } else {
281         HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
282         iResult=-ENODATA;
283       }
284       pData->ReleaseDataObject(pObject);
285       pObject=NULL;
286     } else {
287       HLTError("can not get TObject from HLTOUT buffer");
288       iResult=-ENODATA;
289     }
290   }
291   if (iResult>=0) {
292     if (pData->SelectNextDataBlock()>=0) {
293       HLTWarning("current implementation of trigger decision handler can only handle one block");
294     }
295     return fSize;
296   }
297   fSize=0;
298   return iResult;
299 }
300
301 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
302 {
303   // see header file for class documentation
304   if (!fpData) {
305     pData=NULL;
306     return 0;
307   }
308
309   pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
310   return fSize;
311 }
312
313 int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
314 {
315   // see header file for class documentation
316   int iResult=0;
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);
320   }
321   fSize=0;
322   return iResult;
323 }