]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponent.cxx
reverting r27483 partially in order to cope with bug of the PubSub framework
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.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 //*                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9 //*                  for The ALICE HLT Project.                            *
10 //*                                                                        *
11 //* Permission to use, copy, modify and distribute this software and its   *
12 //* documentation strictly for non-commercial purposes is hereby granted   *
13 //* without fee, provided that the above copyright notice appears in all   *
14 //* copies and that both the copyright notice and this permission notice   *
15 //* appear in the supporting documentation. The authors make no claims     *
16 //* about the suitability of this software for any purpose. It is          *
17 //* provided "as is" without express or implied warranty.                  *
18 //**************************************************************************
19
20 /** @file   AliHLTComponent.cxx
21     @author Matthias Richter, Timm Steinbeck
22     @date   
23     @brief  Base class implementation for HLT components. */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 //#include "AliHLTStdIncludes.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTMessage.h"
33 #include "TString.h"
34 #include "TMath.h"
35 #include "TObjArray.h"
36 #include "TObjectTable.h"
37 #include "TClass.h"
38 #include "TStopwatch.h"
39 #include "AliHLTMemoryFile.h"
40 #include "AliHLTMisc.h"
41 #include <cassert>
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTComponent);
45
46 /** stopwatch macro using the stopwatch guard */
47 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
48 //#define ALIHLTCOMPONENT_STOPWATCH(type) 
49
50 /** stopwatch macro for operations of the base class */
51 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
52 /** stopwatch macro for operations of the detector algorithm (DA) */
53 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
54
55 AliHLTComponent::AliHLTComponent()
56   :
57   fEnvironment(),
58   fCurrentEvent(0),
59   fEventCount(-1),
60   fFailedEvents(0),
61   fCurrentEventData(),
62   fpInputBlocks(NULL),
63   fCurrentInputBlock(-1),
64   fSearchDataType(kAliHLTVoidDataType),
65   fClassName(),
66   fpInputObjects(NULL),
67   fpOutputBuffer(NULL),
68   fOutputBufferSize(0),
69   fOutputBufferFilled(0),
70   fOutputBlocks(),
71   fpStopwatches(new TObjArray(kSWTypeCount)),
72   fMemFiles(),
73   fpRunDesc(NULL),
74   fpDDLList(NULL),
75   fCDBSetRunNoFunc(false),
76   fChainId(),
77   fpBenchmark(NULL),
78   fRequireSteeringBlocks(false)
79 {
80   // see header file for class documentation
81   // or
82   // refer to README to build package
83   // or
84   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85   memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
86   if (fgpComponentHandler)
87     fgpComponentHandler->ScheduleRegister(this);
88   //SetLocalLoggingLevel(kHLTLogDefault);
89 }
90
91 AliHLTComponent::~AliHLTComponent()
92 {
93   // see header file for function documentation
94   if (fpBenchmark) delete fpBenchmark;
95   fpBenchmark=NULL;
96
97   CleanupInputObjects();
98   if (fpStopwatches!=NULL) delete fpStopwatches;
99   fpStopwatches=NULL;
100   AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
101   while (element!=fMemFiles.end()) {
102     if (*element) {
103       if ((*element)->IsClosed()==0) {
104         HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
105         // close but do not flush as we dont know whether the buffer is still valid
106         (*element)->CloseMemoryFile(0);
107       }
108       delete *element;
109       *element=NULL;
110     }
111     element++;
112   }
113   if (fpRunDesc) {
114     delete fpRunDesc;
115     fpRunDesc=NULL;
116   }
117 }
118
119 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
120
121 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) 
122 {
123   // see header file for function documentation
124   int iResult=0;
125   if (fgpComponentHandler==NULL || bOverwrite!=0)
126     fgpComponentHandler=pCH;
127   else
128     iResult=-EPERM;
129   return iResult;
130 }
131
132 int AliHLTComponent::UnsetGlobalComponentHandler() 
133 {
134   // see header file for function documentation
135   return SetGlobalComponentHandler(NULL,1);
136 }
137
138 int AliHLTComponent::Init(const AliHLTComponentEnvironment* comenv, void* environParam, int argc, const char** argv )
139 {
140   // see header file for function documentation
141   HLTLogKeyword(GetComponentID());
142   int iResult=0;
143   if (comenv) {
144     memcpy(&fEnvironment, comenv, sizeof(AliHLTComponentEnvironment));
145     fEnvironment.fParam=environParam;
146   }
147   const char** pArguments=NULL;
148   int iNofChildArgs=0;
149   TString argument="";
150   int bMissingParam=0;
151   if (argc>0) {
152     pArguments=new const char*[argc];
153     if (pArguments) {
154       for (int i=0; i<argc && iResult>=0; i++) {
155         argument=argv[i];
156         if (argument.IsNull()) continue;
157
158         // benchmark
159         if (argument.CompareTo("benchmark")==0) {
160
161           // loglevel
162         } else if (argument.CompareTo("loglevel")==0) {
163           if ((bMissingParam=(++i>=argc))) break;
164           TString parameter(argv[i]);
165           parameter.Remove(TString::kLeading, ' '); // remove all blanks
166           if (parameter.BeginsWith("0x") &&
167               parameter.Replace(0,2,"",0).IsHex()) {
168             AliHLTComponentLogSeverity loglevel=kHLTLogNone;
169             sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
170             SetLocalLoggingLevel(loglevel);
171           } else {
172             HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
173             iResult=-EINVAL;
174           }
175         } else {
176           pArguments[iNofChildArgs++]=argv[i];
177         }
178       }
179     } else {
180       iResult=-ENOMEM;
181     }
182   }
183   if (bMissingParam) {
184     HLTError("missing parameter for argument %s", argument.Data());
185     iResult=-EINVAL;
186   }
187   if (iResult>=0) {
188     iResult=DoInit(iNofChildArgs, pArguments);
189   }
190   if (iResult>=0) {
191     fEventCount=0;
192
193     // find out if the component wants to get the steering events
194     // explicitly
195     AliHLTComponentDataTypeList inputDt;
196     GetInputDataTypes(inputDt);
197     for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
198          dt!=inputDt.end() && !fRequireSteeringBlocks;
199          dt++) {
200       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
201       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
202       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
203       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
204       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
205     }
206   }
207   if (pArguments) delete [] pArguments;
208
209 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
210   // benchmarking stopwatch for the component statistics
211   fpBenchmark=new TStopwatch;
212   if (fpBenchmark) {
213     fpBenchmark->Start();
214   }
215 #endif
216
217   return iResult;
218 }
219
220 int AliHLTComponent::Deinit()
221 {
222   // see header file for function documentation
223   HLTLogKeyword(GetComponentID());
224   int iResult=0;
225   iResult=DoDeinit();
226   if (fpRunDesc) {
227     HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
228     AliHLTRunDesc* pRunDesc=fpRunDesc;
229     fpRunDesc=NULL;
230     delete pRunDesc;
231   }
232   fEventCount=0;
233   return iResult;
234 }
235
236 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
237 {
238   // see header file for function documentation
239   int iResult=0;
240   if (pHandler) {
241   // I have to think about separating the library handling from the
242   // component handler. Requiring the component hanlder here is not
243   // the cleanest solution.
244   // We presume the library already to be loaded
245   // find the symbol
246   AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
247   if (pFunc) {
248     TString path;
249     if (cdbPath && cdbPath[0]!=0) {
250       path=cdbPath;
251       // very temporary fix, have to check for other formats
252       if (!path.BeginsWith("local://")) {
253         path="local://";
254         path+=cdbPath;
255       }
256     }
257     if ((iResult=(*pFunc)(path.Data()))>=0) {
258       if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
259         Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
260                 "can not find function to set CDB run no");
261       }
262     }
263   } else {
264     Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
265             "can not find initialization function");
266     iResult=-ENOSYS;
267   }
268   } else {
269     iResult=-EINVAL;
270   }
271   return iResult;
272 }
273
274 int AliHLTComponent::SetCDBRunNo(int runNo)
275 {
276   // see header file for function documentation
277   if (!fCDBSetRunNoFunc) return 0;
278   return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
279 }
280
281 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
282 {
283   // see header file for function documentation
284   if (!desc) return -EINVAL;
285   if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
286     HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
287     return -EINVAL;
288   }
289
290   if (!fpRunDesc) {
291     fpRunDesc=new AliHLTRunDesc;
292     if (!fpRunDesc) return -ENOMEM;
293     *fpRunDesc=kAliHLTVoidRunDesc;
294   }
295
296   if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
297     HLTWarning("Run description has already been set");
298   }
299   *fpRunDesc=*desc;
300   SetCDBRunNo(fpRunDesc->fRunNo);
301   // TODO: we have to decide about the runType
302   return 0;
303 }
304
305 int AliHLTComponent::SetComponentDescription(const char* desc)
306 {
307   // default implementation, childs can overload
308   int iResult=0;
309   if (!desc) return 0;
310
311   TString descriptor=desc;
312   TObjArray* pTokens=descriptor.Tokenize(" ");
313   if (pTokens) {
314     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
315       TString argument=((TObjString*)pTokens->At(i++))->GetString();
316       if (!argument || argument.IsNull()) continue;
317
318       // -chainid
319       if (argument.BeginsWith("-chainid")) {
320         argument.ReplaceAll("-chainid", "");
321         if (argument.BeginsWith("=")) {
322           fChainId=argument.Replace(0,1,"");
323         } else {
324           fChainId="";
325         }
326       } else {
327         HLTWarning("unknown argument %s", argument.Data());
328       }
329     }
330   }
331   
332   return iResult;
333 }
334
335 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
336 {
337   // default implementation, childs can overload
338   HLTLogKeyword("dummy");
339   return 0;
340 }
341
342 int AliHLTComponent::DoDeinit()
343 {
344   // default implementation, childs can overload
345   HLTLogKeyword("dummy");
346   return 0;
347 }
348
349 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
350 {
351   // default implementation, childs can overload
352   HLTLogKeyword("dummy");
353   return 0;
354 }
355
356 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
357 {
358   // default implementation, childs can overload
359   HLTLogKeyword("dummy");
360   return 0;
361 }
362
363 int AliHLTComponent::StartOfRun()
364 {
365   // default implementation, childs can overload
366   HLTLogKeyword("dummy");
367   return 0;
368 }
369
370 int AliHLTComponent::EndOfRun()
371 {
372   // default implementation, childs can overload
373   HLTLogKeyword("dummy");
374   return 0;
375 }
376
377
378 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
379 {
380   // default implementation, childs can overload
381   HLTLogKeyword("dummy");
382   return 0;
383 }
384
385 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
386 {
387   // see header file for function documentation
388   memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
389   strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
390   strcat( output, ":" );
391   strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
392 }
393
394 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
395 {
396   // see header file for function documentation
397   string out("");
398
399   if (mode==2) {
400     int i=0;
401     char tmp[8];
402     for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
403       sprintf(tmp, "'%d", type.fOrigin[i]);
404       out+=tmp;
405     }
406     out+="':'";
407     for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
408       sprintf(tmp, "%d'", type.fID[i]);
409       out+=tmp;
410     }
411     return out;
412   }
413
414   if (mode==1) {
415     int i=0;
416     char tmp[8];
417     for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
418       unsigned char* puc=(unsigned char*)type.fOrigin;
419       if ((puc[i])<32)
420         sprintf(tmp, "'\\%x", type.fOrigin[i]);
421       else
422         sprintf(tmp, "'%c", type.fOrigin[i]);
423       out+=tmp;
424     }
425     out+="':'";
426     for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
427       unsigned char* puc=(unsigned char*)type.fID;
428       if (puc[i]<32)
429         sprintf(tmp, "\\%x'", type.fID[i]);
430       else
431         sprintf(tmp, "%c'", type.fID[i]);
432       out+=tmp;
433     }
434     return out;
435   }
436
437   if (type==kAliHLTVoidDataType) {
438     out="VOID:VOID";
439   } else {
440     // some gymnastics in order to avoid a '0' which is part of either or both
441     // ID and origin terminating the whole string. Unfortunately, string doesn't
442     // stop appending at the '0' if the number of elements to append was 
443     // explicitely specified
444     string tmp("");
445     tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
446     out.append(tmp.c_str());
447     out.append(":");
448     tmp="";
449     tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
450     out.append(tmp.c_str());
451   }
452   return out;
453 }
454
455
456 void* AliHLTComponent::AllocMemory( unsigned long size ) 
457 {
458   // see header file for function documentation
459   if (fEnvironment.fAllocMemoryFunc)
460     return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
461   HLTFatal("no memory allocation handler registered");
462   return NULL;
463 }
464
465 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
466                                               AliHLTComponentBlockData** outputBlocks ) 
467 {
468   // see header file for function documentation
469     if ( blockCount==NULL || outputBlocks==NULL )
470         return -EFAULT;
471     AliHLTUInt32_t count = blocks.size();
472     if ( !count )
473         {
474         *blockCount = 0;
475         *outputBlocks = NULL;
476         return 0;
477         }
478     *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
479     if ( !*outputBlocks )
480         return -ENOMEM;
481     for ( unsigned long i = 0; i < count; i++ ) {
482         (*outputBlocks)[i] = blocks[i];
483         if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
484           (*outputBlocks)[i].fDataType=GetOutputDataType();
485           /* data type was set to the output data type by the PubSub AliRoot
486              Wrapper component, if data type of the block was ********:****.
487              Now handled by the component base class in order to have same
488              behavior when running embedded in AliRoot
489           memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
490           memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
491           */
492         }
493     }
494     *blockCount = count;
495     return 0;
496
497 }
498
499 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) 
500 {
501   // see header file for function documentation
502   if (fEnvironment.fGetEventDoneDataFunc)
503     return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
504   return -ENOSYS;
505 }
506
507 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList) 
508 {
509   // see header file for function documentation
510   int iResult=0;
511   if (pConsumer) {
512     AliHLTComponentDataTypeList itypes;
513     AliHLTComponentDataTypeList otypes;
514     otypes.push_back(GetOutputDataType());
515     if (otypes[0]==kAliHLTMultipleDataType) {
516       otypes.clear();
517       int count=0;
518       if ((count=GetOutputDataTypes(otypes))>0) {
519       } else if (GetComponentType()!=kSink) {
520         HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
521       }
522     }
523     ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
524     AliHLTComponentDataTypeList::iterator itype=itypes.begin();
525     while (itype!=itypes.end()) {
526       //PrintDataTypeContent((*itype), "consumer \'%s\'");
527       AliHLTComponentDataTypeList::iterator otype=otypes.begin();
528       while (otype!=otypes.end() && (*itype)!=(*otype)) otype++;
529       //if (otype!=otypes.end()) PrintDataTypeContent(*otype, "publisher \'%s\'");
530       if (otype!=otypes.end()) {
531         if (tgtList) tgtList->push_back(*itype);
532         iResult++;
533       }
534       itype++;
535     }
536   } else {
537     iResult=-EINVAL;
538   }
539   return iResult;
540 }
541
542 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
543 {
544   // see header file for function documentation
545   const char* fmt="\'%s\'";
546   if (format) fmt=format;
547   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
548   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, 
549                          Form("%x %x %x %x %x %x %x %x : %x %x %x %x", 
550                               dt.fID[0],
551                               dt.fID[1],
552                               dt.fID[2],
553                               dt.fID[3],
554                               dt.fID[4],
555                               dt.fID[5],
556                               dt.fID[6],
557                               dt.fID[7],
558                               dt.fOrigin[0],
559                               dt.fOrigin[1],
560                               dt.fOrigin[2],
561                               dt.fOrigin[3]));
562 }
563
564 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
565 {
566   // see header file for function documentation
567   blockData.fStructSize = sizeof(blockData);
568   FillShmData( blockData.fShmKey );
569   blockData.fOffset = ~(AliHLTUInt32_t)0;
570   blockData.fPtr = NULL;
571   blockData.fSize = 0;
572   FillDataType( blockData.fDataType );
573   blockData.fSpecification = kAliHLTVoidDataSpec;
574 }
575
576 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
577 {
578   // see header file for function documentation
579   shmData.fStructSize = sizeof(shmData);
580   shmData.fShmType = gkAliHLTComponentInvalidShmType;
581   shmData.fShmID = gkAliHLTComponentInvalidShmID;
582 }
583
584 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
585 {
586   // see header file for function documentation
587   dataType=kAliHLTAnyDataType;
588 }
589
590 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) 
591 {
592   // see header file for function documentation
593   memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
594   memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
595 }
596
597 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) 
598 {
599   // see header file for function documentation
600   tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
601   if (id) {
602     memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
603     strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
604   }
605   if (origin) {
606     memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
607     strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
608   }
609 }
610
611 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
612 {
613   // see header file for function documentation
614   dt.fStructSize=sizeof(AliHLTComponentDataType);
615   assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
616   assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
617   memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
618   memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
619 }
620
621 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
622 {
623   // see header file for function documentation
624   memset(&evtData, 0, sizeof(AliHLTComponentEventData));
625   evtData.fStructSize=sizeof(AliHLTComponentEventData);
626 }
627
628 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) 
629 {
630   // see header file for function documentation
631   TString msg;
632   msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
633   for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
634    if (dt.fID[i]!=0) msg+=dt.fID[i];
635    else msg+="\\0";
636   }
637   msg+="\" Origin=\"";
638   for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
639    if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
640    else msg+="\\0";
641   }
642   msg+="\"";
643   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
644 }
645
646 int AliHLTComponent::GetEventCount() const
647 {
648   // see header file for function documentation
649   return fEventCount;
650 }
651
652 int AliHLTComponent::IncrementEventCounter()
653 {
654   // see header file for function documentation
655   if (fEventCount>=0) fEventCount++;
656   return fEventCount;
657 }
658
659 int AliHLTComponent::GetNumberOfInputBlocks() const
660 {
661   // see header file for function documentation
662   if (fpInputBlocks!=NULL) {
663     return fCurrentEventData.fBlockCnt;
664   }
665   return 0;
666 }
667
668 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
669                                                     const char* classname,
670                                                     int bForce)
671 {
672   // see header file for function documentation
673   ALIHLTCOMPONENT_BASE_STOPWATCH();
674   fSearchDataType=dt;
675   if (classname) fClassName=classname;
676   else fClassName.clear();
677   int idx=FindInputBlock(fSearchDataType, 0, 1);
678   TObject* pObj=NULL;
679   if (idx>=0) {
680     HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
681     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
682       fCurrentInputBlock=idx;
683     } else {
684     }
685   }
686   return pObj;
687 }
688
689 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, 
690                                                     const char* dtOrigin,
691                                                     const char* classname,
692                                                     int         bForce)
693 {
694   // see header file for function documentation
695   ALIHLTCOMPONENT_BASE_STOPWATCH();
696   AliHLTComponentDataType dt;
697   SetDataType(dt, dtID, dtOrigin);
698   return GetFirstInputObject(dt, classname, bForce);
699 }
700
701 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
702 {
703   // see header file for function documentation
704   ALIHLTCOMPONENT_BASE_STOPWATCH();
705   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
706   //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
707   TObject* pObj=NULL;
708   if (idx>=0) {
709     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
710       fCurrentInputBlock=idx;
711     }
712   }
713   return pObj;
714 }
715
716 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
717 {
718   // see header file for function documentation
719   int iResult=-ENOENT;
720   if (fpInputBlocks!=NULL) {
721     int idx=startIdx<0?0:startIdx;
722     for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
723       if (dt!=fpInputBlocks[idx].fDataType) continue;
724
725       if (bObject!=0) {
726         if (fpInputBlocks[idx].fPtr==NULL) continue;
727         AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
728         if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
729       }
730       iResult=idx;
731     }
732   }
733   return iResult;
734 }
735
736 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
737 {
738   // see header file for function documentation
739   TObject* pObj=NULL;
740   if (fpInputBlocks!=NULL) {
741     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
742       if (fpInputBlocks[idx].fPtr) {
743         AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
744         if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
745           HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
746           AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
747           TClass* objclass=msg.GetClass();
748           pObj=msg.ReadObject(objclass);
749           if (pObj && objclass) {
750             HLTDebug("object %p type %s created", pObj, objclass->GetName());
751           } else {
752           }
753           //} else {
754         } else if (bForce!=0) {
755           HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
756         }
757       } else {
758         HLTFatal("block descriptor empty");
759       }
760     } else {
761       HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
762     }
763   } else {
764     HLTError("no input blocks available");
765   }
766   
767   return pObj;
768 }
769
770 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
771 {
772   // see header file for function documentation
773   if (fpInputObjects==NULL) {
774     fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
775   }
776   TObject* pObj=NULL;
777   if (fpInputObjects) {
778     pObj=fpInputObjects->At(idx);
779     if (pObj==NULL) {
780       pObj=CreateInputObject(idx, bForce);
781       if (pObj) {
782         fpInputObjects->AddAt(pObj, idx);
783       }
784     }
785   } else {
786     HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
787   }
788   return pObj;
789 }
790
791 int AliHLTComponent::CleanupInputObjects()
792 {
793   // see header file for function documentation
794   if (!fpInputObjects) return 0;
795   TObjArray* array=fpInputObjects;
796   fpInputObjects=NULL;
797   for (int i=0; i<array->GetEntries(); i++) {
798     TObject* pObj=array->At(i);
799     // grrr, garbage collection strikes back: When read via AliHLTMessage
800     // (CreateInputObject), and written to a TFile afterwards, the
801     // TFile::Close calls ROOOT's garbage collection. No clue why the
802     // object ended up in the key list and needs to be deleted
803     if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj;
804   }
805   delete array;
806   return 0;
807 }
808
809 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
810 {
811   // see header file for function documentation
812   ALIHLTCOMPONENT_BASE_STOPWATCH();
813   AliHLTComponentDataType dt=kAliHLTVoidDataType;
814   int idx=fCurrentInputBlock;
815   if (pObject) {
816     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
817     } else {
818       HLTError("unknown object %p", pObject);
819     }
820   }
821   if (idx>=0) {
822     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
823       dt=fpInputBlocks[idx].fDataType;
824     } else {
825       HLTFatal("severe internal error, index out of range");
826     }
827   }
828   return dt;
829 }
830
831 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
832 {
833   // see header file for function documentation
834   ALIHLTCOMPONENT_BASE_STOPWATCH();
835   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
836   int idx=fCurrentInputBlock;
837   if (pObject) {
838     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
839     } else {
840       HLTError("unknown object %p", pObject);
841     }
842   }
843   if (idx>=0) {
844     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
845       iSpec=fpInputBlocks[idx].fSpecification;
846     } else {
847       HLTFatal("severe internal error, index out of range");
848     }
849   }
850   return iSpec;
851 }
852
853 int AliHLTComponent::Forward(const TObject* pObject)
854 {
855   // see header file for function documentation
856   int iResult=0;
857   int idx=fCurrentInputBlock;
858   if (pObject) {
859     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
860     } else {
861       HLTError("unknown object %p", pObject);
862       iResult=-ENOENT;
863     }
864   }
865   if (idx>=0) {
866     fOutputBlocks.push_back(fpInputBlocks[idx]);
867   }
868   return iResult;
869 }
870
871 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
872 {
873   // see header file for function documentation
874   int iResult=0;
875   int idx=fCurrentInputBlock;
876   if (pBlock) {
877     if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
878     } else {
879       HLTError("unknown Block %p", pBlock);
880       iResult=-ENOENT;      
881     }
882   }
883   if (idx>=0) {
884     // check for fpInputBlocks pointer done in FindInputBlock
885     fOutputBlocks.push_back(fpInputBlocks[idx]);
886   }
887   return iResult;
888 }
889
890 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
891 {
892   // see header file for function documentation
893   ALIHLTCOMPONENT_BASE_STOPWATCH();
894   fSearchDataType=dt;
895   fClassName.clear();
896   int idx=FindInputBlock(fSearchDataType, 0);
897   const AliHLTComponentBlockData* pBlock=NULL;
898   if (idx>=0) {
899     // check for fpInputBlocks pointer done in FindInputBlock
900     pBlock=&fpInputBlocks[idx];
901     fCurrentInputBlock=idx;
902   }
903   return pBlock;
904 }
905
906 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, 
907                                                                     const char* dtOrigin)
908 {
909   // see header file for function documentation
910   ALIHLTCOMPONENT_BASE_STOPWATCH();
911   AliHLTComponentDataType dt;
912   SetDataType(dt, dtID, dtOrigin);
913   return GetFirstInputBlock(dt);
914 }
915
916 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index)
917 {
918   // see header file for function documentation
919   ALIHLTCOMPONENT_BASE_STOPWATCH();
920   assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
921   return &fpInputBlocks[index];
922 }
923
924 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
925 {
926   // see header file for function documentation
927   ALIHLTCOMPONENT_BASE_STOPWATCH();
928   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
929   const AliHLTComponentBlockData* pBlock=NULL;
930   if (idx>=0) {
931     // check for fpInputBlocks pointer done in FindInputBlock
932     pBlock=&fpInputBlocks[idx];
933     fCurrentInputBlock=idx;
934   }
935   return pBlock;
936 }
937
938 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
939 {
940   // see header file for function documentation
941   int iResult=-ENOENT;
942   if (fpInputBlocks!=NULL) {
943     if (pBlock) {
944       if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
945         iResult=(int)(pBlock-fpInputBlocks);
946       }
947     } else {
948       iResult=-EINVAL;
949     }
950   }
951   return iResult;
952 }
953
954 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
955 {
956   // see header file for function documentation
957   ALIHLTCOMPONENT_BASE_STOPWATCH();
958   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
959   int idx=fCurrentInputBlock;
960   if (pBlock) {
961     if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
962     } else {
963       HLTError("unknown Block %p", pBlock);
964     }
965   }
966   if (idx>=0) {
967     // check for fpInputBlocks pointer done in FindInputBlock
968     iSpec=fpInputBlocks[idx].fSpecification;
969   }
970   return iSpec;
971 }
972
973 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, 
974                               void* pHeader, int headerSize)
975 {
976   // see header file for function documentation
977   ALIHLTCOMPONENT_BASE_STOPWATCH();
978   int iResult=0;
979   if (pObject) {
980     AliHLTMessage msg(kMESS_OBJECT);
981     msg.WriteObject(pObject);
982     Int_t iMsgLength=msg.Length();
983     if (iMsgLength>0) {
984       msg.SetLength(); // sets the length to the first (reserved) word
985       iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize);
986       if (iResult>=0) {
987         HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
988       }
989     } else {
990       HLTError("object serialization failed for object %p", pObject);
991       iResult=-ENOMSG;
992     }
993   } else {
994     iResult=-EINVAL;
995   }
996   return iResult;
997 }
998
999 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1000                               void* pHeader, int headerSize)
1001 {
1002   // see header file for function documentation
1003   ALIHLTCOMPONENT_BASE_STOPWATCH();
1004   AliHLTComponentDataType dt;
1005   SetDataType(dt, dtID, dtOrigin);
1006   return PushBack(pObject, dt, spec, pHeader, headerSize);
1007 }
1008
1009 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1010                               void* pHeader, int headerSize)
1011 {
1012   // see header file for function documentation
1013   ALIHLTCOMPONENT_BASE_STOPWATCH();
1014   return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1015 }
1016
1017 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1018                               void* pHeader, int headerSize)
1019 {
1020   // see header file for function documentation
1021   ALIHLTCOMPONENT_BASE_STOPWATCH();
1022   AliHLTComponentDataType dt;
1023   SetDataType(dt, dtID, dtOrigin);
1024   return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1025 }
1026
1027 int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1028                               void* pHeader, int iHeaderSize)
1029 {
1030   // see header file for function documentation
1031   int iResult=0;
1032   int iBlkSize = iBufferSize + iHeaderSize;
1033   if (pBuffer) {
1034     if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1035       AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1036       AliHLTComponentBlockData bd;
1037       FillBlockData( bd );
1038       bd.fOffset        = fOutputBufferFilled;
1039       bd.fSize          = iBlkSize;
1040       bd.fDataType      = dt;
1041       bd.fSpecification = spec;
1042       if (pHeader!=NULL && pHeader!=pTgt) {
1043         memcpy(pTgt, pHeader, iHeaderSize);
1044       }
1045
1046       pTgt += (AliHLTUInt8_t) iHeaderSize;
1047
1048       if (pBuffer!=NULL && pBuffer!=pTgt) {
1049         memcpy(pTgt, pBuffer, iBufferSize);
1050         
1051         //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); 
1052         //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1053       }
1054       fOutputBufferFilled+=bd.fSize;
1055       fOutputBlocks.push_back( bd );
1056       //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1057     } else {
1058       if (fpOutputBuffer) {
1059         HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize);
1060       } else {
1061         HLTError("output buffer not available");
1062       }
1063       iResult=-ENOSPC;
1064     }
1065   } else {
1066     iResult=-EINVAL;
1067   }
1068   return iResult;
1069 }
1070
1071 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1072 {
1073   // see header file for function documentation
1074   if (!pObject) return -EINVAL;
1075     AliHLTMessage msg(kMESS_OBJECT);
1076     msg.WriteObject(pObject);
1077     return msg.Length();  
1078 }
1079
1080 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1081                                                     const char* dtOrigin,
1082                                                     AliHLTUInt32_t spec)
1083 {
1084   // see header file for function documentation
1085   ALIHLTCOMPONENT_BASE_STOPWATCH();
1086   AliHLTComponentDataType dt;
1087   SetDataType(dt, dtID, dtOrigin);
1088   return CreateMemoryFile(capacity, dt, spec);
1089 }
1090
1091 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1092                                                     const AliHLTComponentDataType& dt,
1093                                                     AliHLTUInt32_t spec)
1094 {
1095   // see header file for function documentation
1096   ALIHLTCOMPONENT_BASE_STOPWATCH();
1097   AliHLTMemoryFile* pFile=NULL;
1098   if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1099     AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1100     pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1101     if (pFile) {
1102       unsigned int nofBlocks=fOutputBlocks.size();
1103       if (nofBlocks+1>fMemFiles.size()) {
1104         fMemFiles.resize(nofBlocks+1, NULL);
1105       }
1106       if (nofBlocks<fMemFiles.size()) {
1107         fMemFiles[nofBlocks]=pFile;
1108         AliHLTComponentBlockData bd;
1109         FillBlockData( bd );
1110         bd.fOffset        = fOutputBufferFilled;
1111         bd.fSize          = capacity;
1112         bd.fDataType      = dt;
1113         bd.fSpecification = spec;
1114         fOutputBufferFilled+=bd.fSize;
1115         fOutputBlocks.push_back( bd );
1116       } else {
1117         HLTError("can not allocate/grow object array");
1118         pFile->CloseMemoryFile(0);
1119         delete pFile;
1120         pFile=NULL;
1121       }
1122     }
1123   } else {
1124     HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1125   }
1126   return pFile;
1127 }
1128
1129 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1130                                                     const char* dtOrigin,
1131                                                     AliHLTUInt32_t spec,
1132                                                     float capacity)
1133 {
1134   // see header file for function documentation
1135   ALIHLTCOMPONENT_BASE_STOPWATCH();
1136   AliHLTComponentDataType dt;
1137   SetDataType(dt, dtID, dtOrigin);
1138   int size=fOutputBufferSize-fOutputBufferFilled;
1139   if (capacity<0 || capacity>1.0) {
1140     HLTError("invalid parameter: capacity %f", capacity);
1141     return NULL;
1142   }
1143   size=(int)(size*capacity);
1144   return CreateMemoryFile(size, dt, spec);
1145 }
1146
1147 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1148                                                     AliHLTUInt32_t spec,
1149                                                     float capacity)
1150 {
1151   // see header file for function documentation
1152   ALIHLTCOMPONENT_BASE_STOPWATCH();
1153   int size=fOutputBufferSize-fOutputBufferFilled;
1154   if (capacity<0 || capacity>1.0) {
1155     HLTError("invalid parameter: capacity %f", capacity);
1156     return NULL;
1157   }
1158   size=(int)(size*capacity);
1159   return CreateMemoryFile(size, dt, spec);
1160 }
1161
1162 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1163                            const char* key, int option)
1164 {
1165   // see header file for function documentation
1166   int iResult=0;
1167   if (pFile && pObject) {
1168     pFile->cd();
1169     iResult=pObject->Write(key, option);
1170     if (iResult>0) {
1171       // success
1172     } else {
1173       iResult=-pFile->GetErrno();
1174       if (iResult==-ENOSPC) {
1175         HLTError("error writing memory file, buffer too small");
1176       }
1177     }
1178   } else {
1179     iResult=-EINVAL;
1180   }
1181   return iResult;
1182 }
1183
1184 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1185 {
1186   // see header file for function documentation
1187   int iResult=0;
1188   if (pFile) {
1189     AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1190     int i=0;
1191     while (element!=fMemFiles.end() && iResult>=0) {
1192       if (*element && *element==pFile) {
1193         iResult=pFile->CloseMemoryFile();
1194         
1195         // sync memory files and descriptors
1196         if (iResult>=0) {
1197           fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1198         }
1199         delete *element;
1200         *element=NULL;
1201         return iResult;
1202       }
1203       element++; i++;
1204     }
1205     HLTError("can not find memory file %p", pFile);
1206     iResult=-ENOENT;
1207   } else {
1208     iResult=-EINVAL;
1209   }
1210   return iResult;
1211 }
1212
1213 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/)
1214 {
1215   // see header file for function documentation
1216   int iResult=-ENOSYS;
1217   //#warning  function not yet implemented
1218   HLTWarning("function not yet implemented");
1219   return iResult;
1220 }
1221
1222 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1223                                    const AliHLTComponentBlockData* blocks, 
1224                                    AliHLTComponentTriggerData& trigData,
1225                                    AliHLTUInt8_t* outputPtr, 
1226                                    AliHLTUInt32_t& size,
1227                                    AliHLTUInt32_t& outputBlockCnt, 
1228                                    AliHLTComponentBlockData*& outputBlocks,
1229                                    AliHLTComponentEventDoneData*& edd )
1230 {
1231   // see header file for function documentation
1232   HLTLogKeyword(GetComponentID());
1233   ALIHLTCOMPONENT_BASE_STOPWATCH();
1234   int iResult=0;
1235   fCurrentEvent=evtData.fEventID;
1236   fCurrentEventData=evtData;
1237   fpInputBlocks=blocks;
1238   fCurrentInputBlock=-1;
1239   fSearchDataType=kAliHLTAnyDataType;
1240   fpOutputBuffer=outputPtr;
1241   fOutputBufferSize=size;
1242   fOutputBufferFilled=0;
1243   fOutputBlocks.clear();
1244   outputBlockCnt=0;
1245   outputBlocks=NULL;
1246   AliHLTComponentStatisticsList compStats;
1247 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1248   AliHLTComponentStatistics outputStat;
1249   memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1250   compStats.push_back(outputStat);
1251   if (fpBenchmark) {
1252     fpBenchmark->Reset();
1253     fpBenchmark->Start();
1254   }
1255 #endif
1256
1257   // data processing is skipped if there are only steering events
1258   // in the block list. It is not skipped if there is no block list
1259   // at all for the sake of data source components. Data processing
1260   // is always skipped if the event is of type
1261   // - gkAliEventTypeConfiguration
1262   // - gkAliEventTypeReadPreprocessor
1263   const unsigned int skipModeDefault=0x1;
1264   const unsigned int skipModeForce=0x2;
1265   unsigned int bSkipDataProcessing=skipModeDefault;
1266
1267   // find special events
1268   if (fpInputBlocks && evtData.fBlockCnt>0) {
1269     // first look for all special events and execute in the appropriate
1270     // sequence afterwords
1271     AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
1272     int indexComConfEvent=-1;
1273     int indexUpdtDCSEvent=-1;
1274     int indexSOREvent=-1;
1275     int indexEOREvent=-1;
1276     for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1277       if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1278         indexSOREvent=i;
1279         // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1280         bSkipDataProcessing&=~skipModeDefault;
1281       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1282         // run type string
1283         // handling is not clear yet
1284         if (fpInputBlocks[i].fPtr) {
1285           HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1286         }
1287       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1288         indexEOREvent=i;
1289         // the calibration processor relies on the SOR and EOR events
1290         bSkipDataProcessing&=~skipModeDefault;
1291       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1292         // DDL list
1293         // this event is most likely deprecated
1294       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1295         indexComConfEvent=i;
1296       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1297         indexUpdtDCSEvent=i;
1298       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1299         eventType=fpInputBlocks[i].fSpecification;
1300         if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1301         if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1302       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1303         if (compStats.size()>0) {
1304           AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1305           for (AliHLTUInt32_t offset=0;
1306                offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1307                offset+=sizeof(AliHLTComponentStatistics)) {
1308             AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1309             if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1310               compStats[0].fLevel=pStat->fLevel+1;
1311             }
1312             compStats.push_back(*pStat);
1313           }
1314         }
1315       } else {
1316         // the processing function is called if there is at least one
1317         // non-steering data block. Steering blocks are not filtered out
1318         // for sake of performance 
1319         bSkipDataProcessing&=~skipModeDefault;
1320         if (compStats.size()>0) {
1321           compStats[0].fInputBlockCount++;
1322           compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1323         }
1324       }
1325     }
1326
1327     if (indexSOREvent>=0) {
1328       // start of run
1329       if (fpRunDesc==NULL) {
1330         fpRunDesc=new AliHLTRunDesc;
1331       }
1332       if (fpRunDesc) {
1333         AliHLTRunDesc rundesc;
1334         if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1335           if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1336             *fpRunDesc=rundesc;
1337             HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1338             SetCDBRunNo(fpRunDesc->fRunNo);
1339           } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1340             HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1341           }
1342         }
1343       } else {
1344         iResult=-ENOMEM;
1345       }
1346     }
1347     if (indexEOREvent>=0) {
1348       if (fpRunDesc!=NULL) {
1349         if (fpRunDesc) {
1350           AliHLTRunDesc rundesc;
1351           if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1352             if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1353               HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1354             } else {
1355               HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1356             }
1357           }
1358           AliHLTRunDesc* pRunDesc=fpRunDesc;
1359           fpRunDesc=NULL;
1360           delete pRunDesc;
1361         }
1362       } else {
1363         HLTWarning("did not receive SOR, ignoring EOR");
1364       }
1365     }
1366     if (indexComConfEvent>=0 || eventType==gkAliEventTypeConfiguration) {
1367       TString cdbEntry;
1368       if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1369         cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1370       }
1371       HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1372       int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1373       if (tmpResult<0) {
1374         HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1375       }
1376     }
1377     if (indexUpdtDCSEvent>=0 || eventType==gkAliEventTypeReadPreprocessor) {
1378       TString modules;
1379       if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1380         modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1381       }
1382       HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1383       int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1384       if (tmpResult<0) {
1385         HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1386       }
1387     }
1388   } else {
1389     // processing function needs to be called if there are no input data
1390     // blocks in order to make data source components working.
1391     bSkipDataProcessing&=~skipModeDefault;
1392   }
1393
1394   // data processing is not skipped if the component explicitly asks
1395   // for the private blocks
1396   if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1397
1398   AliHLTComponentBlockDataList blockData;
1399   if (iResult>=0 && !bSkipDataProcessing)
1400   { // dont delete, sets the scope for the stopwatch guard
1401     // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1402     // in order to avoid 'shadowed variable' warning
1403     AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1404     iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1405   } // end of the scope of the stopwatch guard
1406   if (iResult>=0 && !bSkipDataProcessing) {
1407     if (fOutputBlocks.size()>0) {
1408       // High Level interface
1409
1410       //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());      
1411       // sync memory files and descriptors
1412       AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1413       int i=0;
1414       while (element!=fMemFiles.end() && iResult>=0) {
1415         if (*element) {
1416           if ((*element)->IsClosed()==0) {
1417             HLTWarning("memory file has not been closed, force flush");
1418             iResult=CloseMemoryFile(*element);
1419           }
1420         }
1421         element++; i++;
1422       }
1423
1424       if (iResult>=0) {
1425         // create the descriptor list
1426         if (blockData.size()>0) {
1427           HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1428           iResult=-EFAULT;
1429         } else {
1430           if (compStats.size()>0) {
1431             int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1432             if (offset>0) fOutputBufferFilled+=offset;
1433           }
1434           iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1435           size=fOutputBufferFilled;
1436         }
1437       }
1438     } else {
1439       // Low Level interface
1440       if (compStats.size()>0) {
1441         int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1442         if (offset>0) size+=offset;
1443       }
1444       iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1445     }
1446     if (iResult<0) {
1447       HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1448     }
1449   }
1450   if (iResult<0 || bSkipDataProcessing) {
1451     outputBlockCnt=0;
1452     outputBlocks=NULL;
1453   }
1454   CleanupInputObjects();
1455   if (iResult>=0 && !bSkipDataProcessing) {
1456     IncrementEventCounter();
1457   }
1458   if (outputBlockCnt==0) {
1459     // no output blocks, set size to 0
1460     size=0;
1461   }
1462   return iResult;
1463 }
1464
1465 int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks, 
1466                                              AliHLTUInt8_t* buffer,
1467                                              AliHLTUInt32_t bufferSize,
1468                                              AliHLTUInt32_t offset,
1469                                              AliHLTComponentStatisticsList& stats) const
1470 {
1471   // see header file for function documentation
1472   int iResult=0;
1473   if (stats.size()==0) return -ENOENT;
1474   stats[0].fTotalOutputSize=offset;
1475   stats[0].fOutputBlockCount=blocks.size();
1476   if (fpBenchmark) {
1477     stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*1000000);
1478     stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*1000000);
1479   }
1480   if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1481     AliHLTComponentBlockData bd;
1482     FillBlockData( bd );
1483     bd.fOffset        = offset;
1484     bd.fSize          = stats.size()*sizeof(AliHLTComponentStatistics);
1485     bd.fDataType      = kAliHLTDataTypeComponentStatistics;
1486     bd.fSpecification = kAliHLTVoidDataSpec;
1487     unsigned int master=0;
1488     for (unsigned int i=1; i<blocks.size(); i++) {
1489       if (blocks[i].fSize>blocks[master].fSize && 
1490           !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1491         master=i;
1492     }
1493     if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1494       // take the data origin of the biggest block as specification
1495       // this is similar to the treatment in the HOMER interface. For traditional
1496       // reasons, the bytes are swapped there on a little endian architecture, so
1497       // we do it as well.
1498       memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1499 #ifdef R__BYTESWAP // set on little endian architectures
1500       bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) | 
1501         ((bd.fSpecification & 0xFF00ULL) << 8) | 
1502         ((bd.fSpecification & 0xFF0000ULL) >> 8) | 
1503         ((bd.fSpecification & 0xFF000000ULL) >> 24);
1504 #endif
1505     }
1506     memcpy(buffer+offset, &(stats[0]), bd.fSize);
1507     blocks.push_back(bd);
1508     iResult=bd.fSize;
1509   }
1510   return iResult;
1511 }
1512
1513 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1514   :
1515   fpStopwatch(NULL),
1516   fpPrec(NULL)
1517 {
1518   // standard constructor (not for use)
1519 }
1520
1521 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1522   :
1523   fpStopwatch(pStopwatch),
1524   fpPrec(NULL)
1525 {
1526   // constructor
1527
1528   // check for already existing guard
1529   if (fgpCurrent) fpPrec=fgpCurrent;
1530   fgpCurrent=this;
1531
1532   // stop the preceeding guard if it controls a different stopwatch
1533   int bStart=1;
1534   if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1535
1536   // start the stopwatch if the current guard controls a different one
1537   if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1538 }
1539
1540 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
1541   :
1542   fpStopwatch(NULL),
1543   fpPrec(NULL)
1544 {
1545   //
1546   // copy constructor not for use
1547   //
1548 }
1549
1550 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1551 {
1552   //
1553   // assignment operator not for use
1554   //
1555   fpStopwatch=NULL;
1556   fpPrec=NULL;
1557   return *this;
1558 }
1559
1560 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1561
1562 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1563 {
1564   // destructor
1565
1566   // resume the preceeding guard if it controls a different stopwatch
1567   int bStop=1;
1568   if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1569
1570   // stop the stopwatch if the current guard controls a different one
1571   if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1572
1573   // resume to the preceeding guard
1574   fgpCurrent=fpPrec;
1575 }
1576
1577 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1578 {
1579   // see header file for function documentation
1580   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1581   return fpStopwatch!=pSucc?1:0;
1582 }
1583
1584 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1585 {
1586   // see header file for function documentation
1587   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1588   return fpStopwatch!=pSucc?1:0;
1589 }
1590
1591 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) 
1592 {
1593   // see header file for function documentation
1594   int iResult=0;
1595   if (pSW!=NULL && type<kSWTypeCount) {
1596     if (fpStopwatches) {
1597       TObject* pObj=fpStopwatches->At((int)type);
1598       if (pSW==NULL        // explicit reset
1599           || pObj==NULL) { // explicit set
1600         fpStopwatches->AddAt(pSW, (int)type);
1601       } else if (pObj!=pSW) {
1602         HLTWarning("stopwatch %d already set, reset first", (int)type);
1603         iResult=-EBUSY;
1604       }
1605     }
1606   } else {
1607     iResult=-EINVAL;
1608   }
1609   return iResult;
1610 }
1611
1612 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1613 {
1614   // see header file for function documentation
1615   if (pStopwatches==NULL) return -EINVAL;
1616
1617   int iResult=0;
1618   for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1619     SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1620   return iResult;
1621 }
1622
1623 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1624 {
1625   // see header file for function documentation
1626   if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
1627   return fpRunDesc->fRunNo;
1628 }
1629
1630 AliHLTUInt32_t AliHLTComponent::GetRunType() const
1631 {
1632   // see header file for function documentation
1633   if (fpRunDesc==NULL) return kAliHLTVoidRunType;
1634   return fpRunDesc->fRunType;
1635 }
1636
1637 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1638                                 const char* structname, const char* eventname)
1639 {
1640   // see header file for function documentation
1641   int iResult=0;
1642   if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
1643     if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
1644       AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
1645       if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
1646         AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
1647         if (fpInputBlocks[iBlockNo].fSize!=copy) {
1648           HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
1649           if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
1650         }
1651         if (copy!=iStructSize) {
1652           HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
1653           if (copy>iStructSize) {
1654             copy=iStructSize;
1655           } else {
1656             memset(pTgt, 0, iStructSize);
1657           }
1658         }
1659         memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
1660         *pTgt=iStructSize;
1661         iResult=copy;
1662       } else {
1663         HLTWarning("%s event: missing data block", eventname);
1664       }
1665     } else {
1666       iResult=-ENODATA;
1667     }
1668   } else {
1669     HLTError("invalid struct");
1670     iResult=-EINVAL;
1671   }
1672   return iResult;
1673 }
1674
1675 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
1676 {
1677   // see header file for function documentation
1678   
1679   // -- Detector offset
1680   Int_t ddlIdBase =  TMath::FloorNint( (Double_t) ddlId / 256.0 );
1681   
1682   // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 ) 
1683   Int_t wordBase = 0;
1684
1685   if ( ddlIdBase <= 3 )
1686     wordBase = ddlIdBase;
1687   else if ( ddlIdBase > 3 && ddlIdBase < 5 )
1688     wordBase = ddlIdBase + 7;
1689   else 
1690     wordBase = ddlIdBase + 9;
1691
1692   // -- Bit index in Word
1693   Int_t bitIdx = ddlId % 32;
1694
1695   // -- Index of word
1696   Int_t wordIdx = wordBase;
1697
1698   // -- if TPC (3) or TOD (5) add word idx
1699   if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
1700     wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
1701   }
1702
1703   // -- Set -- 'OR' word with bit mask;
1704   if ( state )
1705     list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
1706   // -- Unset -- 'AND' word with bit mask;
1707   else
1708     list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
1709 }
1710
1711 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
1712 {
1713   // see header file for function documentation
1714
1715   Int_t iResult = -1;
1716
1717   for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
1718
1719     if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
1720       // check for special cases TPC and TOF
1721       if ( wordNdx > 3 && wordNdx <= 10 ) {
1722         wordNdx = 10;
1723         iResult = 3;
1724       }
1725       else if ( wordNdx > 12 && wordNdx <= 14 ) {
1726         wordNdx = 14;
1727         iResult = 12;
1728       }
1729       else
1730         iResult = wordNdx;
1731     }
1732     else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
1733       HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
1734       iResult = -1;
1735       break;
1736     }
1737   }
1738
1739   return iResult;
1740 }