1 |
/** |
2 |
* FTrkCalibQLook_BASIC.cc |
3 |
* |
4 |
* autor: D.Fedele |
5 |
* version v1r07 |
6 |
* Parameters: |
7 |
* file - path of the root file to analyze (give at least this parameter) |
8 |
* fromevent - first event to analyze |
9 |
* toevent - last event to analyze |
10 |
* outDir - total path of output file |
11 |
* format - extension of output file (pdf,ps,gif,jpg) |
12 |
* |
13 |
*/ |
14 |
#include <TString.h> |
15 |
#include <fcntl.h> |
16 |
#include <unistd.h> |
17 |
|
18 |
extern void FTrkCalibQLook_BASIC(TString file, Int_t fromevent, Int_t toevent, TString outdir, TString format); |
19 |
extern void info(); |
20 |
|
21 |
void usage(){ |
22 |
printf("\nUsage:\n FTrkCalibQLook_BASIC file [OPTIONS] \n\n"); |
23 |
printf("\t --help: print this help and exit \n"); |
24 |
printf("\t file: path of the root file to analyze (give at least this parameter) \n"); |
25 |
printf("\nOPTIONS:\n"); |
26 |
printf("\t -v: be verbose \n"); |
27 |
printf("\t -fromev: first event to analyze [default = 0] \n"); |
28 |
printf("\t -toev: last event to analyze [default = 0] \n"); |
29 |
printf("\t -outDir: path of the output directory [default = ./] (with or without final '/')\n"); |
30 |
printf("\t -format: format for output file (without . )[default = pdf] (accepted formats: pdf, ps, png, jpg, gif)\n"); |
31 |
printf("\nExamples:\n\tFTrkCalibQLook_BASIC /home/pamela/filesfromyoda/DW_050523_01600.root -v \n\n"); |
32 |
printf("\tFTrkCalibQLook_BASIC /home/pamela/filesfromyoda/DW_050523_01600.root -v -format jpg\n\n"); |
33 |
printf("\tFTrkCalibQLook_BASIC /home/pamela/filesfromyoda/DW_050523_01600.root -v -format jpg -outDir ~/tmp/ \n\n"); |
34 |
} |
35 |
|
36 |
|
37 |
int main(int argc, char* argv[]){ |
38 |
|
39 |
TString FILE,OUTDIR="./",FORMAT="pdf"; |
40 |
Int_t FROMEVENT=0,TOEVENT=0; |
41 |
bool beverbose = false; |
42 |
int nul = 0; |
43 |
|
44 |
if(argc>1){ |
45 |
if ( !strcmp(argv[1],"--version") ){ |
46 |
info(); |
47 |
return(0); |
48 |
}; |
49 |
if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || argc>11){ |
50 |
usage(); |
51 |
return(0); |
52 |
} |
53 |
if ( (!strcmp(argv[1],"-v") || !strcmp(argv[1],"--verbose"))&& argc == 2 ){ |
54 |
info(); |
55 |
return(0); |
56 |
} |
57 |
else { |
58 |
|
59 |
FILE = argv[1]; |
60 |
for(int i=2; i<argc;i++){ |
61 |
|
62 |
if ( !strcmp(argv[i],"-v") || !strcmp(argv[i],"--verbose") ) |
63 |
beverbose = true; |
64 |
|
65 |
if (!strcmp(argv[i], "-outDir")){ |
66 |
if (++i >= argc || !strcmp(argv[i],"-v") || !strcmp(argv[i], "-format") || !strcmp(argv[i], "-fromev") || !strcmp(argv[i], "-toev")){ |
67 |
printf( "\n-outDir needs arguments. \n"); |
68 |
usage(); |
69 |
return(0); |
70 |
} |
71 |
else{ |
72 |
OUTDIR = argv[i]; |
73 |
continue; |
74 |
} |
75 |
} |
76 |
|
77 |
if (!strcmp(argv[i], "-fromev")){ |
78 |
if (++i >= argc || !strcmp(argv[i],"-v") || !strcmp(argv[i], "-format") || !strcmp(argv[i], "-toev") || !strcmp(argv[i], "-outDir")){ |
79 |
printf( "\n-fromev needs arguments. \n"); |
80 |
usage(); |
81 |
return(0); |
82 |
} |
83 |
else{ |
84 |
FROMEVENT = atoi(argv[i]); |
85 |
continue; |
86 |
} |
87 |
} |
88 |
|
89 |
if (!strcmp(argv[i], "-toev")){ |
90 |
if (++i >= argc || !strcmp(argv[i],"-v") || !strcmp(argv[i], "-format") || !strcmp(argv[i], "-fromev") || !strcmp(argv[i], "-outDir")){ |
91 |
printf( "\n-toev needs arguments. \n"); |
92 |
usage(); |
93 |
return(0); |
94 |
} |
95 |
else{ |
96 |
TOEVENT = atoi(argv[i]); |
97 |
continue; |
98 |
} |
99 |
} |
100 |
|
101 |
if (!strcmp(argv[i], "-format")){ |
102 |
if (++i >= argc || !strcmp(argv[i],"-v") || !strcmp(argv[i], "-fromev") || !strcmp(argv[i], "-toev") || !strcmp(argv[i], "-outDir")){ |
103 |
printf( "\n-format needs arguments. \n"); |
104 |
usage(); |
105 |
return(0); |
106 |
} |
107 |
else{ |
108 |
FORMAT = argv[i]; |
109 |
continue; |
110 |
} |
111 |
} |
112 |
|
113 |
if(strcmp(argv[i], "-format") && strcmp(argv[i], "-outDir") && strcmp(argv[i],"-v") && strcmp(argv[i],"--verbose") && strcmp(argv[i], "-fromev") && strcmp(argv[i], "-toev") ){ |
114 |
printf( "\n------>Warning: WRONG OPTIONS!\n"); |
115 |
usage(); |
116 |
return(0); |
117 |
} |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
else if(argc==1){ |
123 |
printf("\n\tYou have to insert at least the file to analyze \n"); |
124 |
usage(); |
125 |
return(0); |
126 |
} |
127 |
if ( !beverbose ){ |
128 |
// |
129 |
// redirect to /dev/null the stdout and stderr |
130 |
// |
131 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
132 |
dup2(nul,1); |
133 |
dup2(nul,2); |
134 |
}; |
135 |
printf("\n Welcome to FTrkCalibQLook_BASIC! \n\n"); |
136 |
// |
137 |
FTrkCalibQLook_BASIC(FILE,FROMEVENT,TOEVENT,OUTDIR,FORMAT); |
138 |
// |
139 |
if ( !beverbose ) close(nul); |
140 |
return(0); |
141 |
} |
142 |
|