]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTConfigurationHandler.cxx
adding a component for statistics and monitoring of the DAQ readout list
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfigurationHandler.cxx
CommitLineData
7a436c89 1// $Id$
2// splitted from AliHLTConfiguration.cxx,v 1.25 2007/10/12 13:24:47
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 AliHLTConfigurationHandler.cxx
20 @author Matthias Richter
21 @date
22 @brief Implementation of HLT tasks.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#if __GNUC__>= 3
32using namespace std;
33#endif
34
35#include <cerrno>
36#include <iostream>
37#include <string>
38#include "AliHLTConfigurationHandler.h"
39#include "AliHLTConfiguration.h"
40
41/** ROOT macro for the implementation of ROOT specific class methods */
42ClassImp(AliHLTConfigurationHandler)
43
44AliHLTConfigurationHandler::AliHLTConfigurationHandler()
45 :
46 fgListConfigurations()
47{
48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53 SetLocalLoggingLevel(kHLTLogInfo);
54}
55
56AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
57{
58 // see header file for function documentation
59 TObjLink* lnk=NULL;
60 while ((lnk=fgListConfigurations.FirstLink())!=NULL) {
61 AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject();
62 HLTDebug("delete configuration \"%s\"", pConf->GetName());
63 fgListConfigurations.Remove(lnk);
64 delete pConf;
65 }
66}
67
b005ef92 68AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
69int AliHLTConfigurationHandler::fgNofInstances=0;
70
71AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
72{
73 // see header file for class documentation
74 if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
75 fgNofInstances++;
76 return fgpInstance;
77}
78
79int AliHLTConfigurationHandler::Destroy()
80{
81 // see header file for class documentation
82 int nofInstances=0;
83 if (fgpInstance==this) {
84 nofInstances=fgNofInstances--;
85 }
86 if (nofInstances==0) delete this;
87 return nofInstances;
88}
89
90
7a436c89 91int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
92{
93 // see header file for function documentation
94 int iResult=0;
95 if (pConf) {
d4a18597 96 AliHLTConfiguration* pExisting=NULL;
97 if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
7a436c89 98 AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
99 fgListConfigurations.Add(pClone);
100 HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
101
102 // mark all configurations with unresolved dependencies for re-evaluation
103 TObjLink* lnk=fgListConfigurations.FirstLink();
104 while (lnk) {
105 AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
106 if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
107 pSrc->InvalidateSources();
108 }
109 lnk=lnk->Next();
110 }
111 } else {
d4a18597 112 if ((*pExisting)!=(*pConf)) {
7a436c89 113 iResult=-EEXIST;
d4a18597 114 HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
115 }
7a436c89 116 }
117 } else {
118 iResult=-EINVAL;
119 }
120 return iResult;
121}
122
123int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
124{
125 // see header file for function documentation
126 int iResult=0;
127 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
128 if (pConf) {
129 // the configuration will be registered automatically, if this failes the configuration
130 // is missing -> delete it
131 if (FindConfiguration(id)==NULL) {
132 delete pConf;
133 pConf=NULL;
134 iResult=-EEXIST;
135 }
136 } else {
137 HLTError("system error: object allocation failed");
138 iResult=-ENOMEM;
139 }
140 return iResult;
141}
142
143void AliHLTConfigurationHandler::PrintConfigurations()
144{
145 // see header file for function documentation
146 HLTLogKeyword("configuration listing");
147 HLTMessage("registered configurations:");
148 TObjLink *lnk = fgListConfigurations.FirstLink();
149 while (lnk) {
150 TObject *obj = lnk->GetObject();
151 HLTMessage(" %s", obj->GetName());
152 lnk = lnk->Next();
153 }
154}
155
156int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
157{
158 // see header file for function documentation
159 int iResult=0;
160 if (id) {
161 AliHLTConfiguration* pConf=NULL;
162 if ((pConf=FindConfiguration(id))!=NULL) {
163 iResult=RemoveConfiguration(pConf);
164 delete pConf;
165 pConf=NULL;
166 } else {
167 HLTWarning("can not find configuration \"%s\"", id);
168 iResult=-ENOENT;
169 }
170 } else {
171 iResult=-EINVAL;
172 }
173 return iResult;
174}
175
176int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
177{
178 // see header file for function documentation
179 int iResult=0;
180 if (pConf) {
181 // remove the configuration from the list
182 HLTDebug("remove configuration \"%s\"", pConf->GetName());
183 fgListConfigurations.Remove(pConf);
184 // remove cross links in the remaining configurations
185 TObjLink* lnk=fgListConfigurations.FirstLink();
186 while (lnk && iResult>=0) {
187 AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
188 if (pRem) {
189 pRem->InvalidateSource(pConf);
190 } else {
191 iResult=-EFAULT;
192 }
193 lnk=lnk->Next();
194 }
195 }
196 return iResult;
197}
198
199AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
200{
201 // see header file for function documentation
202 AliHLTConfiguration* pConf=NULL;
203 if (id) {
204 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
205 }
206 return pConf;
207}
208