--- calo/flight/FQLOOK/src/FCaloQLOOK.cc 2006/03/13 09:01:26 1.2 +++ calo/flight/FQLOOK/src/FCaloQLOOK.cc 2006/09/22 13:38:59 1.6 @@ -10,78 +10,138 @@ // #include #include +#include #include #include #include // -extern void FCaloQLOOK(TString, int, int, TString, TString); +extern void FCaloQLOOK(TString, int, int, TString, TString, Bool_t, Bool_t); extern void info(); +extern void stringcopy(TString& , const TString& , Int_t , Int_t ); using namespace std; // void usage(){ - printf("\nUsage:\n\n FCaloQLOOK [-v] file from_event to_event output_dir figure_format \n"); - printf("\n -v be verbose \n"); - printf( " file must be in the form: /path/to/filesfromyoda/dw_000000_00000/ \n"); - printf( " from_event is an integer (progressive number) \n"); - printf( " to_event is an integer (progressive number) \n"); - printf( " output_dir directory where to store figures \n"); - printf( " figure format any format recognized by ROOT (ps,eps,gif,...)\n"); - printf("\nExample: \n\nFCaloQLOOK /home/pamela/filesfromyoda/dw_050301_00100/ 0 0 /tmp/ ps \n\n"); + printf("\nUsage:\n\n FCaloQLOOK [-name] file [OPTIONS] \n"); + printf("\n file must be in the form: /path/to/filesfromyoda/ZZZ_XXX_YYYYY_cln2.root \n"); + printf( " if in the first position \"-name\" can be omitted. \n"); + printf("\n OPTIONS: \n"); + printf("\n -v be verbose \n"); + printf( " -fromev from_event first event to analyze [default = 0] \n"); + printf( " -toev to_event last event to analyze [default = 0] \n"); + printf( " -oudDir output_dir path of the output directory [default = ./] (with or without final '/') \n"); + printf( " -format format format for output file (without . )[default = png] \n"); + printf( " -interactive shows figures on the screen [default = non-interactive] \n"); + printf( " -wait wait for canvas to be closed before going on [default = don't wait] \n"); + printf("\nExamples: "); + printf("\n\nFCaloQLOOK /home/pamela/filesfromyoda/dw_050301_00100.root \n"); + printf("\nFCaloQLOOK -v -name /home/pamela/filesfromyoda/dw_050301_00100.root \n"); + printf("\nFCaloQLOOK /home/pamela/filesfromyoda/DW_050523_01600.root -v -fromev 0 -toev 0 -outDir /tmp/ -format gif \n\n"); } int main(int numinp, char *inps[]){ TString name; - TString outdir = ""; - TString format = "ps"; + TString outdir = "./"; + TString format = "png"; int fromev = 0; int toev = 0; int nul = 0; bool beverbose = false; - if ( numinp == 1 ){ - usage(); - return(0); - }; + Bool_t iactive = false; + Bool_t w4i = false; + // if ( numinp > 1 ){ - if ( !strcmp(inps[1],"--version") ){ - info(); - return(0); - }; - if ( !strcmp(inps[1],"-h") || !strcmp(inps[1],"--help") || numinp>7 ){ - usage(); - return(0); - } else { - if ( !strcmp(inps[1],"-v") || !strcmp(inps[1],"--verbose") ){ - beverbose = true; - if ( numinp == 2 ) { - info(); - return(0); + name = (TString)inps[1]; + for ( int i = 0; i < numinp; i++ ){ + + if ( !strcmp(inps[i],"--version") ){ + info(); + return(0); + }; + if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ + usage(); + return(0); + }; + if ( !strcmp(inps[i],"-name") ) { + if ( numinp-1 < i+1 ){ + usage(); + exit(-3); + }; + name = (TString)inps[i+1]; + }; + if ( !strcmp(inps[i],"-outDir") ) { + if ( numinp-1 < i+1 ){ + usage(); + exit(-3); }; - if ( numinp >= 3 ) name = (TString)inps[2]; - if ( numinp >= 4 ) fromev = atoi(inps[3]); - if ( numinp >= 5 ) toev = atoi(inps[4]); - if ( numinp >= 6 ) outdir = (TString)inps[5]; - if ( numinp == 7 ) format = (TString)inps[6]; - } else { - if ( numinp >= 2 ) name = (TString)inps[1]; - if ( numinp >= 3 ) fromev = atoi(inps[2]); - if ( numinp >= 4 ) toev = atoi(inps[3]); - if ( numinp >= 5 ) outdir = (TString)inps[4]; - if ( numinp == 6 ) format = (TString)inps[5]; + outdir = (TString)inps[i+1]; }; + if ( !strcmp(inps[i],"-format") ) { + if ( numinp-1 < i+1 ){ + usage(); + exit(-3); + }; + format = (TString)inps[i+1]; + }; + + if ( !strcmp(inps[i],"-fromev") ) { + if ( numinp-1 < i+1 ){ + usage(); + exit(-3); + }; + fromev = atoi(inps[i+1]); + }; + if ( !strcmp(inps[i],"-toev") ) { + if ( numinp-1 < i+1 ){ + usage(); + exit(-3); + }; + toev = atoi(inps[i+1]); + }; + if ( !strcmp(inps[i],"-interactive") ) { + iactive = true; + }; + if ( !strcmp(inps[i],"-wait") ) { + w4i = true; + }; + if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; }; + } else { + // + // no input parameters exit with error, we need at least the run id. + // + usage(); + return(0); }; // if ( !beverbose ){ // + const string fil = gSystem->BaseName(name.Data()); + Int_t posiz = fil.find(".root"); + // + TString file2; + if ( posiz == -1 ){ + file2 = gSystem->BaseName(name.Data()); + } else { + Int_t posiz2 = 0; + stringcopy(file2,gSystem->BaseName(name.Data()),posiz2,posiz); + }; + const char *figrec = file2; + // + const char *outDir = outdir; + stringstream figsave; + figsave.str(""); + figsave << outDir << "/" ; + figsave << figrec << "_CaloQLOOK.txt"; + // // redirect to /dev/null the stdout and stderr // - nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); + nul = open(figsave.str().c_str(), O_CREAT | O_RDWR,S_IREAD | S_IWRITE); dup2(nul,1); dup2(nul,2); }; printf("\n Welcome to FCaloQLOOK! \n"); // - FCaloQLOOK(name,fromev,toev,outdir,format); + FCaloQLOOK(name,fromev,toev,outdir,format,iactive,w4i); // if ( !beverbose ) close(nul); //