Skip to content
Snippets Groups Projects
Commit 52439752 authored by Meg Millhouse's avatar Meg Millhouse
Browse files

Merge branch 'checkpoint_segfault_fix' into 'master'

fixing segfault when --checkpoint but no --outputDir supplied

See merge request !282
parents 99fde627 7cf1f13a
Branches master
No related tags found
No related merge requests found
......@@ -1547,57 +1547,82 @@ void set_frequency_data_from_checkpoint(struct Data *data){
}
}
int get_number_of_ifos_from_command_line(ProcessParamsTable *commandLine){
int NI = 0; // Number of IFOS
ProcessParamsTable *this = commandLine;
for(this = commandLine; this; this = this->next)
{
if(!strcmp(this->param,"--ifo"))
{
(NI)++;
}
}
return NI;
}
char ** get_list_of_ifo_names_from_command_line(ProcessParamsTable *commandLine){
int NI = get_number_of_ifos_from_command_line(commandLine);
char **ifos = (char**)malloc(NI * sizeof(char*));
ProcessParamsTable *ppt = commandLine;
int i = 0;
for(ppt = commandLine; ppt; ppt = ppt->next)
{
if(!strcmp(ppt->param,"--ifo"))
{
ifos[i] = (char*)malloc(MAXSTRINGSIZE * sizeof(char));
strcpy(ifos[i], ppt->value);
i += 1;
}
}
return ifos;
}
void free_list_of_ifo_names(int NI, char** ifos){
for (int i = 0; i < NI; i++){
free(ifos[i]);
}
free(ifos);
}
int set_cache_from_checkpoint_asd(ProcessParamsTable *commandLine)
{
int NI = 0;
char cache[MAXSTRINGSIZE];
char interpfilename[MAXSTRINGSIZE];
char filename[MAXSTRINGSIZE];
int file_exists = 1;
// WILL BREAK FOR MORE THAN 8 IFOS
char **ifos = (char**)malloc(8 * sizeof(char*));
// get directory file name
char outputDirectory[MAXSTRINGSIZE];
int NI = get_number_of_ifos_from_command_line(commandLine);
/* Construct a list of IFO names*/
ProcessParamsTable *this = commandLine;
for(this = commandLine; this; this = this->next)
{
if(!strcmp(this->param,"--ifo"))
{
(NI)++;
ifos[NI-1] = (char*)malloc((2 + 1) * sizeof(char));
strcpy(ifos[NI-1], this->value);
}
}
for (int i = 0; i < NI; i++)
{
char **ifos = get_list_of_ifo_names_from_command_line(commandLine);
ProcessParamsTable *ppt = LALInferenceGetProcParamVal(commandLine, "--outputDir");
if(ppt) {
sprintf(outputDirectory,"%s",ppt->value);
}
else sprintf(outputDirectory,".");
for (int i = 0; i < NI; i++) {
/* Set up strings and filenames*/
sprintf(cache, "--%s-cache", ifos[i]);
sprintf(filename,"%s/checkpoint/asd_%s.dat.0",
LALInferenceGetProcParamVal(commandLine, "--outputDir")->value, ifos[i]);
// this is just filename but with interp before it
sprintf(interpfilename, "interp:%s", filename);
sprintf(filename, "%s/checkpoint/asd_%s.dat.0", outputDirectory, ifos[i]);
sprintf(interpfilename, "interp:%s", filename); // this is just filename but with interp before it
/* Check to see if checkpoint/psd_IFO exists */
/* WARNING, lalInferenceReadData will fail if the checkpoint file exists but is empty*/
FILE *PSDfile=NULL;
if((PSDfile = fopen(filename,"r")) != NULL)
{
FILE *PSDfile = NULL;
if ((PSDfile = fopen(filename, "r")) != NULL) {
/*change '--IFO-cache' in command line to interp:trigdir/checkpoint/psd_IFO.dat.0*/
ProcessParamsTable *ppt = NULL;
ppt = LALInferenceGetProcParamVal(commandLine, cache);
ppt = NULL;
ppt = LALInferenceGetProcParamVal(commandLine, cache);
strcpy(ppt->value, interpfilename);
fclose(PSDfile);
}
else
{
} else {
file_exists = 0;
fprintf(stdout, "%s is NULL, checkpointing hasn't happened yet.\n", filename);
}
}
for (int i = 0; i < NI; i++){
free(ifos[i]);
}
}
free(ifos);
free_list_of_ifo_names(NI, ifos);
return file_exists;
}
......
......@@ -35,14 +35,26 @@ REAL8TimeSeries *readTseries(CHAR *cachefile, CHAR *channel, LIGOTimeGPS start,
void InjectFromMDC(ProcessParamsTable *commandLine, LALInferenceIFOData *IFOdata, double *SNR);
void BayesWaveInjection(ProcessParamsTable *commandLine, struct Data *data, struct Chain *chain, struct Prior *prior, double **psd, int *NC);
void getChannels(ProcessParamsTable *commandLine, char **channel);
// reads command line and returns number of IFOs
int get_number_of_ifos_from_command_line(ProcessParamsTable *commandLine);
/*
* sets list of ifos names from command line
* Modifies: ifos
* Returns: list of ifo names
*/
char ** get_list_of_ifo_names_from_command_line(ProcessParamsTable *commandLine);
/*
* Modifies the command line arguments so that the --IFO-cache point to the checkpointed psds instead
* frees ifo list set by set_list_of_ifos_from_command_line
*/
void free_list_of_ifo_names(int NI, char** ifos);
/*
* Modifies the command line arguments so that the --IFO-cache point to the checkpointed psds instead of cache files
* Only will modify command line if checkpointing has happened (this avoids a transient frame read error)
* Modifies
* commandLine
* Requres:
* Fewer than 8 IFOs, but only because I am not sure how to realloc memory
*
* Returns 1 if checkpoint file exists, retuns 0 if file does not exist
* Returns 1 (True) if checkpoint file exists, returns 0 (False) if file does not exist
*/
int set_cache_from_checkpoint_asd(ProcessParamsTable *commandLine);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment