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