--- PamelaDigitizer/Pamelagp2Digits.cxx 2008/12/18 17:11:47 1.12 +++ PamelaDigitizer/Pamelagp2Digits.cxx 2009/10/16 09:15:51 1.14 @@ -9,23 +9,28 @@ // // // HOWTO (RECOMMENDED): -// ./ Pamelagp2Digits filename.his +// ./ Pamelagp2Digits -hbookfile filename.his // It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info) // // NB: more details are present in the file HOW-TO-DIGIT.TXT // -// HOWTO (only for testing purposes) -// Pamelagp2Digits hbook_filename root_filename raw_filename compress tolower -// - If the 2nd and 3rd parameters are missing the names are generated from the hbook file name. -// - The following flags are from h2root and default values are used: -// if compress is missing (or = 1) the ROOT file will be compressed -// if compress = 0 the ROOT file will not be compressed. -// if tolower is missing (or = 1) ntuple column names are converted to lower case -// but the first character is converted to upper case. -// if tolower = 2 same as tolower=1 except that the first character is also +// HOWTO +// see usage(). Example: +// Pamelagp2Digits -hbookfile filename.his -rootfile filename.root -pamfile filename.pam -calocompress [VAL] -rootcompress [VAL] +// The following flags are from h2root and default values are used: +// if rootcompress is missing (or = 1) the ROOT file will be compressed +// if rootcompress = 0 the ROOT file will not be compressed. +// if tolower is missing (or = 1) ntuple column names are converted to lower case +// but the first character is converted to upper case. +// if tolower = 2 same as tolower=1 except that the first character is also // convertex to lower case // +// // MODIFICATIONS: +// (C.Pizzolotto. Trieste. october 2009) +// - added DigitizeCALOCOMPRESS to write calorimeter data in compress mode +// - changed way of reading input parameters. now the input order is not important. +// // v. 1.5 (S.Orsi, Roma2, 11 October 2007) // - file HOW-TO-DIGIT.TXT written (mainly by S.Bottai): contains information on how to run the chain from the DB creation to DarthVader through Digitizer, yoda and YodaProfiler // @@ -106,6 +111,7 @@ int ncx,ncy,nwt,idb; int lcont, lcid, lcdir; float xmin,xmax,ymin,ymax; +int comprcalomode; const Int_t kMIN1 = 7; const Int_t kMAX1 = 8; @@ -266,71 +272,175 @@ char *DigitizerInfo(bool print); -int main(int argc, char **argv) -{ - // char* cha=DigitizerInfo(1); - if (argc < 2) { - printf("Error: Pamelagp2Digits \n"); - printf("Pamelagp2Digits file.hbook file.root file.pam [compress] [tolower] [lrecl] [bufsize] [optcwn] \n"); - printf(" if file.root is not given it will be = file.root\n"); - printf(" compress = 1 by default (use 0 for no compression)\n"); - printf(" tolower = 1 by default (use 0 to keep case of column names)\n"); - printf(" lrecl =0 by default (must be specified if >8092)\n"); - printf(" bufsize = 8000 by default (branch buffer size)\n"); - printf(" for cwn ntuple only: optcwn = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n"); - return 1; - } +void usage(){ + printf("\nUsage:\n"); + printf("\n Pamelagp2Digits [options] -hbookfile file.hbook \n"); + printf("\n -hbookfile path to the file that has to be converted \n"); + printf("\n Options are:\n\n"); + printf(" -h | --help print this help and exit \n"); + printf(" -rootfile name of the root file in output finename.root,\n"); + printf(" if parameter is missing the name is generated from the hbook file name\n"); + printf(" -pamfile name of the pam file in output filename.pam \n"); + printf(" if parameter is missing the name is generated from the hbook file name\n"); + printf(" -calocompress compression of data in calorimeter- By default is 1.\n"); + printf(" 0 is RAW, 1 is COMPRESS, 2 is FULL (2 not yet implemented)\n"); + printf(" -rootcompress compression of root file = 1 by default (use 0 for no compression)\n"); + printf(" -tolower = 1 by default : ntuple column names are converted to lower case \n"); + printf(" but the first character is converted to upper case.\n"); + printf(" if 2 same as tolower=1 but also the first character is converted to lower case.\n"); + printf(" use 0 to keep case of column names\n"); + printf(" -lrecl =0 by default (must be specified if >8092)\n"); + printf(" -bufsize = 8000 by default (branch buffer size)\n"); + printf(" -optcwn for cwn ntuple only: optcwn\n"); + printf(" = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n"); + printf("\n The order of input files and options does not matter. \n"); + printf("\n Example: \n"); + printf(" Pamelagp2Digits -hbookfile /path/to/files/protons_1_300-500.rz -caloCompress 1 \n\n"); +} + +int main(int argc, char *argv[]) +{ + + printf("init\n"); lq = &pawc[9]; iq = &pawc[17]; void *qq = iq; - q = (float*)qq; - char *file_in=argv[1]; - char *file_out = " "; - char *file_raw; - - Int_t compress = 1; - int ier=0, record_size=0; + q = (float*)qq; - if (argc > 8) { - optcwn = atoi(argv[8]); - } - if (argc > 7) { - bufsize = atoi(argv[7]); - } - if (argc > 6) { - record_size = atoi(argv[6]); - } - if (argc > 5) { - golower = atoi(argv[5]); - } - if (argc > 4) { - compress = atoi(argv[4]); - } - - if (argc > 3) { - file_raw=argv[3]; + char *file_out = new char[512]; + strcpy(file_out," "); + char *file_raw; + Int_t rootcompress = 1; + Int_t calocompress = 1; + int ier=0, record_size=0; + + char *rootfile = new char[512]; + strcpy(rootfile," "); + char *pamfile = new char[512]; + strcpy(pamfile," "); + char *file_in; + file_in = NULL ; + + Int_t i = 0; + if ( argc > 1 ){ + while ( i < argc ){ + if ( !strcmp(argv[i],"-h") || !strcmp(argv[i],"--help") ){ + usage(); + return 0; + }; + if ( !strcmp(argv[i],"-hbookfile") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + file_in = argv[i+1]; + }; + if ( !strcmp(argv[i],"-rootfile") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + rootfile = argv[i+1]; + }; + if ( !strcmp(argv[i],"-pamfile") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + pamfile = argv[i+1]; + }; + if ( !strcmp(argv[i],"-calocompress") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + calocompress = atoi(argv[i+1]); + }; + if ( !strcmp(argv[i],"-rootcompress") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + rootcompress = atoi(argv[i+1]); + }; + if ( !strcmp(argv[i],"-tolower") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + golower = atoi(argv[i+1]); + }; + if ( !strcmp(argv[i],"-lrecl") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + record_size = atoi(argv[i+1]); + }; + if ( !strcmp(argv[i],"-bufsize") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + bufsize = atoi(argv[i+1]); + }; + if ( !strcmp(argv[i],"-optcwn") ) { + if ( argc-1 < i+1 ){ + usage(); + return 1; + }; + optcwn = atoi(argv[i+1]); + }; + i++; + }; } else { + // + // no input parameters exit with error, we need at least the input file + // + cout << "\n ERROR: NO INPUT PARAMETERS \n"; + usage(); + return 1; + }; + + if ( file_in==NULL) { + // + // file is not defined. exit with error, we need at least the input file + // + cout << "\n ERROR: NO INPUT PARAMETERS \n"; + usage(); + return 1; + } + + // define calo writing format (general variable) + comprcalomode = calocompress ; + // Define the root and pam file + if ( !strcmp(pamfile," ")) { file_raw= new char[2000]; strcpy(file_raw,file_in); char *dot = strrchr(file_raw,'.'); if (dot) strcpy(dot+1,"pam"); else strcat(file_out,".pam"); - } - - if (argc > 2) { - file_out=argv[2]; } else { + file_raw=pamfile; + } + if (!strcmp(rootfile," ")) { file_out= new char[2000]; strcpy(file_out,file_in); char *dot = strrchr(file_out,'.'); if (dot) strcpy(dot+1,"gp.root"); //modified S.Orsi 09/'07 else strcat(file_out,".gp.root"); + } else { + file_out=rootfile; } + cout<<" Check input parameters inputfile="<Write(); cout << "Invoking Digitizer" << endl << flush; - char *ndl[8],*q,*q1; + const char *ndl[9]; + char *q,*q1; q=(char*)malloc(5 *sizeof(char)); q1=(char*)malloc(5 *sizeof(char)); ndl[0]="nspe"; @@ -820,8 +931,9 @@ ndl[5]="ncal"; ndl[6]="nndd"; ndl[7]="nstr"; + ndl[8]="comprcalomod"; - int nspe=200,ntof=200,ncat=50,ncas=50,ncar=100,ncal=1000,nnd=200,nstr=1000,par[8],tmp=0,t; + int nspe=200,ntof=200,ncat=50,ncas=50,ncar=100,ncal=1000,nnd=200,nstr=1000,par[9],tmp=0,t; par[0]=nspe; par[1]=ntof; par[2]=ncat; @@ -830,6 +942,7 @@ par[5]=ncal; par[6]=nnd; par[7]=nstr; + par[8]=comprcalomode; ifstream np("vectpar.dat",ios::in); if(!np)printf("ATTENTION: Using default vector legths!\n"); @@ -843,7 +956,7 @@ } t=0; while(tmp){ - q1=ndl[t]; + strcpy(q1,ndl[t]); if(q[0]==q1[0] && q[1]==q1[1] && q[2]==q1[2] && q[3]==q1[3]){ par[t]=tmp; tmp=0; @@ -860,8 +973,9 @@ ncal=par[5]; nnd=par[6]; nstr=par[7]; + comprcalomode=par[8]; } - Digitizer* dig = new Digitizer(tree,file_raw,nspe,ntof,ncat,ncas,ncar,ncal,nnd,nstr); + Digitizer* dig = new Digitizer(tree,file_raw,nspe,ntof,ncat,ncas,ncar,ncal,nnd,nstr,comprcalomode); dig->Loop(); dig->Close();