Logo coherent WaveBurst  
Config Reference Guide
Logo
ReadLoudestList.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define LOUDEST_MAX_SIZE 1000
20 
21 /*
22  TString run[LOUDEST_MAX_SIZE];
23  int chunk[LOUDEST_MAX_SIZE];
24  double gps[LOUDEST_MAX_SIZE];
25  TString bbh_name[LOUDEST_MAX_SIZE];
26  double ifar_sec[LOUDEST_MAX_SIZE];
27  double ifar_year[LOUDEST_MAX_SIZE];
28  int obs_time_sec[LOUDEST_MAX_SIZE];
29  double obs_time_day[LOUDEST_MAX_SIZE];
30  double expected[LOUDEST_MAX_SIZE];
31  int observed[LOUDEST_MAX_SIZE];
32  double cumul_FAP[LOUDEST_MAX_SIZE];
33  double sigma[LOUDEST_MAX_SIZE];
34 
35  int nLoudest = ReadLoudestList(ifile, run, chunk, gps, bbh_name, ifar_sec, ifar_year,
36  obs_time_sec, obs_time_day, expected, observed, cumul_FAP, sigma);
37 
38 */
39 
40 int ReadLoudestList(TString ifile, TString* run, int* chunk, double* gps, TString* bbh_name, double* ifar_sec, double* ifar_year,
41  double* obs_time_sec, double* obs_time_day, double* expected, int* observed, double* cumul_FAP, double* sigma) {
42 
43  CWB::Toolbox::checkFile(ifile);
44 
45  // Open chunk list
46  ifstream in;
47  in.open(ifile.Data(),ios::in);
48  if (!in.good()) {cout << "Error Opening File : " << ifile << endl;exit(1);}
49 
50  int isize=0;
51  char str[1024];
52  int fpos=0;
53  while(true) {
54  in.getline(str,1024);
55  if (!in.good()) break;
56  if(str[0] != '#') isize++;
57  }
58 // cout << "size " << isize << endl;
59  in.clear(ios::goodbit);
60  in.seekg(0, ios::beg);
61  if(isize==0) {cout << "Error : File " << ifile << " is empty" << endl;return 0;}
62  if(isize>LOUDEST_MAX_SIZE) {cout << "Error : File " << ifile << " > " << LOUDEST_MAX_SIZE << endl;exit(1);}
63 
64  char srun[256];
65  char sbbh[256];
66 
67  int k=0;
68  while(true) {
69  fpos=in.tellg();
70  in.getline(str,1024);
71  if (!in.good()) break;
72  if(str[0] == '#' || str[0]=='\0') continue;
73  in.seekg(fpos, ios::beg);
74  in >> srun >> chunk[k] >> gps[k] >> sbbh >> ifar_sec[k] >> ifar_year[k] >> obs_time_sec[k]
75  >> obs_time_day[k] >> expected[k] >> observed[k] >> cumul_FAP[k] >> sigma[k];
76  if(!in.good()) break;
77  run[k]=srun;
78  bbh_name[k]=sbbh;
79  //cout << "\t" << run[k] << "\t" << chunk[k] << "\t" << gps[k] << "\t" << bbh_name[k] << "\t" << ifar_sec[k] << "\t" << ifar_year[k] << "\t" << obs_time_sec[k]
80  // << "\t" << obs_time_day[k] << "\t" << expected[k] << "\t" << observed[k] << "\t" << cumul_FAP[k] << "\t" << sigma[k] << endl;
81  k++;
82  if(k>=LOUDEST_MAX_SIZE) {
83  cout << "WARNING: loudest events exceed LOUDEST_MAX_SIZE = " << LOUDEST_MAX_SIZE << endl;
84  break;
85  }
86  }
87  in.close();
88 
89  return k;
90 }
int ReadLoudestList(TString ifile, TString *run, int *chunk, double *gps, TString *bbh_name, double *ifar_sec, double *ifar_year, double *obs_time_sec, double *obs_time_day, double *expected, int *observed, double *cumul_FAP, double *sigma)
#define LOUDEST_MAX_SIZE
string run
Definition: cWB_conf.py:6