]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModuleAgent.cxx
bugfix: added missing function AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex
[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 #include "AliHLTModuleAgent.h"
27 #include "AliHLTOUTHandler.h"
28
29 /** ROOT macro for the implementation of ROOT specific class methods */
30 ClassImp(AliHLTModuleAgent)
31
32 AliHLTModuleAgent::AliHLTModuleAgent(const char* id)
33   :
34   fpNext(NULL),
35   fpComponentHandler(NULL),
36   fModuleId(id)
37 {
38   // see header file for class documentation
39   // or
40   // refer to README to build package
41   // or
42   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43   Register(this);
44 }
45
46 AliHLTModuleAgent::~AliHLTModuleAgent()
47 {
48   // see header file for function documentation
49   Unregister(this);
50 }
51
52 const char* AliHLTModuleAgent::GetModuleId() const
53 {
54   // see header file for function documentation
55   return fModuleId.Data();
56 }
57
58 void AliHLTModuleAgent::PrintStatus(const char* agent)
59 {
60   // see header file for function documentation
61   AliHLTLogging log;
62  if (agent) {
63    AliHLTModuleAgent* pCurrent=fAnchor;
64    while (pCurrent!=NULL && strcmp(pCurrent->GetName(), agent)!=0) pCurrent=pCurrent->fpNext;
65    if (pCurrent) {
66      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
67                  "agent %s available", pCurrent->GetName());
68    } else {
69      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
70                  "agent %s not found", agent);
71    }
72   } else {
73    AliHLTModuleAgent* pCurrent=fAnchor;
74    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
75    log.Logging(kHLTLogInfo, "AliHLT", "", "available module agents");
76    if (pCurrent==NULL)
77      log.Logging(kHLTLogInfo, "AliHLT", "", "   none");
78    while (pCurrent) {
79      TString msg;
80      msg.Form("   %s : %p", pCurrent->GetName(), pCurrent);
81      log.Logging(kHLTLogInfo, "AliHLT", "", msg.Data());
82      pCurrent=pCurrent->fpNext;
83    }
84    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
85   }
86 }
87
88 int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
89                                             AliRawReader* /*rawReader*/,
90                                             AliRunLoader* /*runloader*/) const
91 {
92   // default method, nothing to be done, child classes can overload
93   return 0;
94 }
95
96 const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
97                                                        AliRunLoader* /*runloader*/) const
98 {
99   // default method, nothing to be done, child classes can overload
100   return NULL;
101 }
102
103 const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
104 {
105   // default method, nothing to be done, child classes can overload
106   return NULL;
107 }
108
109 int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType /*dt*/,
110                                              AliHLTUInt32_t /*spec*/,
111                                              AliHLTOUTHandlerDesc& /*desc*/) const
112 {
113   // default method, nothing to be done, child classes can overload
114   return 0;
115 }
116
117 AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType /*dt*/,
118                                                       AliHLTUInt32_t /*spec*/)
119 {
120   // default method, nothing to be done, child classes can overload
121   return NULL;
122 }
123
124 int AliHLTModuleAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
125 {
126   // default method, simply deletes object
127   if (pInstance) return -EINVAL;
128   delete pInstance;
129   return 0;
130 }
131
132
133 // likely to be moved to AliHLTOUTHandler
134 // AliRawStream* AliHLTModuleAgent::GetRawStream(AliHLTComponentDataType /*dt*/,
135 //                                            AliHLTUInt32_t /*spec*/,
136 //                                            const AliHLTOUT* /*pData*/) const
137 // {
138 //   // default method, nothing to be done, child classes can overload
139 //   return NULL;
140 // }
141
142 int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
143 {
144   int iResult=0;
145   if (pHandler==NULL) {
146     if (fpComponentHandler!=NULL) {
147       // reset and think about deregistration
148       fpComponentHandler=NULL;
149       HLTWarning("deregistration of components not yet implemented");
150     }
151     return 0;
152   }
153   if (fpComponentHandler!=NULL) {
154     if (pHandler!=fpComponentHandler) {
155       HLTError("only one component handler can be activated per agent");
156       return -EINVAL;
157     }
158     return 0;
159   }
160   if ((iResult=RegisterComponents(pHandler))>=0) {
161     fpComponentHandler=pHandler;
162   }
163   return iResult;
164 }
165
166 int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
167 {
168   // default method, nothing to be done, child classes can overload
169   return 0;
170 }
171
172 AliHLTModulePreprocessor* AliHLTModuleAgent::GetPreprocessor()
173 {
174   // default method, nothing to be done, child classes can overload
175   return NULL;
176 }
177
178 AliHLTModuleAgent* AliHLTModuleAgent::fAnchor=NULL;
179 AliHLTModuleAgent* AliHLTModuleAgent::fCurrent=NULL;
180 int AliHLTModuleAgent::fCount=0;
181
182 AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
183 {
184   // see header file for function documentation
185   fCurrent=fAnchor;
186   return fAnchor;
187 }
188
189 AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
190 {
191   // see header file for function documentation
192   if (fCurrent!=NULL) fCurrent=fCurrent->fpNext;
193   return fCurrent;
194 }
195
196 int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
197 {
198   // see header file for function documentation
199   AliHLTLogging log;
200   if (!pAgent) return -EINVAL;
201   if (fAnchor==NULL) {
202     fAnchor=pAgent;
203   } else {
204     pAgent->fpNext=fAnchor;
205     fAnchor=pAgent;
206   }
207   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
208   fCount++;
209   return 0;     
210 }
211
212 int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
213 {
214   // see header file for function documentation
215   AliHLTLogging log;
216   if (!pAgent) return -EINVAL;
217   fCurrent=NULL;
218   AliHLTModuleAgent* prev=NULL;
219   AliHLTModuleAgent* handler=fAnchor;
220   while (handler!=NULL && handler!=pAgent) {
221     prev=handler;
222     handler=handler->fpNext;
223   }
224   if (handler) {
225     if (prev==NULL) {
226       fAnchor=handler->fpNext;
227     } else {
228       prev->fpNext=handler->fpNext;
229     }
230     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
231     fCount--;
232   }
233   return 0;
234 }