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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Thu Sep 7 09:47:08 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.5: +1 -1 lines
Adapted to profiler version v2r00

1 mocchiut 1.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 mocchiut 1.5 printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
36     printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n");
37     printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n");
38 mocchiut 1.3 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 mocchiut 1.4 printf("\n -runat [ -tzone timezone -time \"yyyy-mm-dd hh:mm:ss\" ] \n");
42     printf("\n returns run number which contains the given date in the given time zone \n");
43 mocchiut 1.1 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 mocchiut 1.3 UInt_t run = 0ULL;
59 mocchiut 1.1 //
60     TString filename = "";
61     //
62     TSQLServer *dbc = 0;
63     TString host = "mysql://localhost/pamelaprod";
64     TString user = "anonymous";
65     TString psw = "";
66 mocchiut 1.5 //
67     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
68     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
69     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
70     if ( strcmp(pamdbhost,"") ) host = pamdbhost;
71     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
72     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
73     //
74 mocchiut 1.6 // printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data());
75 mocchiut 1.5 //
76 mocchiut 1.3 TString tzone = "MSK";
77 mocchiut 1.4 TString tzone2 = "MSK";
78 mocchiut 1.3 TString runtime = "1970-01-01 00:00:00";
79     UInt_t dbti = 0;
80     Bool_t convert = false;
81     Bool_t ruti = false;
82 mocchiut 1.1 //
83 mocchiut 1.4 TSQLResult *pResult;
84     TSQLRow *Row;
85     int t;
86     int r;
87     stringstream myquery;
88 mocchiut 1.1 //
89     // Checking input parameters
90     //
91     Int_t i = 0;
92     if ( numinp > 1 ){
93     while ( i < numinp ){
94     if ( !strcmp(inps[i],"--version") ){
95     DarthVaderInfo(true);
96     exit(0);
97     };
98     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
99     r2d2usage();
100     exit(0);
101     };
102     if ( !strcmp(inps[i],"-idRun") ) {
103     if ( numinp-1 < i+1 ) {
104     r2d2usage();
105     exit(-3);
106     };
107 mocchiut 1.3 run = (UInt_t)atoll(inps[i+1]);
108 mocchiut 1.1 };
109     if ( !strcmp(inps[i],"-filename") ) {
110     if ( numinp-1 < i+1 ){
111     r2d2usage();
112     exit(-3);
113     };
114     filename = (TString)inps[i+1];
115     };
116     if ( !strcmp(inps[i],"-host") ) {
117     if ( numinp-1 < i+1 ){
118     r2d2usage();
119     exit(-3);
120     };
121     host = (TString)inps[i+1];
122     };
123     if ( !strcmp(inps[i],"-user") ) {
124     if ( numinp-1 < i+1 ){
125     r2d2usage();
126     exit(-3);
127     };
128     user = (TString)inps[i+1];
129     };
130     if ( !strcmp(inps[i],"-psw") ) {
131     if ( numinp-1 < i+1 ){
132     r2d2usage();
133     exit(-3);
134     };
135     psw = (TString)inps[i+1];
136     };
137 mocchiut 1.3 //
138     if ( !strcmp(inps[i],"-convert") ) {
139     convert = true;
140     if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
141     if ( numinp < i+2 ){
142     r2d2usage();
143     throw -3;
144     };
145     i += 2;
146     while ( strcmp(inps[i],"]") ){
147     if ( !strcmp(inps[i],"-tzone") ) {
148     if ( numinp-1 < i+1 ){
149     r2d2usage();
150     exit(-3);
151     };
152     tzone = (TString)inps[i+1];
153     };
154     if ( !strcmp(inps[i],"-dbtime") ) {
155     if ( numinp-1 < i+1 ){
156     r2d2usage();
157     exit(-3);
158     };
159     dbti = (UInt_t)atoll(inps[i+1]);
160     };
161     i++;
162     if ( i > numinp-1 ){
163     r2d2usage();
164     throw -3;
165     };
166     };
167     };
168     };
169     //
170 mocchiut 1.4 if ( !strcmp(inps[i],"-runat") ) {
171     ruti = true;
172     if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
173     if ( numinp < i+2 ){
174     r2d2usage();
175     throw -3;
176     };
177     i += 2;
178     while ( strcmp(inps[i],"]") ){
179     if ( !strcmp(inps[i],"-tzone") ) {
180     if ( numinp-1 < i+1 ){
181     r2d2usage();
182     exit(-3);
183     };
184     tzone2 = (TString)inps[i+1];
185     };
186     if ( !strcmp(inps[i],"-time") ) {
187     if ( numinp-1 < i+1 ){
188     r2d2usage();
189     exit(-3);
190     };
191     runtime = (TString)inps[i+1];
192     };
193     i++;
194     if ( i > numinp-1 ){
195     r2d2usage();
196     throw -3;
197     };
198     };
199     };
200     };
201     //
202 mocchiut 1.1 i++;
203     };
204     //
205     } else {
206     //
207     // no input parameters exit with error, we need at least the run id.
208     //
209     r2d2usage();
210     exit(-2);
211     };
212     //
213     // Connect to the DB
214     //
215     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
216     if( !dbc ) throw -2;
217     //
218     bool connect = dbc->IsConnected();
219     //
220     if( !connect ){
221     printf(" Error, not connected to DB\n");
222     exit(-1);
223     };
224     //
225     GL_ROOT *glroot = new GL_ROOT();
226     GL_RUN *glrun = new GL_RUN();
227 mocchiut 1.3 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
228     //
229     // At which date correspond the DB time "dbti"?
230     //
231     if ( convert ){
232 mocchiut 1.4 printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data());
233 mocchiut 1.3 };
234 mocchiut 1.1 //
235 mocchiut 1.3 // Which run contains the date "runtime"?
236     //
237     if ( ruti ){
238 mocchiut 1.4 //
239     TDatime *time = new TDatime(runtime.Data());
240     UInt_t dbti = time->Convert();
241     //
242     TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti);
243     //
244     TDatime *time2 = new TDatime(thetime.Data());
245     UInt_t mytime = time2->Convert();
246     //
247     myquery.str("");
248     myquery << "select ";
249     myquery << " ID ";
250     myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
251     << " RUNTRAILER_TIME>=" << mytime << " ;";
252     // printf("myquery is %s \n",myquery.str().c_str());
253     pResult = dbc->Query(myquery.str().c_str());
254     for( r=0; r < 1000; r++){
255     Row = pResult->Next();
256     if ( !r && !Row ){
257     printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime);
258     };
259     if( Row == NULL ) break;
260     printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone2.Data(),mytime,(UInt_t)atoll(Row->GetField(0)));
261     };
262 mocchiut 1.3 };
263     //
264     // To which file the run "run" belongs?
265     //
266     if ( run != 0 ){
267     glrun->Clear();
268 mocchiut 1.1 error = glrun->Query_GL_RUN(run,dbc);
269 mocchiut 1.3 glroot->Clear();
270     error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
271 mocchiut 1.1 if ( error ){
272     printf(" Error querying the DB! \n");
273     exit(-4);
274     };
275 mocchiut 1.3 if ( !glrun->ID ){
276     printf("\n No run with ID=%u in the DB!\n",run);
277     } else {
278     printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
279     };
280 mocchiut 1.1 };
281 mocchiut 1.3 //
282     // Which runs are contained in the file "filename"?
283     //
284 mocchiut 1.1 if ( strcmp(filename.Data(),"") ){
285     // ----------------
286     Int_t ID = 0;
287     Int_t ID_RAW = 0;
288     //
289 mocchiut 1.2 const char *rawpath = "";
290     const char *rawname = "";
291 mocchiut 1.1 //
292     myquery.str("");
293     myquery << "select ";
294     myquery << " ID";
295     myquery << ",ID_RAW";
296     myquery << ",PATH";
297     myquery << ",NAME";
298     myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
299     pResult = dbc->Query(myquery.str().c_str());
300     for( r=0; r < 1000; r++){
301     Row = pResult->Next();
302     if( Row == NULL ) break;
303     for( t = 0; t < pResult->GetFieldCount(); t++){
304     if(t==0) ID = atoi(Row->GetField(t));
305     if(t==1) ID_RAW = atoi(Row->GetField(t));
306     };
307     };
308     delete pResult;
309 mocchiut 1.3 if ( !ID && !ID_RAW ){
310     printf("\n No file with name %s in the DB!\n",filename.Data());
311     } else {
312     myquery.str("");
313     myquery << "select ";
314     myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
315     myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";
316     pResult = dbc->Query(myquery.str().c_str());
317     for( r=0; r < 1000; r++){
318     Row = pResult->Next();
319     if ( !r && !Row ){
320 mocchiut 1.4 printf("\n No run associated to the file %s \n",filename.Data());
321 mocchiut 1.3 };
322     if( Row == NULL ) break;
323 mocchiut 1.4 if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data());
324     printf(" => ID = %i _-_-_ the run started at %s UTC ended at %s UTC \n\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());
325 mocchiut 1.1 };
326 mocchiut 1.3 delete pResult;
327     myquery.str("");
328     myquery << "select ";
329     myquery << " PATH,NAME";
330     myquery << " from GL_RAW where ID=" << ID_RAW << ";";
331     pResult = dbc->Query(myquery.str().c_str());
332     for( r=0; r < 1000; r++){
333     Row = pResult->Next();
334     if( Row == NULL ) break;
335     for( t = 0; t < pResult->GetFieldCount(); t++){
336     if(t==0) rawpath = Row->GetField(t);
337     if(t==1) rawname = Row->GetField(t);
338     };
339 mocchiut 1.1 };
340 mocchiut 1.3 delete pResult;
341 mocchiut 1.4 printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
342 mocchiut 1.1 };
343     };
344     //
345     // Close the DB connection
346     //
347     if ( dbc ) dbc->Close();
348     //
349     printf("\n");
350     //
351     exit(0);
352     }

  ViewVC Help
Powered by ViewVC 1.1.23