void PST_Edge::debug_draw( int color, bool flush ) { GfxDebug::draw_line( float(start_coord().x()), float(start_coord().y()), float(start_coord().z()), float( end_coord().x()), float( end_coord().y()), float( end_coord().z()), color ); if( flush ) GfxDebug::flush(); }
double PST_Edge::closest_on_line( const CubitVector& P ) { CubitVector B = start_coord(); CubitVector M = end_coord() - B; if( M.length_squared() < RESABS_SQR ) return 0.0; return ( M % ( P - B ) ) / ( M % M ); }
int make_wu_headers(std::vector<dr2_compact_block_t> &tapebuffer, telescope_id tel, std::vector<workunit> &wuheader) { int procid=getpid(); double receiver_freq; int bandno; FILE *tmpfile; char tmpstr[256]; char buf[64]; static const receiver_config &r(rcvr); static const settings &s(splitter_settings); bool group_is_vlar; if (!strncmp(s.splitter_cfg->data_type,"encoded", std::min(static_cast<size_t>(7),sizeof(s.splitter_cfg->data_type)))) { noencode=0; } else { noencode=1; } tapebuffer[0].header.samplerate*=1e+6; seconds sample_time(1.0/tapebuffer[0].header.samplerate); seti_time start_time(tapebuffer[0].header.data_time -tapebuffer[0].data.size()*0.5*sample_time); seti_time end_time(tapebuffer[tapebuffer.size()-1].header.data_time); workunit_grp wugrp; sprintf(wugrp.name,"%s.%ld.%d.%d.%d", tapebuffer[0].header.name, procid, tapebuffer[0].header.dataseq, tel-AO_430, s.id); wugrp.receiver_cfg=r; wugrp.recorder_cfg=s.recorder_cfg; wugrp.splitter_cfg=s.splitter_cfg; wugrp.analysis_cfg=s.analysis_cfg; wugrp.data_desc.nsamples=NSAMPLES; wugrp.data_desc.true_angle_range=0; coordinate_t start_coord(cmap_interp(coord_history,start_time)); coordinate_t end_coord(cmap_interp(coord_history,end_time)); wugrp.data_desc.start_ra=start_coord.ra; wugrp.data_desc.end_ra=end_coord.ra; wugrp.data_desc.start_dec=start_coord.dec; wugrp.data_desc.end_dec=end_coord.dec; coordinate_t last_coord=start_coord; double sample_rate=tapebuffer[0].header.samplerate/NSTRIPS; // find the bracketing entries in the coordinate history std::map<seti_time,coordinate_t>::iterator above(coord_history.upper_bound(end_time)); std::map<seti_time,coordinate_t>::iterator below(coord_history.lower_bound(start_time)); std::map<seti_time,coordinate_t>::iterator p; if (above==coord_history.begin()) { above++; } if (below==coord_history.end()) { below=above; below--; } if (above==below) { below--; } // Calculate the angular distance the beam has traveled for (p=below;p!=above;p++) { wugrp.data_desc.true_angle_range+=angdist(last_coord,p->second); last_coord=p->second; } wugrp.data_desc.true_angle_range+=angdist(last_coord,end_coord); if (wugrp.data_desc.true_angle_range==0) wugrp.data_desc.true_angle_range=1e-10; // Calculate the number of unique signals that could be found in a workunit. // We will use these numbers to calculate thresholds. double numgauss=2.36368e+08/std::min(wugrp.data_desc.true_angle_range,10.0); double numpulse=std::min(4.52067e+10/std::min(wugrp.data_desc.true_angle_range,10.0),2.00382e+11); double numtrip=std::min(3.25215e+12/std::min(wugrp.data_desc.true_angle_range,10.0),1.44774e+13); // check for VLAR workunits if (wugrp.data_desc.true_angle_range < 0.12) { group_is_vlar=true; } else { group_is_vlar=false; } // if (useanalysiscfgid > 0) { // log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,"Re-reading analysis cfg id: %d (set by user):\n",useanalysiscfgid); // s.analysis_cfg = useanalysiscfgid; // } // Calculate a unique key to describe this analysis config. long keyuniq=floor(std::min(wugrp.data_desc.true_angle_range*100,1000.0)+0.5)+ s.analysis_cfg.id*1024; if ((keyuniq>((s.analysis_cfg.id+1)*1024)) ||(keyuniq<(s.analysis_cfg.id)*1024)) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Invalid keyuniq value!\n"); log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%d %d %f\n",keyuniq,s.analysis_cfg.id,wugrp.data_desc.true_angle_range); exit(1); } keyuniq*=-1; long save_keyuniq=keyuniq; splitter_settings.analysis_cfg=wugrp.analysis_cfg; sprintf(tmpstr,"where keyuniq=%d",keyuniq); // Check if we've already done this analysis_config... // Fetch through splitter_settings, since it's alias (s) is const. splitter_settings.analysis_cfg.id=0; splitter_settings.analysis_cfg->fetch(tmpstr); if (s.analysis_cfg->id==0) { if (keyuniq != save_keyuniq) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"keyuniq value changed!\n"); exit(1); } // If not calculate the thresholds based upon the input analysis_config // Triplets are distributed exponentially... wugrp.analysis_cfg->triplet_thresh+=(log(numtrip)-29.0652); // Gaussians are based upon chisqr... double p_gauss=lcgf(32.0,wugrp.analysis_cfg->gauss_null_chi_sq_thresh*32.0); p_gauss-=(log(numgauss)-19.5358); wugrp.analysis_cfg->gauss_null_chi_sq_thresh=invert_lcgf(p_gauss,32,1e-4)*0.03125; // Pulses thresholds are log of the probability wugrp.analysis_cfg->pulse_thresh+=(log(numpulse)-24.7894); wugrp.analysis_cfg->keyuniq=keyuniq; wugrp.analysis_cfg->insert(); } else { wugrp.analysis_cfg=s.analysis_cfg; } strlcpy(wugrp.data_desc.time_recorded, short_jd_string(start_time.jd().uval()), sizeof(wugrp.data_desc.time_recorded)); wugrp.data_desc.time_recorded_jd=start_time.jd().uval(); wugrp.data_desc.coords.clear(); wugrp.data_desc.coords.push_back(start_coord); for (p=below;p!=above;p++) { wugrp.data_desc.coords.push_back(p->second); } wugrp.data_desc.coords.push_back(end_coord); wugrp.tape_info->id=0; sprintf(buf,"%d",tel-AO_ALFA_0_0); wugrp.tape_info->fetch(std::string("where name=\'")+tapebuffer[0].header.name+"\' and beam="+buf); wugrp.tape_info->start_time=tapebuffer[0].header.data_time.jd().uval(); wugrp.tape_info->last_block_time=wugrp.tape_info->start_time; wugrp.tape_info->last_block_done=tapebuffer[0].header.dataseq; wugrp.tape_info->beam=tel-AO_ALFA_0_0; if (!nodb) { if (wugrp.tape_info.id) { if (!(wugrp.tape_info->update())) { char buf[1024]; log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%s",sql_error_message()); exit(1); } } else { strlcpy(wugrp.tape_info->name,tapebuffer[0].header.name,sizeof(wugrp.tape_info->name)); wugrp.tape_info->insert(); } } if (!nodb) { sqlint8_t wgid; if ((wgid=wugrp.insert())<=0) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Workunit_grp insert failed\nwgid=%d\nSQLCODE=%d\nLAST_NON_ZERO_SQLCODE=%d\n",wgid,sql_error_code(),sql_last_error_code()); exit( 1 ); } wugrp.id=wgid; } int i; wu_database_id.resize(NSTRIPS); bin_data.resize(NSTRIPS); wuheader.resize(NSTRIPS); for (i=0;i<NSTRIPS;i++) { bin_data[i].clear(); wuheader[i].group_info=wugrp; wuheader[i].group_info.id=wugrp.id; sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapebuffer[0].header.name, procid, tapebuffer[0].header.dataseq, tel-AO_430,s.id,i); if (group_is_vlar) { strlcat(wuheader[i].name,".vlar",sizeof(wuheader[i].name)); } wuheader[i].subband_desc.sample_rate=tapebuffer[0].header.samplerate/NSTRIPS; receiver_freq=tapebuffer[0].header.sky_freq; bandno=((i+NSTRIPS/2)%NSTRIPS)-NSTRIPS/2; wuheader[i].subband_desc.base=receiver_freq+ (double)(bandno)*wuheader[i].subband_desc.sample_rate; wuheader[i].subband_desc.center=receiver_freq+wuheader[i].subband_desc.sample_rate*NSTRIPS*((double)IFFT_LEN*bandno/FFT_LEN+(double)IFFT_LEN/(2*FFT_LEN)-1.0/(2*FFT_LEN)); wuheader[i].subband_desc.number=i; if (!nodb ) { if (!(wu_database_id[i]=wuheader[i].id=wuheader[i].insert())) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Database error in make_wu_headers()\n"); exit(EXIT_FAILURE); } } sprintf(tmpstr,"./wu_inbox/%s",wuheader[i].name); if ((tmpfile=fopen(tmpstr,"w"))) { fprintf(tmpfile,"<workunit>\n"); fprintf(tmpfile,wuheader[i].print_xml().c_str()); fclose(tmpfile); } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open file ./wu_inbox/%s, errno=%d\n",wuheader[i].name,errno); exit(1); } bin_data[i].reserve(wuheaders[i].group_info->recorder_cfg->bits_per_sample* wuheaders[i].group_info->data_desc.nsamples/8); } return(1); }