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