]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModuleAgent.cxx
HLTcalo module
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTModuleAgent.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  *                  for The ALICE HLT 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   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
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
32 #include "AliHLTModuleAgent.h"
33 #include "AliHLTOUTHandler.h"
34
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTModuleAgent)
37
38 AliHLTModuleAgent::AliHLTModuleAgent(const char* id)
39   :
40   fpNext(NULL),
41   fpComponentHandler(NULL),
42   fModuleId(id)
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
52 const char* AliHLTModuleAgent::GetQAPlugins() const
53 {
54   // default implementation, childs can overload
55   return "";
56 }
57
58 const AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc;
59
60 AliHLTModuleAgent::~AliHLTModuleAgent()
61 {
62   // see header file for function documentation
63   Unregister(this);
64 }
65
66 const char* AliHLTModuleAgent::GetModuleId() const
67 {
68   // see header file for function documentation
69   return fModuleId.Data();
70 }
71
72 void AliHLTModuleAgent::PrintStatus(const char* agent)
73 {
74   // see header file for function documentation
75   AliHLTLogging log;
76  if (agent) {
77    AliHLTModuleAgent* pCurrent=fgAnchor;
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    }
86   } else {
87    AliHLTModuleAgent* pCurrent=fgAnchor;
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", "", "-----------------------");
99   }
100 }
101
102 UInt_t AliHLTModuleAgent::GetDetectorMask() const
103 {
104   /* all detectors */
105   return (UInt_t)(-1);
106 }
107
108 int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
109                                             AliRawReader* /*rawReader*/,
110                                             AliRunLoader* /*runloader*/) const
111 {
112   // default method, nothing to be done, child classes can overload
113   return 0;
114 }
115
116 const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
117                                                        AliRunLoader* /*runloader*/) const
118 {
119   // default method, nothing to be done, child classes can overload
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
129 int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/,
130                                              AliHLTUInt32_t /*spec*/,
131                                              AliHLTOUTHandlerDesc& /*desc*/) const
132 {
133   // default method, nothing to be done, child classes can overload
134   return 0;
135 }
136
137 AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/,
138                                                       AliHLTUInt32_t /*spec*/)
139 {
140   // default method, nothing to be done, child classes can overload
141   return NULL;
142 }
143
144 int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
145 {
146   // default method, simply deletes object
147   if (!pInstance) return -EINVAL;
148   HLTWarning("potential memory leak due to missing implementation, agent %s must implement function DeleteOutputHandler", GetModuleId());
149   return -ENOSYS;
150 }
151
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
161 int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
162 {
163   // see header file for function documentation
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
187 {
188   // default method, nothing to be done, child classes can overload
189   return 0;
190 }
191
192 AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor()
193 {
194   // default method, nothing to be done, child classes can overload
195   return NULL;
196 }
197
198 AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL;
199 AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL;
200 int AliHLTModuleAgent::fgCount=0;
201
202 AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
203 {
204   // see header file for function documentation
205   fgCurrent=fgAnchor;
206   return fgAnchor;
207 }
208
209 AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
210 {
211   // see header file for function documentation
212   if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext;
213   return fgCurrent;
214 }
215
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
231 int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
232 {
233   // see header file for function documentation
234   AliHLTLogging log;
235   if (!pAgent) return -EINVAL;
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   }
244   if (fgAnchor==NULL) {
245     fgAnchor=pAgent;
246   } else {
247     pAgent->fpNext=fgAnchor;
248     fgAnchor=pAgent;
249   }
250   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
251   fgCount++;
252   return 0;     
253 }
254
255 int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
256 {
257   // see header file for function documentation
258   AliHLTLogging log;
259   if (!pAgent) return -EINVAL;
260   fgCurrent=NULL;
261   AliHLTModuleAgent* prev=NULL;
262   AliHLTModuleAgent* handler=fgAnchor;
263   while (handler!=NULL && handler!=pAgent) {
264     prev=handler;
265     handler=handler->fpNext;
266   }
267   if (handler) {
268     if (prev==NULL) {
269       fgAnchor=handler->fpNext;
270     } else {
271       prev->fpNext=handler->fpNext;
272     }
273     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
274     fgCount--;
275   }
276   return 0;
277 }