ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
ForwardDetectors
ALFA
ALFA_Geometry
src
ALFA_ConfigParams.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// DefaultParams.cpp: implementation of the ALFA_ConfigParams class.
6
//
8
9
#include "
ALFA_Geometry/ALFA_ConfigParams.h
"
10
#include <cstdio>
11
#include <cstdlib>
12
#include <cstring>
13
15
// Construction/Destruction
17
18
void
ALFA_ConfigParams::UnInitialize
()
19
{
20
m_bIsValid
=
false
;
21
m_strSection
=
"invalid"
;
22
m_mapParams
.clear();
23
}
24
25
int
ALFA_ConfigParams::Init
(
const
char
*szFile,
const
char
*szSection)
26
{
27
bool
bRes=
false
;
28
FILE* pfile=
nullptr
;
29
char
szbuff[256],szsec[256];
30
char
* ppv;
31
32
UnInitialize
();
33
34
if
((pfile=fopen(szFile,
"r"
))==
nullptr
)
return
false
;
35
36
//read section
37
memset(szsec,0,
sizeof
(szsec));
38
if
(szSection) strncpy(szsec,szSection,
sizeof
(szsec)-1);
39
//strlwr(szsec);
40
m_strSection
=szsec;
41
42
while
(!feof(pfile)){
43
fgets(szbuff,
sizeof
(szbuff),pfile);
44
if
(*(szbuff+strlen(szbuff)-1)==
'\n'
) *(szbuff+strlen(szbuff)-1)=0;
45
if
(strcmp(szbuff,szsec) != 0)
continue
;
//if(strcmp(strlwr(szbuff),szsec)) continue;
46
else
{ bRes=
true
;
break
; }
47
}
48
49
if
(!bRes){
50
fclose(pfile);
51
return
0;
52
}
53
54
while
(!feof(pfile)){
55
fgets(szbuff,
sizeof
(szbuff),pfile);
56
if
(*szbuff==0 || *szbuff==
' '
|| *szbuff==
'\n'
|| *szbuff==
';'
)
continue
;
57
if
(*szbuff==
'['
)
break
;
58
if
((ppv=strchr(szbuff,
'='
))==
nullptr
)
continue
;
59
60
if
(*(szbuff+strlen(szbuff)-1)==
'\n'
) *(szbuff+strlen(szbuff)-1)=0;
61
*ppv=0; ppv++;
62
m_mapParams
.insert(StringStringMap::value_type(szbuff,ppv));
63
}
64
65
fclose(pfile);
66
if
(!
m_mapParams
.empty())
m_bIsValid
=
true
;
67
68
return
m_mapParams
.size();
69
}
70
71
const
char
*
ALFA_ConfigParams::GetParameter
(
const
char
*szKey)
const
72
{
73
if
(!
m_bIsValid
)
return
nullptr
;
74
75
char
szbuff[256];
76
memset(szbuff,0,
sizeof
(szbuff));
77
if
(szKey) strncpy(szbuff,szKey,
sizeof
(szbuff)-1);
78
//strlwr(szbuff);
79
80
StringStringMap::const_iterator iter;
81
if
((iter=
m_mapParams
.find(szbuff))!=
m_mapParams
.end()){
82
return
(*iter).second.c_str();
83
}
84
else
return
nullptr
;
85
}
86
87
bool
ALFA_ConfigParams::IsKey
(
const
char
*szKey)
const
88
{
89
if
(!
m_bIsValid
)
return
false
;
90
91
char
szbuff[256];
92
memset(szbuff,0,
sizeof
(szbuff));
93
if
(szKey) strncpy(szbuff,szKey,
sizeof
(szbuff)-1);
94
//strlwr(szbuff);
95
96
StringStringMap::const_iterator iter;
97
return
(iter=
m_mapParams
.find(szbuff))!=
m_mapParams
.end();
98
}
99
ALFA_ConfigParams.h
ALFA_ConfigParams::GetParameter
const char * GetParameter(const char *szKey) const
Definition
ALFA_ConfigParams.cxx:71
ALFA_ConfigParams::m_strSection
std::string m_strSection
Definition
ALFA_ConfigParams.h:20
ALFA_ConfigParams::m_bIsValid
bool m_bIsValid
Definition
ALFA_ConfigParams.h:19
ALFA_ConfigParams::UnInitialize
void UnInitialize()
Definition
ALFA_ConfigParams.cxx:18
ALFA_ConfigParams::m_mapParams
StringStringMap m_mapParams
Definition
ALFA_ConfigParams.h:21
ALFA_ConfigParams::Init
int Init(const char *szFile, const char *szSection)
Definition
ALFA_ConfigParams.cxx:25
ALFA_ConfigParams::IsKey
bool IsKey(const char *szKey) const
Definition
ALFA_ConfigParams.cxx:87
Generated on
for ATLAS Offline Software by
1.17.0