]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTModuleAgent.cxx
- implemented component registration via agents
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTModuleAgent.cxx
CommitLineData
242bb794 1// @(#) $Id$
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
242bb794 6 * *
9be2600f 7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
242bb794 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 */
29ClassImp(AliHLTModuleAgent)
30
31AliHLTModuleAgent::AliHLTModuleAgent()
79c114b5 32 :
f3506ea2 33 fpNext(NULL),
34 fpComponentHandler(NULL)
242bb794 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
242bb794 44AliHLTModuleAgent::~AliHLTModuleAgent()
45{
46 // see header file for function documentation
47 Unregister(this);
48}
49
50void AliHLTModuleAgent::PrintStatus(const char* agent)
51{
52 // see header file for function documentation
53 AliHLTLogging log;
7617ca1e 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 }
242bb794 64 } else {
7617ca1e 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", "", "-----------------------");
242bb794 77 }
78}
79
04a939f7 80int AliHLTModuleAgent::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/,
dee38f1b 81 AliRawReader* /*rawReader*/,
04a939f7 82 AliRunLoader* /*runloader*/) const
242bb794 83{
84 // default method, nothing to be done, child classes can overload
242bb794 85 return 0;
86}
87
dee38f1b 88const char* AliHLTModuleAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
89 AliRunLoader* /*runloader*/) const
242bb794 90{
91 // default method, nothing to be done, child classes can overload
242bb794 92 return NULL;
93}
94
95const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
96{
97 // default method, nothing to be done, child classes can overload
98 return NULL;
99}
100
f3506ea2 101int 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
125int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
242bb794 126{
242bb794 127 // default method, nothing to be done, child classes can overload
128 return 0;
129}
130
7617ca1e 131AliHLTModuleAgent* AliHLTModuleAgent::fAnchor=NULL;
132AliHLTModuleAgent* AliHLTModuleAgent::fCurrent=NULL;
133int AliHLTModuleAgent::fCount=0;
134
242bb794 135AliHLTModuleAgent* AliHLTModuleAgent::GetFirstAgent()
136{
137 // see header file for function documentation
7617ca1e 138 fCurrent=fAnchor;
139 return fAnchor;
242bb794 140}
141
142AliHLTModuleAgent* AliHLTModuleAgent::GetNextAgent()
143{
144 // see header file for function documentation
7617ca1e 145 if (fCurrent!=NULL) fCurrent=fCurrent->fpNext;
146 return fCurrent;
242bb794 147}
148
149int AliHLTModuleAgent::Register(AliHLTModuleAgent* pAgent)
150{
151 // see header file for function documentation
152 AliHLTLogging log;
153 if (!pAgent) return -EINVAL;
7617ca1e 154 if (fAnchor==NULL) {
155 fAnchor=pAgent;
156 } else {
157 pAgent->fpNext=fAnchor;
158 fAnchor=pAgent;
242bb794 159 }
7617ca1e 160 // log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Register", "", "module agent %p registered", pAgent);
161 fCount++;
162 return 0;
242bb794 163}
164
165int AliHLTModuleAgent::Unregister(AliHLTModuleAgent* pAgent)
166{
167 // see header file for function documentation
168 AliHLTLogging log;
169 if (!pAgent) return -EINVAL;
7617ca1e 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 }
80e562fa 183 //log.Logging(kHLTLogDebug, "AliHLTModuleAgent::Unregister", "", "module agent %p removed", pAgent);
7617ca1e 184 fCount--;
242bb794 185 }
186 return 0;
187}