1 |
kusanagi |
1.1 |
|
2 |
|
|
#include <log4cxx/logger.h> |
3 |
|
|
#include <log4cxx/basicconfigurator.h> |
4 |
|
|
#include <log4cxx/fileappender.h> |
5 |
|
|
#include <log4cxx/patternlayout.h> |
6 |
|
|
#include <log4cxx/propertyconfigurator.h> |
7 |
|
|
|
8 |
|
|
#include <TSQLServer.h> |
9 |
|
|
#include <TSQLResult.h> |
10 |
|
|
#include <YSQLConnection.h> |
11 |
|
|
#include <PamelaDBOperations.h> |
12 |
|
|
#include <YException.h> |
13 |
|
|
|
14 |
|
|
#include <cstdlib> |
15 |
|
|
#include <iostream> |
16 |
|
|
#include <errno.h> |
17 |
|
|
|
18 |
|
|
extern "C" { |
19 |
|
|
#include <dirent.h> |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
using namespace log4cxx; |
23 |
|
|
using namespace std; |
24 |
|
|
using namespace yngn::YException; |
25 |
|
|
using namespace pamela; |
26 |
|
|
|
27 |
|
|
static LoggerPtr logger = Logger::getLogger(_T("YodaProfiler")); |
28 |
|
|
|
29 |
|
|
/* |
30 |
|
|
NOTE!!! |
31 |
|
|
This program assume that on the '.' directory is present a structure having a |
32 |
|
|
|
33 |
|
|
- filesFromYoda folder containing the unpacked data |
34 |
|
|
*/ |
35 |
|
|
|
36 |
|
|
int main(int argc, char* argv[]) { |
37 |
|
|
|
38 |
|
|
/* |
39 |
|
|
if (argc < 2){ |
40 |
|
|
printf("You have to insert at least the file to analyze \n"); |
41 |
|
|
printf("Try '--help' for more information. \n"); |
42 |
|
|
exit(1); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
if (!strcmp(argv[1], "--help")){ |
46 |
|
|
printf( "Usage: -exec[operation] [OPTIONS] \n"); |
47 |
|
|
printf( "\t --help Print this help and exit \n"); |
48 |
|
|
printf( "\t OPTIONS: \n"); |
49 |
|
|
|
50 |
|
|
printf( "\t -sqlParams[path] Path to the configuration file to connect to the Database server \n"); |
51 |
|
|
printf( "\t The configuration file (remember to chmod it to '500') have to be in the format \n"); |
52 |
|
|
printf( "\t #HOST=hostname \n"); |
53 |
|
|
printf( "\t #USER=username \n"); |
54 |
|
|
printf( "\t #PSW=password \n"); |
55 |
|
|
printf( "\t #DB=databaseName \n"); |
56 |
|
|
|
57 |
|
|
printf( "\t -host[name] The name of the host where the database is installed\n"); |
58 |
|
|
printf( "\t -user[name] The name of the user accessing to the database\n"); |
59 |
|
|
printf( "\t -psw[name] The password of the user accessing to the database\n"); |
60 |
|
|
|
61 |
|
|
printf( "\t Notice that by default [-host -name -password -database] overload the [-sqlParams] param \n"); |
62 |
|
|
|
63 |
|
|
printf( "\t -exec[nameOperation] Execute the required operation"); |
64 |
|
|
printf( "\t -rawPath[path] Path to the raw file \n"); |
65 |
|
|
printf( "\t -rawFile[name] Name of the raw file \n"); |
66 |
|
|
|
67 |
|
|
printf( "\n \t Operations list: \n"); |
68 |
|
|
printf( "\t insertPamelaRawFile -rawPath[path] -rawFile[name]); \n"); |
69 |
|
|
exit(1); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
for (int i = 2; i < argc; i++){ |
73 |
|
|
if (!strcmp(argv[i], "-outDir")){ |
74 |
|
|
if (++i >= argc){ |
75 |
|
|
printf( "-outDir needs arguments. \n"); |
76 |
|
|
printf( "Try '--help' for more information. \n"); |
77 |
|
|
exit(1); |
78 |
|
|
} else { |
79 |
|
|
outDir = argv[i]; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
if (!strcmp(argv[i], "-xslPath")) |
84 |
|
|
if (++i >= argc){ |
85 |
|
|
printf( "-xslPath needs arguments. \n"); |
86 |
|
|
printf( "Try '--help' for more information. \n"); |
87 |
|
|
exit(1); |
88 |
|
|
} else { |
89 |
|
|
xslPath = argv[i]; |
90 |
|
|
continue; |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
*/ |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
stringstream oss; |
98 |
|
|
|
99 |
|
|
TSQLServer *sqlServer = 0; |
100 |
|
|
char *rawPathName = argv[1]; |
101 |
|
|
char *rawFileName = argv[2]; |
102 |
|
|
char *symbolicName = ""; |
103 |
|
|
|
104 |
|
|
char *result = NULL; |
105 |
|
|
char buffer[999]; |
106 |
|
|
char *host = argv[3]; |
107 |
|
|
char *user = argv[4]; |
108 |
|
|
char *password = argv[5]; |
109 |
|
|
char *rootPathName = argv[6]; |
110 |
|
|
char *rootFileName = argv[7]; |
111 |
|
|
|
112 |
|
|
|
113 |
|
|
//Here I have to put some check for the arguments...... |
114 |
|
|
/* |
115 |
|
|
ifstream config(argv[4]); |
116 |
|
|
if (! config.is_open()) |
117 |
|
|
{ cout << "Error opening file"; exit (1); } |
118 |
|
|
while (! config.eof() ) |
119 |
|
|
{ |
120 |
|
|
config.getline (buffer,255); |
121 |
|
|
|
122 |
|
|
if (strstr(buffer, "=") != NULL){ |
123 |
|
|
result = strtok( buffer, "=" ); |
124 |
|
|
while( result != NULL ) { |
125 |
|
|
//The fisrt strok skip the "user" or "password" keys |
126 |
|
|
result = strtok( NULL, delims ); |
127 |
|
|
user = strtok( NULL, delims ); |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
}*/ |
131 |
|
|
try{ |
132 |
|
|
oss.str(""); |
133 |
|
|
sqlServer = yngn::sql::YSQLConnection::getConnection(host, user, password); |
134 |
|
|
} catch (YException exc) { |
135 |
|
|
cout << exc.print(); |
136 |
|
|
exit(1); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
//Insert a Raw file in GL_RAW |
140 |
|
|
//------------------------------------------------------------------------------------------- |
141 |
|
|
try { |
142 |
|
|
PamelaDBOperations::insertPamelaRawFile(sqlServer, rawPathName, rawFileName); |
143 |
|
|
} catch (YException exc) { |
144 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
145 |
|
|
} |
146 |
|
|
//------------------------------------------------------------------------------------------- |
147 |
|
|
|
148 |
|
|
//Insert single unpack ROOTs files in GL_ROOT |
149 |
|
|
//------------------------------------------------------------------------------------------- |
150 |
|
|
try { |
151 |
|
|
PamelaDBOperations::insertPamelaRootFiles(sqlServer, rootPathName, rootFileName, rawPathName, rawFileName); |
152 |
|
|
} catch (YException exc) { |
153 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
154 |
|
|
} |
155 |
|
|
//------------------------------------------------------------------------------------------- |
156 |
|
|
|
157 |
|
|
|
158 |
|
|
//Update a single GL_RAW record with its BOOT_NUMBER |
159 |
|
|
//------------------------------------------------------------------------------------------- |
160 |
|
|
try { |
161 |
|
|
PamelaDBOperations::assignBOOT_NUMBER(sqlServer, rawPathName, rawFileName); |
162 |
|
|
} catch (YException exc) { |
163 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
164 |
|
|
} |
165 |
|
|
//------------------------------------------------------------------------------------------- |
166 |
|
|
|
167 |
|
|
//Insert a record in GL_TIMESYNC with data relative to a single unpack |
168 |
|
|
//------------------------------------------------------------------------------------------- |
169 |
|
|
try { |
170 |
|
|
PamelaDBOperations::insertPamelaGL_TIMESYNC(sqlServer, rawPathName, rawFileName); |
171 |
|
|
} catch (YException exc) { |
172 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
173 |
|
|
} |
174 |
|
|
|
175 |
kusanagi |
1.2 |
|
176 |
kusanagi |
1.1 |
//------------------------------------------------------------------------------------------- |
177 |
|
|
//Generate the Registry files for a single unpack |
178 |
|
|
//------------------------------------------------------------------------------------------- |
179 |
|
|
try { |
180 |
kusanagi |
1.2 |
PamelaDBOperations::createPamelaRegistry(sqlServer, rawPathName, rawFileName, true); |
181 |
kusanagi |
1.1 |
} catch (YException exc) { |
182 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
183 |
|
|
} |
184 |
|
|
//------------------------------------------------------------------------------------------- |
185 |
|
|
|
186 |
|
|
//Insert in GL_RUN runs information records relative to a single unpack |
187 |
|
|
//------------------------------------------------------------------------------------------- |
188 |
|
|
try { |
189 |
|
|
PamelaDBOperations::insertPamelaRUN(sqlServer, rawPathName, rawFileName); |
190 |
|
|
} catch (YException exc) { |
191 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
//------------------------------------------------------------------------------------------- |
195 |
|
|
|
196 |
|
|
//Insert in GL_CALO_CALIB calibration information records relative to a single unpack |
197 |
|
|
//------------------------------------------------------------------------------------------- |
198 |
|
|
try { |
199 |
|
|
PamelaDBOperations::insertNEW_CALO_CALIB(sqlServer, rawPathName, rawFileName); |
200 |
|
|
} catch (YException exc) { |
201 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
202 |
|
|
} |
203 |
|
|
//------------------------------------------------------------------------------------------- |
204 |
|
|
|
205 |
|
|
|
206 |
|
|
//Insert in GL_S4_CALIB calibration information records relative to a single unpack |
207 |
|
|
//------------------------------------------------------------------------------------------- |
208 |
|
|
try { |
209 |
|
|
PamelaDBOperations::insertNEW_S4_CALIB(sqlServer, rawPathName, rawFileName); |
210 |
|
|
} catch (YException exc) { |
211 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
212 |
|
|
} |
213 |
|
|
//------------------------------------------------------------------------------------------- |
214 |
|
|
|
215 |
|
|
//Insert in GL_TRK_CALIB calibration information records relative to a single unpack |
216 |
|
|
//------------------------------------------------------------------------------------------- |
217 |
|
|
try { |
218 |
|
|
PamelaDBOperations::insertNEW_TRK_CALIB(sqlServer, rawPathName, rawFileName); |
219 |
|
|
} catch (YException exc) { |
220 |
|
|
cout << "Eccezione! " << exc.print() << "\n" ; |
221 |
|
|
} |
222 |
|
|
//--------------------------------------------------------------------------------------- |
223 |
|
|
sqlServer->Close(); |
224 |
|
|
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
225 |
|
|
//return 1; |
226 |
|
|
} |