Logo coherent WaveBurst  
Library Reference Guide
Logo
frame.hh
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 /**********************************************************
20  * Package: frame Class Library
21  * File name: frame.hh
22  * Author: Gabriele Vedovato (vedovato@lnl.infn.it)
23  **********************************************************/
24 
25 
26 #ifndef CWBFRAME_HH
27 #define CWBFRAME_HH
28 
29 #include "TROOT.h"
30 #include "TMath.h"
31 #include "TSystem.h"
32 #include "TString.h"
33 #include "TTree.h"
34 #include "TFile.h"
35 #include "TRandom.h"
36 #include "TRandom3.h"
37 #include "TNamed.h"
38 
39 #include <string>
40 #include <iostream>
41 #include <fstream>
42 #include <stdlib.h>
43 #include <math.h>
44 #include <ctype.h>
45 #include <vector>
46 #include <string.h>
47 
48 #include "wavearray.hh"
49 #include "network.hh"
50 
51 #include "FrameL.h"
52 
53 #define LST_TREE_NAME "frl"
54 
55 #ifndef TOOLBOX_HH
56 struct frfile {
57  int start;
58  int stop;
59  int length;
60  vector<TString> file;
61 };
62 #endif
63 
64 using namespace std;
65 
66 namespace CWB {
67 
68 class frame : public TNamed {
69 
70 public:
71 
72  frame();
73  frame(TString ioFile, TString chName="", Option_t* option = "", bool onDisk=false, TString label=".gwf", unsigned int mode=0);
74  ~frame();
75 
76  void open(TString ioFile, TString chName="", Option_t* option = "", bool onDisk=false, TString label=".gwf", unsigned int mode=0);
77 
78  // read in w the channel data contained in the frames defined in the filename
79  // filename : in - name of frame file
80  // channel : in - name of channel to be extracted
81  // w : out - data array which contains the data read
82  void readFrames(char* filename, char *channel, wavearray<double> &w);
83 
84  // read in w the channel data contained in the frames defined in the frf structure
85  // frf : in - frame file structure
86  // channel : in - name of channel to be extracted
87  // w : out - data array which contains the data read
88  void readFrames(frfile frf, char *channel, wavearray<double> &w);
89 
90  // read in w the channel data contained in the frames
91  // w : out - data array which contains the data read
92  void readFrames(wavearray<double> &w);
93 
94  // write in frame the channel data contained in the wavearray x
96 
97  // dump to file ofName the list of frames defined in frf structures (list file used for the old cWB analysis)
98  int dumpFrList(frfile frf, TString ofName, double sRate=16384.);
99 
100  // return the frame list of frames contained in the range [start-segEdge,stop-segEdge]
101  frfile getFrList(int istart, int istop, int segEdge);
102 
103  // return the frame list of frames contained in the range [start,stop]
104  vector<frfile> getFrList(int istart=0, int istop=0);
105 
106  // return the begin and end range of the frame list
108 
109  // return the number of frame files read from input list
110  int getNfiles() {return nfiles;}
111 
112  // set resample index : used to resample data after read from files
113  // resample rate = pow(2,srIndex)
114  void setSRIndex(int srIndex) {this->srIndex=srIndex;}
115 
116  // get resample index
117  int getSRIndex() {return srIndex;}
118 
119  // set data channel name
120  void setChName(TString chName) {this->chName=chName;}
121 
122  // get data channel name
124 
125  // set frame name
126  void setFrName(TString frName) {this->frName=frName;}
127 
128  // get frame name
130 
131  // get frame file option (READ/WRITE)
132  TString getOption() {return fOption;}
133 
134  void close();
135 
136  // if true then print more infos
137  void setVerbose(bool verbose=true) {this->verbose=verbose;}
138 
139  // frame reading retry time (sec) : 0 -> disable
140  // retry time = frRetryTime*(num of trials) : max trials = 3
141  void setRetryTime(int frRetryTime=60) {this->frRetryTime=frRetryTime;}
142 
143  bool fNameCheck(TString fName);
144 
145  // set the range interval for input files
146  // if xstart!=0 then only files with gps>=xstart are stored in the tree
147  // if xstop!=0 then only files with gps<=xstop are stored in the tree
148  void setTimeRange(int xstart=0, int xstop=0) {
149  this->xstart = xstart>0 ? this->xstart=xstart : 0;
150  this->xstop = xstop>0 ? this->xstop=xstop : 0;
151  }
152 
153 private:
154 
155  // return the frame list of frames contained in the range [start-segEdge,stop-segEdge]
156  // if itree=NULL use the private frtree_List
157  frfile getFrList(int istart, int istop, int segEdge, TTree* itree);
158 
159  // return the frame list of frames contained in the range [start-segEdge,stop-segEdge]
160  // use the tree contained in rfName root file
161  frfile getFrList(TString rfName, int istart, int istop, int segEdge=0);
162 
163  // return the begin and end range of the frame list
164  // if itree=NULL use the private frtree_List
165  waveSegment getFrRange(TTree* itree);
166 
167  // convert frl (frame file list) file to tree and save to rfName
168  // if rfName=="" the tree is saved & sorted to the private frtree_List
169  int frl2FrTree(TString iFile, TString rfName="", TString label=".gwf", unsigned int mode=0);
170 
171  // sort iFile Tree and save the sorted tree to rfName
172  int sortFrTree(TString iFile, TString rfName);
173 
174  int sortFrTree();
175 
176  TTree* frtree_List; //!auxiliary tree used to store frame file infos
177  TString chName; // data channel name
178  TString frName; // frame name
179  TString rfName; // auxiliary root file name containing the tree
180  int nfiles; // number of frame files read from input list
181  FrFile *frFile; //!frame file pointer
182  TString fOption; // define the READ/WRITE mode
183  int srIndex; // resample rate = pow(2,srIndex) - 0 : disabled resampling
184  bool verbose; // if true then print more infos
185  int frRetryTime; // frame reading retry time (sec) : 0 -> disable
186 
187  double xstart; // start time range used to fill frtree_List
188  double xstop; // stop time range used to fill frtree_List
189 
190  ClassDef(frame,3)
191 };
192 
193 } // end namespace
194 
195 // get operator
197 // put operator
198 CWB::frame& operator << (CWB::frame& fr, wavearray<double>& x);
199 // put operator
201 
202 #endif
TString getOption()
Definition: frame.hh:132
double sRate
Definition: TestFrame5.C:14
TString rfName
Definition: frame.hh:179
TString ofName
int nfiles
int stop
Definition: Toolbox.hh:94
Definition: ced.hh:42
TString getFrName()
Definition: frame.hh:129
void setFrName(TString frName)
Definition: frame.hh:126
TString("c")
int start
Definition: Toolbox.hh:93
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
CWB::frame fr(FRLIST_NAME)
STL namespace.
double segEdge
Definition: test_config1.C:49
int srIndex
Definition: frame.hh:183
TString chName
auxiliary tree used to store frame file infos
Definition: frame.hh:177
waveSegment getFrRange()
Definition: frame.hh:107
void setChName(TString chName)
Definition: frame.hh:120
TString frName
Definition: frame.hh:178
size_t mode
wavearray< double > w
Definition: Test1.C:27
int getSRIndex()
Definition: frame.hh:117
void setTimeRange(int xstart=0, int xstop=0)
Definition: frame.hh:148
int nfiles
Definition: frame.hh:180
TString chName[NIFO_MAX]
double xstart
Definition: frame.hh:187
fr writeFrame(x, frName, chName)
int length
Definition: Toolbox.hh:95
TString label
Definition: MergeTrees.C:21
frfile frf
void setVerbose(bool verbose=true)
Definition: frame.hh:137
int getNfiles()
Definition: frame.hh:110
void setSRIndex(int srIndex)
Definition: frame.hh:114
bool verbose
Definition: frame.hh:184
int * xstart
TString getChName()
Definition: frame.hh:123
TString frName[NIFO_MAX]
wavearray< double > & operator>>(CWB::frame &fr, wavearray< double > &x)
Definition: frame.cc:129
int frRetryTime
Definition: frame.hh:185
TString fOption
frame file pointer
Definition: frame.hh:182
TTree * frtree_List
Definition: frame.hh:176
in open(HEN_LIST, ios::in)
TTree * itree
FrFile * frFile
Definition: frame.hh:181
vector< TString > file
Definition: Toolbox.hh:96
in close()
void setRetryTime(int frRetryTime=60)
Definition: frame.hh:141
char fName[256]
double xstop
Definition: frame.hh:188