]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModuleAgent.cxx
086de37c2ded7bc151a68f807ea4ea640324c341
[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
28 /** ROOT macro for the implementation of ROOT specific class methods */
29 ClassImp(AliHLTModuleAgent)
30
31 AliHLTModuleAgent::AliHLTModuleAgent()
32   :
33   fpNext(NULL),
34   fpComponentHandler(NULL)
35 {
36   // see header file for class documentation
37   // or
38   // refer to README to build package
39   // or
40   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
41   Register(this);
42 }
43
44 AliHLTModuleAgent::~AliHLTModuleAgent()
45 {
46   // see header file for function documentation
47   Unregister(this);
48 }
49
50 void AliHLTModuleAgent::PrintStatus(const char* agent)
51 {
52   // see header file for function documentation
53   AliHLTLogging log;
54  if (agent) {
55    AliHLTModuleAgent* pCurrent=fAnchor;
56    while (pCurrent!=NULL && strcmp(pCurrent->GetName(), agent)!=0) pCurrent=pCurrent->fpNext;
57    if (pCurrent) {
58      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
59                  "agent %s available", pCurrent->GetName());
60    } else {
61      log.Logging(kHLTLogInfo, "AliHLTModuleAgent::PrintStatus", "module agents", 
62                  "agent %s not found", agent);
63    }
64   } else {
65    AliHLTModuleAgent* pCurrent=fAnchor;
66    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
67    log.Logging(kHLTLogInfo, "AliHLT", "", "available module agents");
68    if (pCurrent==NULL)
69      log.Logging(kHLTLogInfo, "AliHLT", "", "   none");
70    while (pCurrent) {
71      TString msg;
72      msg.Form("   %s : %p", pCurrent->GetName(), pCurrent);
73      log.Logging(kHLTLogInfo, "AliHLT", "", msg.Data());
74      pCurrent=pCurrent->fpNext;
75    }
76    log.Logging(kHLTLogInfo, "AliHLT", "", "-----------------------");
77   }
78 }
79
80 int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
81                                             AliRawReader* /*rawReader*/,
82                                             AliRunLoader* /*runloader*/) const
83 {
84   // default method, nothing to be done, child classes can overload
85   return 0;
86 }
87
88 const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
89                                                        AliRunLoader* /*runloader*/) const
90 {
91   // default method, nothing to be done, child classes can overload
92   return NULL;
93 }
94
95 const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
96 {
97   // default method, nothing to be done, child classes can overload
98   return NULL;
99 }
100
101 int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
102 {
103   int iResult=0;
104   if (pHandler==NULL) {
105     if (fpComponentHandler!=NULL) {
106       // reset and think about deregistration
107       fpComponentHandler=NULL;
108       HLTWarning("deregistration of components not yet implemented");
109     }
110     return 0;
111   }
112   if (fpComponentHandler!=NULL) {
113     if (pHandler!=fpComponentHandler) {
114       HLTError("only one component handler can be activated per agent");
115       return -EINVAL;
116     }
117     return 0;
118   }
119   if ((iResult=RegisterComponents(pHandler))>=0) {
120     fpComponentHandler=pHandler;
121   }
122   return iResult;
123 }
124
125 int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
126 {
127   // default method, nothing to be done, child classes can overload
128   return 0;
129 }
130
131 AliHLTModuleAgent* AliHLTModuleAgent::fAnchor=NULL;
132 AliHLTModuleAgent* AliHLTModuleAgent::fCurrent=NULL;
133 int AliHLTModuleAgent::fCount=0;
134
135 AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
136 {
137   // see header file for function documentation
138   fCurrent=fAnchor;
139   return fAnchor;
140 }
141
142 AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
143 {
144   // see header file for function documentation
145   if (fCurrent!=NULL) fCurrent=fCurrent->fpNext;
146   return fCurrent;
147 }
148
149 int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
150 {
151   // see header file for function documentation
152   AliHLTLogging log;
153   if (!pAgent) return -EINVAL;
154   if (fAnchor==NULL) {
155     fAnchor=pAgent;
156   } else {
157     pAgent->fpNext=fAnchor;
158     fAnchor=pAgent;
159   }
160   //  log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
161   fCount++;
162   return 0;     
163 }
164
165 int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
166 {
167   // see header file for function documentation
168   AliHLTLogging log;
169   if (!pAgent) return -EINVAL;
170   fCurrent=NULL;
171   AliHLTModuleAgent* prev=NULL;
172   AliHLTModuleAgent* handler=fAnchor;
173   while (handler!=NULL && handler!=pAgent) {
174     prev=handler;
175     handler=handler->fpNext;
176   }
177   if (handler) {
178     if (prev==NULL) {
179       fAnchor=handler->fpNext;
180     } else {
181       prev->fpNext=handler->fpNext;
182     }
183     //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
184     fCount--;
185   }
186   return 0;
187 }