]>
Commit | Line | Data |
---|---|---|
1 | // $Id$ | |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
8 | * for The ALICE Off-line Project. * | |
9 | * * | |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
19 | /** @file AliHLTComponent.cxx | |
20 | @author Matthias Richter, Timm Steinbeck | |
21 | @date | |
22 | @brief Base class implementation for HLT components. */ | |
23 | ||
24 | #if __GNUC__>= 3 | |
25 | using namespace std; | |
26 | #endif | |
27 | ||
28 | #include "AliHLTStdIncludes.h" | |
29 | #include "AliHLTComponent.h" | |
30 | #include "AliHLTComponentHandler.h" | |
31 | #include "AliHLTSystem.h" | |
32 | ||
33 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
34 | ClassImp(AliHLTComponent) | |
35 | ||
36 | AliHLTComponent::AliHLTComponent() | |
37 | : | |
38 | fEnvironment(), | |
39 | fCurrentEvent(0) | |
40 | { | |
41 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); | |
42 | if (fpComponentHandler) | |
43 | fpComponentHandler->ScheduleRegister(this); | |
44 | } | |
45 | ||
46 | AliHLTComponent::~AliHLTComponent() | |
47 | { | |
48 | } | |
49 | ||
50 | AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL; | |
51 | ||
52 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) | |
53 | { | |
54 | int iResult=0; | |
55 | if (fpComponentHandler==NULL || bOverwrite!=0) | |
56 | fpComponentHandler=pCH; | |
57 | else | |
58 | iResult=-EPERM; | |
59 | return iResult; | |
60 | } | |
61 | ||
62 | int AliHLTComponent::UnsetGlobalComponentHandler() { | |
63 | return SetGlobalComponentHandler(NULL,1); | |
64 | } | |
65 | ||
66 | int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv ) | |
67 | { | |
68 | int iResult=0; | |
69 | if (environ) { | |
70 | memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment)); | |
71 | fEnvironment.fParam=environ_param; | |
72 | } | |
73 | iResult=DoInit(argc, argv); | |
74 | return iResult; | |
75 | } | |
76 | ||
77 | int AliHLTComponent::Deinit() | |
78 | { | |
79 | int iResult=0; | |
80 | iResult=DoDeinit(); | |
81 | return iResult; | |
82 | } | |
83 | ||
84 | int AliHLTComponent::DoInit( int argc, const char** argv ) | |
85 | { | |
86 | if (argc==0 && argv==NULL) { | |
87 | // this is currently just to get rid of the warning "unused parameter" | |
88 | } | |
89 | return 0; | |
90 | } | |
91 | ||
92 | int AliHLTComponent::DoDeinit() | |
93 | { | |
94 | return 0; | |
95 | } | |
96 | ||
97 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[14] ) { | |
98 | memset( output, 0, 14 ); | |
99 | strncat( output, type.fOrigin, 4 ); | |
100 | strcat( output, ":" ); | |
101 | strncat( output, type.fID, 8 ); | |
102 | } | |
103 | ||
104 | void* AliHLTComponent::AllocMemory( unsigned long size ) { | |
105 | if (fEnvironment.fAllocMemoryFunc) | |
106 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
107 | return NULL; | |
108 | } | |
109 | ||
110 | int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount, | |
111 | AliHLTComponentBlockData** outputBlocks ) { | |
112 | if ( !blockCount || !outputBlocks ) | |
113 | return EFAULT; | |
114 | AliHLTUInt32_t count = blocks.size(); | |
115 | if ( !count ) | |
116 | { | |
117 | *blockCount = 0; | |
118 | *outputBlocks = NULL; | |
119 | return 0; | |
120 | } | |
121 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); | |
122 | if ( !*outputBlocks ) | |
123 | return ENOMEM; | |
124 | for ( unsigned long i = 0; i < count; i++ ) | |
125 | (*outputBlocks)[i] = blocks[i]; | |
126 | *blockCount = count; | |
127 | return 0; | |
128 | ||
129 | } | |
130 | ||
131 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) { | |
132 | if (fEnvironment.fGetEventDoneDataFunc) | |
133 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
134 | return -ENOSYS; | |
135 | } | |
136 | ||
137 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) | |
138 | { | |
139 | int iResult=0; | |
140 | if (pConsumer) { | |
141 | vector<AliHLTComponentDataType> ctlist; | |
142 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist); | |
143 | vector<AliHLTComponentDataType>::iterator type=ctlist.begin(); | |
144 | while (type!=ctlist.end() && iResult==0) { | |
145 | if ((*type)==GetOutputDataType()) { | |
146 | if (tgtList) tgtList->push_back(*type); | |
147 | iResult++; | |
148 | break; | |
149 | } | |
150 | type++; | |
151 | } | |
152 | } else { | |
153 | iResult=-EINVAL; | |
154 | } | |
155 | return iResult; | |
156 | } |