/[PAMELA software]/DarthVader/src/R2-D2.cpp
ViewVC logotype

Contents of /DarthVader/src/R2-D2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Wed Sep 6 11:03:34 2006 UTC (18 years, 5 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +114 -34 lines
Adapted to the new profiler

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <sstream>
6 //
7 // ROOT headers
8 //
9 #include <TString.h>
10 #include <TSQLServer.h>
11 #include <TFile.h>
12 #include <TSystem.h>
13 //
14 // Detector's package headers
15 //
16 #include <GLTables.h>
17 //
18 using namespace std;
19 //
20 //
21 //
22 #include <DarthVaderVerl2.h>
23 //
24 // Usage subroutine
25 //
26 void r2d2usage(){
27 printf("\nUsage:\n");
28 printf("\n DarthVader [-h | --help] [--version] [-idRun ID_RUN] [-filename filename]\n");
29 printf("\n [-host host] [-user username] [-psw password] \n");
30 printf("\n --version print informations about compilation and exit\n");
31 printf("\n -h | --help print this help and exit \n");
32 printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
33 printf("\n -idRun ID_RUN: ID number of the run \n");
34 printf("\n -filename output yoda filename \n");
35 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
36 printf("\n -user username for the DB [default = anonymous] \n");
37 printf("\n -psw password for the DB [default = \"\"]\n");
38 printf("\n -convert [ -tzone timezone -dbtime dbtime ] \n");
39 printf("\n convert the dbtime given in seconds (from the DB) to a string for\n");
40 printf("\n the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n");
41 printf("\n -runat \"yyyy-mm-dd hh:mm:ss\" \n");
42 printf("\n returns run number which contain the given date in MSK (if any)\n");
43 printf("\nExamples: \n");
44 printf("\n R2-D2 -idRun 1085 \n");
45 printf("\n R2-D2 -filename DW_050208_00900.root \n");
46 printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n");
47 };
48 //
49 // Here the main
50 //
51 int main(int numinp, char *inps[]){
52 //
53 // Variables booking
54 //
55 TString message;
56 Int_t error = 0;
57 //
58 UInt_t run = 0ULL;
59 //
60 TString filename = "";
61 //
62 TSQLServer *dbc = 0;
63 TString host = "mysql://localhost/pamelaprod";
64 TString user = "anonymous";
65 TString psw = "";
66 TString tzone = "MSK";
67 TString runtime = "1970-01-01 00:00:00";
68 UInt_t dbti = 0;
69 Bool_t convert = false;
70 Bool_t ruti = false;
71 //
72 //
73 // Checking input parameters
74 //
75 Int_t i = 0;
76 if ( numinp > 1 ){
77 while ( i < numinp ){
78 if ( !strcmp(inps[i],"--version") ){
79 DarthVaderInfo(true);
80 exit(0);
81 };
82 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
83 r2d2usage();
84 exit(0);
85 };
86 if ( !strcmp(inps[i],"-idRun") ) {
87 if ( numinp-1 < i+1 ) {
88 r2d2usage();
89 exit(-3);
90 };
91 run = (UInt_t)atoll(inps[i+1]);
92 };
93 if ( !strcmp(inps[i],"-filename") ) {
94 if ( numinp-1 < i+1 ){
95 r2d2usage();
96 exit(-3);
97 };
98 filename = (TString)inps[i+1];
99 };
100 if ( !strcmp(inps[i],"-host") ) {
101 if ( numinp-1 < i+1 ){
102 r2d2usage();
103 exit(-3);
104 };
105 host = (TString)inps[i+1];
106 };
107 if ( !strcmp(inps[i],"-user") ) {
108 if ( numinp-1 < i+1 ){
109 r2d2usage();
110 exit(-3);
111 };
112 user = (TString)inps[i+1];
113 };
114 if ( !strcmp(inps[i],"-psw") ) {
115 if ( numinp-1 < i+1 ){
116 r2d2usage();
117 exit(-3);
118 };
119 psw = (TString)inps[i+1];
120 };
121 //
122 if ( !strcmp(inps[i],"-runat") ) {
123 ruti = true;
124 if ( numinp-1 < i+1 ){
125 r2d2usage();
126 exit(-3);
127 };
128 runtime = (TString)inps[i+1];
129 };
130 //
131 if ( !strcmp(inps[i],"-convert") ) {
132 convert = true;
133 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
134 if ( numinp < i+2 ){
135 r2d2usage();
136 throw -3;
137 };
138 i += 2;
139 while ( strcmp(inps[i],"]") ){
140 if ( !strcmp(inps[i],"-tzone") ) {
141 if ( numinp-1 < i+1 ){
142 r2d2usage();
143 exit(-3);
144 };
145 tzone = (TString)inps[i+1];
146 };
147 if ( !strcmp(inps[i],"-dbtime") ) {
148 if ( numinp-1 < i+1 ){
149 r2d2usage();
150 exit(-3);
151 };
152 dbti = (UInt_t)atoll(inps[i+1]);
153 };
154 i++;
155 if ( i > numinp-1 ){
156 r2d2usage();
157 throw -3;
158 };
159 };
160 };
161 };
162 //
163 i++;
164 };
165 //
166 } else {
167 //
168 // no input parameters exit with error, we need at least the run id.
169 //
170 r2d2usage();
171 exit(-2);
172 };
173 //
174 // Connect to the DB
175 //
176 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
177 if( !dbc ) throw -2;
178 //
179 bool connect = dbc->IsConnected();
180 //
181 if( !connect ){
182 printf(" Error, not connected to DB\n");
183 exit(-1);
184 };
185 //
186 GL_ROOT *glroot = new GL_ROOT();
187 GL_RUN *glrun = new GL_RUN();
188 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
189 //
190 // At which date correspond the DB time "dbti"?
191 //
192 if ( convert ){
193 printf("\n Time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data());
194 };
195 //
196 // Which run contains the date "runtime"?
197 //
198 if ( ruti ){
199
200 };
201 //
202 // To which file the run "run" belongs?
203 //
204 if ( run != 0 ){
205 glrun->Clear();
206 error = glrun->Query_GL_RUN(run,dbc);
207 glroot->Clear();
208 error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
209 if ( error ){
210 printf(" Error querying the DB! \n");
211 exit(-4);
212 };
213 if ( !glrun->ID ){
214 printf("\n No run with ID=%u in the DB!\n",run);
215 } else {
216 printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
217 };
218 };
219 //
220 // Which runs are contained in the file "filename"?
221 //
222 if ( strcmp(filename.Data(),"") ){
223 TSQLResult *pResult;
224 TSQLRow *Row;
225 int t;
226 int r;
227 stringstream myquery;
228 // ----------------
229 Int_t ID = 0;
230 Int_t ID_RAW = 0;
231 //
232 const char *rawpath = "";
233 const char *rawname = "";
234 //
235 myquery.str("");
236 myquery << "select ";
237 myquery << " ID";
238 myquery << ",ID_RAW";
239 myquery << ",PATH";
240 myquery << ",NAME";
241 myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
242 pResult = dbc->Query(myquery.str().c_str());
243 if(!pResult->GetRowCount()) return (-51);
244 for( r=0; r < 1000; r++){
245 Row = pResult->Next();
246 if( Row == NULL ) break;
247 for( t = 0; t < pResult->GetFieldCount(); t++){
248 if(t==0) ID = atoi(Row->GetField(t));
249 if(t==1) ID_RAW = atoi(Row->GetField(t));
250 };
251 };
252 delete pResult;
253 if ( !ID && !ID_RAW ){
254 printf("\n No file with name %s in the DB!\n",filename.Data());
255 } else {
256 myquery.str("");
257 myquery << "select ";
258 myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
259 myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";
260 pResult = dbc->Query(myquery.str().c_str());
261 if(!pResult->GetRowCount()) return (-51);
262 for( r=0; r < 1000; r++){
263 Row = pResult->Next();
264 if ( !r && !Row ){
265 printf(" No run associated to the file %s \n",filename.Data());
266 };
267 if( Row == NULL ) break;
268 if ( !r ) printf("\n File %s contains the following runs: \n",filename.Data());
269 printf(" => %i -> Start at %s UTC end at %s UTC \n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime("UTC",(UInt_t)atoll(Row->GetField(1))).Data(),dbtime->ConvertTime("UTC",(UInt_t)atoll(Row->GetField(2))).Data());
270 };
271 delete pResult;
272 myquery.str("");
273 myquery << "select ";
274 myquery << " PATH,NAME";
275 myquery << " from GL_RAW where ID=" << ID_RAW << ";";
276 pResult = dbc->Query(myquery.str().c_str());
277 if(!pResult->GetRowCount()) return (-51);
278 for( r=0; r < 1000; r++){
279 Row = pResult->Next();
280 if( Row == NULL ) break;
281 for( t = 0; t < pResult->GetFieldCount(); t++){
282 if(t==0) rawpath = Row->GetField(t);
283 if(t==1) rawname = Row->GetField(t);
284 };
285 };
286 delete pResult;
287 printf(" File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
288 };
289 };
290 //
291 // Close the DB connection
292 //
293 if ( dbc ) dbc->Close();
294 //
295 printf("\n");
296 //
297 exit(0);
298 }

  ViewVC Help
Powered by ViewVC 1.1.23