]>
Commit | Line | Data |
---|---|---|
242bb794 | 1 | // @(#) $Id$ |
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 | ||
c5123824 | 52 | const AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc; |
53 | ||
242bb794 | 54 | AliHLTModuleAgent::~AliHLTModuleAgent() |
55 | { | |
56 | // see header file for function documentation | |
57 | Unregister(this); | |
58 | } | |
59 | ||
626bfcc1 | 60 | const char* AliHLTModuleAgent::GetModuleId() const |
61 | { | |
62 | // see header file for function documentation | |
63 | return fModuleId.Data(); | |
64 | } | |
65 | ||
242bb794 | 66 | void AliHLTModuleAgent::PrintStatus(const char* agent) |
67 | { | |
68 | // see header file for function documentation | |
69 | AliHLTLogging log; | |
7617ca1e | 70 | if (agent) { |
13398559 | 71 | AliHLTModuleAgent* pCurrent=fgAnchor; |
7617ca1e | 72 | while (pCurrent!=NULL && strcmp(pCurrent->GetName(), agent)!=0) pCurrent=pCurrent->fpNext; |
73 | if (pCurrent) { | |
74 | log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", | |
75 | "agent %s available", pCurrent->GetName()); | |
76 | } else { | |
77 | log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", | |
78 | "agent %s not found", agent); | |
79 | } | |
242bb794 | 80 | } else { |
13398559 | 81 | AliHLTModuleAgent* pCurrent=fgAnchor; |
7617ca1e | 82 | log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------"); |
83 | log.Logging(kHLTLogInfo, "AliHLT", "", "available module agents"); | |
84 | if (pCurrent==NULL) | |
85 | log.Logging(kHLTLogInfo, "AliHLT", "", " none"); | |
86 | while (pCurrent) { | |
87 | TString msg; | |
88 | msg.Form(" %s : %p", pCurrent->GetName(), pCurrent); | |
89 | log.Logging(kHLTLogInfo, "AliHLT", "", msg.Data()); | |
90 | pCurrent=pCurrent->fpNext; | |
91 | } | |
92 | log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------"); | |
242bb794 | 93 | } |
94 | } | |
95 | ||
04a939f7 | 96 | int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/, |
dee38f1b | 97 | AliRawReader* /*rawReader*/, |
04a939f7 | 98 | AliRunLoader* /*runloader*/) const |
242bb794 | 99 | { |
100 | // default method, nothing to be done, child classes can overload | |
242bb794 | 101 | return 0; |
102 | } | |
103 | ||
dee38f1b | 104 | const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/, |
105 | AliRunLoader* /*runloader*/) const | |
242bb794 | 106 | { |
107 | // default method, nothing to be done, child classes can overload | |
242bb794 | 108 | return NULL; |
109 | } | |
110 | ||
111 | const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const | |
112 | { | |
113 | // default method, nothing to be done, child classes can overload | |
114 | return NULL; | |
115 | } | |
116 | ||
62bb3cd4 | 117 | int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/, |
118 | AliHLTUInt32_t /*spec*/, | |
626bfcc1 | 119 | AliHLTOUTHandlerDesc& /*desc*/) const |
62bb3cd4 | 120 | { |
121 | // default method, nothing to be done, child classes can overload | |
122 | return 0; | |
123 | } | |
124 | ||
125 | AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/, | |
164de2ba | 126 | AliHLTUInt32_t /*spec*/) |
62bb3cd4 | 127 | { |
128 | // default method, nothing to be done, child classes can overload | |
129 | return NULL; | |
130 | } | |
131 | ||
164de2ba | 132 | int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance) |
62bb3cd4 | 133 | { |
164de2ba | 134 | // default method, simply deletes object |
135 | if (pInstance) return -EINVAL; | |
136 | delete pInstance; | |
137 | return 0; | |
62bb3cd4 | 138 | } |
139 | ||
164de2ba | 140 | |
141 | // likely to be moved to AliHLTOUTHandler | |
142 | // AliRawStream* AliHLTModuleAgent::GetRawStream(AliHLTComponentDataType /*dt*/, | |
143 | // AliHLTUInt32_t /*spec*/, | |
144 | // const AliHLTOUT* /*pData*/) const | |
145 | // { | |
146 | // // default method, nothing to be done, child classes can overload | |
147 | // return NULL; | |
148 | // } | |
149 | ||
f3506ea2 | 150 | int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler) |
151 | { | |
13398559 | 152 | // see header file for function documentation |
f3506ea2 | 153 | int iResult=0; |
154 | if (pHandler==NULL) { | |
155 | if (fpComponentHandler!=NULL) { | |
156 | // reset and think about deregistration | |
157 | fpComponentHandler=NULL; | |
158 | HLTWarning("deregistration of components not yet implemented"); | |
159 | } | |
160 | return 0; | |
161 | } | |
162 | if (fpComponentHandler!=NULL) { | |
163 | if (pHandler!=fpComponentHandler) { | |
164 | HLTError("only one component handler can be activated per agent"); | |
165 | return -EINVAL; | |
166 | } | |
167 | return 0; | |
168 | } | |
169 | if ((iResult=RegisterComponents(pHandler))>=0) { | |
170 | fpComponentHandler=pHandler; | |
171 | } | |
172 | return iResult; | |
173 | } | |
174 | ||
175 | int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const | |
242bb794 | 176 | { |
242bb794 | 177 | // default method, nothing to be done, child classes can overload |
178 | return 0; | |
179 | } | |
180 | ||
12ec5482 | 181 | AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor() |
182 | { | |
183 | // default method, nothing to be done, child classes can overload | |
184 | return NULL; | |
185 | } | |
186 | ||
13398559 | 187 | AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL; |
188 | AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL; | |
189 | int AliHLTModuleAgent::fgCount=0; | |
7617ca1e | 190 | |
242bb794 | 191 | AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent() |
192 | { | |
193 | // see header file for function documentation | |
13398559 | 194 | fgCurrent=fgAnchor; |
195 | return fgAnchor; | |
242bb794 | 196 | } |
197 | ||
198 | AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent() | |
199 | { | |
200 | // see header file for function documentation | |
13398559 | 201 | if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext; |
202 | return fgCurrent; | |
242bb794 | 203 | } |
204 | ||
205 | int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent) | |
206 | { | |
207 | // see header file for function documentation | |
208 | AliHLTLogging log; | |
209 | if (!pAgent) return -EINVAL; | |
555bbe8c | 210 | // The following check is for extra protection. In some strange cases the agent might |
211 | // try to register itself more than once. So we need to check for that and prevent it. | |
212 | // Otherwise we create a cycle in our linked list and go into an infinite loop. | |
213 | AliHLTModuleAgent* current=fgAnchor; | |
214 | while (current!=NULL) { | |
215 | if (current == pAgent) return 0; | |
216 | current = current->fpNext; | |
217 | } | |
13398559 | 218 | if (fgAnchor==NULL) { |
219 | fgAnchor=pAgent; | |
7617ca1e | 220 | } else { |
13398559 | 221 | pAgent->fpNext=fgAnchor; |
222 | fgAnchor=pAgent; | |
242bb794 | 223 | } |
7617ca1e | 224 | // log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent); |
13398559 | 225 | fgCount++; |
7617ca1e | 226 | return 0; |
242bb794 | 227 | } |
228 | ||
229 | int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent) | |
230 | { | |
231 | // see header file for function documentation | |
232 | AliHLTLogging log; | |
233 | if (!pAgent) return -EINVAL; | |
13398559 | 234 | fgCurrent=NULL; |
7617ca1e | 235 | AliHLTModuleAgent* prev=NULL; |
13398559 | 236 | AliHLTModuleAgent* handler=fgAnchor; |
7617ca1e | 237 | while (handler!=NULL && handler!=pAgent) { |
238 | prev=handler; | |
239 | handler=handler->fpNext; | |
240 | } | |
241 | if (handler) { | |
242 | if (prev==NULL) { | |
13398559 | 243 | fgAnchor=handler->fpNext; |
7617ca1e | 244 | } else { |
245 | prev->fpNext=handler->fpNext; | |
246 | } | |
80e562fa | 247 | //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent); |
13398559 | 248 | fgCount--; |
242bb794 | 249 | } |
250 | return 0; | |
251 | } |