]>
Commit | Line | Data |
---|---|---|
1b41ab20 | 1 | // $Id$ |
2 | ||
2589c3a3 | 3 | /************************************************************************** |
4 | * This file is property of and copyright by the Experimental Nuclear * | |
5 | * Physics Group, Dep. of Physics * | |
6 | * University of Oslo, Norway, 2007 * | |
7 | * * | |
8 | * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.* | |
9 | * Contributors are mentioned in the code where appropriate. * | |
10 | * Please report bugs to perthi@fys.uio.no * | |
11 | * * | |
12 | * Permission to use, copy, modify and distribute this software and its * | |
13 | * documentation strictly for non-commercial purposes is hereby granted * | |
14 | * without fee, provided that the above copyright notice appears in all * | |
15 | * copies and that both the copyright notice and this permission notice * | |
16 | * appear in the supporting documentation. The authors make no claims * | |
17 | * about the suitability of this software for any purpose. It is * | |
18 | * provided "as is" without express or implied warranty. * | |
19 | **************************************************************************/ | |
20 | #include "AliHLTPHOSUtilities.h" | |
0b308975 | 21 | #include <cstdlib> |
87434909 | 22 | #include <cstdio> |
2589c3a3 | 23 | |
24 | AliHLTPHOSUtilities::AliHLTPHOSUtilities() | |
25 | { | |
26 | ||
27 | } | |
28 | ||
29 | ||
30 | AliHLTPHOSUtilities::~AliHLTPHOSUtilities() | |
31 | { | |
32 | ||
33 | } | |
34 | ||
35 | ||
36 | bool | |
37 | AliHLTPHOSUtilities::ScanSingleIntArgument(int argc, const char** argv, const char *name, int *value) | |
38 | { | |
94594220 | 39 | // cout << "AliHLTPHOSUtilities::ScanSingleIntArgument " << name <<" = " << DoExistArgument(argc, argv, name) <<endl; |
2589c3a3 | 40 | int tmpIndex = DoExistArgument(argc, argv, name); |
41 | ||
42 | if( tmpIndex >= 0) | |
43 | { | |
44 | if(value == 0) | |
45 | { | |
46 | return true; | |
47 | } | |
48 | ||
49 | else | |
50 | { | |
51 | if(tmpIndex +1 < argc) | |
52 | { | |
53 | *value = atoi(argv[tmpIndex +1]); | |
54 | return true; | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | else | |
60 | { | |
61 | return false; | |
62 | } | |
e304ea31 | 63 | return false; |
2589c3a3 | 64 | } |
65 | ||
66 | bool | |
67 | AliHLTPHOSUtilities::ScanSingleFloatArgument(int argc, const char** argv, const char *name, float *value) | |
68 | { | |
94594220 | 69 | // cout << "AliHLTPHOSUtilities::ScanSingleFloatArgument " << name <<" = " << DoExistArgument(argc, argv, name) <<endl; |
2589c3a3 | 70 | |
71 | int tmpIndex = DoExistArgument(argc, argv, name); | |
72 | ||
73 | if( tmpIndex >= 0) | |
74 | { | |
75 | if(value == 0) | |
76 | { | |
77 | return true; | |
78 | } | |
79 | ||
80 | else | |
81 | { | |
82 | if(tmpIndex +1 < argc) | |
83 | { | |
84 | *value = atof(argv[tmpIndex +1]); | |
85 | return true; | |
86 | } | |
87 | } | |
88 | } | |
89 | else | |
90 | { | |
91 | return false; | |
92 | } | |
e304ea31 | 93 | return false; |
2589c3a3 | 94 | } |
95 | ||
96 | ||
97 | ||
98 | bool | |
99 | AliHLTPHOSUtilities::ScanSingleNameArgument(int argc, const char** argv, const char *name, char *outname) | |
100 | { | |
94594220 | 101 | // cout << "AliHLTPHOSUtilities::ScanSingleNameArgument " << name <<" = " << DoExistArgument(argc, argv, name) <<endl; |
2589c3a3 | 102 | |
103 | int tmpIndex = DoExistArgument(argc, argv, name); | |
104 | ||
105 | if( tmpIndex >= 0) | |
106 | { | |
107 | if(outname == 0) | |
108 | { | |
109 | return true; | |
110 | } | |
111 | ||
112 | else | |
113 | { | |
114 | if(tmpIndex +1 < argc) | |
115 | { | |
116 | // *value = atoi(argv[tmpIndex +1]); | |
117 | sprintf(outname, "%s", argv[tmpIndex +1] ); | |
e304ea31 | 118 | |
2589c3a3 | 119 | return true; |
120 | } | |
121 | } | |
122 | } | |
123 | else | |
124 | { | |
125 | return false; | |
126 | } | |
e304ea31 | 127 | return false; |
2589c3a3 | 128 | } |
129 | ||
94594220 | 130 | |
2589c3a3 | 131 | bool |
132 | AliHLTPHOSUtilities::ScanSingleArgument(int argc, const char** argv, const char *name) | |
133 | { | |
94594220 | 134 | // cout << "AliHLTPHOSUtilities::ScanSingleArgument " << name <<" = " << DoExistArgument(argc, argv, name) <<endl; |
2589c3a3 | 135 | |
94594220 | 136 | if( DoExistArgument(argc, argv, name) >=0) |
2589c3a3 | 137 | { |
138 | // cout << "AliHLTPHOSUtilities::ScanSingleArgument " << name <<" > 0" <<endl; | |
139 | return true; | |
140 | } | |
141 | else | |
142 | { | |
143 | // cout << "AliHLTPHOSUtilities::ScanSingleArgument " << name <<" > 0" <<endl; | |
144 | return false; | |
145 | } | |
146 | ||
147 | } | |
148 | ||
149 | ||
150 | ||
151 | bool | |
152 | AliHLTPHOSUtilities::CheckFile(const char *fileName, const char *opt) const | |
153 | { | |
154 | //returns true if the file specified by "fileName exists and has acceees rights specified by "opt", | |
155 | //returns false if it doesnt exist, or it exists, but doesnt have the access right specified by "opt" | |
156 | FILE *fp = fopen(fileName, opt); | |
157 | ||
158 | if(fp == 0) | |
159 | { | |
160 | return false; | |
161 | } | |
162 | else | |
163 | { | |
164 | fclose(fp); | |
165 | return true; | |
166 | } | |
167 | } | |
168 | ||
169 | ||
170 | // returns the index if the argument if it exists | |
171 | // returns a negative value if it doesnt exist | |
172 | int | |
9a2451f1 | 173 | AliHLTPHOSUtilities::DoExistArgument(const int argc, const char** argv, const char *name) |
2589c3a3 | 174 | { |
175 | string s1; | |
176 | ||
177 | for(int i= 0; i< argc; i++) | |
178 | { | |
179 | s1.assign(argv[i]); | |
180 | ||
181 | if(s1 == name) | |
182 | { | |
183 | // cout << "AliHLTPHOSUtilities::DoExistArgumen , argument = " << name << " Exists" <<endl; | |
184 | return i; | |
185 | } | |
186 | } | |
187 | ||
188 | // cout << "AliHLTPHOSUtilities::DoExistArgumen , argument = " << name << " does not exist " <<endl; | |
189 | return -1; | |
190 | ||
191 | ||
192 | } |