Changeset 2792 in Sophya for trunk/SophyaPI/PIext/pawexecut.cc
- Timestamp:
- Jun 1, 2005, 3:24:48 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r2775 r2792 13 13 #include "histerr.h" 14 14 #include "ntuple.h" 15 #include "datatable.h" 15 16 16 17 #include "pawexecut.h" … … 99 100 100 101 kw = "n/read"; 101 usage = "Read columns in an ASCII file and fill a NTuple ";102 usage = "Read columns in an ASCII file and fill a NTuple or a DataTable"; 102 103 usage += "\n n/read nt fascii [options] var_1,c_1 var_2,c_2 ... var_n,c_n "; 103 usage += "\n var_i,c_i : ntuple variable name, associated column in ASCII file [0,n["; 104 usage += "\n nt : NTuple or DataTable (see options) name"; 105 usage += "\n var_i,c_i : variable name, associated column in ASCII file [0,n["; 104 106 usage += "\n where [options] are:"; 107 usage += "\n \"-dt\": create a DataTable of double instead of a NTuple"; 105 108 usage += "\n \"=s\": separator character is \'s\' (could be \"\t\")"; 106 109 usage += "\n \"-^abcd\": do not read lines beginning with string \"abcd\" "; … … 655 658 string nament = tokens[0]; 656 659 string nameascii = tokens[1]; 660 bool create_datatable = false; 657 661 vector<string> donotreadbeg; 658 662 vector<string> donotreadin; … … 667 671 int lc = tokens[i].size(); 668 672 if(lc<2) continue; 673 if(tokens[i].find("-dt")==0) { // create DataTable instead of NTuple 674 create_datatable = true; 675 continue; 676 } 669 677 const char *c = tokens[i].c_str(); 670 678 if(c[0]=='=') { // Separator … … 739 747 } 740 748 741 // Creation du NTuple 742 char** ntvn = new char*[nvar]; 743 for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str()); 749 // Creation du NTuple ou de la DataTable 750 NTuple *nt = NULL; 751 DataTable *dt = NULL; 752 if(!create_datatable) { //create NTuple 753 char** ntvn = new char*[nvar]; 754 for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str()); 755 nt = new NTuple(nvar,ntvn); 756 delete [] ntvn; 757 } else { //create DataTable 758 dt = new DataTable(); 759 for(int i=0;i<nvar;i++) dt->AddDoubleColumn(varname[i]); 760 } 744 761 r_8 *xnt = new r_8[nvar]; 745 NTuple *nt = new NTuple(nvar,ntvn);746 762 747 763 // Read file … … 808 824 if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne 809 825 810 // Remplissage du NTuple 826 // Remplissage du NTuple ou de la DataTable 811 827 for(int i=0;i<nvar;i++) { 812 828 xnt[i] = 0.; … … 815 831 xnt[i] = atof(vs[ic].c_str()); 816 832 } 817 nt->Fill(xnt); 833 if(nt) nt->Fill(xnt); 834 else if(dt) dt->Fill(xnt); 818 835 //cout<<"...xnt"; for(int i=0;i<nvar;i++) cout<<" "<<xnt[i]; cout<<endl; 819 836 820 837 } 838 int_4 nentries = (nt)? nt->NEntry(): dt->NEntry(); 821 839 cout<<"n_read: "<<nline<<" lines in file, " 822 840 <<nlinecom<<" commentary, " 823 <<n t->NEntry()<<" Ntupleentries"<<endl;824 825 // On sauve le NTuple si besoin, on ferme et detruit ce qu'il faut841 <<nentries<<" object entries"<<endl; 842 843 // On sauve le NTuple/DataTable si besoin, on ferme et detruit ce qu'il faut 826 844 NamedObjMgr omg; 827 if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt; 828 delete [] ntvn; 845 if(nentries>0) { 846 if(nt) omg.AddObj(nt,nament); 847 if(dt) omg.AddObj(dt,nament); 848 } else { 849 if(nt) delete nt; 850 if(dt) delete dt; 851 } 829 852 delete [] xnt; 830 853 delete [] line;
Note:
See TracChangeset
for help on using the changeset viewer.