1 |
// |
2 |
// EventViewer.cc -- standalone program to call the EventViewer macro. |
3 |
// by Emiliano Mocchiutti |
4 |
// |
5 |
// Version 1.00 (2005/11/07) |
6 |
// |
7 |
// Changelog: |
8 |
// |
9 |
// 0.00 - 1.00 : working. |
10 |
// |
11 |
#include <sys/stat.h> |
12 |
#include <TSystem.h> |
13 |
#include <iostream> |
14 |
#include <sys/types.h> |
15 |
#include <unistd.h> |
16 |
#include <stdio.h> |
17 |
// |
18 |
#include <FEventViewerCore.h> |
19 |
#include <FEVVerl2.h> |
20 |
// |
21 |
using namespace std; |
22 |
Bool_t NODB; |
23 |
// |
24 |
|
25 |
void usage(){ |
26 |
printf("\nUsage:\n\n EventViewer [-v] file selection_file output_dir \n"); |
27 |
printf("\n -v be verbose and do not fork after launching the GUI\n"); |
28 |
printf( " -file file must be in the form: /path/to/filesfromyoda/dw_000000_00000/ \n"); |
29 |
printf( " -selfile selection_file selection file, empty if no selection is required \n"); |
30 |
printf( " -outputDir outDir directory where to save figures\n"); |
31 |
printf( " -noDB do not DB connection in PamLevel2 (RUNINFO WILL NOT WORK!)\n"); |
32 |
printf("\nExamples: \n\nEventViewer /home/pamela/filesfromyoda/dw_050301_00100/ \"\" /home/pamela/\n"); |
33 |
printf( "EventViewer -v /home/pamela/filesfromyoda/dw_050301_00100/ muselection.c \"\"\n\n"); |
34 |
printf( "EventViewer \n\n"); |
35 |
printf( "EventViewer -v \n\n"); |
36 |
} |
37 |
|
38 |
// |
39 |
int main(int numinp, char *inps[]){ |
40 |
TString name = ""; |
41 |
TString selfile = ""; |
42 |
TString outdir = ""; |
43 |
bool beverbose = false; |
44 |
|
45 |
|
46 |
for (int i = 1; i < numinp; i++){ |
47 |
// -----------------------------------------------------// |
48 |
if (!strcmp(inps[i], "-file")){ |
49 |
name = (TString)inps[++i]; |
50 |
cout << "file "<<name.Data()<<endl; |
51 |
continue; |
52 |
} |
53 |
// -----------------------------------------------------// |
54 |
else if (!strcmp(inps[i], "-outputDir")){ |
55 |
outdir = (TString)inps[++i]; |
56 |
cout << "outputDir "<<outdir.Data()<<endl; |
57 |
continue; |
58 |
} |
59 |
// -----------------------------------------------------// |
60 |
else if (!strcmp(inps[i], "-selfile")){ |
61 |
selfile = (TString)inps[++i]; |
62 |
cout << "selfile "<<selfile.Data()<<endl; |
63 |
continue; |
64 |
} |
65 |
// -----------------------------------------------------// |
66 |
else if (!strcmp(inps[i], "-v")){ |
67 |
beverbose = true; |
68 |
continue; |
69 |
} |
70 |
// -----------------------------------------------------// |
71 |
else if (!strcmp(inps[i], "-h")){ |
72 |
beverbose = true; |
73 |
usage(); |
74 |
return(0); |
75 |
} |
76 |
else if (!strcmp(inps[i], "-noDB")){ |
77 |
NODB = true; |
78 |
continue; |
79 |
} |
80 |
else if (!strcmp(inps[i], "--version")){ |
81 |
FEVInfo(true); |
82 |
return(0); |
83 |
} |
84 |
}; |
85 |
// |
86 |
if ( !strcmp(name.Data(),"") ){ |
87 |
if ( numinp > 1 ){ |
88 |
if ( !strcmp(inps[1],"--version") ){ |
89 |
FEVInfo(true); |
90 |
return(0); |
91 |
}; |
92 |
if ( !strcmp(inps[1],"-h") || !strcmp(inps[1],"--help") || numinp>7 ){ |
93 |
usage(); |
94 |
return(0); |
95 |
}; |
96 |
if ( !strcmp(inps[1],"-v") || !strcmp(inps[1],"--verbose") ){ |
97 |
beverbose = true; |
98 |
if ( numinp >= 3 ) name = (TString)inps[2]; |
99 |
if ( numinp >= 4 ) selfile = (TString)inps[3]; |
100 |
if ( numinp == 5 ) outdir = (TString)inps[4]; |
101 |
} else { |
102 |
name = (TString)inps[1]; |
103 |
if ( numinp >= 3 ) selfile = (TString)inps[2]; |
104 |
if ( numinp >= 4 ) outdir = (TString)inps[3]; |
105 |
}; |
106 |
}; |
107 |
}; |
108 |
// |
109 |
// |
110 |
// |
111 |
if ( beverbose ){ |
112 |
ShowEvent(name,selfile,outdir); |
113 |
} else { |
114 |
// |
115 |
// redirect to dev/null the stdout |
116 |
// |
117 |
int nul; |
118 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IRUSR | S_IWUSR); |
119 |
dup2(nul,1); |
120 |
dup2(nul,2); |
121 |
close(nul); |
122 |
// |
123 |
printf("\n Welcome to the PAMELA event viewer! \n\n"); |
124 |
// |
125 |
// fork process |
126 |
// |
127 |
pid_t pid; |
128 |
if( (pid=fork()) == -1 ){ |
129 |
fprintf(stderr," Fork error. Exiting.\n"); |
130 |
return(1); |
131 |
}; |
132 |
if( !pid ) { |
133 |
ShowEvent(name,selfile,outdir); |
134 |
}; |
135 |
}; |
136 |
// |
137 |
return(0); |
138 |
} |