int main(void) { int64 t0,t1,t2,t3; d(); s=(int64*)calloc(q,sizeof(int64)); gw(2,0,1000); gw(3,0,1500000); sa(gr(3,0)); gw(tm(gr(3,0),gr(2,0)),(td(gr(3,0),gr(2,0)))+3,0); _1: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa((sp()!=0)?0:1); if(sp()!=0)goto _3;else goto _2; _2: sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),gr(2,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(2,0))); sa(sp()+3LL); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _1; _3: gw(6,0,0); gw(8,0,1); sp(); _4: if(((gr(8,0)*gr(8,0)*4)+(gr(8,0)*6)+2)>gr(3,0))goto _20;else goto _5; _5: sa(gr(8,0)+1); gw(9,0,gr(8,0)+1); _6: sa(sr()); t0=sr()*2; sa(sp()*t0); t1=sp(); sa(sp()*gr(8,0)*2); sa(t1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+sp()); t0=sp(); t0=t0>gr(3,0)?1:0; if((t0)!=0)goto _19;else goto _7; _7: t0=(gr(9,0)*gr(9,0))-(gr(8,0)*gr(8,0)); gw(2,1,(gr(9,0)*gr(9,0))-(gr(8,0)*gr(8,0))); t1=gr(8,0)*gr(9,0)*2; gw(3,1,gr(8,0)*gr(9,0)*2); t2=(gr(9,0)*gr(9,0))+(gr(8,0)*gr(8,0)); gw(4,1,(gr(9,0)*gr(9,0))+(gr(8,0)*gr(8,0))); t3=t1+t2; t1=t0+t3; gw(6,1,t1); if(gr(2,1)>gr(3,1))goto _18;else goto _8; _8: sa(1); sa(gr(6,1)>gr(3,0)?1:0); _9: if(sp()!=0)goto _17;else goto _10; _10: t0=sr()*((((gr(2,1)*7)+gr(3,1))*5)+gr(4,1)); gw(8,1,t0); sa(sr()*gr(6,1)); sa(tm(sr(),gr(2,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(2,0))); sa(sp()+3LL); {int64 v0=sp();sa(gr(sp(),v0));} sa(sr()); if(sp()!=0)goto _13;else goto _11; _11: sp(); sa(sr()*gr(6,1)); sa(gr(8,1)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),gr(2,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(2,0))); sa(sp()+3LL); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(6,0,gr(6,0)+1); _12: sa(sp()+1LL); sa((sr()*gr(6,1))>gr(3,0)?1:0); goto _9; _13: if(sr()!=gr(8,1))goto _14;else goto _16; _14: sa((sp()<0)?1:0); if(sp()!=0)goto _12;else goto _15; _15: sa(sr()*gr(6,1)); sa(-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),gr(2,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(2,0))); sa(sp()+3LL); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(6,0,gr(6,0)-1); goto _12; _16: sp(); goto _12; _17: sp(); sa(gr(9,0)+1); gw(9,0,gr(9,0)+1); goto _6; _18: t0=gr(2,1); gw(2,1,gr(3,1)); gw(3,1,t0); goto _8; _19: gw(8,0,gr(8,0)+1); goto _4; _20: printf("%lld", gr(6,0)); return 0; }
int main(void) { int64 t0,t1; d(); s=(int64*)calloc(q,sizeof(int64)); gw(10,10,1); sa(9); _1: sa(sr()); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sp()-1LL); sa(sr()); if(sp()!=0)goto _1;else goto _3; _3: gw(3,0,5); gw(2,0,48); sp(); sa(49); _4: sa(0); sa(gr(gr(2,0),gr(3,0))-48); gw(5,0,gr(gr(2,0),gr(3,0))-48); sa(sp()+12LL); sa(7); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(0); sa(gr(gr(2,0)+1,gr(3,0))-48); gw(6,0,gr(gr(2,0)+1,gr(3,0))-48); sa(sp()+12LL); sa(7); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(0); sa(gr(gr(2,0)+2,gr(3,0))-48); gw(7,0,gr(gr(2,0)+2,gr(3,0))-48); sa(sp()+12LL); sa(7); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(gr(5,0)+1,gr(6,0)+1,2); gw(gr(5,0)+1,gr(7,0)+1,2); gw(gr(6,0)+1,gr(7,0)+1,2); gw(gr(7,0)+1,gr(5,0)+1,0); gw(gr(7,0)+1,gr(6,0)+1,0); gw(gr(6,0)+1,gr(5,0)+1,0); sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _18;else goto _5; _5: gw(9,0,0); sp(); sa(9); sa(gr(21,7)); _6: if(sp()!=0)goto _7;else goto _17; _7: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa((sp()!=0)?0:1); if(sp()!=0)goto _9;else goto _8; _8: sa(sr()+12); sa(7); {int64 v0=sp();sa(gr(sp(),v0));} goto _6; _9: sa(sp()+1LL); _10: if(sr()-gr(9,0)==0)goto _13;else goto _11; _11: sa(sr()); sa(sr()); sa(sr()+12); sa(9); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()+1LL); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+11LL); sa(9); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()+1LL); {int64 v0=sp();t0=gr(sp(),v0);} sa(sp()*t0); t1=sp(); t1=(t1!=0)?0:1; if((t1)!=0)goto _9;else goto _12; _12: sa(sr()); sa(sr()); sa(sr()+12); sa(9); {int64 v0=sp();t0=gr(sp(),v0);} gw(2,0,t0); sa(sp()+11LL); sa(9); {int64 v0=sp();sa(gr(sp(),v0));} {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+12LL); sa(9); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sp()-1LL); sa(sr()); sa(gr(2,0)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+12LL); sa(9); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _10; _13: printf("%lld", gr(12,9)); sp(); sa(1); sa((1-gr(9,0)!=0)?0:1); _14: if(sp()!=0)goto _15;else goto _16; _15: sp(); return 0; _16: sa(sr()+12); sa(9); {int64 v0=sp();t0=gr(sp(),v0);} printf("%lld", t0); sa(sp()+1LL); sa((sr()-gr(9,0)!=0)?0:1); goto _14; _17: sa(sr()); sa(gr(9,0)); gw(9,0,gr(9,0)+1); sa(sp()+12LL); sa(9); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _7; _18: t0=(td(sr(),10))+1; gw(3,0,t0); t0=((tm(sr(),10))*4)+12; gw(2,0,t0); goto _4; }
bool SKCommandHandler::handle(char *s) { string sr(s); return handle(sr); }
// Test CpG sites in this read for methylation void calculate_methylation_for_read(const ModelMap& model_map, const Fast5Map& name_map, const faidx_t* fai, const bam_hdr_t* hdr, const bam1_t* record, size_t read_idx, const OutputHandles& handles) { // Load a squiggle read for the mapped read std::string read_name = bam_get_qname(record); std::string fast5_path = name_map.get_path(read_name); SquiggleRead sr(read_name, fast5_path); // An output map from reference positions to scored CpG sites std::map<int, ScoredSite> site_score_map; for(size_t strand_idx = 0; strand_idx < NUM_STRANDS; ++strand_idx) { std::vector<double> site_scores; std::vector<int> site_starts; std::vector<int> site_ends; std::vector<int> site_count; // replace the baked-in pore model with the methylation model // (including unmethylated kmers) for this strand std::string curr_model = sr.pore_model[strand_idx].name; std::string methyl_model = curr_model + ".ecoli_er2925.pcr_MSssI.timp.021216.alphabet_cpg.model"; auto model_iter = model_map.find(methyl_model); if(model_iter != model_map.end()) { sr.pore_model[strand_idx].update_states( model_iter->second ); } else { fprintf(stderr, "Error, methylated model %s not found\n", methyl_model.c_str()); exit(EXIT_FAILURE); } size_t k = sr.pore_model[strand_idx].k; // Align in event space using the new model EventAlignmentParameters params; params.sr = &sr; params.fai = fai; params.hdr = hdr; params.record = record; params.strand_idx = strand_idx; params.read_idx = read_idx; params.alphabet = mtest_alphabet; std::vector<EventAlignment> alignment_output = align_read_to_ref(params); if(alignment_output.empty()) continue; std::string contig = alignment_output.front().ref_name.c_str(); // Convert the EventAlignment to a map between reference positions and events std::vector<AlignedPair> event_aligned_pairs; for(size_t i = 0; i < alignment_output.size(); ++i) { AlignedPair ap = { alignment_output[i].ref_position, alignment_output[i].event_idx }; event_aligned_pairs.push_back(ap); } int ref_start_pos = event_aligned_pairs.front().ref_pos; int ref_end_pos = event_aligned_pairs.back().ref_pos; // Extract the reference sequence for this region int fetched_len = 0; assert(ref_end_pos >= ref_start_pos); std::string ref_seq = get_reference_region_ts(params.fai, contig.c_str(), ref_start_pos, ref_end_pos, &fetched_len); // Remove non-ACGT bases from this reference segment ref_seq = gDNAAlphabet.disambiguate(ref_seq); // Scan the sequence for CpGs std::vector<int> cpg_sites; assert(ref_seq.size() != 0); for(size_t i = 0; i < ref_seq.size() - 1; ++i) { if(ref_seq[i] == 'C' && ref_seq[i+1] == 'G') { cpg_sites.push_back(i); } } // Batch the CpGs together into groups that are separated by some minimum distance int min_separation = 10; size_t curr_idx = 0; while(curr_idx < cpg_sites.size()) { // Find the endpoint of this group of sites size_t end_idx = curr_idx + 1; while(end_idx < cpg_sites.size()) { if(cpg_sites[end_idx] - cpg_sites[end_idx - 1] > min_separation) break; end_idx += 1; } // the coordinates on the reference substring for this group of sites int sub_start_pos = cpg_sites[curr_idx] - min_separation; int sub_end_pos = cpg_sites[end_idx - 1] + min_separation; if(sub_start_pos > min_separation && cpg_sites[end_idx - 1] - cpg_sites[curr_idx] < 200) { std::string subseq = ref_seq.substr(sub_start_pos, sub_end_pos - sub_start_pos + 1); std::string rc_subseq = mtest_alphabet->reverse_complement(subseq); // using the reference-to-event map, look up the event indices for this segment AlignedPairRefLBComp lb_comp; AlignedPairConstIter start_iter = std::lower_bound(event_aligned_pairs.begin(), event_aligned_pairs.end(), sub_start_pos + ref_start_pos, lb_comp); AlignedPairConstIter stop_iter = std::lower_bound(event_aligned_pairs.begin(), event_aligned_pairs.end(), sub_end_pos + ref_start_pos, lb_comp); // Only process this region if the the read is aligned within the boundaries // and the span between the start/end is not unusually short if(start_iter != event_aligned_pairs.end() && stop_iter != event_aligned_pairs.end() && abs(start_iter->read_pos - stop_iter->read_pos) > 10) { uint32_t hmm_flags = HAF_ALLOW_PRE_CLIP | HAF_ALLOW_POST_CLIP; // Set up event data HMMInputData data; data.read = &sr; data.anchor_index = -1; // unused data.strand = strand_idx; data.rc = alignment_output.front().rc; data.event_start_idx = start_iter->read_pos; data.event_stop_idx = stop_iter->read_pos; data.event_stride = data.event_start_idx <= data.event_stop_idx ? 1 : -1; // Calculate the likelihood of the unmethylated sequence HMMInputSequence unmethylated(subseq, rc_subseq, mtest_alphabet); double unmethylated_score = profile_hmm_score(unmethylated, data, hmm_flags); // Methylate all CpGs in the sequence and score again std::string mcpg_subseq = mtest_alphabet->methylate(subseq); std::string rc_mcpg_subseq = mtest_alphabet->reverse_complement(mcpg_subseq); // Calculate the likelihood of the methylated sequence HMMInputSequence methylated(mcpg_subseq, rc_mcpg_subseq, mtest_alphabet); double methylated_score = profile_hmm_score(methylated, data, hmm_flags); // Aggregate score int start_position = cpg_sites[curr_idx] + ref_start_pos; auto iter = site_score_map.find(start_position); if(iter == site_score_map.end()) { // insert new score into the map ScoredSite ss; ss.chromosome = contig; ss.start_position = start_position; ss.end_position = cpg_sites[end_idx - 1] + ref_start_pos; ss.n_cpg = end_idx - curr_idx; // extract the CpG site(s) with a k-mers worth of surrounding context size_t site_output_start = cpg_sites[curr_idx] - k + 1; size_t site_output_end = cpg_sites[end_idx - 1] + k; ss.sequence = ref_seq.substr(site_output_start, site_output_end - site_output_start); // insert into the map iter = site_score_map.insert(std::make_pair(start_position, ss)).first; } // set strand-specific score // upon output below the strand scores will be summed iter->second.ll_unmethylated[strand_idx] = unmethylated_score; iter->second.ll_methylated[strand_idx] = methylated_score; } } curr_idx = end_idx; } } // for strands #pragma omp critical(methyltest_write) { // these variables are sums over all sites within a read double ll_ratio_sum_strand[2] = { 0.0f, 0.0f }; double ll_ratio_sum_both = 0; size_t num_positive = 0; // write all sites for this read for(auto iter = site_score_map.begin(); iter != site_score_map.end(); ++iter) { const ScoredSite& ss = iter->second; double sum_ll_m = ss.ll_methylated[0] + ss.ll_methylated[1]; double sum_ll_u = ss.ll_unmethylated[0] + ss.ll_unmethylated[1]; double diff = sum_ll_m - sum_ll_u; num_positive += diff > 0; fprintf(handles.site_writer, "%s\t%d\t%d\t", ss.chromosome.c_str(), ss.start_position, ss.end_position); fprintf(handles.site_writer, "ReadIdx=%zu;", read_idx); fprintf(handles.site_writer, "LogLikMeth=%.2lf;LogLikUnmeth=%.2lf;LogLikRatio=%.2lf;", sum_ll_m, sum_ll_u, diff); fprintf(handles.site_writer, "LogLikMethByStrand=%.2lf,%.2lf;", ss.ll_methylated[0], ss.ll_methylated[1]); fprintf(handles.site_writer, "LogLikUnmethByStrand=%.2lf,%.2lf;", ss.ll_unmethylated[0], ss.ll_unmethylated[1]); fprintf(handles.site_writer, "NumCpGs=%d;Sequence=%s\n", ss.n_cpg, ss.sequence.c_str()); ll_ratio_sum_strand[0] += ss.ll_methylated[0] - ss.ll_unmethylated[0]; ll_ratio_sum_strand[1] += ss.ll_methylated[1] - ss.ll_unmethylated[1]; ll_ratio_sum_both += diff; } std::string complement_model = sr.pore_model[C_IDX].name; fprintf(handles.read_writer, "%s\t%.2lf\t%zu\t%s\tNumPositive=%zu\n", fast5_path.c_str(), ll_ratio_sum_both, site_score_map.size(), complement_model.c_str(), num_positive); for(size_t si = 0; si < NUM_STRANDS; ++si) { std::string model = sr.pore_model[si].name; fprintf(handles.strand_writer, "%s\t%.2lf\t%zu\t%s\n", fast5_path.c_str(), ll_ratio_sum_strand[si], site_score_map.size(), model.c_str()); } } }
double nb_0(double q_tot, double sz, double emit_n, double E, double n_p_cgs, double m_ion_amu) { double _sr = sr(emit_n, E, n_p_cgs, m_ion_amu); return nb_0(q_tot, sz, _sr); }
int main(void) { int64 t0,t1; d(); s=(int64*)calloc(q,sizeof(int64)); gw(0,2,99); _1: if(gr(0,2)!=1000)goto _2;else goto _47; _2: t0=gr(0,2)+1; t1=gr(0,2)+1; gw(0,2,gr(0,2)+1); t1%=2; t1=(t1!=0)?0:1; if((t1)!=0)goto _1;else goto _3; _3: t0%=5; t0=(t0!=0)?0:1; if((t0)!=0)goto _1;else goto _4; _4: gw(1,2,3); _5: t0=gr(1,2)+1; gw(1,2,gr(1,2)+1); t0-=14; t0=(t0!=0)?0:1; if((t0)!=0)goto _1;else goto _6; _6: gw(2,2,0); if(((gr(0,gr(1,2))-48)+gr(2,2))!=0)goto _8;else goto _7; _7: t0=gr(2,2)+1; gw(2,2,gr(2,2)+1); t0-=3; t0=(t0!=0)?0:1; if((t0)!=0)goto _5;else goto _8; _8: gw(4,2,gr(0,2)); sa(5); sa(gr(5,gr(1,2))-48); _9: if(sp()!=0)goto _10;else goto _46; _10: sa(sr()); sa((tm(gr(4,2),10))+48); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+7LL); sa(gr(1,2)); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(4,2,td(gr(4,2),10)); _11: sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _12;else goto _45; _12: sp(); sa(gr(12,gr(1,2))-48); sa(4); _13: sa(sr()+7); sa(gr(1,2)); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()-48LL); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _44;else goto _14; _14: sp(); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sr()); gw(7,2,sp()); if(tm(sr(),2)!=0)goto _16;else goto _15; _15: sp(); goto _7; _16: if(tm(sr(),3)!=0)goto _17;else goto _15; _17: gw(5,2,sp()); sa(7); sa(tm(gr(5,2),7)); _18: if(sp()!=0)goto _19;else goto _15; _19: if(sr()>(td(gr(5,2),2)))goto _22;else goto _20; _20: sa(sr()-2); sa(gr(5,2)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} {int64 v0=sp();sa(tm(sp(),v0));} sa((sp()!=0)?0:1); if(sp()!=0)goto _15;else goto _21; _21: sa(sp()+6LL); sa(sr()); sa(gr(5,2)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} {int64 v0=sp();sa(tm(sp(),v0));} goto _18; _22: gw(8,2,1); gw(9,2,gr(2,2)); gw(9,2,gr(9,2)+1); gw(4,2,gr(0,2)); sp(); _23: sa(5); sa(gr(5,gr(1,2))-48); _24: if(sp()!=0)goto _25;else goto _43; _25: sa(sr()); sa((tm(gr(4,2),10))+48); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+7LL); sa(gr(9,2)+4); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(4,2,td(gr(4,2),10)); _26: sa(sr()); if(sp()!=0)goto _42;else goto _27; _27: sp(); sa(gr(12,gr(9,2)+4)-48); sa(4); _28: sa(sr()+7); sa(gr(9,2)+4); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()-48LL); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _41;else goto _29; _29: sp(); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); sa(sp()*10LL); sa(sp()+sp()); if(tm(sr(),2)!=0)goto _34;else goto _30; _30: sp(); if(gr(9,2)!=9)goto _31;else goto _32; _31: gw(9,2,gr(9,2)+1); gw(4,2,gr(0,2)); goto _23; _32: if(gr(8,2)!=8)goto _7;else goto _33; _33: printf("%lld", gr(7,2)); return 0; _34: if(tm(sr(),3)!=0)goto _35;else goto _30; _35: gw(5,2,sp()); sa(7); sa(tm(gr(5,2),7)); _36: if(sp()!=0)goto _37;else goto _30; _37: if(sr()>(td(gr(5,2),2)))goto _40;else goto _38; _38: sa(sr()-2); sa(gr(5,2)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} {int64 v0=sp();sa(tm(sp(),v0));} sa((sp()!=0)?0:1); if(sp()!=0)goto _30;else goto _39; _39: sa(sp()+6LL); sa(sr()); sa(gr(5,2)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} {int64 v0=sp();sa(tm(sp(),v0));} goto _36; _40: gw(8,2,gr(8,2)+1); goto _30; _41: sa(sp()-1LL); goto _28; _42: sa(sp()-1LL); sa(sr()); sa(gr(1,2)); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()-48LL); goto _24; _43: sa(sr()); sa(gr(9,2)+48); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+7LL); sa(gr(9,2)+4); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _26; _44: sa(sp()-1LL); goto _13; _45: sa(sp()-1LL); sa(sr()); sa(gr(1,2)); {int64 v0=sp();sa(gr(sp(),v0));} sa(sp()-48LL); goto _9; _46: sa(sr()); sa(gr(2,2)+48); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+7LL); sa(gr(1,2)); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _11; _47: return 0; }
StatusWith<std::tuple<bool, std::string>> SaslSCRAMServerMechanism<Policy>::_firstStep( OperationContext* opCtx, StringData inputData) { const auto badCount = [](int got) { return Status(ErrorCodes::BadValue, str::stream() << "Incorrect number of arguments for first SCRAM client message, got " << got << " expected at least 3"); }; /** * gs2-cbind-flag := ("p=" cb-name) / 'y' / 'n' * gs2-header := gs2-cbind-flag ',' [ authzid ] ',' * reserved-mext := "m=" 1*(value-char) * client-first-message-bare := [reserved-mext ','] username ',' nonce [',' extensions] * client-first-message := gs2-header client-first-message-bare */ const auto gs2_cbind_comma = inputData.find(','); if (gs2_cbind_comma == std::string::npos) { return badCount(1); } const auto gs2_cbind_flag = inputData.substr(0, gs2_cbind_comma); if (gs2_cbind_flag.startsWith("p=")) { return Status(ErrorCodes::BadValue, "Server does not support channel binding"); } if ((gs2_cbind_flag != "y") && (gs2_cbind_flag != "n")) { return Status(ErrorCodes::BadValue, str::stream() << "Incorrect SCRAM client message prefix: " << gs2_cbind_flag); } const auto gs2_header_comma = inputData.find(',', gs2_cbind_comma + 1); if (gs2_header_comma == std::string::npos) { return badCount(2); } auto authzId = inputData.substr(gs2_cbind_comma + 1, gs2_header_comma - (gs2_cbind_comma + 1)); if (authzId.size()) { if (authzId.startsWith("a=")) { authzId = authzId.substr(2); } else { return Status(ErrorCodes::BadValue, str::stream() << "Incorrect SCRAM authzid: " << authzId); } } const auto client_first_message_bare = inputData.substr(gs2_header_comma + 1); if (client_first_message_bare.startsWith("m=")) { return Status(ErrorCodes::BadValue, "SCRAM mandatory extensions are not supported"); } /* StringSplitter::split() will ignore consecutive delimiters. * e.g. "foo,,bar" => {"foo","bar"} * This makes our implementation of SCRAM *slightly* more generous * in what it will accept than the standard calls for. * * This does not impact _authMessage, as it's composed from the raw * string input, rather than the output of the split operation. */ const auto input = StringSplitter::split(client_first_message_bare.toString(), ","); if (input.size() < 2) { // gs2-header is not included in this count, so add it back in. return badCount(input.size() + 2); } if (!str::startsWith(input[0], "n=") || input[0].size() < 3) { return Status(ErrorCodes::BadValue, str::stream() << "Invalid SCRAM user name: " << input[0]); } ServerMechanismBase::_principalName = input[0].substr(2); decodeSCRAMUsername(ServerMechanismBase::_principalName); if (!authzId.empty() && ServerMechanismBase::_principalName != authzId) { return Status(ErrorCodes::BadValue, str::stream() << "SCRAM user name " << ServerMechanismBase::_principalName << " does not match authzid " << authzId); } if (!str::startsWith(input[1], "r=") || input[1].size() < 6) { return Status(ErrorCodes::BadValue, str::stream() << "Invalid SCRAM client nonce: " << input[1]); } const auto clientNonce = input[1].substr(2); // SERVER-16534, SCRAM-SHA-1 must be enabled for authenticating the internal user, so that // cluster members may communicate with each other. Hence ignore disabled auth mechanism // for the internal user. UserName user(ServerMechanismBase::ServerMechanismBase::_principalName, ServerMechanismBase::getAuthenticationDatabase()); if (!sequenceContains(saslGlobalParams.authenticationMechanisms, "SCRAM-SHA-1") && user != internalSecurity.user->getName()) { return Status(ErrorCodes::BadValue, "SCRAM-SHA-1 authentication is disabled"); } // The authentication database is also the source database for the user. User* userObj; auto authManager = AuthorizationManager::get(opCtx->getServiceContext()); Status status = authManager->acquireUser(opCtx, user, &userObj); if (!status.isOK()) { return status; } User::CredentialData credentials = userObj->getCredentials(); UserName userName = userObj->getName(); authManager->releaseUser(userObj); _scramCredentials = credentials.scram<HashBlock>(); if (!_scramCredentials.isValid()) { // Check for authentication attempts of the __system user on // systems started without a keyfile. if (userName == internalSecurity.user->getName()) { return Status(ErrorCodes::AuthenticationFailed, "It is not possible to authenticate as the __system user " "on servers started without a --keyFile parameter"); } else { return Status(ErrorCodes::AuthenticationFailed, "Unable to perform SCRAM authentication for a user with missing " "or invalid SCRAM credentials"); } } _secrets = scram::Secrets<HashBlock>("", base64::decode(_scramCredentials.storedKey), base64::decode(_scramCredentials.serverKey)); // Generate server-first-message // Create text-based nonce as base64 encoding of a binary blob of length multiple of 3 const int nonceLenQWords = 3; uint64_t binaryNonce[nonceLenQWords]; std::unique_ptr<SecureRandom> sr(SecureRandom::create()); binaryNonce[0] = sr->nextInt64(); binaryNonce[1] = sr->nextInt64(); binaryNonce[2] = sr->nextInt64(); _nonce = clientNonce + base64::encode(reinterpret_cast<char*>(binaryNonce), sizeof(binaryNonce)); StringBuilder sb; sb << "r=" << _nonce << ",s=" << _scramCredentials.salt << ",i=" << _scramCredentials.iterationCount; std::string outputData = sb.str(); // add client-first-message-bare and server-first-message to _authMessage _authMessage = client_first_message_bare.toString() + "," + outputData; return std::make_tuple(false, std::move(outputData)); }
// Update the training data with aligned events from a read void add_aligned_events(const Fast5Map& name_map, const faidx_t* fai, const bam_hdr_t* hdr, const bam1_t* record, size_t read_idx, int region_start, int region_end, size_t round, ModelTrainingMap& training) { // Load a squiggle read for the mapped read std::string read_name = bam_get_qname(record); std::string fast5_path = name_map.get_path(read_name); // load read SquiggleRead sr(read_name, fast5_path); // replace the models that are built into the read with the current trained model sr.replace_models(opt::trained_model_type); for(size_t strand_idx = 0; strand_idx < NUM_STRANDS; ++strand_idx) { // skip if 1D reads and this is the wrong strand if(!sr.has_events_for_strand(strand_idx)) { continue; } // set k uint32_t k = sr.pore_model[strand_idx].k; // Align to the new model EventAlignmentParameters params; params.sr = &sr; params.fai = fai; params.hdr = hdr; params.record = record; params.strand_idx = strand_idx; params.alphabet = mtrain_alphabet; params.read_idx = read_idx; params.region_start = region_start; params.region_end = region_end; std::vector<EventAlignment> alignment_output = align_read_to_ref(params); if (alignment_output.size() == 0) return; // Update pore model based on alignment std::string curr_model = sr.pore_model[strand_idx].metadata.get_short_name(); double orig_score = -INFINITY; if (opt::output_scores) { orig_score = model_score(sr, strand_idx, fai, alignment_output, 500, NULL); #pragma omp critical(print) std::cout << round << " " << curr_model << " " << read_idx << " " << strand_idx << " Original " << orig_score << std::endl; } if ( opt::calibrate ) { double resid = 0.; recalibrate_model(sr, strand_idx, alignment_output, mtrain_alphabet, resid, true); if (opt::output_scores) { double rescaled_score = model_score(sr, strand_idx, fai, alignment_output, 500, NULL); #pragma omp critical(print) { std::cout << round << " " << curr_model << " " << read_idx << " " << strand_idx << " Rescaled " << rescaled_score << std::endl; std::cout << round << " " << curr_model << " " << read_idx << " " << strand_idx << " Delta " << rescaled_score-orig_score << std::endl; } } } // Get the training data for this model auto& emission_map = training[curr_model]; for(size_t i = 0; i < alignment_output.size(); ++i) { const EventAlignment& ea = alignment_output[i]; std::string model_kmer = ea.model_kmer; // Grab the previous/next model kmer from the alignment_output table. // If the read is from the same strand as the reference // the next kmer comes from the next alignment_output (and vice-versa) // other the indices are swapped int next_stride = ea.rc ? -1 : 1; std::string prev_kmer = ""; std::string next_kmer = ""; if(i > 0 && i < alignment_output.size() - 1) { // check that the event indices are correct for the next expected position assert(alignment_output[i + next_stride].event_idx - ea.event_idx == 1); assert(alignment_output[i - next_stride].event_idx - ea.event_idx == -1); // only set the previous/next when there was exactly one base of movement along the referenc if( std::abs(alignment_output[i + next_stride].ref_position - ea.ref_position) == 1) { next_kmer = alignment_output[i + next_stride].model_kmer; } if( std::abs(alignment_output[i - next_stride].ref_position - ea.ref_position) == 1) { prev_kmer = alignment_output[i - next_stride].model_kmer; } } // Get the rank of the kmer that we aligned to (on the sequencing strand, = model_kmer) uint32_t rank = mtrain_alphabet->kmer_rank(model_kmer.c_str(), k); assert(rank < emission_map.size()); auto& kmer_summary = emission_map[rank]; // We only use this event for training if its not at the end of the alignment // (to avoid bad alignments around the read edges) and if its not too short (to // avoid bad measurements from effecting the levels too much) bool use_for_training = i > opt::min_distance_from_alignment_end && i + opt::min_distance_from_alignment_end < alignment_output.size() && alignment_output[i].hmm_state == 'M' && sr.get_duration( alignment_output[i].event_idx, strand_idx) >= opt::min_event_duration && sr.get_fully_scaled_level(alignment_output[i].event_idx, strand_idx) >= 1.0; if(use_for_training) { StateTrainingData std(sr, ea, rank, prev_kmer, next_kmer); #pragma omp critical(kmer) kmer_summary.events.push_back(std); } if(ea.hmm_state == 'M') { #pragma omp atomic kmer_summary.num_matches += 1; } else if(ea.hmm_state == 'E') { #pragma omp atomic kmer_summary.num_stays += 1; } } } // for strands }
int main(void) { int64 t0,t1,t2; d(); s=(int64*)calloc(q,sizeof(int64)); gw(1,0,150); gw(2,0,35); gw(4,0,5250); gw(3,0,2); gw(1,1,2000); gw(2,1,5000); gw(2,2,0); gw(1,2,1); gw(3,1,10000000); _1: gw(0,3,32); gw(1,3,32); gw(8,0,1073741824); gw(tm(gr(3,0),gr(1,0)),(td(gr(3,0),gr(1,0)))+3,88); sa(gr(3,0)+gr(3,0)); sa((gr(3,0)+gr(3,0))<gr(4,0)?1:0); _2: if(sp()!=0)goto _38;else goto _3; _3: sp(); _4: sa(gr(3,0)+1); gw(3,0,gr(3,0)+1); sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=32; if((t0)!=0)goto _6;else goto _4; _6: if(gr(4,0)>gr(3,0))goto _1;else goto _7; _7: gw(3,0,0); sa(gr(1,1)); gw(4,2,gr(1,1)); _8: sa(sr()); sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=88; if((t0)!=0)goto _9;else goto _12; _9: sa(sp()+1LL); if(sr()!=gr(2,1))goto _10;else goto _11; _10: sa(sr()); gw(4,2,sp()); goto _8; _11: printf("%lld", gr(1,2)); sp(); return 0; _12: sa(sr()+1); _13: sa(sr()); gw(5,2,sp()); sa(sr()); sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=88; if((t0)!=0)goto _16;else goto _14; _14: t0=gr(4,2)*gr(5,2); gw(7,2,gr(4,2)*gr(5,2)); t0=t0>gr(3,1)?1:0; if((t0)!=0)goto _17;else goto _15; _15: t0=gr(7,2)*gr(2,2); t1=(gr(4,2)-1)*(gr(5,2)-1); gw(8,2,(gr(4,2)-1)*(gr(5,2)-1)); t1*=gr(1,2); t2=t0>t1?1:0; if((t2)!=0)goto _16;else goto _18; _16: sa(sp()+1LL); if(sr()!=gr(2,1))goto _13;else goto _17; _17: sp(); goto _9; _18: sa(0); sa(tm(gr(7,2),10)); sa(gr(7,2)); sa(gr(7,2)); _19: if(sp()!=0)goto _20;else goto _24; _20: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(9); _21: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _23;else goto _22; _22: sp(); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),10)); sa(tm(sr(),10)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); goto _19; _23: sa(sp()-1LL); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()*9LL); goto _21; _24: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sp(); sp(); _25: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _26;else goto _27; _26: sa(sp()+sp()); goto _25; _27: sa(sp()+sp()); sa(0); sa(tm(gr(8,2),10)); sa(gr(8,2)); sa(gr(8,2)); _28: if(sp()!=0)goto _29;else goto _33; _29: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(9); _30: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _32;else goto _31; _31: sp(); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),10)); sa(tm(sr(),10)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); goto _28; _32: sa(sp()-1LL); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()*9LL); goto _30; _33: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sp(); sp(); _34: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sr()); if(sp()!=0)goto _37;else goto _35; _35: sa(sp()+sp()); t0=sp(); sa(sp()-t0); t1=sp(); if((t1)!=0)goto _16;else goto _36; _36: gw(1,2,gr(7,2)); gw(2,2,gr(8,2)); goto _16; _37: sa(sp()+sp()); goto _34; _38: sa(sr()); sa(32); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sp()+gr(3,0)); sa(sr()<gr(4,0)?1:0); goto _2; }
void SearchManager::onData(const uint8_t* buf, size_t aLen, const string& remoteIp) { string x((char*)buf, aLen); if(x.compare(0, 4, "$SR ") == 0) { string::size_type i, j; // Directories: $SR <nick><0x20><directory><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>) // Files: $SR <nick><0x20><filename><0x05><filesize><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>) i = 4; if( (j = x.find(' ', i)) == string::npos) { return; } string nick = x.substr(i, j-i); i = j + 1; // A file has 2 0x05, a directory only one size_t cnt = count(x.begin() + j, x.end(), 0x05); SearchResult::Types type = SearchResult::TYPE_FILE; string file; int64_t size = 0; if(cnt == 1) { // We have a directory...find the first space beyond the first 0x05 from the back // (dirs might contain spaces as well...clever protocol, eh?) type = SearchResult::TYPE_DIRECTORY; // Get past the hubname that might contain spaces if((j = x.rfind(0x05)) == string::npos) { return; } // Find the end of the directory info if((j = x.rfind(' ', j-1)) == string::npos) { return; } if(j < i + 1) { return; } file = x.substr(i, j-i) + '\\'; } else if(cnt == 2) { if( (j = x.find((char)5, i)) == string::npos) { return; } file = x.substr(i, j-i); i = j + 1; if( (j = x.find(' ', i)) == string::npos) { return; } size = Util::toInt64(x.substr(i, j-i)); } i = j + 1; if( (j = x.find('/', i)) == string::npos) { return; } int freeSlots = Util::toInt(x.substr(i, j-i)); i = j + 1; if( (j = x.find((char)5, i)) == string::npos) { return; } int slots = Util::toInt(x.substr(i, j-i)); i = j + 1; if( (j = x.rfind(" (")) == string::npos) { return; } string hubName = x.substr(i, j-i); i = j + 2; if( (j = x.rfind(')')) == string::npos) { return; } string hubIpPort = x.substr(i, j-i); string url = ClientManager::getInstance()->findHub(hubIpPort); string encoding = ClientManager::getInstance()->findHubEncoding(url); nick = Text::toUtf8(nick, encoding); file = Text::toUtf8(file, encoding); hubName = Text::toUtf8(hubName, encoding); UserPtr user = ClientManager::getInstance()->findUser(nick, url); if(!user) { // Could happen if hub has multiple URLs / IPs user = ClientManager::getInstance()->findLegacyUser(nick); if(!user) return; } string tth; if(hubName.compare(0, 4, "TTH:") == 0) { tth = hubName.substr(4); StringList names = ClientManager::getInstance()->getHubNames(user->getCID()); hubName = names.empty() ? _("Offline") : Util::toString(names); } if(tth.empty() && type == SearchResult::TYPE_FILE) { return; } SearchResultPtr sr(new SearchResult(user, type, slots, freeSlots, size, file, hubName, url, remoteIp, TTHValue(tth), Util::emptyString)); fire(SearchManagerListener::SR(), sr); } else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) { AdcCommand c(x.substr(0, x.length()-1)); if(c.getParameters().empty()) return; string cid = c.getParam(0); if(cid.size() != 39) return; UserPtr user = ClientManager::getInstance()->findUser(CID(cid)); if(!user) return; // This should be handled by AdcCommand really... c.getParameters().erase(c.getParameters().begin()); onRES(c, user, remoteIp); } /*else if(x.compare(1, 4, "SCH ") == 0 && x[x.length() - 1] == 0x0a) { try { respond(AdcCommand(x.substr(0, x.length()-1))); } catch(ParseException& ) { } }*/ // Needs further DoS investigation }
int main(void) { int64 t0,t1,t2; d(); s=(int64*)calloc(q,sizeof(int64)); gw(1,0,400); gw(0,0,10000); sa(gr(0,0)-1); sa(0); sa((gr(0,0)-1)/2); sa((gr(0,0)-1)/2); gw(2,0,gr(0,0)-1); _1: if(sp()!=0)goto _2;else goto _15; _2: t0=gr(2,0); sa(sr()); sa(t0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} {int64 v0=sp();sa(tm(sp(),v0));} t1=sp(); if((t1)!=0)goto _14;else goto _3; _3: sa(sr()); gw(3,0,sp()); sa(sp()+sp()); sa(gr(3,0)-1); sa(gr(3,0)-1); _4: if(sp()!=0)goto _2;else goto _5; _5: sp(); gw(tm(gr(2,0),gr(1,0)),(td(gr(2,0),gr(1,0)))+1,sp()); _6: sa(sr()); if(sp()!=0)goto _13;else goto _7; _7: gw(0,1,0); gw(2,0,gr(0,0)-1); gw(9,0,0); sp(); sp(); _8: gw(4,0,gr(tm(gr(2,0),gr(1,0)),(td(gr(2,0),gr(1,0)))+1)); gw(5,0,gr(tm(gr(4,0),gr(1,0)),(td(gr(4,0),gr(1,0)))+1)); if((gr(2,0)-gr(5,0))!=0)goto _9;else goto _11; _9: t2=gr(2,0); gw(2,0,gr(2,0)-1); if((t2)!=0)goto _8;else goto _10; _10: printf("%lld ", gr(9,0)); return 0; _11: if(gr(2,0)>gr(4,0))goto _12;else goto _9; _12: printf("%lld ", gr(2,0)); printf(" - "); printf("%lld ", gr(4,0)); printf("\n"); gw(9,0,gr(9,0)+gr(2,0)+gr(4,0)); goto _9; _13: sa(sp()-1LL); sa(sr()); sa(sr()); gw(2,0,sp()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()/2LL); sa(sr()); goto _1; _14: sa(sp()-1LL); sa(sr()); goto _4; _15: gw(tm(gr(2,0),gr(1,0)),(td(gr(2,0),gr(1,0)))+1,1); goto _6; }
void CCSMainView::SearchL() { iContainer->SaveDataL(); iContainer->DisableEditorIndicators(); // if GPS or Cell Info data is available if ( iSavedData.iUseFromGps && IsGpsConnectedOrCellidAvailable() && /*iWayfinderAppUi->GetCellCountry() == */iSavedData.iCountryId == -1) { // user has selected to search from GPS TInt32 lat, lon; TUint cellRadius = 0; TInt heading, speed, alt; iWayfinderAppUi->GetDataHolder()->GetInputData(lat,lon, heading, speed, alt); // if there is no lat and long from GPS check for cell pos values if (lat == MAX_INT32 || lon == MAX_INT32) { Nav2Coordinate navCoOrd(MAX_INT32,MAX_INT32); if ( iWayfinderAppUi->GetCellPosIfAvailable(navCoOrd, cellRadius) ) { lat = navCoOrd.nav2lat; lon = navCoOrd.nav2lon; } } if (lat == MAX_INT32 || lon == MAX_INT32) { // user wants to search from gps but the gps haven't reported any // valid coords yet iWayfinderAppUi->ShowErrorDialogL(0x0200, R_WAYFINDER_NO_GPS_POS_MSG); } else { // got valid coords from the gps so perfrom the search based on this if (iSavedData.iWhat.Length() > 0) { char* searchString = WFTextUtil::newTDesDupL(iSavedData.iWhat); char* categoryId = WFTextUtil::newTDesDupL(iSavedData.iCategoryId); SearchRecord sr(MAX_UINT32, "", "", searchString, categoryId, lat, lon); iSearchRecord = sr; delete[] categoryId; delete[] searchString; iWayfinderAppUi->HandleCommandL(EWayFinderCmdCSNewSearch); } else { // The user still needs to specify what to search for. WFDialog::ShowInformationL( R_WAYFINDER_NOHITS_MSG ); } } } else { // user has entered searchfields to search from (not from GPS) if (iSavedData.iCountry.Length() > 0 && (iSavedData.iWhat.Length() > 0 || iSavedData.iWhere.Length() > 0)) { TInt countryId = iSavedData.iCountryId; char* areaName = WFTextUtil::newTDesDupL(iSavedData.iWhere); char* searchString = WFTextUtil::newTDesDupL(iSavedData.iWhat); char* categoryId = WFTextUtil::newTDesDupL(iSavedData.iCategoryId); char* countryName = WFTextUtil::newTDesDupL(iSavedData.iCountry); char* charCountryId = WFTextUtil::uint32AsStringL(iSavedData.iCountryId); iWayfinderAppUi->GetCSDispatcher()-> getCombinedSearchDataHolder().addSearchHistoryItem(searchString, areaName, countryName, charCountryId, categoryId); SearchRecord sr(countryId, "", areaName, searchString, categoryId); iSearchRecord = sr; delete[] areaName; delete[] searchString; delete[] categoryId; delete[] countryName; delete[] charCountryId; iWayfinderAppUi->HandleSaveSearchHistoryL(); iWayfinderAppUi->HandleCommandL(EWayFinderCmdCSNewSearch); } else { // The user has not given enough information to search for. // Display a dialog about this. WFDialog::ShowInformationL( R_WAYFINDER_NOHITS_MSG ); iContainer->EnableEditorIndicators(); } } }
int scorereads_main(int argc, char** argv) { parse_scorereads_options(argc, argv); omp_set_num_threads(opt::num_threads); Fast5Map name_map(opt::reads_file); ModelMap models; if (!opt::models_fofn.empty()) models = read_models_fofn(opt::models_fofn); // Open the BAM and iterate over reads // load bam file htsFile* bam_fh = sam_open(opt::bam_file.c_str(), "r"); assert(bam_fh != NULL); // load bam index file std::string index_filename = opt::bam_file + ".bai"; hts_idx_t* bam_idx = bam_index_load(index_filename.c_str()); assert(bam_idx != NULL); // read the bam header bam_hdr_t* hdr = sam_hdr_read(bam_fh); // load reference fai file faidx_t *fai = fai_load(opt::genome_file.c_str()); hts_itr_t* itr; // If processing a region of the genome, only emit events aligned to this window int clip_start = -1; int clip_end = -1; if(opt::region.empty()) { // TODO: is this valid? itr = sam_itr_queryi(bam_idx, HTS_IDX_START, 0, 0); } else { fprintf(stderr, "Region: %s\n", opt::region.c_str()); itr = sam_itr_querys(bam_idx, hdr, opt::region.c_str()); hts_parse_reg(opt::region.c_str(), &clip_start, &clip_end); } #ifndef H5_HAVE_THREADSAFE if(opt::num_threads > 1) { fprintf(stderr, "You enabled multi-threading but you do not have a threadsafe HDF5\n"); fprintf(stderr, "Please recompile nanopolish's built-in libhdf5 or run with -t 1\n"); exit(1); } #endif // Initialize iteration std::vector<bam1_t*> records(opt::batch_size, NULL); for(size_t i = 0; i < records.size(); ++i) { records[i] = bam_init1(); } int result; size_t num_reads_realigned = 0; size_t num_records_buffered = 0; do { assert(num_records_buffered < records.size()); // read a record into the next slot in the buffer result = sam_itr_next(bam_fh, itr, records[num_records_buffered]); num_records_buffered += result >= 0; // realign if we've hit the max buffer size or reached the end of file if(num_records_buffered == records.size() || result < 0) { #pragma omp parallel for schedule(dynamic) for(size_t i = 0; i < num_records_buffered; ++i) { bam1_t* record = records[i]; size_t read_idx = num_reads_realigned + i; if( (record->core.flag & BAM_FUNMAP) == 0) { //load read std::string read_name = bam_get_qname(record); std::string fast5_path = name_map.get_path(read_name); SquiggleRead sr(read_name, fast5_path); // TODO: early exit when have processed all of the reads in readnames if (!opt::readnames.empty() && std::find(opt::readnames.begin(), opt::readnames.end(), read_name) == opt::readnames.end() ) continue; for(size_t strand_idx = 0; strand_idx < NUM_STRANDS; ++strand_idx) { std::vector<EventAlignment> ao = alignment_from_read(sr, strand_idx, read_idx, models, fai, hdr, record, clip_start, clip_end); if (ao.size() == 0) continue; // Update pore model based on alignment if ( opt::calibrate ) recalibrate_model(sr, strand_idx, ao, false); double score = model_score(sr, strand_idx, fai, ao, 500); if (score > 0) continue; #pragma omp critical(print) std::cout << read_name << " " << ( strand_idx ? "complement" : "template" ) << " " << sr.pore_model[strand_idx].name << " " << score << std::endl; } } } num_reads_realigned += num_records_buffered; num_records_buffered = 0; } } while(result >= 0); // cleanup records for(size_t i = 0; i < records.size(); ++i) { bam_destroy1(records[i]); } // cleanup sam_itr_destroy(itr); bam_hdr_destroy(hdr); fai_destroy(fai); sam_close(bam_fh); hts_idx_destroy(bam_idx); return 0; }
int main(void) { int64 t0; d(); s=(int64*)calloc(q,sizeof(int64)); gw(3,3,29); gw(2,0,0); gw(17,0,0); sa(8); _1: sa(sp()-1LL); sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+9LL); sa(0); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()); if(sp()!=0)goto _1;else goto _3; _3: gw(2,1,0); gw(2,2,0); gw(13,1,0); gw(13,2,0); sp(); sa(8); _4: sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()); if(sp()!=0)goto _92;else goto _5; _5: sp(); sa(9); _6: sa(sr()); sa(sr()+8); sa(0); {int64 v0=sp();t0=gr(sp(),v0);} if((t0)!=0)goto _89;else goto _7; _7: sa(sr()); sa(sr()); sa(sp()*sp()); sa(td(sp(),10)); sa(sr()+4); sa(2); {int64 v0=sp();t0=gr(sp(),v0);} t0=(t0!=0)?0:1; t0+=gr(2,2); gw(2,2,t0); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()); sa(sp()*sp()); sa(tm(sp(),10)); if(sr()!=9)goto _88;else goto _8; _8: gw(2,1,(((gr(10,1))!=0)?0:1)+gr(2,1)); gw(10,1,1); sp(); _9: sa(sp()-1LL); sa(sr()); if(sp()!=0)goto _6;else goto _10; _10: sp(); if((gr(2,1)>6?1:0)+(gr(2,2)>6?1LL:0LL)==0)goto _17;else goto _11; _11: gw(17,0,((gr(17,0))!=0)?0:1); sa(8); sa(8); sa(gr(17,0)); _12: if(sp()!=0)goto _16;else goto _13; _13: sa((sp()!=0)?0:1); if(sp()!=0)goto _14;else goto _15; _14: printf("%lld", gr(2,0)); sp(); return 0; _15: sa(sp()-1LL); sa(sr()); sa(sr()); sa(sr()); sa(sr()+9); sa(0); {int64 v0=sp();sa(gr(sp(),v0));} sa((sp()!=0)?0:1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+9LL); sa(0); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sp()+9LL); sa(0); {int64 v0=sp();sa(gr(sp(),v0));} goto _12; _16: sp(); sp(); sa(0); goto _3; _17: if(6!=gr(2,1))goto _87;else goto _18; _18: sa(2); _19: if(gr(2,2)!=6)goto _20;else goto _86; _20: sa(9); sa(gr(13,2)); _21: if(sp()!=0)goto _22;else goto _45; _22: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _23;else goto _24; _23: sa(sr()+4); sa(2); {int64 v0=sp();sa(gr(sp(),v0));} goto _21; _24: sp(); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _44;else goto _26; _26: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _31;else goto _27; _27: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _28;else goto _30; _28: gw(17,0,((gr(17,0))!=0)?0:1); sp(); sa(8); sa(8); sa(gr(17,0)); goto _12; _30: return 0; _31: sp(); sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} _33: if(sp()!=0)goto _34;else goto _28; _34: sa(sr()+4); sa(1); {int64 v0=sp();sa(gr(sp(),v0));} _35: if(sp()!=0)goto _43;else goto _36; _36: sa(sr()); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} if(5!=gr(2,1))goto _38;else goto _37; _37: sa(1); goto _19; _38: sa(9); sa(gr(13,1)); _39: if(sp()!=0)goto _40;else goto _42; _40: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _41;else goto _31; _41: sa(sr()+4); sa(1); {int64 v0=sp();sa(gr(sp(),v0));} goto _39; _42: sa(sr()); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(0); goto _19; _43: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} goto _33; _44: sp(); sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _40; _45: sa(sr()); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} if(5!=gr(2,2))goto _46;else goto _85; _46: sa(9); sa(gr(13,2)); _47: if(sp()!=0)goto _48;else goto _52; _48: sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _51;else goto _49; _49: sp(); sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _23;else goto _24; _51: sa(sr()+4); sa(2); {int64 v0=sp();sa(gr(sp(),v0));} goto _47; _52: sa(sr()); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(4,0,(((gr(10,1))!=0)?0:1)+gr(13,1)); gw(5,0,(((gr(10,2))!=0)?0:1)+gr(13,2)); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(0); _53: sa(0); _54: sa(8); _55: sa(sr()+4); sa(1); {int64 v0=sp();t0=gr(sp(),v0);} t0+=gr(6,0)*2; gw(6,0,t0); sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _55;else goto _57; _57: gw(7,0,gr(13,2)+(gr(7,0)*2)); sp(); sa(8); _58: sa(sr()+4); sa(2); {int64 v0=sp();t0=gr(sp(),v0);} t0+=gr(7,0)*2; gw(7,0,t0); sa(sr()-1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} if(sp()!=0)goto _58;else goto _60; _60: sp(); sa(gr(7,0)); sa(gr(6,0)); if(gr(6,0)>gr(7,0))goto _61;else goto _62; _61: {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} _62: sa(sp()*1024LL); sa(sp()+sp()); t0=sp(); gw(3,0,t0); sa(1279); sa(gr(79,15+gr(3,3))); sa(gr(79,15+gr(3,3))-gr(3,0)); _63: if(sp()!=0)goto _64;else goto _84; _64: sa(sp()-35LL); sa((sp()!=0)?0:1); if(sp()!=0)goto _65;else goto _83; _65: sa(gr(3,0)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),80)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),80)); sa(sp()+gr(3,3)); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} gw(2,0,gr(2,0)+1); _66: sa(sp()+1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _82;else goto _67; _67: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _80;else goto _68; _68: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _79;else goto _69; _69: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _70;else goto _30; _70: gw(10,1,1); gw(13,1,0); gw(10,2,1); gw(13,2,0); sp(); _71: if((gr(4,0))==0)goto _72;else goto _73; _72: gw(10,1,0); gw(13,1,1); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(1); goto _54; _73: if((gr(5,0))==0)goto _78;else goto _74; _74: sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _77;else goto _75; _75: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _49;else goto _76; _76: sa(sp()-1LL); sa(sr()); sa((sp()!=0)?0:1); if(sp()!=0)goto _24;else goto _30; _77: sp(); sa(sr()); sa(0); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _48; _78: gw(10,2,0); gw(13,2,1); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(-1); goto _54; _79: gw(10,1,1); gw(13,1,0); sp(); goto _73; _80: sp(); if((gr(4,0)+gr(5,0))!=0)goto _71;else goto _81; _81: gw(10,1,0); gw(13,1,1); gw(10,2,0); gw(13,2,1); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(2); goto _54; _82: gw(10,2,1); gw(13,2,0); sp(); goto _74; _83: sa(sp()-1LL); sa(sr()); sa(tm(sr(),80)); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),80)); sa(sp()+gr(3,3)); {int64 v0=sp();sa(gr(sp(),v0));} sa(sr()-gr(3,0)); goto _63; _84: sp(); sp(); goto _66; _85: gw(4,0,(((gr(10,1))!=0)?0:1)+gr(13,1)); gw(5,0,(((gr(10,2))!=0)?0:1)+gr(13,2)); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(1); goto _53; _86: gw(4,0,(((gr(10,1))!=0)?0:1)+gr(13,1)); gw(5,0,(((gr(10,2))!=0)?0:1)+gr(13,2)); gw(6,0,0); gw(7,0,0); gw(6,0,gr(13,1)+(gr(6,0)*2)); sa(2); goto _53; _87: sa(9); sa(gr(13,1)); goto _35; _88: sa(sr()+4); sa(1); {int64 v0=sp();t0=gr(sp(),v0);} t0=(t0!=0)?0:1; t0+=gr(2,1); gw(2,1,t0); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _9; _89: sa(sr()); sa(sr()); sa(sp()*sp()); sa(td(sp(),10)); sa(sr()+4); sa(1); {int64 v0=sp();t0=gr(sp(),v0);} t0=(t0!=0)?0:1; t0+=gr(2,1); gw(2,1,t0); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(1); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sr()); sa(sp()*sp()); sa(tm(sp(),10)); if(sr()!=9)goto _91;else goto _90; _90: gw(2,2,(((gr(10,2))!=0)?0:1)+gr(2,2)); gw(10,2,1); sp(); goto _9; _91: sa(sr()+4); sa(2); {int64 v0=sp();t0=gr(sp(),v0);} t0=(t0!=0)?0:1; t0+=gr(2,2); gw(2,2,t0); sa(1); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(sp()+4LL); sa(2); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} goto _9; _92: sa(sp()-1LL); goto _4; }
int main(void) { int64 t0; d(); s=(int64*)calloc(q,sizeof(int64)); gw(1,0,600); gw(2,0,150); gw(9,0,90000); gw(3,0,2); gw(4,0,1000); gw(3,1,0); _1: gw(tm(gr(3,0),gr(1,0)),(td(gr(3,0),gr(1,0)))+3,88); sa(gr(3,0)+gr(3,0)); sa((gr(3,0)+gr(3,0))<gr(9,0)?1:0); _2: if(sp()!=0)goto _21;else goto _3; _3: sp(); _4: sa(gr(3,0)+1); gw(3,0,gr(3,0)+1); sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=32; if((t0)!=0)goto _6;else goto _4; _6: if(gr(9,0)>gr(3,0))goto _1;else goto _7; _7: gw(0,3,32); gw(1,3,32); gw(5,0,1-gr(4,0)); gw(6,0,2); _8: gw(7,0,0); sa((gr(5,0)*gr(7,0))+gr(6,0)); sa(((gr(5,0)*gr(7,0))+gr(6,0))>1?1:0); _9: if(sp()!=0)goto _10;else goto _20; _10: sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=32; if((t0)!=0)goto _19;else goto _11; _11: t0=gr(7,0); if(gr(7,0)>gr(3,1))goto _18;else goto _12; _12: t0=gr(5,0)+2; gw(5,0,gr(5,0)+2); t0=t0>gr(4,0)?1:0; t0=(t0!=0)?0:1; if((t0)!=0)goto _8;else goto _13; _13: gw(5,0,1-gr(4,0)); _14: sa(gr(6,0)+1); gw(6,0,gr(6,0)+1); sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();t0=gr(sp(),v0);} t0-=32; t0=(t0!=0)?0:1; if((t0)!=0)goto _14;else goto _16; _16: if(gr(6,0)<=gr(4,0))goto _8;else goto _17; _17: printf("%lld", gr(1,1)*gr(2,1)); return 0; _18: gw(3,1,t0); gw(1,1,gr(5,0)); gw(2,1,gr(6,0)); goto _12; _19: sa(gr(7,0)+1); gw(7,0,gr(7,0)+1); sa(sr()); sa(sp()*sp()); sa(sp()+(gr(5,0)*gr(7,0))+gr(6,0)); sa(sr()>1?1:0); goto _9; _20: sp(); goto _11; _21: sa(sr()); sa(32); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(tm(sr(),gr(1,0))); {int64 v0=sp();int64 v1=sp();sa(v0);sa(v1);} sa(td(sp(),gr(1,0))); sa(sp()+3LL); {int64 v0=sp();int64 v1=sp();gw(v1,v0,sp());} sa(sp()+gr(3,0)); sa(sr()<gr(9,0)?1:0); goto _2; }
unsigned getCCRandomSeed() { scoped_ptr<SecureRandom> sr( SecureRandom::create() ); return sr->nextInt64(); }
void TListItem::DrawItem(BView *owner, BRect r, bool /* complete */) { if (IsSelected()) { owner->SetHighColor(180, 180, 180); owner->SetLowColor(180, 180, 180); } else { owner->SetHighColor(255, 255, 255); owner->SetLowColor(255, 255, 255); } owner->FillRect(r); owner->SetHighColor(0, 0, 0); BFont font = *be_plain_font; font.SetSize(font.Size() * kPlainFontSizeScale); owner->SetFont(&font); owner->MovePenTo(r.left + 24, r.bottom - 4); if (fComponent) { // if it's already a mail component, we don't have an icon to // draw, and the entry_ref is invalid BMailAttachment *attachment = dynamic_cast<BMailAttachment *>(fComponent); char name[B_FILE_NAME_LENGTH * 2]; if ((attachment == NULL) || (attachment->FileName(name) < B_OK)) strcpy(name, "unnamed"); BMimeType type; if (fComponent->MIMEType(&type) == B_OK) sprintf(name + strlen(name), ", Type: %s", type.Type()); owner->DrawString(name); BRect iconRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1); BBitmap bitmap(iconRect, B_COLOR_8_BIT); if (GetTrackerIcon(type, &bitmap, B_MINI_ICON) == B_NO_ERROR) { BRect rect(r.left + 4, r.top + 1, r.left + 4 + 15, r.top + 1 + 15); owner->SetDrawingMode(B_OP_OVER); owner->DrawBitmap(&bitmap, iconRect, rect); owner->SetDrawingMode(B_OP_COPY); } else { // ToDo: find some nicer image for this :-) owner->SetHighColor(150, 150, 150); owner->FillEllipse(BRect(r.left + 8, r.top + 4, r.left + 16, r.top + 13)); } return; } BFile file(&fRef, O_RDONLY); BEntry entry(&fRef); BPath path; if (entry.GetPath(&path) == B_OK && file.InitCheck() == B_OK) { owner->DrawString(path.Path()); BNodeInfo info(&file); BRect sr(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1); BBitmap bitmap(sr, B_COLOR_8_BIT); if (info.GetTrackerIcon(&bitmap, B_MINI_ICON) == B_NO_ERROR) { BRect dr(r.left + 4, r.top + 1, r.left + 4 + 15, r.top + 1 + 15); owner->SetDrawingMode(B_OP_OVER); owner->DrawBitmap(&bitmap, sr, dr); owner->SetDrawingMode(B_OP_COPY); } } else owner->DrawString("<missing attachment>"); }
void SubRectAllocator::GetRect(CRect& rect, const Subtitle* s, const Align& align, int tlb, int brb) { SubRect sr(rect, s->m_layer); sr.rect.InflateRect(tlb, tlb, brb, brb); StringMapW<SubRect>::CPair* pPair = Lookup(s->m_name); if(pPair && pPair->m_value.rect != sr.rect) { RemoveKey(s->m_name); pPair = NULL; } if(!pPair) { bool vertical = s->m_direction.primary == _T("down") || s->m_direction.primary == _T("up"); bool fOK = false; while(!fOK) { fOK = true; POSITION pos = GetStartPosition(); while(pos) { const SubRect& sr2 = GetNextValue(pos); if(sr.layer == sr2.layer && !(sr.rect & sr2.rect).IsRectEmpty()) { if(vertical) { if(align.h < 0.5) { sr.rect.right = sr2.rect.right + sr.rect.Width(); sr.rect.left = sr2.rect.right; } else { sr.rect.left = sr2.rect.left - sr.rect.Width(); sr.rect.right = sr2.rect.left; } } else { if(align.v < 0.5) { sr.rect.bottom = sr2.rect.bottom + sr.rect.Height(); sr.rect.top = sr2.rect.bottom; } else { sr.rect.top = sr2.rect.top - sr.rect.Height(); sr.rect.bottom = sr2.rect.top; } } fOK = false; } } } SetAt(s->m_name, sr); rect = sr.rect; rect.DeflateRect(tlb, tlb, brb, brb); } }
int main(void) { int64 t0,t1,t2,t3; int64 x0=1000; int64 x1=2; int64 x2=34; int64 x3=53; s=(int64*)calloc(q,sizeof(int64)); _1: x2=1; _2: sa((x2*x2)+(x1*x1)); x3=(x2*x2)+(x1*x1); sa(0); sa(0-x3); _3: if(sp()!=0)goto _4;else goto _10; _4: sa(sp()+1LL); if(sr()!=x0)goto _9;else goto _5; _5: sp(); sp(); _6: t0=x2+1; x2++; t0-=x1; if((t0)!=0)goto _2;else goto _7; _7: t0=x1+1; x1++; t0-=x0; if((t0)!=0)goto _1;else goto _8; _8: return 0; _9: sa(sr()); sa(sr()); sa(sp()*sp()); sa(sp()-x3); goto _3; _10: x3=sr(); sa(sp()+x2+x1); sa(sp()-x0); if(sp()!=0)goto _11;else goto _12; _11: sp(); goto _6; _12: t0=x2; printf("%lld", x2); printf(" "); t1=x1; printf("%lld", x1); printf(" "); t2=x3; printf("%lld", x3); printf("="); t3=t1*t2; t1=t0*t3; printf("%lld", t1); return 0; }
static void testschurproblem(const ap::real_2d_array& a, int n, double& materr, double& orterr, bool& errstruct, bool& wfailed) { ap::real_2d_array s; ap::real_2d_array t; ap::real_1d_array sr; ap::real_1d_array astc; ap::real_1d_array sastc; int i; int j; int k; double v; double locerr; sr.setbounds(0, n-1); astc.setbounds(0, n-1); sastc.setbounds(0, n-1); // // Schur decomposition, convergence test // t.setbounds(0, n-1, 0, n-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { t(i,j) = a(i,j); } } if( !rmatrixschur(t, n, s) ) { wfailed = true; return; } // // decomposition error // locerr = 0; for(j = 0; j <= n-1; j++) { ap::vmove(&sr(0), &s(j, 0), ap::vlen(0,n-1)); for(k = 0; k <= n-1; k++) { v = ap::vdotproduct(&t(k, 0), &sr(0), ap::vlen(0,n-1)); astc(k) = v; } for(k = 0; k <= n-1; k++) { v = ap::vdotproduct(&s(k, 0), &astc(0), ap::vlen(0,n-1)); sastc(k) = v; } for(k = 0; k <= n-1; k++) { locerr = ap::maxreal(locerr, fabs(sastc(k)-a(k,j))); } } materr = ap::maxreal(materr, locerr); // // orthogonality error // locerr = 0; for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { v = ap::vdotproduct(s.getcolumn(i, 0, n-1), s.getcolumn(j, 0, n-1)); if( i!=j ) { locerr = ap::maxreal(locerr, fabs(v)); } else { locerr = ap::maxreal(locerr, fabs(v-1)); } } } orterr = ap::maxreal(orterr, locerr); // // T matrix structure // for(j = 0; j <= n-1; j++) { for(i = j+2; i <= n-1; i++) { if( t(i,j)!=0 ) { errstruct = true; } } } }
/* the function called by each thread is "mainLoop" */ void* mainLoop(void* arg) { loopArg *loopA = (loopArg*)arg; istream* testSStream = loopA->inpt; ostream* pstatStream = loopA->outpt; int id = loopA->id; double log600 = log2(600.0); PrintStack printStack; for( ; ; ) { InputTree correct; InputTree* cuse; /* first lock to read in the material */ pthread_mutex_lock(&readlock); if( !*testSStream ) { pthread_mutex_unlock(&readlock); break; } *testSStream >> correct; if( !*testSStream ){ pthread_mutex_unlock(&readlock); break; } totWords += correct.length()+1; int locCount = sentenceCount++; list<ECString> wtList; correct.make(wtList); SentRep sr( wtList ); // used in precision calc ExtPos extPos; if(params.extPosIfstream) extPos.read(params.extPosIfstream,sr); pthread_mutex_unlock(&readlock); cuse = &correct; int len = correct.length(); if(len > params.maxSentLen) continue; //cerr << "Len = " << len << endl; /* if( !params.field().in(sentenceCount) ) { sentenceCount++; continue; } if(sentenceCount < -1) { sentenceCount++; continue; } sentenceCount++; */ vector<ECString> poslist; correct.makePosList(poslist); ScoreTree sc; sc.setEquivInts(poslist); MeChart* chart = new MeChart( sr,extPos,id ); chart->parse( ); Item* topS = chart->topS(); if(!topS) { cerr << "Parse failed" << endl; cerr << correct << endl; error(" could not parse "); delete chart; continue; } // compute the outside probabilities on the items so that we can // skip doing detailed computations on the really bad ones chart->set_Alphas(); Bst& bst = chart->findMapParse(); if( bst.empty()) error( "mapProbs did not return answer"); float bestF = -1; int i; int numVersions = 0; Link diffs(0); //cerr << "Need num diff: " << Bchart::Nth << endl; printStruct printS; printS.sentenceCount = locCount; printS.numDiff = 0; for(numVersions = 0 ; ; numVersions++) { short pos = 0; Val* val = bst.next(numVersions); if(!val) { //cerr << "Breaking" << endl; break; } InputTree* mapparse = inputTreeFromBsts(val,pos,sr); bool isU; int dummy = 0; diffs.is_unique(mapparse, isU, dummy); // cerr << "V " << isU << " " << numVersions << *mapparse << endl; if(isU) { printS.probs.push_back(val->prob()); printS.trees.push_back(mapparse); printS.numDiff++; } else { delete mapparse; } if(printS.numDiff >= Bchart::Nth) break; if(numVersions > 20000) break; } ParseStats* locPst = new ParseStats[Bchart::Nth]; ParseStats bestPs; for(i = 0 ; i <printS.numDiff ; i++) { InputTree *mapparse = printS.trees[i]; assert(mapparse); sc.trips.clear(); ParseStats pSt; sc.recordGold(cuse,pSt); sc.precisionRecall(mapparse,pSt); float newF = pSt.fMeasure(); cerr << printS.sentenceCount << "\t" << newF << endl; if(newF > bestF) { bestF = newF; bestPs = pSt; } if(histPoints[i]) { locPst[i] += bestPs; } } if(printS.numDiff < Bchart::Nth) { for(i = printS.numDiff ; i < Bchart::Nth ; i++) { if(histPoints[i]) locPst[i] += bestPs; } } pthread_mutex_lock(&scorelock); for(i = 0 ; i < Bchart::Nth ; i++) totPst[i]+=locPst[i]; pthread_mutex_unlock(&scorelock); int numPrinted; /* put the sentence with which we just finished at the end of the printStack*/ printStack.push_back(printS); PrintStack::iterator psi = printStack.begin(); /* now look at each item from the front of the print stack to see if it should be printed now */ pthread_mutex_lock(&writelock); for( numPrinted =0; psi != printStack.end(); numPrinted++ ) { printStruct& pstr=(*psi); if(pstr.sentenceCount != printCount) break; *pstatStream << pstr.sentenceCount << "\t" << pstr.numDiff << "\n"; printCount++; for(i = 0 ; i < pstr.numDiff ; i++) { InputTree* mapparse = pstr.trees[i]; assert(mapparse); double logP =log2(pstr.probs[i]); logP -= (sr.length()*log600); *pstatStream << logP << "\n"; if(Bchart::prettyPrint) *pstatStream << *mapparse << "\n\n"; else { mapparse->printproper(*pstatStream); *pstatStream << "\n"; } delete mapparse; } *pstatStream << endl; psi++; } pthread_mutex_unlock(&writelock); for(i = 0 ; i < numPrinted ; i++) printStack.pop_front(); if(Feature::isLM) { double lgram = log2(bst.sum()); lgram -= (sr.length()*log600); double pgram = pow(2,lgram); double iptri = chart->triGram();; double ltri = (log2(iptri)-sr.length()*log600); double ptri = pow(2.0,ltri); double pcomb1 = (0.667 * pgram)+(0.333 * ptri); double lcom1 = log2(pcomb1); totGram -= lgram; totTri -= ltri; totMix -= lcom1; if(locCount%10 == 9) { cerr << locCount << "\t"; cerr << pow(2.0,totGram/(double)totWords); cerr <<"\t" << pow(2.0,totTri/(double)totWords); cerr << "\t" << pow(2.0,totMix/(double)(totWords)); cerr << endl; } } if(locCount%50 == 1) { cerr << sentenceCount << "\t"; for(int i = 0 ; i < Bchart::Nth ; i++) if(histPoints[i]) { cerr << i << " " << totPst[i].fMeasure() << "\t"; } cerr << endl; } delete chart; delete [] locPst; } return 0; }
int a3_getLeptonPrediction(int pdgId, double metCut, double jetptCut, double ptCut, double iasCut, bool doEcaloCut, double ecaloCut, TString region){ gDirectory->Delete(); cout<<endl<<"Get leptonic bkg prediction in "<<region<<"."<<endl; // %%%%%%%%%%%%%%%%%%% Get correct scaling factors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TFile *in = new TFile(Form("templates/leptonScalingFactors_pdgId_%i_metCut_%.f_jetptCut_%.0f_ptCut_%.0f",pdgId,metCut,jetptCut,ptCut) + region + ".root","READ"); TGraphAsymmErrors *GScalingFactors = 0; TString name = Form("%.0f_%.0f",ptCut,ecaloCut); in -> GetObject(name,GScalingFactors); if(GScalingFactors==0){ cout<<"No Graph available!"<<endl; return 1; } double aux; double scalingFactor; GScalingFactors->GetPoint(0,aux,scalingFactor); double scalingFactorErrorUp = GScalingFactors->GetErrorYhigh(0); double scalingFactorErrorLow = GScalingFactors->GetErrorYlow(0); cout.precision(3); cout<<"scaling factor = "<<scientific<<scalingFactor<<" + "<<scalingFactorErrorUp<<" - "<<scalingFactorErrorLow<<endl; // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%% Get number of Events in CR_lepton from data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sample data("data"); sample sr("data"); sr.getTree(fileSR); if(pdgId==211) data.getTree(filePionCS); else if(pdgId==11) data.getTree(fileElectronCS); else if(pdgId==13) data.getTree(fileMuonCS); data.getTreeVariables(); sr.getTreeVariables(); data.histo = new TH1D("data","data",1,0,1); data.histo->Sumw2(); sr.histo = new TH1D("sr","sr",1,0,1); sr.histo->Sumw2(); //data.Selection(0, pdgId, metCut, jetptCut, ptCut, iasCut, doEcaloCut, ecaloCut, 0, region); //sr.Selection( 0, pdgId, metCut, jetptCut, ptCut, iasCut, 1, ecaloCut, 0, region); data.Selection(0, pdgId, metCut, jetptCut, ptCut, 0.0 , doEcaloCut, ecaloCut, 1, region); sr.Selection( 0, pdgId, metCut, jetptCut, ptCut, iasCut, 1 , ecaloCut, 0, region); double nSRInclusive = data.histo->Integral(1,data.histo->GetNbinsX()+1); double nSRErrorUpInclusive = nSRInclusive; double nSRErrorLowInclusive = nSRInclusive; cout<<"Data Yield (CR) = "<<fixed<<nSRInclusive<<endl; if(nSRInclusive==0){ /* nSR = getOneSidedUpperLimit(nSR , 0.6827) - nSR; nSRErrorUp = 0; nSRErrorLow = 0; */ nSRInclusive = 0; nSRErrorUpInclusive = getOneSidedUpperLimit(nSRInclusive , 0.6827); nSRErrorLowInclusive = getOneSidedLowerLimit(nSRInclusive , 0.6827); } nSRInclusive = nSRInclusive * scalingFactor; nSRErrorUpInclusive = nSRErrorUpInclusive * scalingFactorErrorUp; nSRErrorLowInclusive = nSRErrorLowInclusive * scalingFactorErrorLow; // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cout<<"nSRInclusive ("<<pdgId<<") = "<<nSRInclusive<<" + "<<nSRErrorUpInclusive<<" - "<<nSRErrorLowInclusive<<endl; //cout<<"Data Yield (CR) = "<<sr.histo->Integral()<<endl; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Get Ias template from MC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TString filename = Form("templates/IasTemplate_METGt%.0f_JetPtGt%.0f_trackPtGt%0.f_ECaloEq%.0f_pdgId%i.root",metCut,jetptCut,ptCut,ecaloCut,pdgId); cout<<"Ias template from : "<<filename<<endl; TFile *inIas = new TFile(filename,"READ"); TH1D* histoIas = 0; TString histoName = Form("lepton_bkg_data_Iascut_0p%02.0f",iasCut*100); cout<<"histogram = "<<histoName<<endl; inIas -> GetObject(histoName,histoIas); double Ias = 0; double IasErr = 0; if(region=="SR" || region=="CR1"){ Ias = histoIas->GetBinContent(2); IasErr = histoIas->GetBinError(2); } else if(region=="CR2" || region=="CR3"){ Ias = histoIas->GetBinContent(1); IasErr = histoIas->GetBinError(1); } cout<<"histoIas->GetBinContent(1) = "<<histoIas->GetBinContent(1)<<endl; cout<<"histoIas->GetBinContent(2) = "<<histoIas->GetBinContent(2)<<endl; int nEntries = histoIas->GetEntries(); cout<<"nEntries = "<<nEntries<<endl; double a = nEntries/(histoIas->Integral()); double IasErrUp = (getOneSidedUpperLimit(a*Ias , 0.6827) - a*Ias)/a; double IasErrLow = (a*Ias - getOneSidedLowerLimit(a*Ias , 0.6827))/a; if(Ias==0){ double up = getOneSidedUpperLimit(0 , 0.6827); double low = getOneSidedLowerLimit(0 , 0.6827); cout<<"Upper limit = "<<up<<endl; IasErrUp = up/nEntries; IasErrLow = low/nEntries; cout<<"IasErrUp = "<<IasErrUp<<endl; } cout<<"Ias = "<<Ias<<" +/- "<<IasErr<<endl; double nSR = nSRInclusive*Ias; double nSRErrorUp = sqrt( pow( Ias*nSRErrorUpInclusive ,2) + pow( nSRInclusive*IasErrUp ,2) ); double nSRErrorLow = sqrt( pow( Ias*nSRErrorLowInclusive ,2) + pow( nSRInclusive*IasErrLow ,2) ); cout<<"###########################################################################"<<endl; cout.precision(2); cout<<"Statisitcs for "<<pdgId<<" : "<<"pt="<<ptCut<<" ECalo="<<ecaloCut<<endl; cout<<"NEntries in Ias histo = "<<histoIas->Integral()*a<<endl; cout<<"NEntries in high Ias = "<<Ias*a<<" +/- "<<IasErr<<endl; //cout<<"scaling factor = "<<scientific<<scalingFactor<<" + "<<scalingFactorErrorUp<<" - "<<scalingFactorErrorLow<<endl; cout<<"###########################################################################"<<endl; cout<<"nSR ("<<pdgId<<") = "<<nSR<<" + "<<nSRErrorUp<<" - "<<nSRErrorLow<<endl; //%%%%%%%%%%%%%%%%%%%% Write output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% filename = Form("results/Bkg%i_metCutEq%.0f_ptCutEq%.0f_ECaloCutEq%.0f_IasCutEq0p%02.0f_",pdgId,metCut,ptCut,ecaloCut,iasCut*100) + region + ".root"; TFile *out = new TFile(filename,"RECREATE"); if(pdgId==11) name = "electrons"; else if(pdgId==13) name = "muons"; else if(pdgId==211) name = "pions"; double x[1] = {0.5}; double xLow[1] = {0}; double xUp[1] = {0}; double y[1] = {nSR}; double yLow[1] = {nSRErrorLow}; double yUp[1] = {nSRErrorUp}; TGraphAsymmErrors* GnSR = new TGraphAsymmErrors(1,x,y,xLow,xUp,yLow,yUp); GnSR -> SetMarkerStyle(20); GnSR -> Write(name); out->Close(); if(pdgId==211){ filename = Form("results/DataYield_metCutEq%.0f_ptCutEq%.0f_ECaloCutEq%.0f_IasCutEq0p%02.0f_",metCut,ptCut,ecaloCut,iasCut*100) + region + ".root"; TFile *outData = new TFile(filename,"RECREATE"); name="data"; TH1D *histoData = new TH1D(name,name,1,0,1); histoData->Fill("CR1",0); histoData->Fill("CR2",0); histoData->Fill("CR3",0); histoData->Fill("SR",0); int bin = histoData->GetXaxis()->FindBin("SR"); histoData->SetBinContent(bin,sr.histo->Integral()); histoData->SetBinError(bin,sqrt(sr.histo->Integral())); histoData->Write(); outData->Close(); delete outData; } return 0; }
bool LevellerDataset::write_header() { char szHeader[5]; strcpy(szHeader, "trrn"); szHeader[4] = 7; // TER v7 introduced w/ Lev 2.6. if(1 != VSIFWriteL(szHeader, 5, 1, m_fp) || !this->write_tag("hf_w", (size_t)nRasterXSize) || !this->write_tag("hf_b", (size_t)nRasterYSize)) { CPLError( CE_Failure, CPLE_FileIO, "Could not write header" ); return false; } m_dElevBase = 0.0; m_dElevScale = 1.0; if(m_pszProjection == NULL || m_pszProjection[0] == 0) { this->write_tag("csclass", LEV_COORDSYS_RASTER); } else { this->write_tag("coordsys_wkt", m_pszProjection); const UNITLABEL units_elev = this->id_to_code(m_szElevUnits); const int bHasECS = (units_elev != UNITLABEL_PIXEL && units_elev != UNITLABEL_UNKNOWN); this->write_tag("coordsys_haselevm", bHasECS); OGRSpatialReference sr(m_pszProjection); if(bHasECS) { if(!this->compute_elev_scaling(sr)) return false; // Raw-to-real units scaling. this->write_tag("coordsys_em_scale", m_dElevScale); //elev offset, in real units. this->write_tag("coordsys_em_base", m_dElevBase); this->write_tag("coordsys_em_units", units_elev); } if(sr.IsLocal()) { this->write_tag("csclass", LEV_COORDSYS_LOCAL); const double dfLinear = sr.GetLinearUnits(); const int n = this->meter_measure_to_code(dfLinear); this->write_tag("coordsys_units", n); } else { this->write_tag("csclass", LEV_COORDSYS_GEO); } if( m_adfTransform[2] != 0.0 || m_adfTransform[4] != 0.0) { CPLError( CE_Failure, CPLE_IllegalArg, "Cannot handle rotated geotransform" ); return false; } // todo: GDAL gridpost spacing is based on extent / rastersize // instead of extent / (rastersize-1) like Leveller. // We need to look into this and adjust accordingly. // Write north-south digital axis. this->write_tag("coordsys_da0_style", LEV_DA_PIXEL_SIZED); this->write_tag("coordsys_da0_fixedend", 0); this->write_tag("coordsys_da0_v0", m_adfTransform[3]); this->write_tag("coordsys_da0_v1", m_adfTransform[5]); // Write east-west digital axis. this->write_tag("coordsys_da1_style", LEV_DA_PIXEL_SIZED); this->write_tag("coordsys_da1_fixedend", 0); this->write_tag("coordsys_da1_v0", m_adfTransform[0]); this->write_tag("coordsys_da1_v1", m_adfTransform[1]); } this->write_tag_start("hf_data", sizeof(float) * nRasterXSize * nRasterYSize); return true; }
int main() { { Juncture * j = new Juncture(0, "1", 1); delete j; } { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; j->operation(op, res); delete j; } { Juncture * j = new Juncture(0, "1", 1); OpVector res; Atlas::Objects::Operation::Login op; j->operation(op, res); delete j; } // Login op, no args { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; j->LoginOperation(op, res); delete j; } // Login op, empty arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, bad username in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", 0x69e362c6); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username & password in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); arg->setAttr("password", "a12a2f3a-03a4-11e0-8379-001ec93e7c08"); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username & bad password in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); arg->setAttr("password", 0x12a2f3aL); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username & password in arg, connected { ServerRouting sr(*(BaseWorld*)0, "", "", "2", 2, "3", 3); TestJuncture * j = new TestJuncture(0); boost::asio::io_service io_service; CommPeer * cp = new CommPeer("", io_service); j->test_addPeer(new Peer(*cp, sr, "", 6767, "4", 4)); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); arg->setAttr("password", "a12a2f3a-03a4-11e0-8379-001ec93e7c08"); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username & password in arg, connected already authenticating { ServerRouting sr(*(BaseWorld*)0, "", "", "2", 2, "3", 3); TestJuncture * j = new TestJuncture(0); boost::asio::io_service io_service; CommPeer * cp = new CommPeer("", io_service); Peer * p = new Peer(*cp, sr, "", 6767, "4", 4); j->test_addPeer(p); p->setAuthState(PEER_AUTHENTICATING); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); arg->setAttr("password", "a12a2f3a-03a4-11e0-8379-001ec93e7c08"); op->setArgs1(arg); j->LoginOperation(op, res); delete j; } // Login op, username & password in arg, connected, with serialno { ServerRouting sr(*(BaseWorld*)0, "", "", "2", 2, "3", 3); TestJuncture * j = new TestJuncture(0); boost::asio::io_service io_service; CommPeer * cp = new CommPeer("", io_service); j->test_addPeer(new Peer(*cp, sr, "", 6767, "4", 4)); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("username", "69e362c6-03a4-11e0-9608-001ec93e7c08"); arg->setAttr("password", "a12a2f3a-03a4-11e0-8379-001ec93e7c08"); op->setArgs1(arg); op->setSerialno(0x6dc5b5eaL); j->LoginOperation(op, res); delete j; } { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; j->OtherOperation(op, res); delete j; } { Juncture * j = new Juncture(0, "1", 1); OpVector res; Atlas::Objects::Operation::Connect op; j->OtherOperation(op, res); delete j; } // Connect op, no args { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; j->customConnectOperation(op, res); delete j; } // Connect op, no args, already connected { TestJuncture * j = new TestJuncture(0); j->test_addPeer(new Peer(*(CommPeer*)0, *(ServerRouting*)0, "", 6767, "4", 4)); OpVector res; Operation op; j->customConnectOperation(op, res); delete j; } // Connect op, hostname in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("hostname", "3752ca4a-03a9-11e0-bd8a-001ec93e7c08"); op->setArgs1(arg); j->customConnectOperation(op, res); delete j; } // Connect op, bad hostname in arg { Juncture * j = new Juncture(0, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("hostname", 0x3752ca4aL); op->setArgs1(arg); j->customConnectOperation(op, res); delete j; } // Connect op, hostname and port in arg, connected this end { ServerRouting sr(*(BaseWorld*)0, "", "", "2", 2, "3", 3); boost::asio::io_service io_service; CommSocket * cc = new StubSocket(io_service); Connection * c = new Connection(*cc, sr, "", "4", 4); Juncture * j = new Juncture(c, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("hostname", "3752ca4a-03a9-11e0-bd8a-001ec93e7c08"); arg->setAttr("port", 0x03a9); op->setArgs1(arg); j->customConnectOperation(op, res); delete j; } // Connect op, hostname and port in arg, connected this end, connect fails { stub_CommPeer_connect_return = -1; ServerRouting sr(*(BaseWorld*)0, "", "", "2", 2, "3", 3); boost::asio::io_service io_service; CommSocket * cc = new StubSocket(io_service); Connection * c = new Connection(*cc, sr, "", "4", 4); Juncture * j = new Juncture(c, "1", 1); OpVector res; Operation op; Atlas::Objects::Root arg; arg->setAttr("hostname", "3752ca4a-03a9-11e0-bd8a-001ec93e7c08"); arg->setAttr("port", 0x03a9); op->setArgs1(arg); j->customConnectOperation(op, res); stub_CommPeer_connect_return = 0; delete j; } // Teleport unconnected { TestJuncture * j = new TestJuncture(0); j->teleportEntity(0); delete j; } // Teleport connected { TestJuncture * j = new TestJuncture(0); j->test_addPeer(new Peer(*(CommPeer*)0, *(ServerRouting*)0, "", 6767, "4", 4)); j->teleportEntity(0); delete j; } { TestJuncture * j = new TestJuncture(0); j->test_onPeerLost(); delete j; } // Peer replied, unconnected this end { TestJuncture * j = new TestJuncture(0); Operation op; j->test_onPeerReplied(op); delete j; } // Peer replied, connected this end { Connection * c = new Connection(*(CommSocket*)0, *(ServerRouting*)0, "", "4", 4); TestJuncture * j = new TestJuncture(c); Operation op; j->test_onPeerReplied(op); delete j; } return 0; }