]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModuleAgent.cxx
Removed depricted histograms ... cleanup
[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 int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
103                                             AliRawReader* /*rawReader*/,
104                                             AliRunLoader* /*runloader*/) const
105 {
106   // default method, nothing to be done, child classes can overload
107   return 0;
108 }
109
110 const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
111                                                        AliRunLoader* /*runloader*/) const
112 {
113   // default method, nothing to be done, child classes can overload
114   return NULL;
115 }
116
117 const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
118 {
119   // default method, nothing to be done, child classes can overload
120   return NULL;
121 }
122
123 int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/,
124                                              AliHLTUInt32_t /*spec*/,
125                                              AliHLTOUTHandlerDesc& /*desc*/) const
126 {
127   // default method, nothing to be done, child classes can overload
128   return 0;
129 }
130
131 AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/,
132                                                       AliHLTUInt32_t /*spec*/)
133 {
134   // default method, nothing to be done, child classes can overload
135   return NULL;
136 }
137
138 int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
139 {
140   // default method, simply deletes object
141   if (!pInstance) return -EINVAL;
142   HLTWarning("potential memory leak due to missing implementation, agent %s must implement function DeleteOutputHandler", GetModuleId());
143   return -ENOSYS;
144 }
145
146 // likely to be moved to AliHLTOUTHandler
147 // AliRawStream* AliHLTModuleAgent::GetRawStream(AliHLTComponentDataType /*dt*/,
148 //                                            AliHLTUInt32_t /*spec*/,
149 //                                            const AliHLTOUT* /*pData*/) const
150 // {
151 //   // default method, nothing to be done, child classes can overload
152 //   return NULL;
153 // }
154
155 int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
156 {
157   // see header file for function documentation
158   int iResult=0;
159   if (pHandler==NULL) {
160     if (fpComponentHandler!=NULL) {
161       // reset and think about deregistration
162       fpComponentHandler=NULL;
163       HLTWarning("deregistration of components not yet implemented");
164     }
165     return 0;
166   }
167   if (fpComponentHandler!=NULL) {
168     if (pHandler!=fpComponentHandler) {
169       HLTError("only one component handler can be activated per agent");
170       return -EINVAL;
171     }
172     return 0;
173   }
174   if ((iResult=RegisterComponents(pHandler))>=0) {
175     fpComponentHandler=pHandler;
176   }
177   return iResult;
178 }
179
180 int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
181 {
182   // default method, nothing to be done, child classes can overload
183   return 0;
184 }
185
186 AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor()
187 {
188   // default method, nothing to be done, child classes can overload
189   return NULL;
190 }
191
192 AliHLTModuleAgent* AliHLTModuleAgent::fgAnchor=NULL;
193 AliHLTModuleAgent* AliHLTModuleAgent::fgCurrent=NULL;
194 int AliHLTModuleAgent::fgCount=0;
195
196 AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
197 {
198   // see header file for function documentation
199   fgCurrent=fgAnchor;
200   return fgAnchor;
201 }
202
203 AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
204 {
205   // see header file for function documentation
206   if (fgCurrent!=NULL) fgCurrent=fgCurrent->fpNext;
207   return fgCurrent;
208 }
209
210 string AliHLTModuleAgent::GetAgentIds()
211 {
212   // see header file for function documentation
213   string ids;
214   ids.clear();
215   for (AliHLTModuleAgent* pCurrent=fgAnchor;
216        pCurrent;
217        pCurrent=pCurrent->fpNext) {
218     if (ids.size()>0) ids+=" ";
219     ids+=pCurrent->GetModuleId();
220   }
221
222   return ids;
223 }
224
225 int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
226 {
227   // see header file for function documentation
228   AliHLTLogging log;
229   if (!pAgent) return -EINVAL;
230   // The following check is for extra protection. In some strange cases the agent might
231   // try to register itself more than once. So we need to check for that and prevent it.
232   // Otherwise we create a cycle in our linked list and go into an infinite loop.
233   AliHLTModuleAgent* current=fgAnchor;
234   while (current!=NULL) {
235     if (current == pAgent) return 0;
236     current = current->fpNext;
237   }
238   if (fgAnchor==NULL) {
239     fgAnchor=pAgent;
240   } else {
241     pAgent->fpNext=fgAnchor;
242     fgAnchor=pAgent;
243   }
244   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
245   fgCount++;
246   return 0;     
247 }
248
249 int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
250 {
251   // see header file for function documentation
252   AliHLTLogging log;
253   if (!pAgent) return -EINVAL;
254   fgCurrent=NULL;
255   AliHLTModuleAgent* prev=NULL;
256   AliHLTModuleAgent* handler=fgAnchor;
257   while (handler!=NULL && handler!=pAgent) {
258     prev=handler;
259     handler=handler->fpNext;
260   }
261   if (handler) {
262     if (prev==NULL) {
263       fgAnchor=handler->fpNext;
264     } else {
265       prev->fpNext=handler->fpNext;
266     }
267     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
268     fgCount--;
269   }
270   return 0;
271 }