]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EMCAL/AliHLTEMCALAgent.cxx
HLT submodules
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALAgent.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: Federico Ronchetti                                    *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /** @file   AliHLTEMCALAgent.cxx
19  @author Federico Ronchetti
20  @date   
21  @brief  Agent of the libAliHLTEMCAL library
22  */
23
24 #include "AliHLTEMCALAgent.h"
25 #include "AliHLTConfiguration.h"
26 #include "AliHLTEMCALDefinitions.h"
27 #include "AliHLTOUT.h"
28 #include "AliHLTOUTHandlerChain.h"
29 #include "AliHLTErrorGuard.h"
30 #include "AliRunLoader.h"
31 #include "AliDAQ.h"
32 #include "AliCDBManager.h"
33 #include "AliCDBEntry.h"
34
35
36 // #include "AliHLTEMCALConstant.h"
37 #include "AliHLTEMCALConstants.h"
38 #include "AliHLTEMCALMapper.h"
39
40 /** global instance for agent registration */
41 AliHLTEMCALAgent gAliHLTEMCALAgent;
42
43 // component headers
44 //#include "AliHLTEMCALCalibrationComponent.h"
45 #include "AliHLTCaloClusterAnalyser.h"
46 #include "AliHLTEMCALClusterizerComponent.h"
47 #include "AliHLTEMCALDigitMakerComponent.h"
48 //#include "AliHLTEMCALESDEntriesMakerComponent.h"
49 //#include "AliHLTEMCALHistogramProducerComponent.h"
50 //#include "AliHLTEMCALModuleCalibrationProcessorComponent.h"
51 //#include "AliHLTEMCALMonitorTriggerComponent.h"
52 #include "AliHLTEMCALRawAnalyzerComponent.h"
53 #include "AliHLTEMCALRawAnalyzerCrudeComponent.h"
54 #include "AliHLTEMCALRawAnalyzerPeakFinderComponent.h"
55 //#include "AliHLTEMCALRcuCalibrationProcessorComponent.h"
56 //#include "AliHLTEMCALRcuDAComponent.h"
57 #include "AliHLTEMCALRawAnalyzerLMSComponent.h"
58 #include "AliHLTEMCALRawAnalyzerFastFitComponent.h"
59 #include "AliHLTEMCALRawAnalyzerNNComponent.h"
60 #include "AliHLTEMCALClusterizerComponentNbyN.h"
61
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTEMCALAgent)
64
65 AliHLTEMCALAgent::AliHLTEMCALAgent() : AliHLTModuleAgent("EMCAL")
66   , fRawDataHandler(NULL)
67   , fMappers()
68 {
69     // see header file for class documentation
70     // or
71     // refer to README to build package
72     // or
73     // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74 }
75
76 AliHLTEMCALAgent::~AliHLTEMCALAgent()
77 {
78     // see header file for class documentation
79 }
80
81 UInt_t AliHLTEMCALAgent::GetDetectorMask() const
82 {
83   return AliDAQ::kEMCAL;
84 }
85
86 int AliHLTEMCALAgent::CreateConfigurations(AliHLTConfigurationHandler* handler,
87                                            AliRawReader* /*rawReader*/,
88                                            AliRunLoader* /*runloader*/) const
89 {
90     // see header file for class documentation
91     if (handler) 
92     {
93         //      const char* cdbEntry="EMCAL/Calib/Parameters";
94         //AliCDBManager* pMan=AliCDBManager::Instance();
95         //AliEMCALParam* pEMCALParam=NULL;
96         
97         //       if (pMan) 
98         //      {
99         //        AliCDBEntry *pEntry = pMan->Get(cdbEntry);
100         //        if (pEntry && 
101         //            pEntry->GetObject() &&
102         //            (pEMCALParam=dynamic_cast<AliEMCALParam*>(pEntry->GetObject()))) 
103         //          {
104         //          } else 
105         //          {
106         //            HLTWarning("can not load AliEMCALParam from CDB entry %s", cdbEntry);
107         //          }
108         //      }
109         
110         int moduleStart = 0;
111         int moduleEnd = 9;
112         
113         int rcuStart = 0;
114         int rcuEnd = 1;
115         
116         Int_t rcusPerModule = 2;
117         Int_t ddlOffset = 4608; 
118         
119         TString mergerInput;
120         TString sinkClusterInput;
121         TString emInput;
122         
123         for (int module = moduleStart; module <= moduleEnd; module++) 
124         {
125             TString clInput;
126             
127             for(int rcu = rcuStart; rcu < rcuEnd; rcu++) 
128             {
129                 TString arg, publisher, ra, dm;
130                 // raw data publisher components
131                 publisher.Form("EMCAL-RP_%02d_%d", module, rcu);
132                 arg.Form("-verbose -minid %d -datatype 'DDL_RAW ' 'EMCA'  -dataspec 0x%x ", ddlOffset + module*(rcusPerModule) + rcu, 0x1 << (module*rcusPerModule + rcu));
133                 
134                 handler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
135                 
136                 // Raw analyzer
137                 arg = "";
138                 ra.Form("EMCAL-RA_%02d_%d", module, rcu);
139                 handler->CreateConfiguration(ra.Data(), "EmcalRawCrude", publisher.Data(), arg.Data());
140                 
141                 // digit maker components
142                 dm.Form("EMCAL-DM_%02d_%d", module, rcu);
143                 arg="";
144                 arg.Form("-sethighgainfactor 0.0153 -setlowgainfactor 0.2448 -setdigitthresholds 0.005 0.002");
145                 handler->CreateConfiguration(dm.Data(), "EmcalDigitMaker", ra.Data(), arg.Data());
146                 
147                 if(clInput.Length() > 0) clInput += " ";
148                 clInput+=dm;
149             }
150             
151             TString arg, cl, ca;
152             
153             cl.Form("EMCAL-CF_%02d", module);
154             arg = "";
155             arg.Form("-digitthreshold 0.005 -recpointthreshold 0.1 -modulemode");
156             handler->CreateConfiguration(cl.Data(), "EmcalClusterizer", clInput.Data(), arg.Data());
157             
158             //ca.Form("EMCAL-CA_%02d", module);
159             //arg = " ";
160             //handler->CreateConfiguration(ca.Data(), "CaloClusterAnalyser", cl.Data(), arg.Data());
161             
162             if(emInput.Length() > 0) emInput += " ";
163             emInput += ca;
164         }
165         
166         
167         TString arg, em;
168         
169         // tracker finder components
170         
171         // later
172         //      em.Form("EMCAL-EM");
173         //arg = " ";
174         //handler->CreateConfiguration(em.Data(), "EmcalEsdEntriesMaker", emInput.Data(), " ");
175         
176     }
177     
178     return 0;
179 }
180
181 const char* AliHLTEMCALAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
182                                                       AliRunLoader* runloader) const
183 {
184     // see header file for class documentation
185     if (runloader) {
186         // reconstruction chains for AliRoot simulation
187         // Note: run loader is only available while running embedded into
188         // AliRoot simulation
189         
190         // if (runloader->GetLoader("EMCALLoader") != NULL)
191         //     return "EMCAL-EM";
192     }
193     return NULL;
194 }
195
196 const char* AliHLTEMCALAgent::GetRequiredComponentLibraries() const
197 {
198     // see header file for class documentation
199     return NULL;
200 }
201
202 int AliHLTEMCALAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
203 {
204     // see header file for class documentation
205     if (!pHandler) return -EINVAL;
206     
207     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerCrudeComponent);
208     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerLMSComponent);
209     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerPeakFinderComponent);
210     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerFastFitComponent);
211     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerNNComponent);
212     pHandler->AddComponent(new AliHLTEMCALDigitMakerComponent);
213     pHandler->AddComponent(new AliHLTEMCALClusterizerComponent);
214     pHandler->AddComponent(new AliHLTEMCALClusterizerComponentNbyN);
215     //pHandler->AddComponent(new AliHLTCaloClusterAnalyserComponent);                    
216     //pHandler->AddComponent(new AliHLTEMCALESDEntriesMakerComponent);
217     
218     return 0;
219 }
220
221
222 int AliHLTEMCALAgent::GetHandlerDescription(AliHLTComponentDataType dt,
223                                             AliHLTUInt32_t spec,
224                                             AliHLTOUTHandlerDesc& desc) const
225 {
226     // see header file for class documentation
227
228     // raw data blocks to be fed into offline reconstruction
229     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginEMCAL)) 
230     {
231         AliHLTEMCALMapper* pMapper=GetMapper(spec);
232     
233         if(pMapper && pMapper->GetDDLFromSpec(spec) >= 0)
234         {
235             desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
236             return 1;
237         } 
238         else if (pMapper==NULL)
239         {
240             ALIHLTERRORGUARD(5, "failed to create EMCAL mapper");
241             return 0;
242         }
243         else 
244         {
245             HLTWarning("Handler can not process data inconsistent with a single EMCAL DDL from specification % d", spec);
246             return 0;
247         }
248     }
249     return 0;
250 }
251
252 AliHLTOUTHandler* AliHLTEMCALAgent::GetOutputHandler(AliHLTComponentDataType dt,
253                                                      AliHLTUInt32_t /*spec*/)
254 {
255     // see header file for class documentation
256     
257     // raw data blocks to be fed into offline reconstruction
258     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginEMCAL)) 
259     {
260         if (!fRawDataHandler) 
261         {
262             fRawDataHandler = new AliHLTEMCALAgent::AliHLTEMCALRawDataHandler(this);
263         }
264         return fRawDataHandler;
265     }
266     
267     return NULL;
268 }
269
270 int AliHLTEMCALAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
271 {
272     // see header file for class documentation
273     if (pInstance==NULL) return -EINVAL;
274     
275     if (pInstance==fRawDataHandler) {
276         delete fRawDataHandler;
277         fRawDataHandler=NULL;
278     }
279     return 0;
280 }
281
282 AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::AliHLTEMCALRawDataHandler(AliHLTEMCALAgent* pAgent)
283   : fpAgent(pAgent)
284 {
285     // see header file for class documentation
286 }
287
288 AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::~AliHLTEMCALRawDataHandler()
289 {
290     // see header file for class documentation
291 }
292
293 int AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::ProcessData(AliHLTOUT* pData)
294 {
295     // see header file for class documentation
296     if (!pData) return -EINVAL;
297     
298     AliHLTComponentDataType dt = kAliHLTVoidDataType;
299     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
300     
301     AliHLTEMCALMapper* pMapper=fpAgent?fpAgent->GetMapper(spec):NULL;
302     if (!pMapper) {
303       ALIHLTERRORGUARD(5, "%s", fpAgent?"can not retrieve EMCAL mapper from agent":"agent not available to retrieve EMCAL mapper");
304       return -ENODEV;
305     }
306     
307     int iResult = pData->GetDataBlockDescription(dt, spec);
308     if (iResult>=0) 
309     {
310         int ddl = -1;
311         if((ddl = pMapper->GetDDLFromSpec(spec)) >=0)
312         {
313             iResult = ddl;
314         }
315     } 
316     else 
317     {
318         HLTError("Handler can not process data inconsistent with a single EMCAL DDL from specification % d", spec);
319         iResult=-EBADMSG;
320     }
321     return iResult;
322 }
323
324 AliHLTEMCALMapper* AliHLTEMCALAgent::GetMapper(AliHLTUInt32_t spec) const
325 {
326   // get the mapper instance for a specification
327   std::map<AliHLTUInt32_t, AliHLTEMCALMapper*>::const_iterator element=fMappers.find(spec);
328   if (element!=fMappers.end()) return element->second;
329
330   AliHLTEMCALMapper* mapper=new AliHLTEMCALMapper(spec);
331   if (!mapper) return NULL;
332   mapper->InitDDLSpecificationMapping();
333   const_cast<AliHLTEMCALAgent*>(this)->fMappers[spec]=mapper;
334   return mapper;
335 }