FlyoDoc_2011 Pisa 2011 by GmP --- 011
|
00001 /*************************************************************************** 00002 filemg.cpp - description 00003 ------------------- 00004 begin : Sun Dec 10 2000 00005 copyright : (C) 2000 by Giuseppe M Pierazzini 00006 email : pierazzini@unipi.it 00007 *************************************************************************** 00008 * * 00009 * NA48 simulation program. * 00010 * * 00011 ***************************************************************************/ 00012 00013 // CP violation program...... in Obj!! Tirrenia 27.07.00 00014 00015 //----------------------------------------------------------- 00016 #include "parm.h" 00017 #include "ctype.h" 00018 #include "evento.h" 00019 #include <getopt.h> 00020 #include <dirent.h> /* Directory information. */ 00021 00022 //----------------------------------------------------------- 00029 using namespace std; 00030 00031 00032 00033 void Print_Help() 00034 { 00035 printf ( "\nUsage: Flyo [-opzioni] " ); 00036 printf ( "\n\t-h Help: write this help message" ); 00037 printf ( "\n\t-p Pipeline yes/si/no [no] " ); 00038 printf ( "\n*\t-i InPath/input_file " ); 00039 printf ( "\n*\t-d OutPath directory " ); 00040 printf ( "\n*\t-t Data out type: root,hroot,null" ); 00041 printf ( "\n\t-r run number" ); 00042 printf ( "\n\t-e Max event number" ); 00043 printf ( "\n\t-b First gas_reaction to be read from file" ); 00044 printf ( "\n\nnote:\t* field could not be empty!" ); 00045 printf ( "\n\tdefine the absolute paths or \n\trelative to the Flyo working directory" ); 00046 printf ( "\n\tThe apparatus file is usully included at the end of epc file." ); 00047 printf ( "\n -------- end ------" ); 00048 printf ( "\n" ); 00049 exit ( 0 ); 00050 } 00051 //---------------------------------------------------------- 00052 void File_Manager() 00053 { 00054 // char *OutDir=0; 00055 string Versione="V 2010 Psa " ; 00056 printf ( "\n----------------------------------------------------------------" ); 00057 printf ( "\n ************************************************************** " ); 00058 printf ( "\n**** Pisa 2006 ****" ); 00059 printf ( "\n*** ***" ); 00060 printf ( "\n** C++ F L Y O Running **" ); 00061 printf ( "\n*** ***" ); 00062 printf ( "\n**** < by GmP/LF/SG/Am > ****" ); 00063 printf ( "\n ************************************************************** " ); 00064 printf ( "\n **" ); 00065 // 00066 00067 00068 if ( gargc<2 ) 00069 { 00070 cout <<"\n Input error: no input parameters...\n"; 00071 Print_Help(); 00072 } 00073 00074 int inparm=0; 00075 00076 00077 int o; 00078 while ( ( o = getopt ( gargc, gargv, "p:d:i:t:r:e:b:l:h" ) ) !=-1 ) 00079 { 00080 switch ( o ) 00081 { 00082 case 'h': 00083 Print_Help(); 00084 break; 00085 00086 case 'p': 00087 if ( strncmp ( optarg,"si",2 ) ==0 ) Pipeline=1; 00088 if ( strncmp ( optarg,"yes",2 ) ==0 ) Pipeline=1; 00089 cout<< "\n Pipeline status ==> "<< ( Pipeline?"on":"off" ); 00090 //Pipeline time window =0.250 ns fixed in tempo.h 00091 fflush ( stdout ); 00092 break; 00093 00094 00095 case 'd': 00096 OutDir= new char[strlen ( optarg ) +2]; 00097 strcpy ( OutDir,optarg ); 00098 printf ( "\n Output Directory by operator ==> %s",OutDir ); 00099 inparm++; 00100 break; 00101 00102 case 'b': 00103 GasBegin= atol ( optarg ); 00104 printf ( "\n First Gas event from file ==> %d",GasBegin ); 00105 inparm++; 00106 break; 00107 00108 case 'i': 00109 Cardin= new char[strlen ( optarg ) +2]; 00110 strcpy ( Cardin,optarg ); 00111 printf ( "\n Input file by operator ==> %s",Cardin ); 00112 inparm++; 00113 break; 00114 00115 case 't': 00116 Wrt_type_out=optarg; 00117 cout<<"\n Data out type ==> "<<Wrt_type_out; 00118 break; 00119 00120 case 'r': 00121 evento_.Gen.Run = atol ( optarg ); 00122 printf ( "\n Run num. defined by operator ==> %d", evento_.Gen.Run ); 00123 fflush ( stdout ); 00124 break; 00125 00126 case 'e': 00127 evento_.Mxev= atol ( optarg ); 00128 printf ( "\n MaxEvents defined by operator ==> %d",evento_.Mxev ); 00129 fflush ( stdout ); 00130 break; 00131 00132 default: 00133 printf ( "errore nella linea di comando\n" ); 00134 exit ( -1 ); 00135 break; 00136 } 00137 } 00138 if ( inparm<2 ) 00139 { 00140 cout<<"\n\n\n Error: Not enough input parameters!"; 00141 Print_Help(); 00142 } 00143 cout<<"\n------ End input parsing --------"<<endl; 00144 00145 // get run by string 00146 stringstream ostr; 00147 string Srun; 00148 ostr<<evento_.Gen.Run; 00149 ostr>>Srun; 00150 00151 //============= define the nt files or the binary file ================== 00152 // default out file dipendente dal run ... 00153 // char *OutGn_byrun=new char[256]; 00154 00155 string OutGn_byrun; 00156 00157 if ( Wrt_type_out=="root" ) 00158 { 00159 OutGn_byrun= "Fly_"+Srun+".root"; 00160 // sprintf ( OutGn_byrun,"fly_%d.root",evento_.Gen.Run ); 00161 Wrtype=1; 00162 } 00163 else if ( Wrt_type_out=="hroot" ) 00164 { 00165 OutGn_byrun= "Fly_h"+Srun+".root"; 00166 00167 // sprintf ( OutGn_byrun,"fly_h%d.root",evento_.Gen.Run ); 00168 Wrtype=2; 00169 } 00170 else if ( Wrt_type_out=="null" ) 00171 { 00172 OutGn_byrun= "Fly_null"+Srun+".root"; 00173 // sprintf ( OutGn_byrun,"fly_null%d.gn",evento_.Gen.Run ); 00174 Wrtype=0; 00175 } 00176 else if ( Wrt_type_out=="paw" ||Wrt_type_out=="hpaw" ) 00177 { 00178 cout<<" \n Attenzione.... Paw รจ obsoleto..si usa root: exit!?"<<endl ; 00179 exit ( 0 ); 00180 } 00181 00182 else 00183 { 00184 printf ( "\n ERROR File di output non defined, \n Pls set \" -t root, hroot or null\" in command line!" ); 00185 exit ( 0 ); 00186 00187 } 00188 00189 00190 if ( OutDir ) 00191 { 00192 check_file_name ( OutDir,OutGn_byrun ); 00193 sprintf ( OutGn,"%s/%s",OutDir,OutGn_byrun.c_str() ); // Flyo running 00194 } 00195 else 00196 { 00197 check_file_name ( ".",OutGn_byrun ); 00198 00199 sprintf ( OutGn,"./%s",OutGn_byrun.c_str() ); 00200 } 00201 cout<<"\n Results file (by run): ==> "<<OutGn_byrun; 00202 // define the nt out dir/file 00203 cout<<"\n Out location (list,hbook...): ==> "<<OutDir; 00204 cout<<"\n Program name: ==> "<<gargv[0]; 00205 cout<<"\n Program Version: ==> "<<Versione; 00206 cout<< "\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" ; 00207 cout<<"\n ===================================================\n"; 00208 00209 //============= define the output list file================= 00210 00211 // char *Lista_nome=new char[256]; 00212 00213 string Serie; 00214 Serie=OutGn_byrun; 00215 string Lista_nome; 00216 Lista_nome=OutDir; 00217 if ( OutDir ) 00218 { 00219 Serie=Serie.substr ( Serie.find ( "." ) +1,Serie.size() ); 00220 Serie=Serie.substr ( 0,Serie.find ( "." ) ); 00221 Lista_nome+="/list"+Srun+"."+Serie+".txt"; 00222 } 00223 else Lista_nome ="list"+Srun+"."+Serie+".txt"; //default 00224 00225 // redirect the standard output to the file Lista 00226 cout<< "\n You may continue to read the Flyo output lista in\n ==> "<<Lista_nome; 00227 cout<< "\n -----------------------------\n" ; 00228 00229 //*********************************************************************************** 00230 //********************************************************************************* 00231 // uscita in list di debug.... 00232 //*************************************** 00233 Gout.open ( Lista_nome.c_str() ,ios::out ); 00234 00235 //******************************** 00236 if ( Gout ) 00237 { 00238 Gout<<"\n----------------------------------------------------------------"; 00239 Gout<<"\n ************************************************************** "; 00240 Gout<<"\n**** Pisa 2006 ****"; 00241 Gout<<"\n*** ***"; 00242 Gout<<"\n** C++ F L Y O Running **"; 00243 Gout<<"\n*** ***"; 00244 Gout<<"\n**** < by GmP/LF/SG/Am > ****"; 00245 Gout<<"\n ************************************************************** "; 00246 Gout<<"\n **"; 00247 Gout<<"\n Program name: ==> "<<gargv[0]; 00248 Gout<<"\n Program Version: ==> "<<Versione; 00249 if ( OutDir ) Gout<<"\n Output Directory by operator ==> "<<OutDir; 00250 if ( Cardin ) Gout<<"\n Input file by operator ==> "<<Cardin; 00251 if ( evento_.Gen.Run ) Gout<<"\n Run number ==> "<<evento_.Gen.Run; 00252 if ( evento_.Mxev ) Gout<<"\n MaxEvents ==> "<<evento_.Mxev; 00253 } 00254 Gout<<"\n ----------"; 00255 00256 //============= data output file ================== 00257 00258 Gout<<"\n Out data file : ==> "<<OutGn; 00259 Gout<<"\n ==============\n"; 00260 Gout<<"\n Output list: ==> "<<Lista_nome; 00261 time_t tck; 00262 time_t clockstart=time ( &tck ); 00263 Gout<<"\n Flyo starts output list ==> "<<ctime ( &clockstart ); 00264 Gout<<"\n Flyo input base .epc file ==> "<<Cardin; 00265 00267 Legge_input_file ( Cardin ); 00268 // end reading input files...... 00269 00270 } 00271 00272 00273 void check_file_name ( const char *outdir, string &filename ) 00274 { 00275 // Inserisce una flag di serie nelle file di uscita per non sovrascrivere le vecchie... 00276 /* Open the current directory */ 00277 DIR *dir_p; 00278 struct dirent *dir_entry_p; 00279 dir_p = opendir ( outdir ); 00280 string dirfile, dpref,dserie,dsuff; 00281 00282 string prefisso, suffisso,inputfile; 00283 int serie=-1; 00284 // filename // tipo fly_Run.root 00285 prefisso=filename.substr ( 0,filename.find ( "." ) ); // fly_Run 00286 suffisso=filename.substr ( filename.find ( "." ) +1,filename.size() );// root 00287 while ( 0 != ( dir_entry_p = readdir ( dir_p ) ) ) 00288 { 00289 dirfile= dir_entry_p->d_name; //tipo fly_Run.xx.root 00290 int dpos1=dirfile.find ( "." ); 00291 int dpos2=dirfile.rfind ( "." ); 00292 dpref=dirfile.substr ( 0,dpos1 ); // fly_Run 00293 if ( dpos2>dpos1 ) 00294 dserie=dirfile.substr ( dpos1+1,dpos2-dpos1-1 ); // xx 00295 else dserie=""; 00296 dsuff=dirfile.substr ( dpos2+1,dirfile.size() ); // root 00297 00298 if ( dpref==prefisso&& dsuff==suffisso ) 00299 { 00300 // estraggo la serie e ricordo la massima 00301 stringstream ostr; 00302 ostr<<dserie; 00303 int lets=0; 00304 ostr>>lets; 00305 if ( lets>serie ) serie=lets; 00306 } 00307 00308 } 00309 closedir ( dir_p ); 00310 // if (serie>-1) 00311 // { 00312 // aggiungo la serie+1 al filename. 00313 serie++; 00314 dserie=""; 00315 inputfile=""; 00316 stringstream ostr; 00317 ostr<<serie; 00318 ostr>>dserie; 00319 inputfile= prefisso+"."+dserie+"."+suffisso; 00320 filename=inputfile; 00321 // } 00322 00323 }