]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloUtilities.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloUtilities.cxx
1 // $Id: AliHLTCALOUtilities.cxx 34264 2009-08-14 18:29:23Z odjuvsla $
2
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 "AliHLTCaloUtilities.h"
21 #include <cstdlib>
22 #include <cstdio>
23
24 AliHLTCaloUtilities::AliHLTCaloUtilities()
25 {
26
27 }
28
29
30 AliHLTCaloUtilities::~AliHLTCaloUtilities()
31 {
32
33 }
34
35
36 bool 
37 AliHLTCaloUtilities::ScanSingleIntArgument(int argc, const char** argv, const char *name, int *value)
38 {
39   int tmpIndex =  DoExistArgument(argc, argv, name);
40
41   if( tmpIndex  >= 0)
42     {
43       if(value == 0)
44         {
45           return true;
46         }
47       else
48         {
49           if(tmpIndex +1 < argc)
50             {
51               *value =  atoi(argv[tmpIndex +1]);
52               return true;
53             }
54         }
55     }
56   else
57     {
58       return false;
59     }
60   return false;
61 }
62
63  
64 bool 
65 AliHLTCaloUtilities::ScanSingleFloatArgument(int argc, const char** argv, const char *name, float *value)
66 {
67   int tmpIndex =  DoExistArgument(argc, argv, name);
68
69   if( tmpIndex  >= 0)
70     {
71       if(value == 0)
72         {
73           return true;
74         }
75       else
76         {
77           if(tmpIndex +1 < argc)
78             {
79               *value =  atof(argv[tmpIndex +1]);
80               return true;
81             }
82         }
83     }
84   else
85     {
86       return false;
87     }
88   return false;
89 }
90  
91  
92 bool 
93 AliHLTCaloUtilities::ScanSingleNameArgument(int argc, const char** argv, const char *name, char *outname)
94 {
95   int tmpIndex =  DoExistArgument(argc, argv, name);
96
97   if( tmpIndex  >= 0)
98     {
99       if(outname == 0)
100         {
101           return true;
102         }
103       else
104         {
105           if(tmpIndex +1 < argc)
106             {
107               sprintf(outname, "%s", argv[tmpIndex +1] );
108               return true;
109             }
110         }
111     }
112   else
113     {
114       return false;
115     }
116   return false;
117 }
118
119
120 bool 
121 AliHLTCaloUtilities::ScanSingleArgument(int argc, const char** argv, const char *name)
122 {
123   if( DoExistArgument(argc, argv, name) >=0)
124     {
125       return true;
126     }
127   else
128     {
129       return false;
130     }
131
132 }
133
134
135 bool
136 AliHLTCaloUtilities::CheckFile(const char *fileName, const char *opt)
137 {
138   //returns true if the file specified by "fileName exists  and has acceees rights specified  by "opt", 
139   //returns false if it doesnt exist, or it exists, but doesnt have the access right specified by "opt"
140   FILE *fp = fopen(fileName, opt);
141
142   if(fp == 0)
143     {
144       return false;
145     }
146   else
147     {
148       fclose(fp); 
149       return true;
150     }
151 }
152
153
154 // returns the index if the argument if it exists
155 // returns a negative value if it doesnt exist
156 int 
157 AliHLTCaloUtilities::DoExistArgument(const int argc, const char** argv, const char *name)
158 {
159   string s1;
160
161   for(int i= 0; i< argc; i++)
162     {
163       s1.assign(argv[i]);
164       
165       if(s1 == name)
166         {
167           return i;
168         }
169     }
170   return -1;
171 }