StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestFastRead.C
1 #include <string>
2 
3 //Note, if you run this compiled, then you're fine. If not, you have to manually set npos to 1
4 
5 void TestFastRead()
6 {
7  cout <<"TestFastRead()"<<endl;
8  string infile = "Dummy.txt_has_10_events";
9  cout <<"infile:\t"<<infile<<endl;
10  string begin = "_has_";
11  string end = "_events";
12  int where1 = infile.find(begin);
13  int where2 = infile.find(end);
14  //int npos = string::npos; //for compiled code
15  int npos = infile.npos; //for compiled code
16  //int npos=-1 //for interpreted code
17  cout <<"npos:\t"<<npos<<"\twhere1:\t"<<where1<<"\twhere2:\t"<<where2<<endl;
18 
19  int start=where1+begin.size();
20  int stop=where2;
21  cout <<"numbers of events is between indices: ["<<start<<","<<stop<<")"<<endl;
22 
23  cout <<"Get number of events"<<endl;
24  string number;
25  for (int i=start; i<stop; ++i) {
26  number += infile[i];
27  }
28 
29  int nevents = atoi(number.c_str());
30  cout <<"Number of events as string:\t"<<number<<endl;
31  cout <<"Number of events as int: \t"<<nevents<<endl;
32 
33  cout <<"Done"<<endl;
34 }