int solve(int px, int py, int x1, int y1, int x2, int y2){ int xy = ((px-x1)*(py-y2))-((px-x2)*(py-y1)); printf("%d %d %d\n",px,py,xy); if(xy!=0)return 0; if(BW(x1,px,x2) && BW(y1,py,y2)) return 1; else return 0; }
void set_shape(client_t *c) { int n, order; XRectangle temp, *rects; rects = XShapeGetRectangles(dpy, c->win, ShapeBounding, &n, &order); if (n > 1) { XShapeCombineShape(dpy, c->frame, ShapeBounding, 0, frame_height(c), c->win, ShapeBounding, ShapeSet); temp.x = -BW(c); temp.y = -BW(c); temp.width = c->geom.w + 2*BW(c); temp.height = frame_height(c) + BW(c); XShapeCombineRectangles(dpy, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeUnion, YXBanded); temp.x = 0; temp.y = 0; temp.width = c->geom.w; temp.height = frame_height(c) - BW(c); XShapeCombineRectangles(dpy, c->frame, ShapeClip, 0, frame_height(c), &temp, 1, ShapeUnion, YXBanded); c->shaped = 1; } else if (c->shaped) { /* I can't find a ``remove all shaping'' function... */ temp.x = -BW(c); temp.y = -BW(c); temp.width = c->geom.w + 2*BW(c); temp.height = c->geom.h + frame_height(c) + 2*BW(c); XShapeCombineRectangles(dpy, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeSet, YXBanded); } XFree(rects); }
int frame_height(client_t *c) { if (c && c->decor) return (c->trans ? 0 : ASCENT) + DESCENT + 2*opt_pad + BW(c); else return 0; }
static void reparent(client_t *c, strut_t *s) { XSetWindowAttributes pattr; geom_t f; f = frame_geom(c); pattr.override_redirect = True; pattr.background_pixel = bg.pixel; pattr.border_pixel = bd.pixel; pattr.event_mask = SubMask|ButtonPressMask|ExposureMask|EnterWindowMask; c->frame = XCreateWindow(dpy, root, f.x, f.y, f.w, f.h, BW(c), DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); #ifdef SHAPE if (shape) { XShapeSelectInput(dpy, c->win, ShapeNotifyMask); set_shape(c); } #endif #ifdef XFT c->xftdraw = XftDrawCreate(dpy, (Drawable)c->frame, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultColormap(dpy, DefaultScreen(dpy))); #endif XAddToSaveSet(dpy, c->win); XSelectInput(dpy, c->win, ColormapChangeMask|PropertyChangeMask); XSetWindowBorderWidth(dpy, c->win, 0); XResizeWindow(dpy, c->win, c->geom.w, c->geom.h); XReparentWindow(dpy, c->win, c->frame, 0, frame_height(c)); send_config(c); }
Double_t Signal(Double_t* x, Double_t* par) { Double_t xx = x[0]*x[0]; Double_t beta = TMath::Sqrt(1-4*MTOP*MTOP/xx); Double_t y_t= TMath::Log((1+beta)/(1-beta)); Double_t yt2 = y_t*y_t; Double_t beta2 = beta*beta; Double_t pi2 = TMath::Pi() * TMath::Pi(); Double_t constant= 3*pow(ALPHAS,2)*pow(GF,2)*pow(MTOP,6)/( 2048*pow(TMath::Pi(),3) ); Double_t value = constant * beta * pow(yt2+pi2,2) * BW(x,par); return value; }
int AlgorithmHough::DoYourJob(Magick::Image& image) { BW(image); std::cout<<"BW"<<std::endl; Accu(image); std::cout<<"Ac"<<std::endl; Blur(Accu.Accumulator); std::cout<<"Bl"<<std::endl; HoughResult max=Accu.Maximum(); std::cout<<"Max"<<std::endl; Magick::Image result(image.size(), Magick::Color("white")); result.modifyImage(); Magick::Pixels pixelCache(result); Magick::PixelPacket* pixels=pixelCache.set(0,0,image.columns(),image.rows()); for(int x=0; x<image.columns(); x++) for(int y=0; y<image.rows(); y++) { double fi_f=max.Fi-90; double r_=double(x)*cos(fi_f*3.14/180.0)+double(y)*sin(fi_f*3.14/180.0); int pixelIndex=x+y*image.columns(); if(r_<0) //jak wyżej continue; if(round(r_)==max.R) pixels[pixelIndex].red=pixels[pixelIndex].blue=pixels[pixelIndex].green=0; else pixels[pixelIndex].red=pixels[pixelIndex].blue=pixels[pixelIndex].green=(1<<QuantumDepth)-1; } pixelCache.sync(); image=result; std::cout<<"R: "<<max.R<<" FI: "<<max.Fi<<" Value: "<<max.Value<<std::endl; return 0; }
void redraw_frame(client_t *c) { int x, y; if (c && c->decor) { XClearWindow(dpy, c->frame); if (!c->shaded) XDrawLine(dpy, c->frame, border_gc, 0, frame_height(c) - BW(c) + BW(c)/2, c->geom.w, frame_height(c) - BW(c) + BW(c)/2); XDrawLine(dpy, c->frame, border_gc, c->geom.w - frame_height(c) + BW(c)/2, 0, c->geom.w - frame_height(c) + BW(c)/2, frame_height(c)); if (!c->trans && c->name) { x = opt_pad + DESCENT/2; y = opt_pad + ASCENT; #ifdef XFT #ifdef X_HAVE_UTF8_STRING XftDrawStringUtf8(c->xftdraw, &xft_fg, xftfont, x, y, (unsigned char *)c->name, strlen(c->name)); #else XftDrawString8(c->xftdraw, &xft_fg, xftfont, x, y, (unsigned char *)c->name, strlen(c->name)); #endif #else #ifdef X_HAVE_UTF8_STRING Xutf8DrawString(dpy, c->frame, font_set, string_gc, x, y, c->name, strlen(c->name)); #else XDrawString(dpy, c->frame, string_gc, x, y, c->name, strlen(c->name)); #endif #endif } } }
geom_t frame_geom(client_t *c) { geom_t f = c->geom; /* everything else is the same as c->geom was */ f.h = frame_height(c) + (c->shaded ? -BW(c) : c->geom.h); /* X, in its perpetual helpfulness, always does native borders NorthWest * style. This, as usual, ruins everything. So we compensate. */ switch (GRAV(c)) { case NorthWestGravity: break; case NorthGravity: f.x -= BW(c); break; case NorthEastGravity: f.x -= 2 * BW(c); break; case EastGravity: f.x -= 2 * BW(c); f.y -= frame_height(c) / 2 + BW(c); break; case SouthEastGravity: f.x -= 2 * BW(c); f.y -= frame_height(c) + 2 * BW(c); break; case SouthGravity: f.x -= BW(c); f.y -= frame_height(c) + 2 * BW(c); break; case SouthWestGravity: f.y -= frame_height(c) + 2 * BW(c); break; case WestGravity: f.y -= frame_height(c) / 2 + BW(c); break; case StaticGravity: f.y -= frame_height(c) + BW(c); f.x -= BW(c); break; case CenterGravity: f.x -= BW(c); f.y -= frame_height(c) / 2 + BW(c); break; } return f; }
void writer(struct libvchan *ctrl) { int size; unsigned long long write_size = 0; struct timeval tv1, tv2; long t = 0, t1, t2; //int f = open("a", O_RDONLY); while (write_size < total_size) { size = write_size + blocksize > total_size ? total_size - write_size : blocksize; //read(f, buf, size); gettimeofday(&tv1, NULL); size = libvchan_write(ctrl, buf, size); gettimeofday(&tv2, NULL); t1 = tv1.tv_sec*1000000 + tv1.tv_usec; t2 = tv2.tv_sec*1000000 + tv2.tv_usec; t += (t2 - t1); if (size < 0) { perror("vchan write"); exit(1); } write_size += size; } //close(f); printf("BW: %.3f MB/s (%llu bytes in %ld usec), Size: %.2fMB, time: %.3fsec\n", BW(write_size,t), write_size, t, ((double)write_size/(1024*1024)), ((double)t/1000000)); }
void reader(struct libvchan *ctrl) { unsigned long long read_size = 0; int size; struct timeval tv1, tv2; long t = 0, t1, t2; //int f = open("b", O_WRONLY | O_CREAT, 0); while (read_size < total_size) { size = read_size + blocksize > total_size ? total_size - read_size : blocksize; gettimeofday(&tv1, NULL); size = libvchan_read(ctrl, buf, size); gettimeofday(&tv2, NULL); t1 = tv1.tv_sec*1000000 + tv1.tv_usec; t2 = tv2.tv_sec*1000000 + tv2.tv_usec; t += (t2 - t1); if (size < 0) { perror("read vchan"); libvchan_close(ctrl); exit(1); } /*if (size > 0) write(f, buf, size);*/ read_size += size; } //close(f); printf("BW: %.3f MB/s (%llu bytes in %ld usec), Size: %.2fMB, time: %.3fsec\n", BW(read_size,t), read_size, t, ((double)read_size/(1024*1024)), ((double)t/1000000)); }
static int i2c_start_comm_soft_mst(int id, uint8_t *data_out, uint32_t len_out, uint8_t *data_in, uint32_t len_in) { i2c_obj_buf_t *obj_buf = i2c_get_obj_buf(id); gpio_class_t *gpio_obj = &i2c_info.gpio_obj; uint32_t bit_delay = (obj_buf->speed == I2C_SPEED_HIGH) ? I2C_BIT_DELAY_HIGH : I2C_BIT_DELAY_FULL; uint32_t ctdat = 0; uint8_t ctbit = 0; uint8_t error = 0; // Set mode port gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_OUTPUT); gpio_obj->set_mode(obj_buf->port_scl, GPIO_MODE_OUTPUT); // Start bit gpio_obj->set_level(obj_buf->port_scl, 1); gpio_obj->set_level(obj_buf->port_sda, 1); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_sda, 0); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 0); usleep(bit_delay); // Send data for (ctdat = 0; ctdat < len_out; ctdat++) { gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_OUTPUT); for (ctbit = 0; ctbit < 8; ctbit++) { if (data_out[ctdat] & BW(7 - ctbit)) gpio_obj->set_level(obj_buf->port_sda, 1); else gpio_obj->set_level(obj_buf->port_sda, 0); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 1); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 0); } gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_INPUT); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 1); // Check ACK if (gpio_obj->get_level(obj_buf->port_sda)) { // NACK printf("<error i2c_start_comm_soft_mst> NACK, data no = %d, value = 0x%02x\n", ctdat, data_out[ctdat]); error = 1; break; } usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 0); } // Read data if (!error && len_in > 0 && data_in) { for (ctdat = 0; ctdat < len_in; ctdat++) { gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_INPUT); for (ctbit = 0; ctbit < 8; ctbit++) { usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 1); usleep(bit_delay); if (gpio_obj->get_level(obj_buf->port_sda)) data_in[ctdat] |= BW(7 - ctbit); else data_in[ctdat] &= ~(BW(7 - ctbit)); gpio_obj->set_level(obj_buf->port_scl, 0); } // Set ACK / NACK gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_OUTPUT); if (ctdat < (len_in - 1)) gpio_obj->set_level(obj_buf->port_sda, 0); else gpio_obj->set_level(obj_buf->port_sda, 1); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 1); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 0); } } // Stop bit gpio_obj->set_mode(obj_buf->port_sda, GPIO_MODE_OUTPUT); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_scl, 1); usleep(bit_delay); gpio_obj->set_level(obj_buf->port_sda, 1); return error ? -1 : 0; }
pr_debug("EV%d ov: %x, cnt: %x\n", n, overflow, count); return beats; } static void do_bw_sample(struct work_struct *work); static DECLARE_DEFERRED_WORK(bw_sample, do_bw_sample); static struct workqueue_struct *bw_sample_wq; static DEFINE_MUTEX(bw_lock); static ktime_t prev_ts; static u32 prev_r_start_val; static u32 prev_w_start_val; static struct msm_bus_paths bw_levels[] = { BW(0), BW(200), }; static struct msm_bus_scale_pdata bw_data = { .usecase = bw_levels, .num_usecases = ARRAY_SIZE(bw_levels), .name = "cpubw-krait", .active_only = 1, }; static u32 bus_client; static void compute_bw(int mbps); static irqreturn_t mon_intr_handler(int irq, void *dev_id); #define START_LIMIT 100 /* MBps */ static int start_monitoring(void) { int mb_limit;
Double_t Interference(Double_t* x, Double_t *par) // par = m, w, coupl { Double_t xx = x[0]*x[0]; Double_t MA = par[0]; Double_t beta = TMath::Sqrt(1-4*MTOP*MTOP/xx); Double_t y_t= TMath::Log((1+beta)/(1-beta)); Double_t yt2 = y_t*y_t; Double_t beta2 = beta*beta; Double_t pi2 = TMath::Pi() * TMath::Pi(); Double_t constant= -1. * pow(ALPHAS,2)*GF*pow(MTOP,4)/( 32*TMath::Pi()*TMath::Sqrt(2) ); Double_t value = constant * y_t / xx * ( (xx-MA*MA)*(pi2-yt2) + 2*TMath::Pi()*MA*WA(x,par)*y_t) * BW(x,par); return value; }
int main(int argc, char * argv[]) { try { ::libmaus::util::ArgInfo const arginfo(argc,argv); ::libmaus::util::TempFileRemovalContainer::setup(); ::std::vector<std::string> const & inputfilenames = arginfo.restargs; char const * fasuffixes[] = { ".fa", ".fasta", 0 }; std::string defoutname = libmaus::util::OutputFileNameTools::endClipLcp(inputfilenames,&fasuffixes[0]) + ".fa"; while ( ::libmaus::util::GetFileSize::fileExists(defoutname) ) defoutname += "_"; std::string const fatempfilename = arginfo.getValue<std::string>("fatempfilename",defoutname); ::libmaus::util::TempFileRemovalContainer::addTempFile(fatempfilename); // std::cerr << "output file name " << defoutname << std::endl; ::std::vector< ::libmaus::fastx::FastAReader::RewriteInfo > const info = ::libmaus::fastx::FastAReader::rewriteFiles(inputfilenames,fatempfilename); std::map < std::string, uint64_t > fachr; ::libmaus::autoarray::AutoArray < uint64_t > fapref(info.size()+1); for ( uint64_t i = 0; i < info.size(); ++i ) { // std::cerr << info[i].valid << "\t" << info[i].idlen << "\t" << info[i].seqlen << "\t" << info[i].getIdPrefix() << std::endl; fachr[info[i].getIdPrefix()] = i; fapref [ i ] = info[i].getEntryLength() ; } fapref.prefixSums(); for ( uint64_t i = 0; i < info.size(); ++i ) fapref [ i ] += info[i].idlen + 2; // > + newline ::libmaus::bambam::BamDecoder decoder(std::cin); ::libmaus::bambam::BamHeader const & bamheader = decoder.bamheader; // std::vector< ::libmaus::bambam::Chromosome > chromosomes ::libmaus::autoarray::AutoArray<uint8_t> uptab(256,false); for ( uint64_t j = 0; j < uptab.size(); ++j ) uptab[j] = toupper(j); ::libmaus::autoarray::AutoArray < ::libmaus::autoarray::AutoArray<uint8_t>::unique_ptr_type > text(bamheader.chromosomes.size()); for ( uint64_t i = 0; i < bamheader.chromosomes.size(); ++i ) { std::string const bamchrname = bamheader.chromosomes[i].name; if ( fachr.find(bamchrname) == fachr.end() ) { ::libmaus::exception::LibMausException se; se.getStream() << "Unable to find reference sequence " << bamchrname << " in fa file." << std::endl; se.finish(); throw se; } uint64_t const faid = fachr.find(bamchrname)->second; if ( bamheader.chromosomes[i].len != info[faid].seqlen ) { ::libmaus::exception::LibMausException se; se.getStream() << "Reference sequence " << bamchrname << " has len " << bamheader.chromosomes[i].len << " in bam file but " << info[faid].seqlen << " in fa file." << std::endl; se.finish(); throw se; } if ( bamheader.chromosomes.size() < 100 ) std::cerr << "Loading sequence " << bamchrname << " of length " << info[faid].seqlen << std::endl; text [ i ] = UNIQUE_PTR_MOVE(::libmaus::autoarray::AutoArray<uint8_t>::unique_ptr_type(new ::libmaus::autoarray::AutoArray<uint8_t>(info[faid].seqlen,false))); ::libmaus::aio::CheckedInputStream CIS(fatempfilename); CIS.seekg(fapref[faid]); CIS.read(reinterpret_cast<char *>(text[i]->begin()),info[faid].seqlen); // sanity check, next symbol in file should be a newline int c; c = CIS.get(); assert ( c == '\n' ); // convert to upper case for ( uint8_t * pa = text[i]->begin(); pa != text[i]->end(); ++pa ) *pa = uptab[*pa]; } for ( uint64_t i = 0; i < bamheader.chromosomes.size(); ++i ) { assert ( text[i]->size() == bamheader.chromosomes[i].len ); } uint64_t decoded = 0; ::libmaus::bambam::BamWriter BW(std::cout,bamheader); while ( decoder.readAlignment() ) { ++decoded; if ( decoded % (1024*1024) == 0 ) { std::cerr << "[V] " << decoded << std::endl; } ::libmaus::bambam::BamAlignment & alignment = decoder.alignment; bool const cigok = checkCigarValid(alignment,bamheader,text); // if cigar is ok then keep alignment if ( cigok ) { if ( !alignment.isUnmap() ) { uint64_t seqpos = 0; uint64_t refpos = alignment.getPos(); std::string const read = alignment.getRead(); std::string modseq = read; ::libmaus::autoarray::AutoArray<uint8_t> const & ctext = *(text[alignment.getRefID()]); std::ostringstream newcigarstream; for ( uint64_t i = 0; i < alignment.getNCigar(); ++i ) { char const cop = alignment.getCigarFieldOpAsChar(i); int64_t const clen = alignment.getCigarFieldLength(i); switch ( cop ) { // match/mismatch, increment both case 'M': { int64_t low = 0; while ( low != clen ) { int64_t high = low; while ( high != clen && ctext[refpos] == read[seqpos] ) { modseq[seqpos] = '='; ++refpos, ++seqpos, ++ high; } if ( high != low ) newcigarstream << high-low << "="; low = high; while ( high != clen && ctext[refpos] != read[seqpos] ) ++refpos, ++seqpos, ++ high; if ( high != low ) newcigarstream << high-low << "X"; low = high; } break; } case '=': { refpos += clen; for ( int64_t j = 0; j < clen; ++j, ++seqpos ) modseq[seqpos] = '='; newcigarstream << clen << cop; break; } case 'X': { refpos += clen; seqpos += clen; newcigarstream << clen << cop; break; } case 'P': case 'I': { seqpos += clen; newcigarstream << clen << cop; break; } case 'N': case 'D': { refpos += clen; newcigarstream << clen << cop; break; } case 'S': { seqpos += clen; newcigarstream << clen << cop; break; } case 'H': { newcigarstream << clen << cop; break; } } } alignment.replaceCigarString(newcigarstream.str()); alignment.replaceSequence(modseq); } alignment.serialise(BW.bgzfos); } } } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } }
int main(int argc, char **argv) { char *buf1, *buf2; if (argc != 4) { usage(); } int blocksize = atoi(argv[1]); unsigned long long total_size = atoll(argv[2]); unsigned long long buffer_size = atoll(argv[3]); unsigned long long count = 0; long t1, t2, t; struct timeval tv1, tv2; if (buffer_size < blocksize) { printf("buffer_size < blocksize\n"); usage(); } buf1 = (char*) malloc(buffer_size); buf2 = (char*) malloc(total_size); int i; //for (i=0; i<total_size; i++) buf2[i] = i % 10; for(i=0; i<1; i++) { count = 0; gettimeofday(&tv1, NULL); while (count < total_size) { int size = ((total_size - count) < blocksize) ? (total_size - count) : blocksize; int dst_offset = (count % buffer_size) + size > buffer_size ? 0 : count % buffer_size; memcpy(buf1+dst_offset, buf2+count, size); count += size; } gettimeofday(&tv2, NULL); t1 = tv1.tv_sec*1000000 + tv1.tv_usec; t2 = tv2.tv_sec*1000000 + tv2.tv_usec; t = (t2 - t1); printf("BW: %.3f MB/s (%llu bytes in %ld usec), Size: %.2fMB, time: %.3fsec\n", BW(count,t), count, t, ((double)count/(1024*1024)), ((double)t/1000000)); //if(i==1)printf("%.3f\n", BW(count, t)); } free(buf1); free(buf2); return 0; }