BEAscii2Xml.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Craig Robinson , Thomas Cokelaer
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /*
00021  [PURPOSE]
00022          convert ascii file from Bankefficiency code into an xml file
00023 
00024  [INPUT]
00025          an ascii file provideed by BankEfficiency code
00026          which name is "Trigger.dat"
00027  
00028  optional:
00029          a prototype called BE_Proto.xml given by BankEfficiency code 
00030          for non standalone jobs
00031         
00032  [OUTPUT]
00033          the equivalent xml file called "Trigger.xml"
00034  
00035  [USAGE]
00036          BEAscii2Xml 
00037          no optino or argument
00038 
00039  [AUTHOR]
00040         Thomas Cokelaer April 2004
00041 
00042 [Compilation]
00043         gcc BEAscii2Xml.c -o BEAscii2Xml  -I. -I/home/cokelaer/share/include -I../lalapps -I/software/geopptools/include -I../
00044         gcc BEAscii2Xml.c -o BEAscii2Xml -I/<include file>
00045 */
00046 
00047 
00048 
00049 #include "BankEfficiency.h"
00050 #include "lal/LIGOLwXMLRead.h"
00051 #include "lal/LIGOLwXMLInspiralHeaders.h"
00052 
00053 #define BEASCII2XML_INPUT1 "Trigger.dat"
00054 #define BEASCII2XML_INPUT2 "BE_Proto.xml"
00055 #define BEASCII2XML_OUTPUT "Trigger.xml"
00056 #define BEASCII2XML_BANK   "BE_Bank.xml"
00057 
00058 
00059 void
00060 BEAscii2XmlHelp(void);
00061 
00062 
00063 
00064 int
00065 main (int argc, char **argv ) 
00066 {
00067   UINT4 line=0, i;
00068 UINT8  id=0;
00069   UINT4 start = 0;
00070   ResultIn trigger;
00071   REAL4 tau0, tau3, tau0I, tau3I, psi0, psi3, phaseI, coaTime;
00072   FILE *input1, *input2, *bank;
00073   FILE *output;      
00074   SnglInspiralTable     *inputData = NULL;
00075   INT4 numFileTriggers = 0;
00076 
00077   MetadataTable         templateBank;
00078 
00079 
00080 
00081 
00082   char sbuf[512];
00083   
00084   if (argc>1) {
00085     if (strcmp(argv[1], "--help")==0) {
00086       BEAscii2XmlHelp();
00087     }  
00088     if (strcmp(argv[1], "-h")==0) { 
00089       BEAscii2XmlHelp();
00090     }  
00091   }
00092   /* Main program starts here */
00093   /* First we open the file containing the ascii results */
00094   fprintf(stderr,"opening the xml output data file -- %s", BEASCII2XML_OUTPUT);
00095   output = fopen(BEASCII2XML_OUTPUT,"w");
00096   fprintf(stderr,"done\n");
00097 
00098   fprintf(stderr,"opening the xml input data file -- %s", BEASCII2XML_INPUT1);
00099   if  ( (input1  = fopen(BEASCII2XML_INPUT1,"r"))==NULL) {
00100     fprintf(stderr,"error while opening input file %s\n",BEASCII2XML_INPUT1);
00101     exit(0);
00102   }
00103   fprintf(stderr,"done\n");
00104 
00105   fprintf(stderr,"opening the xml prototype (argument of BankEfficiency code) -- ");
00106   if  ( (input2  = fopen(BEASCII2XML_INPUT2,"r"))==NULL)
00107     {
00108       fprintf(stderr,"error while opening input file %s\n",BEASCII2XML_INPUT2);
00109       fprintf(stderr,"the xml file will not contains parameters information\n");
00110       PRINT_LIGOLW_XML_HEADER(output);
00111       fprintf(stderr,"creating the header file -- done\n");
00112     }
00113   else 
00114     {
00115       /* read prototype and save in outputfile */
00116       fprintf(stderr,"parsing the prototype  -- ");
00117       while(fgets(sbuf,1024,input2) !=NULL)
00118         fputs(sbuf, output);
00119       fprintf(stderr," done\n");
00120 
00121       
00122     }
00123   
00124 
00125   /* insert the template bank here */
00126   if  ( (bank  = fopen(BEASCII2XML_BANK,"r"))==NULL)
00127     {
00128       fprintf(stderr,"error while opening input file %s\n",BEASCII2XML_BANK);
00129       fprintf(stderr,"the xml file will not contains the bank table\n");
00130     }
00131   else 
00132     {
00133       /* read prototype and save in outputfile */
00134       fprintf(stderr,"parsing the bank  -- ");
00135       fprintf( stdout, "reading triggers from file: %s\n", BEASCII2XML_BANK );
00136       numFileTriggers = 
00137         LALSnglInspiralTableFromLIGOLw( &inputData,BEASCII2XML_BANK , 0, -1 );
00138       fprintf(stderr," done %d\n", numFileTriggers);      
00139        myfprintf(output, LIGOLW_XML_SNGL_INSPIRAL );
00140        while(inputData)
00141         {
00142           /*      id = inputData->event_id->id;*/
00143           
00144           fprintf(output, SNGL_INSPIRAL_ROW, 
00145                   inputData->ifo,
00146                   inputData->search,
00147                   inputData->channel,
00148                   inputData->end_time.gpsSeconds,
00149                   inputData->end_time.gpsNanoSeconds,
00150                   inputData->end_time_gmst,
00151                   inputData->impulse_time.gpsSeconds,
00152                   inputData->impulse_time.gpsNanoSeconds,
00153                   inputData->template_duration,
00154                   inputData->event_duration,
00155                   inputData->amplitude,
00156                   inputData->eff_distance,
00157                   inputData->coa_phase,
00158                   inputData->mass1,
00159                   inputData->mass2,
00160                   inputData->mchirp,
00161                   inputData->mtotal,
00162                   inputData->eta,
00163                   inputData->tau0,
00164                   inputData->tau2,
00165                   inputData->tau3,
00166                   inputData->tau4,
00167                   inputData->tau5,
00168                   inputData->ttotal,
00169                   inputData->psi0,
00170                   inputData->psi3,
00171                   inputData->alpha,
00172                   inputData->alpha1,
00173                   inputData->alpha2,
00174                   inputData->alpha3,
00175                   inputData->alpha4,
00176                   inputData->alpha5,
00177                   inputData->alpha6,
00178                   inputData->beta,
00179                   inputData->f_final,
00180                   inputData->snr,
00181                   inputData->chisq,
00182                   inputData->chisq_dof,
00183                   inputData->sigmasq,
00184                   id);
00185           inputData = inputData->next;
00186           fprintf(output, "\n");
00187 
00188         }
00189        myfprintf(output, LIGOLW_XML_TABLE_FOOTER );
00190 
00191     }
00192 
00193 
00194 
00195   PRINT_LIGOLW_XML_BANKEFFICIENCY(output);
00196   fprintf(stderr,"done\n");
00197   /* read ascii input and save in xml format */
00198   fprintf(stderr,"reading the ascii file -- and saving xml file");
00199   do  
00200     {
00201       fscanf(input1,BANKEFFICIENCY_PARAMS_ROW_SPACE,
00202              &trigger.psi0_triggerU,
00203              &trigger.psi3_triggerU,
00204              &trigger.psi0_trigger,
00205              &trigger.psi3_trigger,
00206              &psi0, 
00207              &psi3,
00208              &tau0, 
00209              &tau3, 
00210              &tau0I, 
00211              &tau3I,
00212              &trigger.fend_triggerU, 
00213              &trigger.fend_trigger, 
00214              &trigger.fend_inject,
00215              &trigger.mass1_inject,
00216              &trigger.mass2_inject,
00217              &trigger.rho_finalU,
00218              &trigger.phaseU,
00219              &phaseI,
00220              &trigger.alphaFU, 
00221              &trigger.layerU,
00222              &trigger.binU,
00223              &trigger.rho_final,
00224              &trigger.snrAtCoaTime, 
00225              &phaseI,
00226              &trigger.phase,
00227              &trigger.alphaF, 
00228              &trigger.layer,
00229              &trigger.bin, 
00230              &coaTime);
00231 
00232      if (start==0){
00233               start+=1;
00234       }
00235       else 
00236       {
00237               fprintf(output,",\n");
00238       }
00239       fprintf(output, BANKEFFICIENCY_PARAMS_ROW,
00240               trigger.psi0_triggerU,
00241               trigger.psi3_triggerU,
00242               trigger.psi0_trigger,
00243               trigger.psi3_trigger,
00244               psi0, 
00245               psi3,
00246               tau0,
00247               tau3,
00248               tau0I,
00249               tau3I,
00250               trigger.fend_triggerU, 
00251               trigger.fend_trigger, 
00252               trigger.fend_inject,
00253               trigger.mass1_inject,
00254               trigger.mass2_inject,
00255               trigger.rho_finalU,
00256               phaseI,
00257               trigger.phaseU,
00258               trigger.alphaFU, 
00259               trigger.layerU,
00260               trigger.binU,
00261               trigger.rho_final,
00262               trigger.snrAtCoaTime,
00263               phaseI,
00264               trigger.phase,
00265               trigger.alphaF, 
00266               trigger.layer,
00267               trigger.bin, 
00268               coaTime);
00269          line++;
00270     }
00271    while(!feof(input1));
00272 
00273     fprintf(stderr,"read %d lines...done\n", line);
00274   PRINT_LIGOLW_XML_TABLE_FOOTER(output);
00275   PRINT_LIGOLW_XML_FOOTER(output);
00276 
00277   fclose(output);
00278     fprintf(stderr,"closing xml file\n");
00279 
00280   return 0;
00281 }
00282 
00283 
00284 void BEAscii2XmlHelp(void)
00285 {
00286   fprintf(stderr, "BEAscii2Xml help:\n");
00287   fprintf(stderr, "=================\n");
00288   fprintf(stderr, "[PURPOSE]\n\t%s\n \t%s\n \t%s\n \t%s\n", 
00289                   "That code reads a file in ascii format generated by BankEfficiency",
00290                   "code and generate the appropriate xml files. It is used if one forget",
00291                   "to use the appropriate option within BankEfficiency code (--print-result-xml)",
00292                   "or when the bankEfficiency code has been used within the condor ",
00293                   "submit file. In that case indeed several ascii files have been ",
00294                   "generated but no xml files.\n");
00295   
00296   fprintf(stderr, "[INPUT/OUTPUT]\n\t%s\n \t%s\n \t%s\n \t%s %s %s %s\n", 
00297                   "That code do not need any input argument but needs an input file",
00298                   "in ascii format (the user has to be sure it is in the appropriate",
00299                   "format) and then it writes an xml file into an output file \n", 
00300                   "the input and output file name are ", BEASCII2XML_INPUT1, "and", BEASCII2XML_OUTPUT);
00301 
00302   exit(1);
00303   
00304 
00305 }

Generated on Mon Oct 6 02:31:09 2008 for LAL by  doxygen 1.5.2