/[PAMELA software]/PamelaDigitizer/Pamelagp2Digits.cxx
ViewVC logotype

Diff of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by mocchiut, Thu Dec 18 17:11:47 2008 UTC revision 1.14 by pizzolot, Fri Oct 16 09:15:51 2009 UTC
# Line 9  Line 9 
9  //  //
10  //  //
11  //  HOWTO (RECOMMENDED):  //  HOWTO (RECOMMENDED):
12  //  ./ Pamelagp2Digits filename.his  //  ./ Pamelagp2Digits -hbookfile filename.his
13  //  It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info)  //  It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info)
14  //    //  
15  //  NB: more details are present in the file HOW-TO-DIGIT.TXT  //  NB: more details are present in the file HOW-TO-DIGIT.TXT
16  //  //
17  //  HOWTO (only for testing purposes)  //  HOWTO
18  //  Pamelagp2Digits hbook_filename root_filename  raw_filename compress tolower  //  see usage(). Example:
19  //  - If the 2nd and 3rd parameters are missing the names are generated from the hbook file name.  //  Pamelagp2Digits -hbookfile filename.his -rootfile filename.root -pamfile filename.pam -calocompress [VAL] -rootcompress [VAL]
20  //  - The following flags are from h2root and default values are used:  //  The following flags are from h2root and default values are used:
21  //    if compress is missing (or = 1) the ROOT file will be compressed  //   if rootcompress is missing (or = 1) the ROOT file will be compressed
22  //    if compress = 0 the ROOT file will not be compressed.  //   if rootcompress = 0 the ROOT file will not be compressed.
23  //    if tolower is missing (or = 1) ntuple column names are converted to lower case  //   if tolower is missing (or = 1) ntuple column names are converted to lower case
24  //                but the first character is converted to upper case.  //               but the first character is converted to upper case.
25  //    if tolower = 2 same as tolower=1 except that the first character is also  //   if tolower = 2 same as tolower=1 except that the first character is also
26  //                convertex to lower case  //                convertex to lower case
27  //  //
28    //
29  //  MODIFICATIONS:  //  MODIFICATIONS:
30    //  (C.Pizzolotto. Trieste. october 2009)
31    //  - added DigitizeCALOCOMPRESS to write calorimeter data in compress mode
32    //  - changed way of reading input parameters. now the input order is not important.
33    //
34  //  v. 1.5 (S.Orsi, Roma2, 11 October 2007)  //  v. 1.5 (S.Orsi, Roma2, 11 October 2007)
35  //  - 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  //  - 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
36  //  //
# Line 106  char chtitl[128]; Line 111  char chtitl[128];
111  int ncx,ncy,nwt,idb;  int ncx,ncy,nwt,idb;
112  int lcont, lcid, lcdir;  int lcont, lcid, lcdir;
113  float xmin,xmax,ymin,ymax;  float xmin,xmax,ymin,ymax;
114    int comprcalomode;
115  const Int_t kMIN1 = 7;  const Int_t kMIN1 = 7;
116  const Int_t kMAX1 = 8;  const Int_t kMAX1 = 8;
117    
# Line 266  Int_t optcwn = 1; Line 272  Int_t optcwn = 1;
272    
273  char *DigitizerInfo(bool print);  char *DigitizerInfo(bool print);
274    
 int main(int argc, char **argv)  
275    
 {  
   //  char* cha=DigitizerInfo(1);  
276    
277    if (argc < 2) {  void usage(){
278       printf("Error: Pamelagp2Digits \n");    printf("\nUsage:\n");
279       printf("Pamelagp2Digits file.hbook file.root file.pam [compress] [tolower] [lrecl] [bufsize] [optcwn] \n");    printf("\n Pamelagp2Digits [options] -hbookfile file.hbook \n");
280       printf("      if file.root is not given  it will be = file.root\n");    printf("\n -hbookfile      path to the file that has to be converted \n");
281       printf("      compress = 1 by default (use 0 for no compression)\n");    printf("\n Options are:\n\n");
282       printf("      tolower  = 1 by default (use 0 to keep case of column names)\n");    printf(" -h | --help     print this help and exit \n");
283       printf("      lrecl =0 by default (must be specified if >8092)\n");    printf(" -rootfile       name of the root file in output finename.root,\n");
284       printf("      bufsize = 8000 by default (branch buffer size)\n");    printf("                 if parameter is missing the name is generated from the hbook file name\n");
285       printf("      for cwn ntuple only: optcwn  = 1 (default)  1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n");    printf(" -pamfile        name of the pam file in output filename.pam \n");
286       return 1;    printf("                 if parameter is missing the name is generated from the hbook file name\n");
287    }    printf(" -calocompress   compression of data in calorimeter- By default is 1.\n");
288      printf("                 0 is RAW, 1 is COMPRESS, 2 is FULL (2 not yet implemented)\n");
289      printf(" -rootcompress   compression of root file = 1 by default (use 0 for no compression)\n");
290      printf(" -tolower        =  1 by default :  ntuple column names are converted to lower case \n");
291      printf("                      but the first character is converted to upper case.\n");
292      printf("                 if 2  same as tolower=1 but also the first character is converted to lower case.\n");
293      printf("                 use 0 to keep case of column names\n");
294      printf(" -lrecl          =0 by default (must be specified if >8092)\n");
295      printf(" -bufsize        = 8000 by default (branch buffer size)\n");
296      printf(" -optcwn         for cwn ntuple only: optcwn\n");
297      printf("                 = 1 (default)  1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n");
298      printf("\n The order of input files and options does not matter. \n");
299      printf("\n Example: \n");
300      printf(" Pamelagp2Digits -hbookfile /path/to/files/protons_1_300-500.rz  -caloCompress 1  \n\n");
301    }
302    
303    
304    int main(int argc, char *argv[])
305    {
306      
307      printf("init\n");
308    lq = &pawc[9];    lq = &pawc[9];
309    iq = &pawc[17];    iq = &pawc[17];
310    void *qq = iq;    void *qq = iq;
311     q = (float*)qq;    q = (float*)qq;
   char *file_in=argv[1];  
   char *file_out = " ";  
   char *file_raw;  
   
   Int_t compress = 1;  
   int ier=0, record_size=0;  
312    
313    if (argc > 8) {    char *file_out = new char[512];
314      optcwn = atoi(argv[8]);    strcpy(file_out," ");
315    }    char *file_raw;
316    if (argc > 7) {    Int_t rootcompress = 1;
317      bufsize = atoi(argv[7]);    Int_t calocompress = 1;
318    }      int ier=0, record_size=0;
319    if (argc > 6) {  
320      record_size = atoi(argv[6]);    char *rootfile = new char[512];
321    }    strcpy(rootfile," ");
322    if (argc > 5) {    char *pamfile = new char[512];
323      golower = atoi(argv[5]);    strcpy(pamfile," ");
324    }    char *file_in;
325    if (argc > 4) {    file_in = NULL ;
326      compress = atoi(argv[4]);  
327    }    Int_t i = 0;    
328      if ( argc > 1 ){
329    if (argc > 3) {      while ( i < argc ){
330      file_raw=argv[3];        if ( !strcmp(argv[i],"-h") || !strcmp(argv[i],"--help") ){
331            usage();
332            return 0;
333          };
334          if ( !strcmp(argv[i],"-hbookfile") ) {
335            if ( argc-1 < i+1 ){
336              usage();
337              return 1;
338            };
339            file_in = argv[i+1];            
340          };
341          if ( !strcmp(argv[i],"-rootfile") ) {
342            if ( argc-1 < i+1 ){
343              usage();
344              return 1;
345            };
346            rootfile = argv[i+1];          
347          };
348          if ( !strcmp(argv[i],"-pamfile") ) {
349            if ( argc-1 < i+1 ){
350              usage();
351              return 1;
352            };
353            pamfile = argv[i+1];            
354          };
355          if ( !strcmp(argv[i],"-calocompress") ) {
356            if ( argc-1 < i+1 ){
357              usage();
358              return 1;
359            };
360            calocompress =  atoi(argv[i+1]);                
361          };
362         if ( !strcmp(argv[i],"-rootcompress") ) {
363            if ( argc-1 < i+1 ){
364              usage();
365              return 1;
366            };
367             rootcompress = atoi(argv[i+1]);                
368          };
369         if ( !strcmp(argv[i],"-tolower") ) {
370           if ( argc-1 < i+1 ){
371             usage();
372             return 1;
373           };
374            golower = atoi(argv[i+1]);
375         };
376         if ( !strcmp(argv[i],"-lrecl") ) {
377           if ( argc-1 < i+1 ){
378             usage();
379             return 1;
380           };
381           record_size = atoi(argv[i+1]);
382         };
383         if ( !strcmp(argv[i],"-bufsize") ) {
384           if ( argc-1 < i+1 ){
385             usage();
386             return 1;
387           };
388           bufsize = atoi(argv[i+1]);
389         };
390         if ( !strcmp(argv[i],"-optcwn") ) {
391           if ( argc-1 < i+1 ){
392             usage();
393             return 1;
394           };
395           optcwn = atoi(argv[i+1]);
396         };
397         i++;
398        };
399    } else {    } else {
400        //
401        // no input parameters exit with error, we need at least the input file
402        //
403        cout << "\n ERROR: NO INPUT PARAMETERS \n";
404        usage();
405        return 1;
406      };
407    
408      if ( file_in==NULL) {
409        //
410        // file is not defined. exit with error, we need at least the input file
411        //
412        cout << "\n ERROR: NO INPUT PARAMETERS \n";
413        usage();
414        return 1;
415      }
416    
417      // define calo writing format (general variable)
418      comprcalomode = calocompress ;
419      // Define the root and pam file
420      if ( !strcmp(pamfile," ")) {
421      file_raw= new char[2000];      file_raw= new char[2000];
422      strcpy(file_raw,file_in);      strcpy(file_raw,file_in);
423      char *dot = strrchr(file_raw,'.');      char *dot = strrchr(file_raw,'.');
424      if (dot) strcpy(dot+1,"pam");      if (dot) strcpy(dot+1,"pam");
425      else     strcat(file_out,".pam");      else     strcat(file_out,".pam");
   }  
   
   if (argc > 2) {  
     file_out=argv[2];  
426    } else {    } else {
427        file_raw=pamfile;
428      }
429      if (!strcmp(rootfile," ")) {
430      file_out= new char[2000];      file_out= new char[2000];
431      strcpy(file_out,file_in);      strcpy(file_out,file_in);
432      char *dot = strrchr(file_out,'.');      char *dot = strrchr(file_out,'.');
433      if (dot) strcpy(dot+1,"gp.root");     //modified S.Orsi 09/'07      if (dot) strcpy(dot+1,"gp.root");     //modified S.Orsi 09/'07
434      else     strcat(file_out,".gp.root");      else     strcat(file_out,".gp.root");
435      } else {
436        file_out=rootfile;
437    }    }
438    
439    
440      cout<<" Check input parameters  inputfile="<<file_in<<"  root="<<file_out<<"  pam="<<file_raw<<endl;
441      cout<<"                         calocompress="<<calocompress<<"  rootcompress="<<rootcompress<<"  golow="<<golower<<endl;
442      cout<<"                         bufsize="<<bufsize<<"  cwn="<<optcwn<<endl;
443    
444    
445  #if defined(_HIUX_SOURCE) && !defined(__GNUC__)  #if defined(_HIUX_SOURCE) && !defined(__GNUC__)
446    hf_fint((char *)NULL);    hf_fint((char *)NULL);
# Line 355  int main(int argc, char **argv) Line 465  int main(int argc, char **argv)
465    
466    char root_file_title[2000];    char root_file_title[2000];
467    
468    TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress);    TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,rootcompress);
469        
470    if (!hfile) {    if (!hfile) {
471       printf("Error: can't open output file: %s \n",file_out);       printf("Error: can't open output file: %s \n",file_out);
# Line 809  void convert_directory(const char *dir, Line 919  void convert_directory(const char *dir,
919    tree->Write();    tree->Write();
920    
921    cout << "Invoking Digitizer" << endl << flush;    cout << "Invoking Digitizer" << endl << flush;
922    char *ndl[8],*q,*q1;    const char *ndl[9];
923      char *q,*q1;
924    q=(char*)malloc(5 *sizeof(char));    q=(char*)malloc(5 *sizeof(char));
925    q1=(char*)malloc(5 *sizeof(char));    q1=(char*)malloc(5 *sizeof(char));
926    ndl[0]="nspe";    ndl[0]="nspe";
# Line 820  void convert_directory(const char *dir, Line 931  void convert_directory(const char *dir,
931    ndl[5]="ncal";    ndl[5]="ncal";
932    ndl[6]="nndd";    ndl[6]="nndd";
933    ndl[7]="nstr";    ndl[7]="nstr";
934      ndl[8]="comprcalomod";
935    
936    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;
937    par[0]=nspe;    par[0]=nspe;
938    par[1]=ntof;    par[1]=ntof;
939    par[2]=ncat;    par[2]=ncat;
# Line 830  void convert_directory(const char *dir, Line 942  void convert_directory(const char *dir,
942    par[5]=ncal;    par[5]=ncal;
943    par[6]=nnd;    par[6]=nnd;
944    par[7]=nstr;    par[7]=nstr;
945      par[8]=comprcalomode;
946    
947    ifstream np("vectpar.dat",ios::in);    ifstream np("vectpar.dat",ios::in);
948    if(!np)printf("ATTENTION: Using default vector legths!\n");    if(!np)printf("ATTENTION: Using default vector legths!\n");
# Line 843  void convert_directory(const char *dir, Line 956  void convert_directory(const char *dir,
956        }        }
957        t=0;        t=0;
958        while(tmp){        while(tmp){
959          q1=ndl[t];          strcpy(q1,ndl[t]);
960          if(q[0]==q1[0] && q[1]==q1[1] && q[2]==q1[2] && q[3]==q1[3]){          if(q[0]==q1[0] && q[1]==q1[1] && q[2]==q1[2] && q[3]==q1[3]){
961            par[t]=tmp;            par[t]=tmp;
962            tmp=0;            tmp=0;
# Line 860  void convert_directory(const char *dir, Line 973  void convert_directory(const char *dir,
973      ncal=par[5];      ncal=par[5];
974      nnd=par[6];      nnd=par[6];
975      nstr=par[7];      nstr=par[7];
976        comprcalomode=par[8];
977    }    }
978    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);
979    dig->Loop();    dig->Loop();
980    dig->Close();    dig->Close();
981    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.23