]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModuleAgent.cxx
Minor cleanup of code.
[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 AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc;
53
54 AliHLTModuleAgent::~AliHLTModuleAgent()
55 {
56   // see header file for function documentation
57   Unregister(this);
58 }
59
60 const char* AliHLTModuleAgent::GetModuleId() const
61 {
62   // see header file for function documentation
63   return fModuleId.Data();
64 }
65
66 void AliHLTModuleAgent::PrintStatus(const char* agent)
67 {
68   // see header file for function documentation
69   AliHLTLogging log;
70  if (agent) {
71    AliHLTModuleAgent* pCurrent=fgAnchor;
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    }
80   } else {
81    AliHLTModuleAgent* pCurrent=fgAnchor;
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", "", "-----------------------");
93   }
94 }
95
96 int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
97                                             AliRawReader* /*rawReader*/,
98                                             AliRunLoader* /*runloader*/) const
99 {
100   // default method, nothing to be done, child classes can overload
101   return 0;
102 }
103
104 const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
105                                                        AliRunLoader* /*runloader*/) const
106 {
107   // default method, nothing to be done, child classes can overload
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
117 int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/,
118                                              AliHLTUInt32_t /*spec*/,
119                                              AliHLTOUTHandlerDesc& /*desc*/) const
120 {
121   // default method, nothing to be done, child classes can overload
122   return 0;
123 }
124
125 AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/,
126                                                       AliHLTUInt32_t /*spec*/)
127 {
128   // default method, nothing to be done, child classes can overload
129   return NULL;
130 }
131
132 int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
133 {
134   // default method, simply deletes object
135   if (pInstance) return -EINVAL;
136   delete pInstance;
137   return 0;
138 }
139
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
150 int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
151 {
152   // see header file for function documentation
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
176 {
177   // default method, nothing to be done, child classes can overload
178   return 0;
179 }
180
181 AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor()
182 {
183   // default method, nothing to be done, child classes can overload
184   return NULL;
185 }
186
187 AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL;
188 AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL;
189 int AliHLTModuleAgent::fgCount=0;
190
191 AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
192 {
193   // see header file for function documentation
194   fgCurrent=fgAnchor;
195   return fgAnchor;
196 }
197
198 AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
199 {
200   // see header file for function documentation
201   if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext;
202   return fgCurrent;
203 }
204
205 int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
206 {
207   // see header file for function documentation
208   AliHLTLogging log;
209   if (!pAgent) return -EINVAL;
210   if (fgAnchor==NULL) {
211     fgAnchor=pAgent;
212   } else {
213     pAgent->fpNext=fgAnchor;
214     fgAnchor=pAgent;
215   }
216   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
217   fgCount++;
218   return 0;     
219 }
220
221 int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
222 {
223   // see header file for function documentation
224   AliHLTLogging log;
225   if (!pAgent) return -EINVAL;
226   fgCurrent=NULL;
227   AliHLTModuleAgent* prev=NULL;
228   AliHLTModuleAgent* handler=fgAnchor;
229   while (handler!=NULL && handler!=pAgent) {
230     prev=handler;
231     handler=handler->fpNext;
232   }
233   if (handler) {
234     if (prev==NULL) {
235       fgAnchor=handler->fpNext;
236     } else {
237       prev->fpNext=handler->fpNext;
238     }
239     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
240     fgCount--;
241   }
242   return 0;
243 }