int Preprocessor::crop(){ string src = para.crop_src; string dst = para.crop_dst; unsigned int crop_x = para.crop_x; unsigned int crop_y = para.crop_y; unsigned int crop_w = para.crop_w; unsigned int crop_h = para.crop_h; unsigned int serial_beg = para.serial_beg; unsigned int serial_end = para.serial_end; unsigned int thread_num = para.thread_num; string in_pre = para.crop_in_pre; string in_post = para.crop_in_post; string out_pre = para.crop_out_pre; string out_post = para.crop_out_post; unsigned int image_depth = para.image_depth; unsigned int serial_bits = para.serial_bits; string sys_del = para.sys_del; string x_str(""), y_str(""), w_str(""), h_str(""); stringstream str_buffer; str_buffer<<crop_x; str_buffer>>x_str; str_buffer.clear(); str_buffer<<crop_y; str_buffer>>y_str; str_buffer.clear(); str_buffer<<crop_w; str_buffer>>w_str; str_buffer.clear(); str_buffer<<crop_h; str_buffer>>h_str; str_buffer.clear(); cv::Rect roi(crop_x, crop_y, crop_w, crop_h); #pragma omp parallel for num_threads(thread_num) for(int serial_num = int(serial_beg); serial_num <= int(serial_end); ++ serial_num){ cv::Mat out_image, in_image; stringstream tmp_strBuffer; string serial_str, out_name, image_path; tmp_strBuffer<<setw(serial_bits)<<setfill('0')<<serial_num; tmp_strBuffer>>serial_str; tmp_strBuffer.clear(); cout<<serial_str<<" "<<omp_get_thread_num()<<endl; image_path = src + sys_del + in_pre + serial_str + in_post; in_image = cv::imread(image_path, CV_LOAD_IMAGE_UNCHANGED); if(!in_image.data){ cout<<image_path<<" Loaded Error!"<<endl; continue; } if(crop_x < 0 || crop_x + crop_w > in_image.size().width || crop_y < 0 || crop_y + crop_h > in_image.size().height){ cout<<"Out of Range Error!"<<endl; continue; } out_image = cv::Mat(in_image, roi); out_name = dst + sys_del + out_pre + serial_str + "_x" + x_str + "_y" + y_str + "_w" + w_str + "_h" +h_str + out_post; cout<<out_name<<endl; cv::imwrite(out_name, out_image); } return 0; }
void module_info(int nRun , int module){ ostringstream cfg_str(""); cfg_str << "Run_" << nRun << "/config"; CFG cfg(cfg_str.str()); cfg.print(); int FED ; TString dir; get_module_info(module , FED , dir); cout << "Looking at module " << module << " in FED " << FED << " and dir " << dir << endl; TFile* f = TFile::Open("rfio://"+cfg.storedir+"/GainCalibration.root","READ"); assert(f); ostringstream full_dir(""); full_dir << "/DQMData/Run " << nRun << "/Pixel/Run summary/" << dir; //TDirectory* ddir = f->GetDirectory(full_dir.str().c_str()); //assert(ddir); ostringstream h_str(""); h_str << full_dir.str() << "/Gain2d_siPixelCalibDigis_" << module; cout << h_str.str() << endl; TH2F* h_gain = (TH2F*) f->Get(h_str.str().c_str()); assert(h_gain); h_str.str("") ; h_str << full_dir.str() << "/Pedestal2d_siPixelCalibDigis_" << module; TH2F* h_pedestal = (TH2F*) f->Get(h_str.str().c_str()); assert(h_pedestal); h_str.str("") ; h_str << full_dir.str() << "/GainFitResult2d_siPixelCalibDigis_" << module; TH2F* h_fitresult = (TH2F*) f->Get(h_str.str().c_str()); assert(h_fitresult); h_gain->Draw("colz"); gPad->WaitPrimitive(); h_pedestal->Draw("colz"); gPad->WaitPrimitive(); h_fitresult->Draw("colz"); gPad->WaitPrimitive(); }
/** * TODO * * @param name TODO * * @return SRD_OK upon success, a (negative) error code otherwise. */ static int srd_load_decoder(const char *name, struct srd_decoder **dec) { struct srd_decoder *d; PyObject *py_mod, *py_res; int r; fprintf(stdout, "%s: %s\n", __func__, name); /* "Import" the Python module. */ if (!(py_mod = PyImport_ImportModule(name))) { /* NEWREF */ PyErr_Print(); /* Returns void. */ return SRD_ERR_PYTHON; /* TODO: More specific error? */ } /* Get the 'Decoder' class as Python object. */ py_res = PyObject_GetAttrString(py_mod, "Decoder"); /* NEWREF */ if (!py_res) { if (PyErr_Occurred()) PyErr_Print(); /* Returns void. */ Py_XDECREF(py_mod); fprintf(stderr, "Decoder class not found in PD module %s\n", name); return SRD_ERR_PYTHON; /* TODO: More specific error? */ } if (!(d = malloc(sizeof(struct srd_decoder)))) return SRD_ERR_MALLOC; /* We'll just use the name of the module for the ID. */ d->id = strdup(name); if ((r = h_str(py_res, py_mod, "name", &(d->name))) < 0) return r; if ((r = h_str(py_res, py_mod, "longname", &(d->longname))) < 0) return r; if ((r = h_str(py_res, py_mod, "desc", &(d->desc))) < 0) return r; if ((r = h_str(py_res, py_mod, "longdesc", &(d->longdesc))) < 0) return r; if ((r = h_str(py_res, py_mod, "author", &(d->author))) < 0) return r; if ((r = h_str(py_res, py_mod, "email", &(d->email))) < 0) return r; if ((r = h_str(py_res, py_mod, "license", &(d->license))) < 0) return r; d->py_mod = py_mod; d->py_decobj = py_res; /* TODO: Handle func, inputformats, outputformats. */ /* Note: They must at least be set to NULL, will segfault otherwise. */ d->func = NULL; d->inputformats = NULL; d->outputformats = NULL; *dec = d; return SRD_OK; }