]>
Commit | Line | Data |
---|---|---|
eb84342b | 1 | //-*- Mode: C++ -*- |
2 | // $Id: AliHLTGlobalEsdToFlatConverterComponent.cxx $ | |
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: Steffen Weber * | |
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 AliHLTGlobalEsdToFlatConverterComponent.cxx | |
19 | @author Steffen Weber | |
20 | @brief Component to convert ESD objects to flatESD objects | |
21 | */ | |
22 | ||
23 | #include "TMap.h" | |
24 | #include "TSystem.h" | |
25 | #include "TTimeStamp.h" | |
26 | #include "TObjString.h" | |
27 | #include "TList.h" | |
28 | #include "AliESDEvent.h" | |
29 | #include "AliFlatESDEvent.h" | |
30 | #include "AliHLTErrorGuard.h" | |
31 | #include "AliHLTDataTypes.h" | |
32 | #include "AliHLTGlobalEsdToFlatConverterComponent.h" | |
33 | #include "AliHLTITSClusterDataFormat.h" | |
34 | #include "AliHLTTPCDefinitions.h" | |
35 | #include "TTree.h" | |
36 | #include "AliCDBEntry.h" | |
37 | #include "AliCDBManager.h" | |
c2374f56 | 38 | #include "AliSysInfo.h" |
eb84342b | 39 | |
40 | using namespace std; | |
41 | ||
42 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
43 | ClassImp(AliHLTGlobalEsdToFlatConverterComponent) | |
44 | ||
45 | /* | |
46 | * --------------------------------------------------------------------------------- | |
47 | * Constructor / Destructor | |
48 | * --------------------------------------------------------------------------------- | |
49 | */ | |
50 | ||
51 | // ################################################################################# | |
52 | AliHLTGlobalEsdToFlatConverterComponent::AliHLTGlobalEsdToFlatConverterComponent() : | |
53 | AliHLTProcessor() | |
54 | { | |
55 | // an example component which implements the ALICE HLT processor | |
56 | // interface and does some analysis on the input raw data | |
57 | // | |
58 | // see header file for class documentation | |
59 | // or | |
60 | // refer to README to build package | |
61 | // or | |
62 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
63 | // | |
64 | // NOTE: all helper classes should be instantiated in DoInit() | |
65 | } | |
66 | ||
67 | // ################################################################################# | |
68 | AliHLTGlobalEsdToFlatConverterComponent::~AliHLTGlobalEsdToFlatConverterComponent() { | |
69 | // see header file for class documentation | |
70 | } | |
71 | ||
72 | /* | |
73 | * --------------------------------------------------------------------------------- | |
74 | * Public functions to implement AliHLTComponent's interface. | |
75 | * These functions are required for the registration process | |
76 | * --------------------------------------------------------------------------------- | |
77 | */ | |
78 | ||
79 | // ################################################################################# | |
80 | const Char_t* AliHLTGlobalEsdToFlatConverterComponent::GetComponentID() { | |
81 | // see header file for class documentation | |
8e0c1b9d | 82 | return "GlobalEsdToFlatConverter"; |
eb84342b | 83 | } |
84 | ||
85 | // ################################################################################# | |
86 | void AliHLTGlobalEsdToFlatConverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { | |
87 | // see header file for class documentation | |
8e0c1b9d | 88 | list.push_back(kAliHLTDataTypeESDTree|kAliHLTDataOriginOut ); |
89 | list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut ); | |
eb84342b | 90 | list.push_back( kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut ); |
91 | } | |
92 | ||
a88a189e | 93 | |
94 | AliHLTComponentDataType AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataType() | |
95 | { | |
eb84342b | 96 | // see header file for class documentation |
a88a189e | 97 | return kAliHLTMultipleDataType; |
98 | } | |
99 | ||
100 | int AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){ | |
101 | // see header file for class documentation | |
102 | ||
103 | tgtList.clear(); | |
104 | tgtList.push_back( kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut ); | |
105 | tgtList.push_back( kAliHLTDataTypeFlatESDFriend|kAliHLTDataOriginOut ); | |
106 | return tgtList.size(); | |
eb84342b | 107 | } |
108 | ||
109 | // ################################################################################# | |
110 | void AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataSize( ULong_t& constBase, Double_t& inputMultiplier ) { | |
111 | // see header file for class documentation | |
a2e57ab1 | 112 | constBase = 10000; |
ee82d961 | 113 | inputMultiplier = 10.0; |
eb84342b | 114 | } |
115 | ||
116 | ||
117 | // ################################################################################# | |
118 | AliHLTComponent* AliHLTGlobalEsdToFlatConverterComponent::Spawn() { | |
119 | // see header file for class documentation | |
120 | return new AliHLTGlobalEsdToFlatConverterComponent; | |
121 | } | |
122 | ||
123 | /* | |
124 | * --------------------------------------------------------------------------------- | |
125 | * Protected functions to implement AliHLTComponent's interface. | |
126 | * These functions provide initialization as well as the actual processing | |
127 | * capabilities of the component. | |
128 | * --------------------------------------------------------------------------------- | |
129 | */ | |
130 | ||
131 | // ################################################################################# | |
132 | Int_t AliHLTGlobalEsdToFlatConverterComponent::DoInit( Int_t argc, const Char_t** argv ) { | |
133 | // see header file for class documentation | |
134 | printf("AliHLTGlobalEsdToFlatConverterComponent::DoInit\n"); | |
135 | // see header file for class documentation | |
136 | int iResult=0; | |
137 | TString argument=""; | |
138 | int bMissingParam=0; | |
139 | ||
140 | // default list of skiped ESD objects | |
141 | TString skipObjects= | |
142 | // "AliESDRun," | |
143 | // "AliESDHeader," | |
144 | // "AliESDZDC," | |
145 | "AliESDFMD," | |
146 | // "AliESDVZERO," | |
147 | // "AliESDTZERO," | |
148 | // "TPCVertex," | |
149 | // "SPDVertex," | |
150 | // "PrimaryVertex," | |
151 | // "AliMultiplicity," | |
152 | // "PHOSTrigger," | |
153 | // "EMCALTrigger," | |
154 | // "SPDPileupVertices," | |
155 | // "TrkPileupVertices," | |
156 | "Cascades," | |
157 | "Kinks," | |
158 | "AliRawDataErrorLogs," | |
159 | "AliESDACORDE"; | |
160 | ||
161 | iResult=Reconfigure(NULL, NULL); | |
162 | TString allArgs = ""; | |
163 | for ( int i = 0; i < argc; i++ ) { | |
164 | if ( !allArgs.IsNull() ) allArgs += " "; | |
165 | allArgs += argv[i]; | |
166 | } | |
167 | ||
168 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
169 | if (pTokens) { | |
170 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
171 | argument=((TObjString*)pTokens->At(i))->String(); | |
172 | if (argument.IsNull()) continue; | |
173 | if (argument.Contains("-skipobject=")) { | |
174 | argument.ReplaceAll("-skipobject=", ""); | |
175 | skipObjects=argument; | |
176 | } else { | |
177 | HLTError("unknown argument %s", argument.Data()); | |
178 | iResult=-EINVAL; | |
179 | break; | |
180 | } | |
181 | } | |
182 | } | |
183 | if (bMissingParam) { | |
184 | HLTError("missing parameter for argument %s", argument.Data()); | |
185 | iResult=-EINVAL; | |
186 | } | |
187 | ||
188 | ||
189 | if (iResult>=0) { | |
190 | SetupCTPData(); | |
191 | } | |
192 | ||
193 | return iResult; | |
194 | } | |
195 | ||
196 | ||
197 | ||
198 | // ################################################################################# | |
199 | Int_t AliHLTGlobalEsdToFlatConverterComponent::DoDeinit() { | |
200 | // see header file for class documentation | |
201 | ||
202 | ||
203 | return 0; | |
204 | } | |
205 | ||
206 | // ################################################################################# | |
207 | Int_t AliHLTGlobalEsdToFlatConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, | |
208 | const AliHLTComponentBlockData* /*blocks*/, | |
209 | AliHLTComponentTriggerData& /*trigData*/, | |
ee82d961 | 210 | AliHLTUInt8_t* outputPtr, |
211 | AliHLTUInt32_t& size, | |
eb84342b | 212 | AliHLTComponentBlockDataList& outputBlocks) { |
213 | // see header file for class documentation | |
214 | ||
c2374f56 | 215 | |
216 | ||
217 | ||
218 | AliSysInfo::AddStamp("AliHLTGlobalEsdToFlatConverterComponent::DoEvent.Start"); | |
eb84342b | 219 | Int_t iResult=0; |
220 | ||
a88a189e | 221 | Bool_t err = kFALSE; |
a2e57ab1 | 222 | |
223 | ||
224 | size_t maxOutputSize = size; | |
225 | size = 0; | |
226 | ||
eb84342b | 227 | // -- Only use data event |
228 | if (!IsDataEvent()) | |
229 | return 0; | |
0e757649 | 230 | AliESDEvent *esd =0; |
231 | AliESDfriend *esdFriend=0; | |
8e0c1b9d | 232 | |
233 | ||
eb84342b | 234 | for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) { |
b904048c | 235 | esd =dynamic_cast<AliESDEvent*>(const_cast<TObject*>(iter)); |
eb84342b | 236 | if( esd ){ |
a88a189e | 237 | cout <<"ESD object found in input"<<endl; |
0e757649 | 238 | esd->GetStdContent(); |
9be6e605 | 239 | cout <<"nr of tracks:"<<esd->GetNumberOfTracks()<<endl; |
240 | cout <<"nr of v0s:"<<esd->GetNumberOfV0s()<<endl; | |
eb84342b | 241 | iResult=1; |
242 | } else { | |
eb84342b | 243 | } |
244 | } | |
245 | ||
246 | for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDfriendObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) { | |
a88a189e | 247 | esdFriend = dynamic_cast<AliESDfriend*>(const_cast<TObject*>(iter)); |
eb84342b | 248 | if( esdFriend ){ |
a88a189e | 249 | cout <<"ESD friend object found in input"<<endl; |
9be6e605 | 250 | cout <<"nr of friend tracks:"<<esdFriend->GetNumberOfTracks()<<endl; |
eb84342b | 251 | } else { |
eb84342b | 252 | } |
253 | } | |
a88a189e | 254 | AliFlatESDEvent *flatEsd = reinterpret_cast<AliFlatESDEvent*>(outputPtr); |
255 | new (flatEsd) AliFlatESDEvent; | |
9be6e605 | 256 | |
257 | Int_t converted1 = flatEsd->SetFromESD(AliFlatESDEvent::EstimateSize(esd),esd, kTRUE); | |
258 | ||
259 | ||
260 | cout <<"XXX conversion successfull? "<<converted1<<endl; | |
261 | cout <<"nr of flat v0s:"<<flatEsd->GetNumberOfV0s()<<endl; | |
a88a189e | 262 | |
263 | if( maxOutputSize > flatEsd->GetSize() ){ | |
eb84342b | 264 | AliHLTComponentBlockData outBlock; |
265 | FillBlockData( outBlock ); | |
266 | outBlock.fOffset = size; | |
267 | outBlock.fSize = flatEsd->GetSize(); | |
268 | outBlock.fDataType = kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut; | |
eb84342b | 269 | outputBlocks.push_back( outBlock ); |
eb84342b | 270 | size += outBlock.fSize; |
a2e57ab1 | 271 | } |
272 | ||
273 | else { | |
274 | ||
275 | return 0; | |
276 | } | |
a88a189e | 277 | if(esdFriend){ |
278 | AliFlatESDFriend *flatFriend = reinterpret_cast<AliFlatESDFriend*>(outputPtr + size); | |
279 | size_t freeSpaceTotal = maxOutputSize - size; | |
280 | size_t freeSpace = freeSpaceTotal; | |
281 | ||
282 | err = ( freeSpace < sizeof( AliFlatESDEvent ) ); | |
283 | if( err ) return 0; | |
284 | ||
285 | new (flatFriend) AliFlatESDFriend; | |
286 | freeSpace = freeSpaceTotal - flatFriend->GetSize(); | |
287 | ||
9be6e605 | 288 | Int_t converted = flatFriend->SetFromESDfriend(AliFlatESDFriend::EstimateSize(esdFriend),esdFriend); |
289 | ||
290 | cout <<"nr of flat friend tracks:"<<flatFriend->GetNumberOfTracks()<<endl; | |
291 | cout <<"YYY friend conversion successfull? "<<converted<<endl; | |
292 | ||
293 | ||
294 | esd->SaveAs("tmp.root"); | |
295 | TFile * fTmp = new TFile ("tmp.root"); | |
296 | Int_t sizeIn = fTmp->GetSize(); | |
297 | delete fTmp; | |
a88a189e | 298 | |
9be6e605 | 299 | esdFriend->SaveAs("tmp.root"); |
300 | fTmp = new TFile("tmp.root"); | |
301 | sizeIn += fTmp->GetSize(); | |
302 | delete fTmp; | |
303 | ||
304 | AliSysInfo::AddStamp("AliHLTGlobalEsdToFlatConverterComponent::DoEvent.Stop",sizeIn, flatEsd->GetSize()+ flatFriend->GetSize(),flatEsd->GetNumberOfTracks(),flatEsd->GetNumberOfV0s()); | |
305 | ||
a88a189e | 306 | { // set up the output block description |
307 | ||
308 | AliHLTComponentBlockData outBlock; | |
309 | FillBlockData( outBlock ); | |
310 | outBlock.fOffset = size; | |
311 | outBlock.fSize = flatFriend->GetSize(); | |
312 | outBlock.fDataType = kAliHLTDataTypeFlatESDFriend|kAliHLTDataOriginOut; | |
313 | outputBlocks.push_back( outBlock ); | |
314 | size += outBlock.fSize; | |
315 | } | |
316 | ||
317 | ||
318 | } | |
eb84342b | 319 | |
9be6e605 | 320 | |
321 | ||
322 | ||
323 | if(flatEsd->GetNumberOfTracks() > 20 ) | |
324 | flatEsd->SaveAs("flatEsdFromEsd.root"); | |
eb84342b | 325 | |
326 | return iResult; | |
327 | } | |
328 | ||
329 | ||
330 | // ################################################################################# | |
331 | Int_t AliHLTGlobalEsdToFlatConverterComponent::ReadPreprocessorValues(const Char_t* /*modules*/) { | |
332 | // see header file for class documentation | |
333 | ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component"); | |
334 | return 0; | |
335 | } | |
336 | ||
337 | ||
338 | int AliHLTGlobalEsdToFlatConverterComponent::Configure(const char* arguments) | |
339 | { | |
340 | // see header file for class documentation | |
341 | int iResult=0; | |
342 | if (!arguments) return iResult; | |
343 | ||
344 | TString allArgs=arguments; | |
345 | TString argument; | |
346 | int bMissingParam=0; | |
347 | ||
348 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
349 | if (pTokens) { | |
350 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
351 | argument=((TObjString*)pTokens->At(i))->String(); | |
352 | if (argument.IsNull()) continue; | |
353 | HLTError("unknown argument %s", argument.Data()); | |
354 | iResult=-EINVAL; | |
355 | break; | |
356 | } | |
357 | delete pTokens; | |
358 | } | |
359 | if (bMissingParam) { | |
360 | HLTError("missing parameter for argument %s", argument.Data()); | |
361 | iResult=-EINVAL; | |
362 | } | |
363 | ||
364 | return iResult; | |
365 | } | |
366 | ||
367 | int AliHLTGlobalEsdToFlatConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId) | |
368 | { | |
369 | // see header file for class documentation | |
370 | int iResult=0; | |
371 | const char* path=NULL; | |
372 | const char* defaultNotify=""; | |
373 | if (cdbEntry) { | |
374 | path=cdbEntry; | |
375 | defaultNotify=" (default)"; | |
376 | } | |
377 | if (path) { | |
378 | HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>"); | |
379 | AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/); | |
380 | if (pEntry) { | |
381 | TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject()); | |
382 | if (pString) { | |
383 | HLTInfo("received configuration object string: \'%s\'", pString->String().Data()); | |
384 | iResult=Configure(pString->String().Data()); | |
385 | } else { | |
386 | HLTError("configuration object \"%s\" has wrong type, required TObjString", path); | |
387 | } | |
388 | } else { | |
389 | HLTError("can not fetch object \"%s\" from CDB", path); | |
390 | } | |
391 | } | |
392 | ||
393 | return iResult; | |
394 | } |