3 const char* textfile=
"links/P00hk.nofield.refitOS.undoPTCME.slice/dip5.typec.slice.txt";
4 const char* outfile=
"links/P00hk.nofield.refitOS.undoPTCME.slice/dip5.typec.slice.new.root";
7 void readTextFile(
const char* textFile=textfile,
8 const char* outFile=outfile)
10 cout <<
"reading textFile=" << textFile << endl;
11 cout <<
"writing " << outFile << endl;
13 TFile outRoot(outFile,
"RECREATE");
14 if(!outRoot.IsOpen())
return;
16 ifstream iss(textFile);
19 int count(0),limit(1000);
20 TString buffer;
char name[100],title[100],buf[500];
21 bool isarray=
false,
new=
false;
23 int nBin(0),min(0),max(0);
30 if(debug)cout <<
"the line is**" << buf <<
"**" << endl;
32 if(buffer.Contains(
"name:")){
33 parse(buffer,
"name:");
34 strcpy(name,buffer.Data());
37 int stat = h->Write();
39 cout <<
"could not write to " << outFile << endl;
45 if(buffer.Contains(
"title:")){
46 parse(buffer,
"title:");
47 strcpy(title,buffer.Data());
50 if(buffer.Contains(
"bins:")){
51 parse(buffer,
"bins:");
52 nBin=atoi(buffer.Data());
55 if(buffer.Contains(
"isarray")){
59 if(debug)cout <<
"**" << buffer <<
"**" << endl;
64 if(!temp.Length())
break;
65 temp.Replace(temp.First(
' '),temp.Length(),
"");
66 array[count++] = atof(temp.Data());
67 buffer.Replace(0,buffer.First(
' ')+1,
"");
70 for(
int i=0; i<nBin+1; i++){ cout << array[i]<<
" "; }
76 if(buffer.Contains(
"notarray")){
78 iss.getline(buf,500); buffer = buf;
80 min=atof(buffer.Data());
81 iss.getline(buf,500); buffer = buf;
83 max=atof(buffer.Data());
86 if(buffer.Contains(
"bin=")){
91 cout <<
"name=" <<name <<
" title=" << title
92 <<
" nbin=" << nBin << endl;
94 h=
new TH1D(name,title,nBin,array);
97 h=
new TH1D(name,title,nBin,min,max);
100 buffer.ReplaceAll(
"bin=",
"");
101 TString temp = split(buffer);
102 int bin=atoi(temp.Data());
104 buffer.ReplaceAll(
"value: ",
"");
106 double value=atof(temp.Data());
108 buffer.ReplaceAll(
"error: ",
"");
109 double error=atof(buffer.Data());
112 cout <<
"bin=" << bin <<
" value=" << value
113 <<
" error=" << error<<endl;
115 if(!h){cout <<
"h not created?" << endl;
return;}
116 h->SetBinContent(bin,value);
117 h->SetBinError(bin,error);
120 if(debug && ++count>limit)
break;
127 void parse(TString& a,
char* b){
128 a.ReplaceAll(b,
""); a.ReplaceAll(
" ",
"");
131 TString split(TString& a){
132 TString temp=a.Data();
133 temp.Replace(temp.First(
' '),temp.Length(),
"");
134 a.Replace(0,a.First(
' ')+1,
"");