]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTConfigurationHandler.cxx
adding common functionality for the magnetic field to the component interface
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfigurationHandler.cxx
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
32 using 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 */
42 ClassImp(AliHLTConfigurationHandler)
43
44 AliHLTConfigurationHandler::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
56 AliHLTConfigurationHandler::~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
68 AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
69 int AliHLTConfigurationHandler::fgNofInstances=0;
70
71 AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
72 {
73   // see header file for class documentation
74   if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
75   fgNofInstances++;
76   return fgpInstance;
77 }
78
79 int AliHLTConfigurationHandler::Destroy()
80 {
81   // see header file for class documentation
82   int nofInstances=0;
83   if (fgpInstance==this) {
84     nofInstances=fgNofInstances--;
85   }
86   if (fgNofInstances==0) {
87     delete fgpInstance;
88     fgpInstance = NULL;
89   }
90   return nofInstances;
91 }
92
93
94 int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
95 {
96   // see header file for function documentation
97   int iResult=0;
98   if (pConf) {
99     AliHLTConfiguration* pExisting=NULL;
100     if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
101       AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
102       fgListConfigurations.Add(pClone);
103       HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
104
105       // mark all configurations with unresolved dependencies for re-evaluation
106       TObjLink* lnk=fgListConfigurations.FirstLink();
107       while (lnk) {
108         AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
109         if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
110           pSrc->InvalidateSources();
111         }
112         lnk=lnk->Next();
113       }
114     } else {
115       if ((*pExisting)!=(*pConf)) {
116       iResult=-EEXIST;
117       HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
118       }
119     }
120   } else {
121     iResult=-EINVAL;
122   }
123   return iResult;
124 }
125
126 int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
127 {
128   // see header file for function documentation
129   int iResult=0;
130   AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
131   if (pConf) {
132     // the configuration will be registered automatically, if this failes the configuration
133     // is missing -> delete it
134     if (FindConfiguration(id)==NULL) {
135       delete pConf;
136       pConf=NULL;
137       iResult=-EEXIST;
138     }
139   } else {
140     HLTError("system error: object allocation failed");
141     iResult=-ENOMEM;
142   }
143   return iResult;
144 }
145
146 void AliHLTConfigurationHandler::PrintConfigurations()
147 {
148   // see header file for function documentation
149   HLTLogKeyword("configuration listing");
150   HLTMessage("registered configurations:");
151   TObjLink *lnk = fgListConfigurations.FirstLink();
152   while (lnk) {
153     TObject *obj = lnk->GetObject();
154     HLTMessage("  %s", obj->GetName());
155     lnk = lnk->Next();
156   }
157 }
158
159 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
160 {
161   // see header file for function documentation
162   int iResult=0;
163   if (id) {
164     AliHLTConfiguration* pConf=NULL;
165     if ((pConf=FindConfiguration(id))!=NULL) {
166       iResult=RemoveConfiguration(pConf);
167       delete pConf;
168       pConf=NULL;
169     } else {
170       HLTWarning("can not find configuration \"%s\"", id);
171       iResult=-ENOENT;
172     }
173   } else {
174     iResult=-EINVAL;
175   }
176   return iResult;
177 }
178
179 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
180 {
181   // see header file for function documentation
182   int iResult=0;
183   if (pConf) {
184     // remove the configuration from the list
185     HLTDebug("remove configuration \"%s\"", pConf->GetName());
186     fgListConfigurations.Remove(pConf);
187     // remove cross links in the remaining configurations
188     TObjLink* lnk=fgListConfigurations.FirstLink();
189     while (lnk && iResult>=0) {
190       AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
191       if (pRem) {
192         pRem->InvalidateSource(pConf);
193       } else {
194         iResult=-EFAULT;
195       }
196       lnk=lnk->Next();
197     }
198   }
199   return iResult;
200 }
201
202 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
203 {
204   // see header file for function documentation
205   AliHLTConfiguration* pConf=NULL;
206   if (id) {
207     pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id); 
208   }
209   return pConf;
210 }
211