]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EMCAL/AliHLTEMCALClusterizerComponent.cxx
Initial HLT-EMCAL components.
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALClusterizerComponent.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
6  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
7  *                  for The ALICE HLT Project.                            *
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   AliHLTEMCALClusterizerComponent.cxx
19     @author Mateusz Ploskon
20     @date   
21     @brief  EMCAL clusterizer component for HLT. */
22
23 #if __GNUC__== 3
24 using namespace std;
25 #endif
26
27 #include "AliHLTEMCALClusterizerComponent.h"
28 #include "AliHLTEMCALDefinitions.h"
29
30 #include "TString.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
33 #include "AliCDBEntry.h"
34 #include "AliCDBManager.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTEMCALClusterizerComponent)
38
39 AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent()
40   : AliHLTProcessor()
41   , fOutputPercentage(100)
42   , fStorageDBpath("local://$ALICE_ROOT")
43   , fClusterizer(NULL)
44   , fCDB(NULL)
45   , fMemReader(NULL)
46   , fGeometryFileName("")
47   , fGeometryFile(NULL)
48   , fGeoManager(NULL)
49 {
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 }
56
57 AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent(const AliHLTEMCALClusterizerComponent &/*c*/)
58   : AliHLTProcessor()
59   , fOutputPercentage(100)
60   , fStorageDBpath("local://$ALICE_ROOT")
61   , fClusterizer(NULL)
62   , fCDB(NULL)
63   , fMemReader(NULL)
64   , fGeometryFileName("")
65   , fGeometryFile(NULL)
66   , fGeoManager(NULL)
67 {
68   // may not use the copy contructor
69   HLTError("May not use.");
70 }
71
72 AliHLTEMCALClusterizerComponent& AliHLTEMCALClusterizerComponent::operator=(const AliHLTEMCALClusterizerComponent&)
73 {
74   // may not use the copy contructor
75   HLTError("May not use.");
76   return *this;
77 }
78
79 AliHLTEMCALClusterizerComponent::~AliHLTEMCALClusterizerComponent()
80 {
81   // see header file for class documentation
82 }
83
84 AliHLTComponentDataType AliHLTEMCALClusterizerComponent::GetOutputDataType()
85 {
86   return AliHLTEMCALDefinitions::fgkClusterDataType;
87 }
88
89 int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
90 {
91   // see header file for class documentation
92   int iResult=0;
93   HLTInfo("parsing %d arguments", argc);
94
95   TString argument="";
96   TString configuration=""; 
97   int bMissingParam=0;
98   bool bHaveMandatory1=false;
99   bool bHaveMandatory2=false;
100
101   char *cpErr = 0;
102
103   for (int i=0; i<argc && iResult>=0; i++) {
104     argument=argv[i];
105     if (argument.IsNull()) continue;
106
107     // -mandatory1
108     if (argument.CompareTo("-cdb")==0) {
109       bHaveMandatory1|=1;
110       if ((bMissingParam=(++i>=argc))) break;
111       HLTInfo("got \'-cdb\' argument: %s", argv[i]);
112       fStorageDBpath = argv[i];
113       HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
114       // -mandatory2
115     } else if (argument.CompareTo("-geometry")==0) {
116       bHaveMandatory2|=1;
117       HLTInfo("got \'-geometry\' argument");
118       fGeometryFileName = argv[i];
119       HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
120       // -optional1
121     } else if (argument.CompareTo("-output_percentage")==0) {
122       if ((bMissingParam=(++i>=argc))) break;
123       HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
124       fOutputPercentage = strtoul(argv[i], &cpErr, 0);
125       if ( *cpErr )
126         {
127           HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
128           return -EINVAL;
129         }
130
131 //       // -optional2
132 //     } else if (argument.CompareTo("-optional2")==0) {
133 //       HLTInfo("got \'-optional2\' argument");
134
135     } else {
136       // the remaining arguments are treated as configuration
137       if (!configuration.IsNull()) configuration+=" ";
138       configuration+=argument;
139     }
140   }
141   if (bMissingParam) {
142     HLTError("missing parameter for argument %s", argument.Data());
143     iResult=-EINVAL;
144   }
145
146   if (iResult>=0 && !bHaveMandatory1) {
147     HLTError("mandatory argument \'-cdb\' missing");
148     iResult=-EPROTO;
149   }
150   if (iResult>=0 && !bHaveMandatory2) {
151     HLTError("mandatory argument \'-geometry\' missing");
152     iResult=-EPROTO;
153   }
154   if (iResult>=0 && !configuration.IsNull()) {
155     iResult=Configure(configuration.Data());
156   } else {
157     iResult=Reconfigure(NULL, NULL);
158   }
159
160   return iResult;
161 }
162
163 int AliHLTEMCALClusterizerComponent::DoDeinit()
164 {
165   // see header file for class documentation
166   HLTInfo("processing cleanup");
167   return 0;
168 }
169
170 int AliHLTEMCALClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
171                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
172                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
173   // see header file for class documentation
174   HLTInfo("processing data");
175   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
176       outputPtr==0 && size==0)
177   {
178     outputBlocks.clear();
179     // this is just to get rid of the warning "unused parameter"
180   }
181   return 0;
182 }
183
184 int AliHLTEMCALClusterizerComponent::Configure(const char* arguments)
185 {
186   // see header file for class documentation
187   int iResult=0;
188   if (!arguments) return iResult;
189   HLTInfo("parsing configuration string \'%s\'", arguments);
190
191   TString allArgs=arguments;
192   TString argument;
193   int bMissingParam=0;
194
195   TObjArray* pTokens=allArgs.Tokenize(" ");
196   if (pTokens) {
197     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
198       argument=((TObjString*)pTokens->At(i))->GetString();
199       if (argument.IsNull()) continue;
200
201       // -config1
202       if (argument.CompareTo("-config1")==0) {
203         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
204         HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
205
206         // -config2
207       } else if (argument.CompareTo("-config2")==0) {
208         HLTInfo("got \'-config2\'");
209       } else {
210         HLTError("unknown argument %s", argument.Data());
211         iResult=-EINVAL;
212         break;
213       }
214     }
215     delete pTokens;
216   }
217   if (bMissingParam) {
218     HLTError("missing parameter for argument %s", argument.Data());
219     iResult=-EINVAL;
220   }
221   return iResult;
222 }
223
224 int AliHLTEMCALClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
225 {
226   // see header file for class documentation
227   int iResult=0;
228   const char* path="HLT/ConfigSample/EMCALClusterizerComponent";
229   const char* defaultNotify="";
230   if (cdbEntry) {
231     path=cdbEntry;
232     defaultNotify=" (default)";
233   }
234   if (path) {
235     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
236     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
237     if (pEntry) {
238       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
239       if (pString) {
240         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
241         iResult=Configure(pString->GetString().Data());
242       } else {
243         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
244       }
245     } else {
246       HLTError("can not fetch object \"%s\" from CDB", path);
247     }
248   }
249   return iResult;
250 }
251
252 int AliHLTEMCALClusterizerComponent::ReadPreprocessorValues(const char* modules)
253 {
254   // see header file for class documentation
255   int iResult=0;
256   TString detectors(modules!=NULL?modules:"");
257   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
258   return iResult;
259 }