Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FrDisplay.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*/
2 /* File: FrDisplay.c Last update: Jun 26, 2011 */
3 /* */
4 /* Copyright (C) 2011, G.Vedovato */
5 /* For the licensing terms see the LICENSE file. */
6 /* For the list of contributors see the history section of the documentation */
7 /*---------------------------------------------------------------------------*/
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <limits.h>
11 #include "FrameL.h"
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include <math.h>
15 #include <sys/wait.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <sys/time.h>
19 #include <stdio.h>
20 #include <signal.h>
21 #include <sys/param.h>
22 #include <sys/user.h>
23 #include <sys/sysctl.h>
24 #include "Filter.hh"
25 #include "TSystem.h"
26 #include "TString.h"
27 #include "TObjArray.h"
28 #include "TObjString.h"
29 
30 void Help()
31 {
32  printf(" \n"
33  " This program reads frames from one or more input files, and print \n"
34  " the requested information. \n"
35  "-------------------------------------------------------------------- \n"
36  " Syntax is: FrDisplay -i <input file / ldf> \n"
37  " -f <first frame: (run # frame #) or (GPS time)> \n"
38  " -l <last frame: (run # frame #) or (GPS time)> \n"
39  " or length in second \n"
40  " -t <list of tag channels> \n"
41  " -d <debug level> \n"
42  " -c -1 to leave the data uncompressed \n"
43  " -top <number of ADC in the hit-parade> \n"
44  " -x <baudline parameters list> \n"
45  " -o <ldf observatory parameter> \n"
46  " -s <ldf data type parameter> \n"
47  " -k <filter parameters list> \n"
48  " -a <file access mode [s(sequential)/r(random)]> \n"
49  " -h (to get this help) \n"
50  " If one of the next option is there, we do only a partial frame dump\n"
51  " -adc to dump only the FrAdcData information \n"
52  " -sms to dump only the FrSerData information \n"
53  " -proc to dump only the FrProcData information \n"
54  " -sim to dump only the FrSimData information \n"
55  " -sum to dump only the FrSummary information \n"
56  " -stat to dump only the static information \n"
57  " -raw to dump only the raw data information \n"
58  " -event to dump only the FrEvent and FrSimEvent \n"
59  "-------------------------------------------------------------------- \n"
60  " Remarks: \n"
61  " -i : Argument can be one or more file names \n"
62  " -t : Tag is a channel list with wild cards like: ADC122 ADC5* \n"
63  " If a name start by - it is interpreted as an anti-tag \n"
64  " -f -l:These options works only with the debug level > 2 \n"
65  " -d 0: One line per file based on the TOC information \n"
66  " First frame time, file length, time of the first/last event, \n"
67  " -d 1: A few lines per file based on the TOC information \n"
68  " First/last frame time, number of frame in file, missing frame \n"
69  " Count the number of frame elements like ADC, Proc, Sim, Event \n"
70  " Gives the name of few of them and the typical event amplitude \n"
71  " -d 2: More lines per file based on the TOC information \n"
72  " Same as -d 1 plus the full list of channels, event \n"
73  " -d 3: Read the frame to print information \n"
74  " Print the list of all frame (time, length, quality word) \n"
75  " -d 4: Read the frame to print information with more info \n"
76  " Same as -d 3 plus summary information for all channels \n"
77  " Print frame history \n"
78  " -d 5: Read the frame to print information with more info \n"
79  " Same as -d 4 plus a full dump of the channel content... \n"
80  "-------------------------------------------------------------------- \n"
81  "\n");
82 }
83 
84 struct Parameters{
85  char *name; /* input file name */
86  char *tag; /* output tag */
87  char *baudline; /* baudline parameters */
88  char *observatory; /* ldf observatory par */
89  char *datatype; /* ldf data type par */
90  char *filter; /* filter parameters */
91  char *access; /* file access mode */
92  int frun; /* first run to copy */
93  int fframe; /* first frame to copy */
94  int lrun; /* last run to copy */
95  int lframe; /* last frame to copy */
96  double ftime; /* time for the first frame */
97  double ltime; /* time for the last frame */
98  int dType; /* type of dump */
99  int debug; /* debug level */
100  int comp; /* compression level */
101  int nTop; /* number of ADC for the hit parade */
102 };
103 
106 #define UNSET -999
107 #define ADC 0x1
108 #define SMS 0x2
109 #define SIM 0x4
110 #define STAT 0x8
111 #define EVENT 0x10
112 #define SUM 0x20
113 #define RAW 0x40
114 #define PROC 0x80
115 
116 void ReadParameters(int argc, char **argv);
117 void StrCat(char **oldbuf, char *more);
118 
119 double FrVectMax(FrVect *vect, int chId);
120 FrVect* FrVectDumpBinary(FrVect *vect, int fp, int chId, int debugLvl);
121 
122 int StartBaudline(int gpsSec, int gpsNSec, double scale, double sampleRate, char* chname, int nchannel, char* params);
123 void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char* sbdate);
124 int GpsToUnixTime(int gpsSec);
125 int GpsToGpsLeaps(int gpsSec);
126 int System(const char *command);
127 void INThandler(int);
128 pid_t getProcessId(const char * csProcessName);
129 void FrFileDumpBinary(FrFile* file, int fp, double* scale, int nchannel, double sampleRate);
131 
132 struct Parameters Par;
134 char baudline_wNAME[256];
136 char baudline_FFL[256];
137 CWB::Filter* filter[3]={NULL,NULL,NULL};
138 int iglobal[3]={0,0,0};
139 float uscaleby=1;
143 char chnames[3][64]={"","",""};
144 
145 #define MIN_TIME_GAP 256
146 
147 /*--------------------------------------------------------- Main ------------*/
148 int main(int argc, char **argv)
149 /*---------------------------------------------------------------------------*/
150 {FrFile *file;
151  FrameH *frame;
152  FrAdcData *adc;
153  FrSerData *sms;
154  FrProcData *proc;
155  FrSimEvent *simE;
156  FrEvent *evt;
157  FrSimData *sim;
158  FrSummary *sum;
159  double tStart, tEnd, gtime, start, len;
160  double tCurrent=0;
161  double sampleRate = 0.;
162  int fp=0;
163 
164  double scale[3]={0.,0.,0.};
165  int nchannel=0;
166  baudline_rnID=0;
167  baudline_nP=0;
168  signal(SIGINT, INThandler);
169 
170  struct timeval tv;
171  gettimeofday(&tv, NULL);
172  srand(tv.tv_usec);
173  baudline_rnID = rand(); // random name ID
174 
175  TString OS = "";
176  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
177  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
178  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
179 
180  char cmd[256];
181  if(OS=="Linux") sprintf(cmd,"mkdir -p /dev/shm/%s",getlogin());
182  if(OS=="Darwin") sprintf(cmd,"mkdir -p /tmp/%s",getlogin()); //MAC
183  //printf("%s\n",cmd);
184  System(cmd);
185 
186 // workdir=TString(gSystem->Getenv("FRDISPLAY_WORKDIR"));
187 // worksite=TString(gSystem->Getenv("FRDISPLAY_WORKSITE"));
188  char sworkdir[256];
189  sprintf(sworkdir,"%s",getenv("FRDISPLAY_WORKDIR"));
190  workdir=TString(sworkdir);
191  char sworksite[256];
192  sprintf(sworksite,"%s",getenv("FRDISPLAY_WORKSITE"));
193  worksite=TString(sworksite);
194  worksite.ToUpper();
195 
196  /*----------------- Read input arguments -------------------------*/
197 
198  ReadParameters(argc, argv);
199 
200  /*---------------------------- Open the input file(s) ------------*/
201 
202  FrLibSetLvl(Par.debug-3);
203  file = FrFileINew(Par.name);
204  if(file == NULL)
205  {fprintf(stderr,"Cannot open input file %s\n %s",
206  Par.name, FrErrorGetHistory());
207  return(0);}
208  file->compress = Par.comp;
209  file->chkSumFrFlag = FR_YES;
210 
211  /*------------- Table Of Content dump if debugLevel <2 ------------*/
212 
213  if(Par.debug < 3)
214  {FrFileIDumpT(file, stdout, Par.debug+1, Par.tag, Par.ftime, Par.ltime );
215  return(0);}
216  Par.debug -= 2;
217 
218  /*-------------- set the input file(s) to the first frames -------*/
219 
220  if(Par.ftime != 0)
221  {frame = FrameReadT(file, Par.ftime);
222  if(frame == NULL) /* search for the next frame in the requested range */
223  {tStart = FrFileITNextFrame(file, Par.ftime);
224  if(Par.ltime > 100000000) tEnd = Par.ltime;
225  else tEnd = Par.ftime + Par.ltime;
226  if(tStart < tEnd) frame = FrameReadT(file, tStart);}}
227  else if((Par.frun > 0) || (Par.fframe > 0))
228  {frame = FrameReadN(file, Par.frun, Par.fframe);}
229  else{frame = FrameRead(file);}
230  if(frame == NULL) fprintf(stderr,
231  " Cannot read a frame\n %s", FrErrorGetHistory());
232 
233  /*----------------List Channels ----------------------------*/
234 
235  if(Par.debug>2) {
236  if(((Par.dType & ADC) != 0) && (frame->rawData != NULL)) {
237  int nadc=1;
238  for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
239  if(adc->sampleRate>50) {
240  if(Par.tag == NULL) {
241  fprintf(stdout," ADC-%4d: %32s - rate: %15.2f - size: %10lu\n",
242  nadc,adc->name,adc->sampleRate,adc->data->nData);
243  } else if (TString(Par.tag).IsDigit()) {
244  if(TString(Par.tag).Atoi()==nadc) {
245  free((char*)(Par.tag));
246  Par.tag=0;
247  StrCat(&(Par.tag),adc->name);
248  }
249  }
250  nadc++;
251  }
252  }
253  if(Par.tag == NULL) exit(0);
254  }
255  if((Par.dType & PROC) != 0) {
256  int nproc=1;
257  for(proc = frame->procData; proc != NULL; proc = proc->next) {
258  if(Par.tag == NULL) {
259  if(proc->data->dx[0]>0)
260  fprintf(stdout," PROC-%4d: %32s - rate: %15.2f - size: %10lu\n",
261  nproc,proc->name,1./proc->data->dx[0],proc->data->nData);
262  } else if (TString(Par.tag).IsDigit()) {
263  if(TString(Par.tag).Atoi()==nproc) {
264  free((char*)(Par.tag));
265  Par.tag=0;
266  StrCat(&(Par.tag),proc->name);
267  }
268  }
269  nproc++;
270  }
271  if(Par.tag == NULL) exit(0);
272  }
273  }
274 
275  /*----------------Start the Main loop ----------------------------*/
276 
277  int cnt=0;
278  TString cfileName="";
279  while(frame != NULL) {
280 
281  FrFileH *fileH=file->current;
282 
283  /*-------------- Check that we are in the limits -----------------*/
284 
285  if(frame->GTimeS+1.e-9*frame->GTimeN > Par.ltime) break;
286  if(frame->run > Par.lrun) break;
287  if((frame->run == Par.lrun ) && (frame->frame > Par.lframe)) break;
288 
289  /*--------------- Output frame with some tag ---------------------*/
290 
291  if(Par.tag != NULL) FrameTag(frame, Par.tag);
292 
293  /*---------------- Zoom the vectors if needed ---------------------*/
294 
295  if(Par.debug > 2)
296  {gtime = frame->GTimeS+1.e-9*frame->GTimeN;
297  if(Par.ftime > gtime || Par.ltime < gtime+frame->dt)
298  {if(Par.ftime > gtime) start = Par.ftime - gtime;
299  else start = 0;
300  if(Par.ltime < gtime+frame->dt) len = Par.ltime - gtime - start;
301  else len = frame->dt - start;
302  if(frame->rawData != NULL)
303  {for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next)
304  {FrVectZoomIn(adc->data, start, len);}}
305  for(proc = frame->procData; proc != NULL; proc = proc->next)
306  {FrVectZoomIn(proc->data, start, len);}
307  for(sim = frame->simData; sim != NULL; sim = sim->next)
308  {FrVectZoomIn(sim->data, start, len);}}}
309 
310  /*---------------- Dump the data ----------------------------------*/
311 
312  if(Par.dType == 0)
313  {FrameDump(frame, stdout, Par.debug);
314  if(Par.comp != 0) FrameCompDump(frame, stdout, Par.debug);}
315  else
316  {printf("Frame %d/%d GTimeS=%d\n",frame->run,frame->frame,frame->GTimeS);
317  if(((Par.dType & ADC) != 0) && (frame->rawData != NULL)) {
318  if((fp==0) && (Par.debug > 2)) {
319  int size=0;
320  char chname[64]="";
321  FrAdcData *xadc;
322  for(xadc = frame->rawData->firstAdc; xadc != NULL; xadc=xadc->next) {
323  if(nchannel>2)
324  {printf("Multichannel with num channel gt 3 not allowed !!!\n");exit(1);}
325  if(size==0) {
326  size = xadc->data->nData;
327  } else {
328  if(size!=xadc->data->nData)
329  {printf("Multichannel with different size not allowed !!!\n");exit(1);}
330  }
331  if(sampleRate==0) {
332  sampleRate = xadc->sampleRate;
333  } else {
334  if(sampleRate!=xadc->sampleRate)
335  {printf("Multichannel with different sampleRates not allowed !!!\n");exit(1);}
336  }
337  /*----------------- Init Filter -------------------------*/
338  if(Par.filter!=NULL && filter[nchannel]==NULL) {
339  char sratepar[32];
340  sprintf(sratepar," -s %f ",sampleRate);
341  StrCat(&(Par.filter),sratepar);
342  filter[nchannel] = new CWB::Filter(Par.filter);
343  }
344  scale[nchannel]=FrVectMax(xadc->data,nchannel);
345  if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
346  for(int j=0;j<nchannel;j++) if(filter[j]!=NULL) filter[j]->Reset();
347  if(nchannel==0)
348  sprintf(chname,"%s",xadc->name);
349  else
350  sprintf(chname,"%s %s",chname,xadc->name);
351 
352  sprintf(chnames[nchannel],"%s",xadc->name);
353  nchannel++;
354  }
355  if(nchannel==0)
356  {printf("The request channel is not present in the frame !!!\n");exit(1);}
357  double scaleby;
358  if(nchannel==1) {
359  scaleby=scale[0]/4.; // (1./4.) to avoid amplitude cut -> glitches
360  scale[0]=1.;
361  } else {
362  for(int j=0;j<nchannel;j++) scale[j]=32768./scale[j];
363  scaleby=32768./4.;
364  }
365  scaleby*=uscaleby;
366  printf("sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
367  fp=StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel, Par.baudline);
368  }
369  if(fAccess==RANDOM) goto END;
370  int nVect=0;
371  FrVect* outVect[3];
372  for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
373  outVect[nVect]=FrVectDumpBinary(adc->data, 0, nVect, Par.debug);
374  nVect++;
375  }
376  if(nchannel!=0 && nVect!=nchannel)
377  {printf("Multichannel : num of channels is changed !!!\n");exit(1);}
378  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
379  float* buffer = (float*)dumpVect->data;
380  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
381  for(int i=0;i<outVect[0]->nData;i++)
382  for(int j=0;j<nVect;j++)
383  buffer[nVect*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
384  for(int j=0;j<nVect;j++) FrVectFree(outVect[j]);
385  write(fp, buffer, sizeof(float)*dumpVect->nData);
386  FrVectFree(dumpVect);
387  }
388  if(((Par.dType & SMS) != 0) && (frame->rawData != NULL))
389  {for(sms = frame->rawData->firstSer; sms != NULL; sms = sms->next)
390  {printf(" SMS: %s Data:%30s\n", sms->name, sms->data);}}
391  if((Par.dType & STAT) != 0)
392  {if(frame->detectProc != NULL)
393  {printf("Detector used for reconstruction:\n");
394  FrDetectorDump(frame->detectProc, stdout, Par.debug);}
395  if(frame->detectSim != NULL)
396  {printf("Detector used for simulation:\n");
397  FrDetectorDump(frame->detectSim, stdout, Par.debug);}}
398  if((Par.dType & SIM) != 0)
399  {for(sim = frame->simData; sim != NULL; sim = sim->next)
400  {FrSimDataDump(sim, stdout, Par.debug);}}
401  if((Par.dType & EVENT) != 0)
402  {for(simE = frame->simEvent; simE != NULL; simE = simE->next)
403  {FrSimEventDump(simE, stdout,Par.debug);}
404  for(evt = frame->event; evt != NULL; evt = evt->next)
405  {FrEventDump(evt, stdout, Par.debug);}}
406  if((Par.dType & PROC) != 0) {
407  if((fp==0) && (Par.debug > 2)) {
408  int size=0;
409  char chname[64]="";
410  for(proc = frame->procData; proc != NULL; proc = proc->next) {
411  printf("Reconstructed Data: %s\n", proc->name);
412  if(nchannel>2)
413  {printf("Multichannel with num channel gt 3 not allowed !!!\n");exit(1);}
414  if(size==0) {
415  size = proc->data->nData;
416  } else {
417  if(size!=proc->data->nData)
418  {printf("Multichannel with different size not allowed !!!\n");exit(1);}
419  }
420  if(sampleRate==0) {
421  if(proc->data->dx[0] < 1) sampleRate = 1./proc->data->dx[0];
422  else {printf("sampleRate not allowed !!!\n");exit(1);}
423  } else {
424  if(sampleRate!=1./proc->data->dx[0])
425  {printf("Multichannel with different sampleRates not allowed !!!\n");exit(1);}
426  }
427  /*----------------- Init Filter -------------------------*/
428  if(Par.filter!=NULL && filter[nchannel]==NULL) {
429  char sratepar[32];
430  sprintf(sratepar," -s %f ",sampleRate);
431  StrCat(&(Par.filter),sratepar);
432  filter[nchannel] = new CWB::Filter(Par.filter);
433  }
434  scale[nchannel]=FrVectMax(proc->data,nchannel);
435  if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
436  for(int j=0;j<nchannel;j++) if(filter[j]!=NULL) filter[j]->Reset();
437  if(nchannel==0)
438  sprintf(chname,"%s",proc->name);
439  else
440  sprintf(chname,"%s %s",chname,proc->name);
441 
442  sprintf(chnames[nchannel],"%s",proc->name);
443  nchannel++;
444  }
445  if(nchannel==0)
446  {printf("The request channel is not present in the frame !!!\n");exit(1);}
447  double scaleby;
448  if(nchannel==1) {
449  scaleby=scale[0]/4.; // (1./4.) to avoid amplitude cut -> glitches
450  scale[0]=1.;
451  } else {
452  for(int j=0;j<nchannel;j++) scale[j]=32768./scale[j];
453  scaleby=32768./4.;
454  }
455  scaleby*=uscaleby;
456  printf("sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
457  fp=StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel, Par.baudline);
458  }
459  if(fAccess==RANDOM) goto END;
460  int nVect=0;
461  FrVect* outVect[3];
462  for(proc = frame->procData; proc != NULL; proc = proc->next) {
463  outVect[nVect]=FrVectDumpBinary(proc->data, 0, nVect, Par.debug);
464  nVect++;
465  }
466  if(nchannel!=0 && nVect!=nchannel)
467  {printf("Multichannel : num of channels is changed !!!\n");exit(1);}
468  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
469  float* buffer = (float*)dumpVect->data;
470  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
471  for(int i=0;i<outVect[0]->nData;i++)
472  for(int j=0;j<nVect;j++)
473  buffer[nVect*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
474  for(int j=0;j<nVect;j++) FrVectFree(outVect[j]);
475  write(fp, buffer, sizeof(float)*dumpVect->nData);
476  FrVectFree(dumpVect);
477  }
478  if((Par.dType & SUM) != 0)
479  {for(sum = frame->summaryData; sum != NULL; sum = sum->next)
480  {printf("Summary: %s %s \n",sum->name, sum->comment);
481  FrVectDump( sum->moments, stdout, Par.debug);}}
482  if((Par.dType & RAW) != 0)
483  {FrRawDataDump(frame->rawData, stdout, Par.debug);}}
484 
485  if(Par.debug > 1) FrameStat(frame, stdout);
486 
487  if(Par.nTop != -2) FrameDumpTopADC(frame, stdout, Par.nTop, Par.comp);
488 
489  FrameFree(frame);
490 
491  /*---------------------- read the next frame --------------------*/
492 
493  frame = FrameRead(file);
494 
495  /*------------------End the Main loop ----------------------------*/
496  }
497 
498 END:
499  if(fAccess==RANDOM) FrFileDumpBinary(file,fp,scale,nchannel,sampleRate);
500 
501  FrFileIStat(file, stdout);
502 
503  if(Par.debug > 2) {
504  printf("\n\nhit Ctrl-C\n\n");
505  while (1) pause();
506  }
507  exit(0);
508 }
509 
510  /*------------------Read file in random mode --------------------*/
511 void FrFileDumpBinary(FrFile* file, int fp, double* scale,int nchannel,double sampleRate) {
512 
513  double tCurrent=0;
514 
515  FrFileH *fileH=file->fileH;
516  while(fileH!=NULL) {
517  cout << fileH->fileName << endl;
518 
519  FrVect* outVect[3];
520  for(int nVect=0;nVect<nchannel;nVect++) {
521  FrFile* cfile=FrFileINew(fileH->fileName);
522  FrTOCFFLBuild(cfile);
523  FrFileH *cfileH=cfile->current;
524  double cStart=cfileH->tStart;
525  double cEnd=cfileH->tStart+cfileH->length;
526  if(Par.ftime>cStart) cStart=Par.ftime;
527  if(Par.ltime<cEnd) cEnd=Par.ltime;
528  double clength=cEnd-cStart;
529 
530  if(tCurrent!=0 && nVect==0) {
531  if(cStart!=tCurrent) {
532  cout.precision(14);
533  cout << "tCurrent " << tCurrent << endl;
534  cout << "cStart " << cStart << endl;
535  cout << "cEnd " << cEnd << endl;
536  int nullSize=(cStart-tCurrent)*sampleRate;
537  if(((cStart-tCurrent)<=MIN_TIME_GAP)&&((cStart-tCurrent)>0)) {
538  FrVect* nullVect = FrVectNew1D(const_cast<char*>("NULL"), FR_VECT_4R, nullSize, 0, NULL, NULL);
539  float* dF = (float*)nullVect->data;
540  for(int i=0; i<nullSize; i++) dF[i]-0;;
541  write(fp, dF, sizeof(float)*nullSize);
542  FrVectFree(nullVect);
543  } else {
544  cout << "Error : data not contiguous !!!" << endl;
545  exit(1);
546  }
547  }
548  }
549  tCurrent=cEnd;
550 
551  outVect[nVect]=FrFileIGetVectF(cfile, chnames[nVect], cStart, clength);
552  float* dF = (float *) outVect[nVect]->data;
553  if(filter[nVect]!=NULL) {
554  for(int i=0; i<outVect[nVect]->nData; i++)
555  dF[i]=filter[nVect]->Arma((double)dF[i]);
556  }
557  FrFileIClose(cfile);
558  }
559 
560  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nchannel*outVect[0]->nData, 0, NULL, NULL);
561  float* buffer = (float*)dumpVect->data;
562  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
563  for(int i=0;i<outVect[0]->nData;i++)
564  for(int j=0;j<nchannel;j++)
565  buffer[nchannel*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
566  for(int j=0;j<nchannel;j++) FrVectFree(outVect[j]);
567  write(fp, buffer, sizeof(float)*dumpVect->nData);
568  FrVectFree(dumpVect);
569 
570  fileH=fileH->next;
571  }
572 
573  return;
574 }
575 
576 /*------------------------------------------------------ SetParameters ------*/
577 void ReadParameters(int argc, char **argv)
578 /*---------------------------------------------------------------------------*/
579 {int type, i;
580  char cmd[256];
581 
582  if (argc == 1)
583  {Help();
584  exit(0);}
585 
586  /*-------------------- Get Operative System Type -----------------*/
587 
588  TString OS = "";
589  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
590  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
591  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
592 
593  /*-------------------- Default values ----------------------------*/
594 
595  Par.name = NULL;
596  Par.tag = NULL;
597  Par.debug = 1;
598  Par.comp = 0;
599  Par.ftime = UNSET;
600  Par.ltime = UNSET;
601  Par.frun = UNSET;
602  Par.lrun = UNSET;
603  Par.fframe = UNSET;
604  Par.lframe = UNSET;
605  Par.nTop = -2;
606 
607  /*------------------- Loop over the parameters -------------------*/
608 
609  type = UNSET;
610 
611  for (i=1; i<argc; i++)
612  {if (strcmp(argv[i],"-h") == 0)
613  {Help();
614  exit(0);}
615  else if (strcmp(argv[i],"-i") == 0) {type = INPUT;}
616  else if (strcmp(argv[i],"-t") == 0) {type = TAG;}
617  else if (strcmp(argv[i],"-f") == 0) {type = FIRST;}
618  else if (strcmp(argv[i],"-l") == 0) {type = LAST;}
619  else if (strcmp(argv[i],"-d") == 0) {type = DEBUG;}
620  else if (strcmp(argv[i],"-c") == 0) {type = COMPRESS;}
621  else if (strcmp(argv[i],"-x") == 0) {type = BAUDLINE;}
622  else if (strcmp(argv[i],"-o") == 0) {type = OBSERVATORY;}
623  else if (strcmp(argv[i],"-s") == 0) {type = DATATYPE;}
624  else if (strcmp(argv[i],"-k") == 0) {type = FILTER;}
625  else if (strcmp(argv[i],"-a") == 0) {type = ACCESS;}
626  else if (strcmp(argv[i],"-top") == 0) {type = TOP;}
627  else if (strcmp(argv[i],"-adc") == 0) {Par.dType = Par.dType | ADC;}
628  else if (strcmp(argv[i],"-sms") == 0) {Par.dType = Par.dType | SMS;}
629  else if (strcmp(argv[i],"-stat") == 0) {Par.dType = Par.dType | STAT;}
630  else if (strcmp(argv[i],"-sim") == 0) {Par.dType = Par.dType | SIM;}
631  else if (strcmp(argv[i],"-event") == 0) {Par.dType = Par.dType | EVENT;}
632  else if (strcmp(argv[i],"-proc") == 0) {Par.dType = Par.dType | PROC;}
633  else if (strcmp(argv[i],"-sum") == 0) {Par.dType = Par.dType | SUM;}
634  else if (strcmp(argv[i],"-raw") == 0) {Par.dType = Par.dType | RAW;}
635  else
636  {if(type == INPUT) {StrCat(&(Par.name),argv[i]);}
637  if(type == TAG) {StrCat(&(Par.tag),argv[i]);}
638  if(type == BAUDLINE) {StrCat(&(Par.baudline),argv[i]);}
639  if(type == OBSERVATORY) {StrCat(&(Par.observatory),argv[i]);}
640  if(type == DATATYPE) {StrCat(&(Par.datatype),argv[i]);}
641  if(type == FILTER) {StrCat(&(Par.filter),argv[i]);}
642  if(type == ACCESS) {StrCat(&(Par.access),argv[i]);}
643  if(type == FIRST)
644  {if(Par.ftime == UNSET)
645  {Par.ftime = atof(argv[i]);}
646  else {Par.frun = Par.ftime;
647  Par.fframe = atoi(argv[i]);}}
648  if(type == LAST)
649  {if(Par.ltime == UNSET)
650  {Par.ltime = atof(argv[i]);}
651  else {Par.lrun = Par.ltime;
652  Par.lframe = atoi(argv[i]);}}
653  if(type == DEBUG) {Par.debug = atoi(argv[i]);}
654  if(type == COMPRESS) {Par.comp = atoi(argv[i]);}
655  if(type == TOP) {Par.nTop = atoi(argv[i]);}
656  }}
657 
658  /*------------------ Check start/stop parameters------------------*/
659 
660  if(Par.fframe != UNSET) Par.ftime = 0.;
661  if(Par.lframe != UNSET) Par.ltime = 1.e+12;
662  if(Par.frun == UNSET) Par.frun = 0;
663  if(Par.lrun == UNSET) Par.lrun = INT_MAX;
664  if(Par.fframe == UNSET) Par.fframe = 0;
665  if(Par.lframe == UNSET) Par.lframe = INT_MAX;
666  if(Par.ftime == UNSET) Par.ftime = 0;
667  if(Par.ltime == UNSET) Par.ltime = INT_MAX;
668 
669  /*---------------------------- Check filter help --------------*/
670 
671  if(Par.filter!=NULL) {
672  if(strstr(Par.filter,"help")!=NULL) {
673  printf("filter help !!!\n");
674  CWBFilterHelp();
675  exit(0);
676  }
677  }
678 
679  /*---------------------------- Check baudline help --------------*/
680 
681  if(Par.baudline!=NULL) {
682  if(strstr(Par.baudline,"help")!=NULL) {
683  printf("baudline help !!!\n");
684 
685  char baudline[256];
686  if(getenv("BAUDLINE_CMD")!=NULL) {
687  printf("BAUDLINE_CMD : %s\n",getenv("BAUDLINE_CMD"));
688  sprintf(baudline,"%s",getenv("BAUDLINE_CMD"));}
689  else
690  {printf("Cannot get BAUDLINE_CMD env\n");exit(1);}
691 
692  sprintf(cmd,"%s -help",baudline);
693  printf("%s\n",cmd);
694  System(cmd);
695  exit(0);
696  }
697  }
698 
699  /*---------------------------- Set baudline_rc --------------*/
700 
701  int downmix=0;
702  if(Par.baudline!=NULL) {
703  TObjArray* token = TString(Par.baudline).Tokenize(TString(' '));
704  for(int i=0;i<token->GetEntries();i++) {
705  TObjString* tok = (TObjString*)token->At(i);
706  TString stok = tok->GetString();
707  if(stok.CompareTo("-downmix")==0) {
708  if(i==token->GetEntries()-1) {cout << "error : downmix par without value" << endl;exit(1);}
709  TObjString* vtok = (TObjString*)token->At(i+1);
710  TString svtok = vtok->GetString();
711  if(!svtok.IsFloat()) {cout << "error : downmix par not digit" << endl;exit(1);}
712  downmix = svtok.Atoi();
713  }
714  if(stok.CompareTo("-uscaleby")==0) {
715  if(i==token->GetEntries()-1) {cout << "error : scaleby par without value" << endl;exit(1);}
716  TObjString* vtok = (TObjString*)token->At(i+1);
717  TString svtok = vtok->GetString();
718  if(!svtok.IsFloat()) {cout << "error : scaleby par not digit" << endl;exit(1);}
719  uscaleby = svtok.Atof();
720  // remove scaleby from bauline input string
721  sprintf(Par.baudline,"%s","");
722  for(int j=0;j<token->GetEntries();j++) {
723  TObjString* tok = (TObjString*)token->At(j);
724  TString stok = tok->GetString();
725  if(j!=i && j!=i+1) sprintf(Par.baudline,"%s %s",Par.baudline,stok.Data());
726  }
727  }
728  }
729  }
730 
731  //UserGroup_t* uinfo = gSystem->GetUserInfo();
732  //TString uname = uinfo->fUser;
733  TString uhome=TString(gSystem->Getenv("HOME"));
734  char baudline_rc_path[256];
735  sprintf(baudline_rc_path,"%s/.baudline/baudline_rc",uhome.Data());
736  char baudline_rc_tmp_path[256];
737  sprintf(baudline_rc_tmp_path,"%s/.baudline/baudline_rc.tmp",uhome.Data());
738 
739  Long_t id,size,flags,mt;
740  int estat = gSystem->GetPathInfo(baudline_rc_path,&id,&size,&flags,&mt);
741  if (estat==0) {
742 
743  ifstream in;
744  in.open(baudline_rc_path,ios::in);
745  if (!in.good()) {cout << "Error Opening File : " << baudline_rc_path << endl;exit(1);}
746 
747  ofstream out;
748  out.open(baudline_rc_tmp_path,ios::out);
749  if (!out.good()) {cout << "Error Opening File : " << baudline_rc_tmp_path << endl;exit(1);}
750 
751  bool flag=false;
752  char line[256];
753  int cnt=1;
754  while (1) {
755  in.getline(line,256);
756  if (!in.good()) break;
757  //cout << line << endl;
758  TString sline(line);
759  if(sline.Contains("downmix")) {out << "downmix " << downmix << endl;flag=true;}
760  else out << sline.Data() << endl;
761  }
762  if(!flag) {out << "downmix " << downmix << endl;}
763  in.close();
764  out.close();
765 
766  char cmd[256];
767  sprintf(cmd,"mv %s %s",baudline_rc_tmp_path,baudline_rc_path);
768  gSystem->Exec(cmd);
769  }
770 
771  /*---------------------------- Check access file mode ------------*/
772 
773  if((Par.access!=NULL)&&(strcmp(Par.access,"s"))==0) fAccess=SEQUENTIAL;
774  if((Par.access!=NULL)&&(strcmp(Par.access,"r"))==0) fAccess=RANDOM;
775 
776  /*---------------------------- Check if input is an ffl file -----*/
777 
778  if((Par.name!=NULL)&&(TString(Par.name).Contains(".ffl"))==1) {
779 
780  TString ffl_file_path = gSystem->ExpandPathName(Par.name);
781 
782  ifstream in;
783  in.open(ffl_file_path.Data(),ios::in);
784  if (!in.good()) {cout << "Error Opening File : " << ffl_file_path.Data() << endl;exit(1);}
785 
786  ofstream out;
787  if(OS=="Linux") sprintf(baudline_FFL,"/dev/shm/%s/%d.ffl",getlogin(),baudline_rnID);
788  if(OS=="Darwin") sprintf(baudline_FFL,"/tmp/%s/%d.ffl",getlogin(),baudline_rnID); //MAC
789  out.open(baudline_FFL,ios::out);
790  if (!out.good()) {cout << "Error Opening File : " << baudline_FFL << endl;exit(1);}
791 
792  char file_path[1024];
793  double start;
794  double lenght;
795  double dummy1,dummy2;
796  while (1) {
797  in >> file_path >> start >> lenght >> dummy1 >> dummy2;
798  if (!in.good()) break;
799  out.precision(14);
800  cout.precision(14);
801  if((start>=Par.ftime)&&(start<=Par.ltime)) {
802  //cout << file_path << " " << start << " " << lenght << endl;
803  out << file_path << " " << start << " " << lenght << " " << dummy1 << " " << dummy2 << endl;
804  }
805  }
806  in.close();
807 
808  free((char*)(Par.name));
809  Par.name=0;
810  StrCat(&(Par.name),baudline_FFL);
811  }
812 
813  /*---------------------------- Check gw_data_find --------------*/
814 
815  if((Par.name!=NULL)&&(strcmp(Par.name,"ldf"))==0) {
816  // check if gw_data_find is available
817  int ret=gSystem->Exec("gw_data_find -v");
818  if(ret!=0) {printf("gw_data_find is not available !!!\n");exit(1);}
819  if(Par.datatype!=0) {
820  if(strstr(Par.datatype,"help")!=NULL) {
821  sprintf(cmd,"gw_data_find --show-types ");
822  printf("%s\n",cmd);
823  System(cmd);
824  exit(0);
825  }
826  }
827 
828  if(Par.observatory==0) {printf("parameter observatory -o not defined !!!\n");exit(1);}
829  if(Par.ftime==0) {printf("parameter GPS start -f not defined !!!\n");exit(1);}
830  if(Par.ltime==0) {printf("parameter GPS stop -l not defined !!!\n");exit(1);}
831  if(Par.datatype==0) {printf("parameter data type -s not defined !!!\n");exit(1);}
832 
833  if(OS=="Linux") sprintf(baudline_FFL,"/dev/shm/%s/%d.ffl",getlogin(),baudline_rnID);
834  if(OS=="Darwin") sprintf(baudline_FFL,"/tmp/%s/%d.ffl",getlogin(),baudline_rnID); //MAC
835 
836  sprintf(cmd,"gw_data_find --observatory=%s --type=%s --gps-start-time=%d --gps-end-time=%d --url-type=file | sed -e \'s/file:\\/\\/localhost//g\' > %s",Par.observatory,Par.datatype,(int)Par.ftime,(int)Par.ltime,baudline_FFL);
837  printf("%s\n",cmd);
838  int pid=System(cmd);
839 
840  // check if output command file is empty
841  Long_t xid,xsize,xflags,xmt;
842  int xestat = gSystem->GetPathInfo(baudline_FFL,&xid,&xsize,&xflags,&xmt);
843  if (xestat!=0 || xsize==0) { // if empty then remove temporary file
844  sprintf(cmd,"/bin/rm %s",baudline_FFL);
845  gSystem->Exec(cmd);
846  gSystem->Exit(1);
847  }
848 
849  // get rid of duplicate file names
851 
852  printf("pid %d\n",pid);
853 
854  free((char*)(Par.name));
855  Par.name=0;
856  StrCat(&(Par.name),baudline_FFL);
857  }
858 
859 /*
860  if((Par.tag == NULL)&&(Par.debug>4))
861  {fprintf(stderr," Please provide at least one channel name\n");
862  Help();
863  exit(0);}
864 */
865  if(Par.name == NULL)
866  {fprintf(stderr," Please provide at least one input file\n");
867  Help();
868  exit(0);}
869 
870  /*-------------------------- Dump parameters ---------------------*/
871 
872  if(Par.ltime < Par.ftime) Par.ltime += Par.ftime -1.e-6;
873 
874  if (Par.debug>0)
875  {printf("-----------Parameters used--------------\n");
876  printf(" Input Files: %s\n", Par.name);
877  if(Par.tag != NULL) printf(" Tag : %s\n",Par.tag);
878  printf(" First frame : %d %d (GPS=%.1f)\n",
879  Par.frun,Par.fframe,Par.ftime);
880  if(Par.ltime < 100000000)
881  printf(" Lenght : %.1fs\n", Par.ltime);
882  else printf(" Last frame : %d %d (GPS=%.1f)\n",
883  Par.lrun,Par.lframe,Par.ltime);
884  printf(" Debug level : %d\n", Par.debug);
885  if((Par.dType & ADC) != 0) printf(" Dump adc info\n");
886  if((Par.dType & SMS) != 0) printf(" Dump sms info\n");
887  if((Par.dType & STAT) != 0) printf(" Dump Stat info\n");
888  if((Par.dType & SIM) != 0) printf(" Dump sim info\n");
889  if((Par.dType & EVENT) != 0) printf(" Dump event info\n");
890  if((Par.dType & PROC) != 0) printf(" Dump proc info\n");
891  if((Par.dType & SUM) != 0) printf(" Dump summary info\n");
892  if((Par.dType & RAW) != 0) printf(" Dump raw data info\n");
893  if( Par.dType == 0) printf(" Dump all Frame info\n");
894  printf("----------------------------------------\n");}
895 
896  return;
897 }
898 
899 /*----------------------------------------------------------------- StrCat --*/
900 void StrCat(char **oldbuf, char *more)
901 /*---------------------------------------------------------------------------*/
902 {int lenMore;
903  char *newbuf;
904 
905  lenMore = strlen(more);
906 
907  if(*oldbuf == NULL)
908  {*oldbuf = (char*)malloc(strlen(more) + 1);
909  strcpy(*oldbuf, more);
910  return;}
911 
912  newbuf = (char*)malloc( strlen(*oldbuf) + lenMore + 2);
913  sprintf(newbuf,"%s %s",*oldbuf, more);
914  free(*oldbuf);
915  *oldbuf = newbuf;
916 
917  return;}
918 
919 /*---------------------------------------------------------- StartBaudline --*/
920 int StartBaudline(int gpsSec, int gpsNSec, double scale,
921  double sampleRate, char* chname, int nchannel, char* params) {
922 /*---------------------------------------------------------------------------*/
923  char sbdate[256];
924  GetBaudlineDateFormat(gpsSec, gpsNSec, sbdate);
925  printf("date : %s - chname : %s\n",sbdate,chname);
926  printf("sampleRate %f - scale %e\n",sampleRate,scale);
927 
928  char cmd[1024];
929  int pid;
930 
931  char baudline[256];
932  if(getenv("BAUDLINE_CMD")!=NULL) {
933  printf("BAUDLINE_CMD : %s\n",getenv("BAUDLINE_CMD"));
934  sprintf(baudline,"%s",getenv("BAUDLINE_CMD"));}
935  else
936  {printf("Cannot get BAUDLINE_CMD env\n");exit(1);}
937 
938  char palette[256];
939  if(getenv("BAUDLINE_PALETTE")!=NULL) {
940  printf("BAUDLINE_PALETTE : %s\n",getenv("BAUDLINE_PALETTE"));
941  sprintf(palette,"%s",getenv("BAUDLINE_PALETTE"));}
942  else
943  {printf("Cannot get BAUDLINE_PALETTE env\n");exit(1);}
944 
945  TString OS = "";
946  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
947  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
948  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
949 
950  char pipe_name[256];
951  if(OS=="Linux") sprintf(pipe_name,"/dev/shm/%s/cwb-pipe-%d",getlogin(),baudline_rnID);
952  if(OS=="Darwin") sprintf(pipe_name,"/tmp/%s/cwb-pipe-%d",getlogin(),baudline_rnID); //MAC
953  printf("%s\n",pipe_name);
954  if(OS=="Linux") sprintf(cmd,"mknod %s p",pipe_name);
955  if(OS=="Darwin") sprintf(cmd,"mkfifo %s",pipe_name);
956  printf("%s\n",cmd);
957  pid = System(cmd);
958 
959  if(params==NULL) StrCat(&(params),const_cast<char*>(""));
960 
961  char tsession[256];
962  sprintf(tsession,"\"%s - %s - ID%d\"",chname,FrStrUTC(gpsSec,0),baudline_rnID);
963 
964  sprintf(baudline_wNAME,"%s-%s-ID%d",chname,FrStrUTC(gpsSec,0),baudline_rnID);
965  int i;
966  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]==' ') baudline_wNAME[i]='_';
967  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]==':') baudline_wNAME[i]='_';
968  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]=='-') baudline_wNAME[i]='_';
969  printf("%s\n",baudline_wNAME);
970 
971  sprintf(cmd,"cat %s | %s -utc %s -spacebar recordpause -basefrequency 0 -decimateby 1 -psd -format le32f -stdin -overlap 100 -samplerate %f -scaleby %e -average.savepsd -record -memory 10 -reversetimeaxis -tsession %s -overlays 1 -channels %d -palette %s -fftsize 65536 %s&", pipe_name,baudline,sbdate,sampleRate,scale,tsession,nchannel,palette,params);
972  printf("%s\n",cmd);
973  pid = System(cmd);
974  printf("Baudline pid : %d\n",pid);
975 
976  sprintf(cmd,"ps -ef | grep baudline | grep ID%d | awk \'{print $2}\'",baudline_rnID);
977  printf("%s\n",cmd);
978  System(cmd);
979 
980  int fp = open(pipe_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | O_NONBLOCK);
981  if(fp <= 0)
982  {fprintf(stderr,"Cannot open output pipe %s\n %s", pipe_name, FrErrorGetHistory());
983  exit(1);}
984 
985  return fp;
986 }
987 
988 void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char* sbdate) {
989 
990  printf("gpsSec %d - gpsNSec %d\n",gpsSec,gpsNSec);
991  printf("UTC : %s\n",FrStrUTC(gpsSec,0));
992 
993  time_t unix_date_sec = FrGPS2UTC(gpsSec, 0);
994  int us = gpsNSec/1000;
995 
996  struct tm* tp = gmtime(&unix_date_sec);
997 
998  int ss = tp->tm_sec; // seconds 0:59
999  int mm = tp->tm_min; // minutes 0:59
1000  int hh = tp->tm_hour; // hours 0:23
1001  int DD = tp->tm_mday; // day of the month 1:31
1002  int MM = tp->tm_mon+1; // month 0:11
1003  int YY = tp->tm_year; // year since 1900
1004 
1005  char bdate[32]="00:00:00-00:00:00.000000";
1006  char tmp[32];int len=0;
1007  sprintf(tmp,"%d",YY);len=strlen(tmp);
1008  if(len==3) strncpy(bdate+2-len+1,tmp+1,len-1); else strncpy(bdate+2-len,tmp,len);
1009  sprintf(tmp,"%d",MM);len=strlen(tmp);strncpy(bdate+5-len,tmp,len);
1010  sprintf(tmp,"%d",DD);len=strlen(tmp);strncpy(bdate+8-len,tmp,len);
1011  sprintf(tmp,"%d",hh);len=strlen(tmp);strncpy(bdate+11-len,tmp,len);
1012  sprintf(tmp,"%d",mm);len=strlen(tmp);strncpy(bdate+14-len,tmp,len);
1013  sprintf(tmp,"%d",ss);len=strlen(tmp);strncpy(bdate+17-len,tmp,len);
1014  sprintf(tmp,"%d",us);len=strlen(tmp);strncpy(bdate+24-len,tmp,len);
1015 
1016  strcpy(sbdate,bdate);
1017  printf("Baudline Date Format : %s\n",sbdate);
1018 
1019  return;
1020 }
1021 
1022 int System(const char *command) {
1023 
1024  int pid, status;
1025  extern char **environ;
1026 
1027  if (command == NULL) {printf("System : NULL Command\n");exit(1);}
1028  pid = fork();
1029  if (pid == -1) {printf("System : Fork Failed\n");exit(1);}
1030  if (pid == 0) {
1031  char *argv[4];
1032  argv[0] = const_cast<char*>("sh");
1033  argv[1] = const_cast<char*>("-c");
1034  argv[2] = (char*)command;
1035  argv[3] = 0;
1036  execve("/bin/sh", argv, environ);
1037  exit(127);
1038  }
1039  do {
1040  if (waitpid(pid, &status, 0) == -1) {
1041  if (errno != EINTR) {printf("System : waitpid error %d\n",errno);exit(1);}
1042  } else
1043  return pid;
1044  } while(1);
1045 }
1046 
1047 void INThandler(int sig) {
1048 
1049  char c;
1050 
1051  TString OS = "";
1052  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
1053  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
1054  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
1055 
1056  signal(sig, SIG_IGN);
1057  printf("Do you really want to quit? [y/n] or save? [s] ");
1058  c = getchar();
1059  if (c == 'y' || c == 'Y') {
1060  char cmd[256];
1061  //sprintf(cmd,"ps -ef | grep baudline | grep ID%d | awk \'{print $2}\' | xargs kill",baudline_rnID);
1062  if(OS=="Linux") sprintf(cmd,"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1063  if(OS=="Darwin") sprintf(cmd,"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1064  printf("%s\n",cmd);
1065  System(cmd);
1066 
1067  // remove temporary frame file list
1068  sprintf(cmd,"/bin/rm %s",Par.name);
1069  //gSystem->Exec(cmd);
1070 
1071  exit(0);
1072  } else if (c == 's' || c == 'S') {
1073  printf("click window to be saved\n");
1074  char cmd[256];
1075  sprintf(cmd,"import -frame %s/%s_P%d.png",workdir.Data(),baudline_wNAME,baudline_nP++);
1076  printf("%s\n",cmd);
1077  System(cmd);
1078  fflush(stdout);
1079  signal(SIGINT, INThandler);
1080  } else {
1081  fflush(stdout);
1082  signal(SIGINT, INThandler);
1083  }
1084 }
1085 
1086 
1087 /*---------------------------------------------------------FrVectDumpBinary--*/
1088 FrVect* FrVectDumpBinary(FrVect *vect,
1089  int ofp,
1090  int chId,
1091  int debugLvl)
1092 /*---------------------------------------------------------------------------*/
1093 {FRULONG i, nData, inValid;
1094  char *dC, **dSt;
1095  short *dS;
1096  int *dI;
1097  FRLONG *dL;
1098  float *dF, ratio;
1099  double *dD;
1100  unsigned char *dU;
1101  unsigned short *dUS;
1102  unsigned int *dUI;
1103  FRULONG *dUL;
1104 
1105 // if(ofp <= 0) return NULL;
1106  if(vect == NULL) return NULL;
1107  if(debugLvl < 1) return NULL;
1108 
1109  FILE* fp = stdin;
1110 
1111  nData = vect->nData;
1112 /*
1113  if(vect->name == NULL)
1114  {fprintf(fp," Vector:- ndata=%"FRLLD, nData);}
1115  else {fprintf(fp," Vector:%s ndata=%"FRLLD, vect->name, nData);}
1116 
1117  if(vect->GTime != 0) fprintf(fp," GTime=%.5f",vect->GTime);
1118 
1119  if(vect->unitY != NULL)
1120  {fprintf(fp," unitY=%s", vect->unitY);}
1121 
1122  if(vect->nDim == 1)
1123  {if(vect->unitX[0] != NULL) fprintf(fp," unitX=%s", vect->unitX[0]);
1124  fprintf(fp," startX=%g dx=%g\n", vect->startX[0], vect->dx[0]);}
1125  else
1126  {fprintf(fp," nDim=%d\n", vect->nDim);
1127  for(i=0; i<vect->nDim; i++)
1128  {fprintf(fp," Dimension=%"FRLLD" nx=%10"FRLLD" startX=%.2g dx=%g",
1129  i,vect->nx[i], vect->startX[i], vect->dx[i]);
1130  if(vect->unitX[i] != NULL) fprintf(fp," unit=%s\n", vect->unitX[i]);
1131  else fprintf(fp,"\n");}}
1132  fprintf(fp," Data");
1133 */
1134 
1135  /*-------------------------------------- data part ---------------*/
1136  FrVect* outVect=NULL;
1137  if(vect->compress == 0) {
1138  if(vect->type == FR_VECT_4R) { /*----------------- float-------------*/
1139  dF = (float *) vect->data;
1140  if(debugLvl >2) {
1141  outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1142  float* buffer = (float*)outVect->data;
1143  if(filter[chId]!=NULL)
1144  for(i=0; i<nData; i++) buffer[i]=filter[chId]->Arma((double)dF[i]);
1145  else
1146  for(i=0; i<nData; i++) buffer[i]=dF[i];
1147  if(ofp!=0) {
1148  write(ofp, buffer, sizeof(float)*nData);
1149  FrVectFree(outVect);outVect=NULL;
1150  }
1151  }
1152  }
1153  else if(vect->type == FR_VECT_8R) { /*---------------- double ------------*/
1154  dD = (double *) vect->data;
1155  fprintf(fp,"(double) %s\n",FrVectStat(vect));
1156  if(debugLvl >2) {
1157  outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1158  float* buffer = (float*)outVect->data;
1159  if(filter[chId]!=NULL)
1160  for(i=0; i<nData; i++) buffer[i]=filter[chId]->Arma(dD[i]);
1161  else
1162  for(i=0; i<nData; i++) buffer[i]=dD[i];
1163  if(ofp!=0) {
1164  write(ofp, buffer, sizeof(float)*nData);
1165  FrVectFree(outVect);outVect=NULL;
1166  }
1167  }
1168  }
1169  else if(vect->type == FR_VECT_C) /*---------------one byte integer-----*/
1170  {dC = vect->data;
1171  fprintf(fp,"(byte) %s\n",FrVectStat(vect));
1172  if(debugLvl > 2)
1173  {for(i=0; i<nData; i++)
1174  {if(i%20 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1175  fprintf(fp,"%4d",dC[i]);}
1176  fprintf(fp,"\n");}}
1177 
1178  else if(vect->type == FR_VECT_2S) /*-------------- short integer -------*/
1179  {dS = (short *) vect->data;
1180  fprintf(fp,"(short) %s\n",FrVectStat(vect));
1181  if(debugLvl > 2)
1182  {for(i=0; i<nData; i++)
1183  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1184  fprintf(fp," %6d",dS[i]);}
1185  fprintf(fp,"\n");}}
1186 
1187  else if(vect->type == FR_VECT_8S) /*---------------long integer---------*/
1188  {dL = (FRLONG *) vect->data;
1189  fprintf(fp,"(8S) %s\n",FrVectStat(vect));
1190  if(debugLvl > 2)
1191  {for(i=0; i<nData; i++)
1192  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1193  fprintf(fp," %d\"FRLLD\"",dL[i]);}
1194  fprintf(fp,"\n");}}
1195 
1196  else if(vect->type == FR_VECT_4S) /*------------- signed integer -------*/
1197  {dI = (int *) vect->data;
1198  fprintf(fp,"(int) %s\n",FrVectStat(vect));
1199  if(debugLvl > 2)
1200  {for(i=0; i<nData; i++)
1201  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1202  fprintf(fp," %8d",dI[i]);}
1203  fprintf(fp,"\n");}}
1204 
1205  else if(vect->type == FR_VECT_1U) /*--------- unsigned character----*/
1206  {dU = (unsigned char *)vect->dataU;
1207  fprintf(fp,"(1U) %s\n",FrVectStat(vect));
1208  if(debugLvl > 2)
1209  {for(i=0; i<nData; i++)
1210  {if(i%20 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1211  fprintf(fp," %4d",dU[i]);}
1212  fprintf(fp,"\n");}}
1213 
1214  else if(vect->type == FR_VECT_2U) /*-------------unsigned short -----*/
1215  {dUS = (unsigned short *) vect->data;
1216  fprintf(fp,"(2U) %s\n",FrVectStat(vect));
1217  if(debugLvl > 2)
1218  {for(i=0; i<nData; i++)
1219  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1220  fprintf(fp," %6d",dUS[i]);}
1221  fprintf(fp,"\n");}}
1222 
1223  else if(vect->type == FR_VECT_8U)
1224  {dUL = (FRULONG *) vect->data;
1225  fprintf(fp,"(8U) %s\n",FrVectStat(vect));
1226  if(debugLvl > 2)
1227  {for(i=0; i<nData; i++)
1228  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1229  fprintf(fp," %d\"FRLLD\"",dUL[i]);}
1230  fprintf(fp,"\n");}}
1231 
1232  else if(vect->type == FR_VECT_4U)
1233  {dUI = (unsigned int *) vect->data;
1234  fprintf(fp,"(4U) %s\n",FrVectStat(vect));
1235  if(debugLvl > 2)
1236  {for(i=0; i<nData; i++)
1237  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1238  fprintf(fp," %12d",dUI[i]);}
1239  fprintf(fp,"\n");}}
1240 
1241  else if(vect->type == FR_VECT_8C) /*------------- complex float ------*/
1242  {dF = (float *) vect->data;
1243  fprintf(fp,"(8C) %s\n", FrVectStat(vect));
1244  if(debugLvl <3)
1245  {fprintf(fp," (%g,%g)", dF[0],dF[1]);
1246  if(nData > 1) fprintf(fp," (%g,%g) ...", dF[2],dF[3]);
1247  fprintf(fp,"\n");}
1248  else
1249  {for(i=0; i<nData; i++)
1250  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1251  fprintf(fp,"(%12g %12g)",dF[2*i],dF[2*i+1]);}
1252  fprintf(fp,"\n");}}
1253 
1254  else if(vect->type == FR_VECT_16C) /*------------- complex double ------*/
1255  {dD = (double *) vect->data;
1256  fprintf(fp,"(16C) %s\n", FrVectStat(vect));
1257  if(debugLvl <3)
1258  {fprintf(fp," (%g,%g)",dD[0],dD[1]);
1259  if(nData > 1) fprintf(fp," (%g,%g) ...",dD[2],dD[3]);
1260  fprintf(fp,"\n");}
1261  else
1262  {for(i=0; i<nData; i++)
1263  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1264  fprintf(fp,"(%12g %12g)",dD[2*i],dD[2*i+1]);}
1265  fprintf(fp,"\n");}}
1266 
1267  else if(vect->type == FR_VECT_8H) /*-------half complex float -------*/
1268  {dF = (float *) vect->data;
1269  fprintf(fp,"(8H) %s\n", FrVectStat(vect));
1270  if(debugLvl <3)
1271  {fprintf(fp," %g ", dF[0]);
1272  if(nData > 1) fprintf(fp,", (%g,%g) ...", dF[1],dF[nData-1]);
1273  fprintf(fp,"\n");}
1274  else
1275  {fprintf(fp,"%6d:(%12g %12g)", 0, dF[0], 0.);
1276  for(i=1; i<nData/2; i++)
1277  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1278  fprintf(fp,"(%12g %12g)",dF[i],dF[nData-i]);}
1279  if(nData%2 == 0) fprintf(fp,"(%12g 0.)",dF[nData/2]);
1280  fprintf(fp,"\n");}}
1281 
1282  else if(vect->type == FR_VECT_16H) /*----half complex double -------*/
1283  {dD = (double *) vect->data;
1284  fprintf(fp,"(16H) %s\n", FrVectStat(vect));
1285  if(debugLvl <3)
1286  {fprintf(fp," %g",dD[0]);
1287  if(nData > 1) fprintf(fp,", (%g,%g) ...\n",dD[1],dD[nData-1]);
1288  fprintf(fp,"\n");}
1289  else
1290  {fprintf(fp,"%6d:(%12g %12g)", 0, dD[0], 0.);
1291  for(i=1; i<nData/2; i++)
1292  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1293  fprintf(fp,"(%12g %12g)",dD[i],dD[nData-i]);}
1294  if(nData%2 == 0) fprintf(fp,"(%12g 0.)",dD[nData/2]);
1295  fprintf(fp,"\n");}}
1296 
1297  else if(vect->type == FR_VECT_STRING)
1298  {dSt = (char **) vect->data;
1299  fprintf(fp,"(STRING)");
1300  if(dSt[0] != NULL) fprintf(fp," \"%s\"", dSt[0]);
1301  if(dSt[1] != NULL) fprintf(fp," \"%s\"", dSt[1]);
1302  fprintf(fp,"...\n");}
1303  else
1304  {fprintf(fp," unknown type: %d \n",vect->type );}}
1305  else
1306  {ratio = (nData*vect->wSize)/(float) vect->nBytes;
1307  fprintf(fp,"\n the vector is %.2f compressed (%x) nBytes=%d\"FRLLD\" wSize=%d\n",
1308  ratio,vect->compress,vect->nBytes, vect->wSize);}
1309 
1310  if(vect->next != NULL)
1311  {fprintf(fp," Attached information:\n");
1312  FrVectDump(vect->next, fp, debugLvl) ;}
1313 
1314  return outVect;}
1315 
1316 
1317 /*-------------------------------------------------------------FrVectMinMax--*/
1318 double FrVectMax(FrVect *vect, int chId)
1319 /*---------------------------------------------------------------------------*/
1320 /* This function computes the min and max value of the input vector vect. */
1321 /* It returns 1 in case of failure or 0 in case of success. */
1322 /*---------------------------------------------------------------------------*/
1323 {int i;
1324  double value;
1325 
1326  if(vect == NULL) return(1);
1327  if(vect->nData == 0) return(1);
1328 
1329  double min = 1.e+37;
1330  double max =-1.e+37;
1331  if(FrVectIsValid(vect) != 0) return(2);
1332 
1333  if(vect->type == FR_VECT_C)
1334  {for(i=0; i<vect->nData; i++) {value = vect->data[i];
1335  if(value > max) max = value;
1336  if(value < min) min = value;}}
1337  else if(vect->type == FR_VECT_2S)
1338  {for(i=0; i<vect->nData; i++) {value = vect->dataS[i];
1339  if(value > max) max = value;
1340  if(value < min) min = value;}}
1341  else if(vect->type == FR_VECT_8R)
1342  {for(i=0; i<vect->nData; i++) {
1343  if(filter[chId]!=NULL) {
1344  value=filter[chId]->Arma(vect->dataD[i]);
1345  if(i>vect->nData/2) {
1346  if(value > max) max = value;
1347  if(value < min) min = value;
1348  }
1349  } else {
1350  value = vect->dataD[i];
1351  if(value > max) max = value;
1352  if(value < min) min = value;
1353  }
1354  }}
1355  else if(vect->type == FR_VECT_4R)
1356  {for(i=0; i<vect->nData; i++) {
1357  if(filter[chId]!=NULL) {
1358  value=filter[chId]->Arma((double)vect->dataF[i]);
1359  if(i>vect->nData/2) {
1360  if(value > max) max = value;
1361  if(value < min) min = value;
1362  }
1363  } else {
1364  value = vect->dataF[i];
1365  if(value > max) max = value;
1366  if(value < min) min = value;
1367  }
1368  }}
1369  else if(vect->type == FR_VECT_4S)
1370  {for(i=0; i<vect->nData; i++) {value = vect->dataI[i];
1371  if(value > max) max = value;
1372  if(value < min) min = value;}}
1373  else if(vect->type == FR_VECT_8S)
1374  {for(i=0; i<vect->nData; i++) {value = vect->dataL[i];
1375  if(value > max) max = value;
1376  if(value < min) min = value;}}
1377  else if(vect->type == FR_VECT_8C)
1378  {return(0);}
1379  else if(vect->type == FR_VECT_16C)
1380  {return(0);}
1381  else if(vect->type == FR_VECT_2U)
1382  {for(i=0; i<vect->nData; i++) {value = vect->dataUS[i];
1383  if(value > max) max = value;
1384  if(value < min) min = value;}}
1385  else if(vect->type == FR_VECT_4U)
1386  {for(i=0; i<vect->nData; i++) {value = vect->dataUI[i];
1387  if(value > max) max = value;
1388  if(value < min) min = value;}}
1389  else if(vect->type == FR_VECT_8U)
1390  {for(i=0; i<vect->nData; i++) {value = vect->dataUL[i];
1391  if(value > max) max = value;
1392  if(value < min) min = value;}}
1393  else if(vect->type == FR_VECT_1U)
1394  {for(i=0; i<vect->nData; i++) {value = vect->dataU[i];
1395  if(value > max) max = value;
1396  if(value < min) min = value;}}
1397 
1398  min = fabs(min);
1399  max = fabs(max);
1400  if(min > max) max = min;
1401  return(max);}
1402 
1403 
1405 
1406  vector<std::string> ifileList;
1407  vector<std::string> ipathList;
1408  vector<std::string> ofileList;
1409  vector<std::string> opathList;
1410 
1411  ifstream in;
1412  in.open(ifile.Data());
1413  if(!in.good()) {
1414  cout << "FrDisplay - getUniqueFileList : Error Opening Input File : " << ifile.Data() << endl;
1415  gSystem->Exit(1);
1416  }
1417 
1418  // read file list
1419  char istring[1024];
1420  while(1) {
1421  in.getline(istring,1024);
1422  if (!in.good()) break;
1423  TObjArray* token = TString(istring).Tokenize(TString('/'));
1424  // extract last entry -> file name
1425  TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
1426  TString fName = stoken->GetString();
1427  //cout << fName.Data() << endl;
1428  ipathList.push_back(istring);
1429  ifileList.push_back(fName.Data());
1430  }
1431  in.close();
1432 
1433  // extract unique file list
1434  for(int i=0;i<(int)ifileList.size();i++) {
1435  bool check=false;
1436  for(int j=0;j<(int)ofileList.size();j++) {
1437  if(TString(ofileList[j].c_str())==TString(ifileList[i].c_str())) {check=true;break;}
1438  }
1439  if(!check) {
1440  ofileList.push_back(ifileList[i]);
1441  opathList.push_back(ipathList[i]);
1442  }
1443  //cout << i << " " << ipathList[i] << endl;
1444  //cout << i << " " << ifileList[i] << endl;
1445  }
1446 
1447  // write unique file list
1448  ofstream out;
1449  out.open(ofile.Data(),ios::out);
1450  if(!out.good()) {
1451  cout << "FrDisplay - getUniqueFileList : Error Opening Output File : " << ofile.Data() << endl;
1452  gSystem->Exit(1);
1453  }
1454 
1455  for(int i=0;i<(int)ofileList.size();i++) {
1456  out << opathList[i] << endl;
1457  //cout << i << " " << opathList[i] << endl;
1458  //cout << i << " " << ofileList[i] << endl;
1459  }
1460 
1461  out.close();
1462 
1463  return;
1464 }
1465 
1466 
int GpsToGpsLeaps(int gpsSec)
void INThandler(int)
Definition: FrDisplay.cc:1047
char baudline_wNAME[256]
Definition: FrDisplay.cc:134
par[0] value
TString file_path
Definition: cwb_frdisplay.C:96
printf("total live time: non-zero lags = %10.1f \n", liveTot)
char cmd[1024]
fprintf(stdout,"start=%f duration=%f rate=%f\n", x.start(), x.size()/x.rate(), x.rate())
double min(double x, double y)
Definition: eBBH.cc:13
char chnames[3][64]
Definition: FrDisplay.cc:143
int fAccess
Definition: FrDisplay.cc:142
pid_t getProcessId(const char *csProcessName)
par[0] name
int baudline_nP
Definition: FrDisplay.cc:135
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
int palette
Definition: DrawGnetwork2.C:17
int System(const char *command)
Definition: FrDisplay.cc:1022
FileAccess
Definition: FrDisplay.cc:104
int GpsToUnixTime(int gpsSec)
int baudline_rnID
Definition: FrDisplay.cc:133
#define PROC
Definition: FrDisplay.cc:114
void FrFileDumpBinary(FrFile *file, int fp, double *scale, int nchannel, double sampleRate)
Definition: FrDisplay.cc:511
CWB::Filter * filter[3]
Definition: FrDisplay.cc:137
Long_t flags
void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char *sbdate)
Definition: FrDisplay.cc:988
#define SMS
Definition: FrDisplay.cc:108
#define ADC
Definition: FrDisplay.cc:107
cout<< "baudline_FFL : "<< baudline_FFL<< endl;ofstream out;out.open(baudline_FFL, ios::out);if(!out.good()){cout<< "Error Opening File : "<< baudline_FFL<< endl;exit(1);}ifstream in;in.open(frFiles[ifoID], ios::in);if(!in.good()){cout<< "Error Opening File : "<< frFiles[ifoID]<< endl;exit(1);}TString pfile_path="";char istring[1024];while(1){in > istring
Definition: cwb_frdisplay.C:94
Long_t size
char ofile[512]
int j
Definition: cwb_net.C:10
i drho i
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
int debug
Definition: cWB_conf.py:39
TChain sim("waveburst")
ofstream out
Definition: cwb_merge.C:196
int StartBaudline(int gpsSec, int gpsNSec, double scale, double sampleRate, char *chname, int nchannel, char *params)
Definition: FrDisplay.cc:920
#define EVENT
Definition: FrDisplay.cc:111
void Help()
Definition: FrDisplay.cc:30
#define RAW
Definition: FrDisplay.cc:113
int iglobal[3]
Definition: FrDisplay.cc:138
i() int(T_cor *100))
double * tmp
Definition: testWDM_5.C:31
TString worksite
Definition: FrDisplay.cc:141
TString workdir
Definition: FrDisplay.cc:140
#define SIM
Definition: FrDisplay.cc:109
TObjArray * token
string command
Definition: cwb_online.py:382
TFile * ifile
char tag[256]
Definition: cwb_merge.C:74
#define STAT
Definition: FrDisplay.cc:110
FrVect * FrVectDumpBinary(FrVect *vect, int fp, int chId, int debugLvl)
Definition: FrDisplay.cc:1088
#define MIN_TIME_GAP
Definition: FrDisplay.cc:145
TLine * line
Definition: compare_bkg.C:482
ifstream in
int main(int argc, char **argv)
Definition: FrDisplay.cc:148
void ReadParameters(int argc, char **argv)
Definition: FrDisplay.cc:577
#define SUM
Definition: FrDisplay.cc:112
double fabs(const Complex &x)
Definition: numpy.cc:37
string file
Definition: cwb_online.py:385
int estat
strcpy(RunLabel, RUN_LABEL)
TString OS
Definition: cwb_rootlogon.C:25
int cnt
in open(HEN_LIST, ios::in)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
Long_t id
float uscaleby
Definition: FrDisplay.cc:139
#define UNSET
Definition: FrDisplay.cc:106
char fName[256]
int check
double FrVectMax(FrVect *vect, int chId)
Definition: FrDisplay.cc:1318
void getUniqueFileList(TString ifile, TString ofile)
Definition: FrDisplay.cc:1404
Type
Definition: FrDisplay.cc:105
void StrCat(char **oldbuf, char *more)
Definition: FrDisplay.cc:900
wavearray< double > sig
struct Parameters Par
Definition: FrDisplay.cc:132
exit(0)
char baudline_FFL[256]
Definition: FrDisplay.cc:136