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