Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MergeSegments.C
Go to the documentation of this file.
1 //
2 // Merge Segments
3 // this macro read a list of start stop segments from a file
4 // and merge the overlapping segments
5 // Example :
6 // root -b -l 'MergeSegments.C("ifile.txt","ofile.txt")'
7 //
8 // Author : Gabriele Vedovato
9 
10 
12 
13  // --------------------------------------------------------------
14  // Open file segment list
15  // --------------------------------------------------------------
16  ifstream in;
17  in.open(ifile.Data(),ios::in);
18  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;gSystem->Exit(1);}
19  cout << "input file list : " << ifile << endl;
20 
21  char str[1024];
22  int fpos=0;
23  int index=0;
24  double start;
25  double stop;
27  vector<waveSegment> iseg;
28  while (1) {
29  fpos=in.tellg();
30  in.getline(str,1024);
31  if(str[0] == '#') continue;
32  in.seekg(fpos, ios::beg);
33  fpos=in.tellg();
34 
35  in >> start >> stop;
36  if (!in.good()) break;
37 
38  seg.index=index++; seg.start=start; seg.stop=stop; iseg.push_back(seg);
39  }
40 
41  in.close();
42 
43 // cout << "List of input segments" << endl;
44 // for(int n=0;n<iseg.size();n++) cout << n << " " << iseg[n].start << " " << iseg[n].stop << endl;
45 
46  // --------------------------------------------------------------
47  // merge segments
48  // --------------------------------------------------------------
49  vector<waveSegment> oseg = CWB::Toolbox::unionSegments(iseg);
50 
51 // cout << "List of output segments" << endl;
52 // for(int n=0;n<oseg.size();n++) cout << n << " " << oseg[n].start << " " << oseg[n].stop << endl;
53 
54  // --------------------------------------------------------------
55  // Write output file segment list
56  // --------------------------------------------------------------
57  ofstream out;
58  out.open(ofile.Data(),ios::out);
59  out.precision(16);
60  for(int n=0;n<oseg.size();n++) {
61  out << oseg[n].start << " " << oseg[n].stop << endl;
62  }
63  out.close();
64 
65  cout << "output file list : " << ofile << endl;
66 
67  exit(0);
68 }
69 
double start
Definition: network.hh:37
int n
Definition: cwb_net.C:10
vector< waveSegment > oseg
TString("c")
char ofile[512]
static vector< waveSegment > unionSegments(vector< waveSegment > &ilist)
Definition: Toolbox.cc:101
ofstream out
Definition: cwb_merge.C:196
void MergeSegments(TString ifile, TString ofile)
Definition: MergeSegments.C:11
char str[1024]
TFile * ifile
waveSegment seg
int index
Definition: network.hh:36
vector< waveSegment > iseg
ifstream in
wavearray< int > index
double stop
Definition: network.hh:38
exit(0)