]>
Commit | Line | Data |
---|---|---|
75dd2de6 | 1 | // $Id$ |
242bb794 | 2 | |
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
242bb794 | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * | |
242bb794 | 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 AliHLTModuleAgent.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Agent helper class for component libraries. | |
23 | @note The class is used in Offline (AliRoot) context | |
24 | */ | |
25 | ||
13398559 | 26 | // see header file for class documentation |
27 | // or | |
28 | // refer to README to build package | |
29 | // or | |
30 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
31 | ||
242bb794 | 32 | #include "AliHLTModuleAgent.h" |
164de2ba | 33 | #include "AliHLTOUTHandler.h" |
242bb794 | 34 | |
35 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
36 | ClassImp(AliHLTModuleAgent) | |
37 | ||
626bfcc1 | 38 | AliHLTModuleAgent::AliHLTModuleAgent(const char* id) |
79c114b5 | 39 | : |
f3506ea2 | 40 | fpNext(NULL), |
626bfcc1 | 41 | fpComponentHandler(NULL), |
42 | fModuleId(id) | |
242bb794 | 43 | { |
44 | // see header file for class documentation | |
45 | // or | |
46 | // refer to README to build package | |
47 | // or | |
48 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
49 | Register(this); | |
50 | } | |
51 | ||
80df291c | 52 | const char* AliHLTModuleAgent::GetQAPlugins() const |
53 | { | |
54 | // default implementation, childs can overload | |
55 | return ""; | |
56 | } | |
57 | ||
c5123824 | 58 | const AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc; |
59 | ||
242bb794 | 60 | AliHLTModuleAgent::~AliHLTModuleAgent() |
61 | { | |
62 | // see header file for function documentation | |
63 | Unregister(this); | |
64 | } | |
65 | ||
626bfcc1 | 66 | const char* AliHLTModuleAgent::GetModuleId() const |
67 | { | |
68 | // see header file for function documentation | |
69 | return fModuleId.Data(); | |
70 | } | |
71 | ||
242bb794 | 72 | void AliHLTModuleAgent::PrintStatus(const char* agent) |
73 | { | |
74 | // see header file for function documentation | |
75 | AliHLTLogging log; | |
7617ca1e | 76 | if (agent) { |
13398559 | 77 | AliHLTModuleAgent* pCurrent=fgAnchor; |
7617ca1e | 78 | while (pCurrent!=NULL && strcmp(pCurrent->GetName(), agent)!=0) pCurrent=pCurrent->fpNext; |
79 | if (pCurrent) { | |
80 | log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", | |
81 | "agent %s available", pCurrent->GetName()); | |
82 | } else { | |
83 | log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", | |
84 | "agent %s not found", agent); | |
85 | } | |
242bb794 | 86 | } else { |
13398559 | 87 | AliHLTModuleAgent* pCurrent=fgAnchor; |
7617ca1e | 88 | log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------"); |
89 | log.Logging(kHLTLogInfo, "AliHLT", "", "available module agents"); | |
90 | if (pCurrent==NULL) | |
91 | log.Logging(kHLTLogInfo, "AliHLT", "", " none"); | |
92 | while (pCurrent) { | |
93 | TString msg; | |
94 | msg.Form(" %s : %p", pCurrent->GetName(), pCurrent); | |
95 | log.Logging(kHLTLogInfo, "AliHLT", "", msg.Data()); | |
96 | pCurrent=pCurrent->fpNext; | |
97 | } | |
98 | log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------"); | |
242bb794 | 99 | } |
100 | } | |
101 | ||
b0692a71 | 102 | UInt_t AliHLTModuleAgent::GetDetectorMask() const |
103 | { | |
104 | /* all detectors */ | |
105 | return (UInt_t)(-1); | |
106 | } | |
107 | ||
04a939f7 | 108 | int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/, |
dee38f1b | 109 | AliRawReader* /*rawReader*/, |
04a939f7 | 110 | AliRunLoader* /*runloader*/) const |
242bb794 | 111 | { |
112 | // default method, nothing to be done, child classes can overload | |
242bb794 | 113 | return 0; |
114 | } | |
115 | ||
dee38f1b | 116 | const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/, |
117 | AliRunLoader* /*runloader*/) const | |
242bb794 | 118 | { |
119 | // default method, nothing to be done, child classes can overload | |
242bb794 | 120 | return NULL; |
121 | } | |
122 | ||
123 | const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const | |
124 | { | |
125 | // default method, nothing to be done, child classes can overload | |
126 | return NULL; | |
127 | } | |
128 | ||
62bb3cd4 | 129 | int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/, |
130 | AliHLTUInt32_t /*spec*/, | |
626bfcc1 | 131 | AliHLTOUTHandlerDesc& /*desc*/) const |
62bb3cd4 | 132 | { |
133 | // default method, nothing to be done, child classes can overload | |
134 | return 0; | |
135 | } | |
136 | ||
137 | AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/, | |
164de2ba | 138 | AliHLTUInt32_t /*spec*/) |
62bb3cd4 | 139 | { |
140 | // default method, nothing to be done, child classes can overload | |
141 | return NULL; | |
142 | } | |
143 | ||
164de2ba | 144 | int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance) |
62bb3cd4 | 145 | { |
164de2ba | 146 | // default method, simply deletes object |
75dd2de6 | 147 | if (!pInstance) return -EINVAL; |
148 | HLTWarning("potential memory leak due to missing implementation, agent %s must implement function DeleteOutputHandler", GetModuleId()); | |
149 | return -ENOSYS; | |
62bb3cd4 | 150 | } |
151 | ||
164de2ba | 152 | // likely to be moved to AliHLTOUTHandler |
153 | // AliRawStream* AliHLTModuleAgent::GetRawStream(AliHLTComponentDataType /*dt*/, | |
154 | // AliHLTUInt32_t /*spec*/, | |
155 | // const AliHLTOUT* /*pData*/) const | |
156 | // { | |
157 | // // default method, nothing to be done, child classes can overload | |
158 | // return NULL; | |
159 | // } | |
160 | ||
f3506ea2 | 161 | int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler) |
162 | { | |
13398559 | 163 | // see header file for function documentation |
f3506ea2 | 164 | int iResult=0; |
165 | if (pHandler==NULL) { | |
166 | if (fpComponentHandler!=NULL) { | |
167 | // reset and think about deregistration | |
168 | fpComponentHandler=NULL; | |
169 | HLTWarning("deregistration of components not yet implemented"); | |
170 | } | |
171 | return 0; | |
172 | } | |
173 | if (fpComponentHandler!=NULL) { | |
174 | if (pHandler!=fpComponentHandler) { | |
175 | HLTError("only one component handler can be activated per agent"); | |
176 | return -EINVAL; | |
177 | } | |
178 | return 0; | |
179 | } | |
180 | if ((iResult=RegisterComponents(pHandler))>=0) { | |
181 | fpComponentHandler=pHandler; | |
182 | } | |
183 | return iResult; | |
184 | } | |
185 | ||
186 | int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const | |
242bb794 | 187 | { |
242bb794 | 188 | // default method, nothing to be done, child classes can overload |
189 | return 0; | |
190 | } | |
191 | ||
12ec5482 | 192 | AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor() |
193 | { | |
194 | // default method, nothing to be done, child classes can overload | |
195 | return NULL; | |
196 | } | |
197 | ||
13398559 | 198 | AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL; |
199 | AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL; | |
200 | int AliHLTModuleAgent::fgCount=0; | |
7617ca1e | 201 | |
242bb794 | 202 | AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent() |
203 | { | |
204 | // see header file for function documentation | |
13398559 | 205 | fgCurrent=fgAnchor; |
206 | return fgAnchor; | |
242bb794 | 207 | } |
208 | ||
209 | AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent() | |
210 | { | |
211 | // see header file for function documentation | |
13398559 | 212 | if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext; |
213 | return fgCurrent; | |
242bb794 | 214 | } |
215 | ||
7dbfa7c9 | 216 | string AliHLTModuleAgent::GetAgentIds() |
217 | { | |
218 | // see header file for function documentation | |
219 | string ids; | |
220 | ids.clear(); | |
221 | for (AliHLTModuleAgent* pCurrent=fgAnchor; | |
222 | pCurrent; | |
223 | pCurrent=pCurrent->fpNext) { | |
224 | if (ids.size()>0) ids+=" "; | |
225 | ids+=pCurrent->GetModuleId(); | |
226 | } | |
227 | ||
228 | return ids; | |
229 | } | |
230 | ||
242bb794 | 231 | int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent) |
232 | { | |
233 | // see header file for function documentation | |
234 | AliHLTLogging log; | |
235 | if (!pAgent) return -EINVAL; | |
555bbe8c | 236 | // The following check is for extra protection. In some strange cases the agent might |
237 | // try to register itself more than once. So we need to check for that and prevent it. | |
238 | // Otherwise we create a cycle in our linked list and go into an infinite loop. | |
239 | AliHLTModuleAgent* current=fgAnchor; | |
240 | while (current!=NULL) { | |
241 | if (current == pAgent) return 0; | |
242 | current = current->fpNext; | |
243 | } | |
13398559 | 244 | if (fgAnchor==NULL) { |
245 | fgAnchor=pAgent; | |
7617ca1e | 246 | } else { |
13398559 | 247 | pAgent->fpNext=fgAnchor; |
248 | fgAnchor=pAgent; | |
242bb794 | 249 | } |
7617ca1e | 250 | // log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent); |
13398559 | 251 | fgCount++; |
7617ca1e | 252 | return 0; |
242bb794 | 253 | } |
254 | ||
255 | int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent) | |
256 | { | |
257 | // see header file for function documentation | |
258 | AliHLTLogging log; | |
259 | if (!pAgent) return -EINVAL; | |
13398559 | 260 | fgCurrent=NULL; |
7617ca1e | 261 | AliHLTModuleAgent* prev=NULL; |
13398559 | 262 | AliHLTModuleAgent* handler=fgAnchor; |
7617ca1e | 263 | while (handler!=NULL && handler!=pAgent) { |
264 | prev=handler; | |
265 | handler=handler->fpNext; | |
266 | } | |
267 | if (handler) { | |
268 | if (prev==NULL) { | |
13398559 | 269 | fgAnchor=handler->fpNext; |
7617ca1e | 270 | } else { |
271 | prev->fpNext=handler->fpNext; | |
272 | } | |
80e562fa | 273 | //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent); |
13398559 | 274 | fgCount--; |
242bb794 | 275 | } |
276 | return 0; | |
277 | } |