Ejemplo n.º 1
0
Image Histogram::apply(Window im, int buckets, float minVal, float maxVal) {

    float invBucketWidth = buckets / (maxVal - minVal);

    float inc = 1.0f / (im.width * im.height * im.frames);

    Image hg(buckets, 1, 1, im.channels);

    for (int t = 0; t < im.frames; t++) {
        for (int y = 0; y < im.height; y++) {
            for (int x = 0; x < im.width; x++) {
                for (int c = 0; c < im.channels; c++) {
                    double value = im(x, y, t)[c];
                    int bucket;
                    if (isnan((float)value)) {
                        continue;
                    } else if (isinf((float)value)) {
                        continue;
                    } else {
                        bucket = (int)((value - minVal) * invBucketWidth);
                        if (bucket >= buckets) bucket = buckets-1;
                        if (bucket < 0) bucket = 0;
                    }
                    hg(bucket, 0, 0)[c] += inc;
                }
            }
        }
    }

    return hg;
}
Ejemplo n.º 2
0
void engine::filedrop_attachments_impl(std::string server, const std::string& key,
        const std::string& user, const std::string& subject,
        const std::string& message, const strings& fs, report_level s)
{
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    std::string data = std::string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  <message>\
    <api_key>") + key + std::string("</api_key>\
    <from>") + user + std::string("</from>\
    <subject>") + subject + std::string("</subject>\
    <message>") + message + std::string("</message>\
    <attachments type='array'>\
");
    for (strings::const_iterator i = fs.begin(); i != fs.end(); ++i) {
        data += "      <attachment>";
        data += *i;
        data += "</attachment>\n";
    }
    data += "    </attachments>\
  </message>\n";
    curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 0);
    curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data.c_str());
    if (s >= NORMAL) {
        io::mout << "Sending message to filedrop" << io::endl;
    }
    process_filedrop_responce(perform(), s);
}
Ejemplo n.º 3
0
std::string engine::file_request(std::string server,
        const std::string& key,
        const std::string& user,
        const std::string& subject,
        const std::string& message,
        report_level s,
        validate_cert v)
{
    init_curl(key, s, v);
    server += "/requests";
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    std::string data = std::string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  <request>\
    <recipient>") + user + std::string("</recipient>\
    <subject>") + subject + std::string("</subject>\
    <message>") + message + std::string("</message>\
    <send_email>true</send_email>\
");
    data += "</request>\n";
    curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 0);
    curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data.c_str());
    if (s >= NORMAL) {
        io::mout << "Sending file request to user '" << user << "'" << io::endl;
    }
    return process_file_request_responce(perform(), s);
}
Ejemplo n.º 4
0
void engine::download(std::string server,
        const std::string& key,
        const std::string& path,
        const std::string& id,
        report_level s,
        validate_cert v)
{
    std::string r = message_impl(server, key, id, s, v,
        "Retrieving attachments of message.");
    try {
        xml::document<> d;
        d.parse<xml::parse_fastest | xml::parse_no_utf8>(const_cast<char*>(r.c_str()));
        message_responce m;
        m.read(&d);
        curl_header_guard hg(m_curl);
        const std::vector<attachment_responce>& a = m.attachments();
        std::vector<attachment_responce>::const_iterator i = a.begin();
        while (i != a.end()) {
            download_impl(i->url(), path, i->filename(), s);
            ++i;
        }
    } catch (xml::parse_error&) {
        throw invalid_message_id(id);
    }
}
Ejemplo n.º 5
0
STDMETHODIMP VwAccessRoot::accHitTest(long xLeft, long yTop, VARIANT * pvarID)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvarID);
	if (!m_pbox)
		return CO_E_OBJECTNOTCONNECTED;
	VwRootBox * prootb = m_pbox->Root();
	IVwRootSite * psite = prootb->Site();
	Point ptTarget;
	ptTarget.x = xLeft;
	ptTarget.y = yTop;
	psite->ScreenToClient(prootb, &ptTarget);
	HoldGraphicsAtDst hg(prootb, ptTarget);
	VwBox * pboxRes = m_pbox->FindBoxContaining(ptTarget, hg.m_qvg, hg.m_rcSrcRoot,
		hg.m_rcDstRoot);
	if (pboxRes == m_pbox)
	{
		// Doc says to return I4 value as follows if not within a child
		pvarID->vt= VT_I4;
		pvarID->intVal = CHILDID_SELF;
		return S_OK;
	}
	if (!pboxRes)
	{
		pvarID->vt = VT_EMPTY;
		return S_OK;
	}

	pvarID->vt = VT_DISPATCH;
	GetAccessFor(pboxRes, &(pvarID->pdispVal));

	END_COM_METHOD(g_fact, IID_IAccessible);
}
Ejemplo n.º 6
0
STDMETHODIMP VwAccessRoot::accLocation(long * pxLeft, long * pyTop, long * pcxWidth,
	long * pcyHeight, VARIANT varID)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pxLeft);
	ChkComArgPtr(pyTop);
	ChkComArgPtr(pcxWidth);
	ChkComArgPtr(pcyHeight);
	if (!m_pbox)
		return CO_E_OBJECTNOTCONNECTED;
	VwRootBox * prootb = m_pbox->Root();
	IVwRootSite * psite = prootb->Site();
	// Rather arbitrarily, use the coordinate transformation at the top left of the box.
	Point pt(m_pbox->LeftToLeftOfDocument(), m_pbox->TopToTopOfDocument());
	HoldGraphicsAtSrc hg(prootb, pt);
	Rect bounds = m_pbox->GetBoundsRect(hg.m_qvg, hg.m_rcSrcRoot, hg.m_rcDstRoot);
	Point ptTl = bounds.TopLeft();
	psite->ClientToScreen(prootb, &ptTl);
	*pxLeft = ptTl.x;
	*pyTop = ptTl.y;
	*pcxWidth = bounds.Width();
	*pcyHeight = bounds.Height();

	END_COM_METHOD(g_fact, IID_IAccessible);
}
Ejemplo n.º 7
0
gmVector3 CSGUnion::grad(const gmVector3 & x)
{
  if ((m_f!=NULL) && (m_g!=NULL))
    {
      double fx = m_f->proc(x); 
      double gx = m_g->proc(x);
      return hf(fx,gx) * m_f->grad(x) + hg(fx,gx) * m_g->grad(x);
    }
  else
    return gmVector3();
}
Ejemplo n.º 8
0
std::string engine::message_impl(std::string server, const std::string& key,
        std::string id, report_level s, validate_cert v, std::string log)
{
    init_curl(key, s, v);
    server += "/message/";
    server += id;
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    if (s >= NORMAL) {
        io::mout << log << io::endl;
    }
    return perform();
}
cps_api_return_code_t cps_api_process_rollback_request(cps_api_transaction_params_t *param,
        size_t ix) {
    cps_api_return_code_t rc = cps_api_ret_code_ERR;

    cps_api_object_t obj = cps_api_object_list_get(param->prev,ix);
    if (obj==NULL) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","No Revert Object");
        return rc;
    }

    cps_api_channel_t handle;
    cps_api_key_t *key = cps_api_object_key(obj);

    char buff[CPS_API_KEY_STR_MAX];
    EV_LOG(TRACE,DSAPI,0, "CPS IPC", "Object for rollback request: %s ",
                                    cps_api_key_name_print(key, buff, sizeof(buff)));

    if (!cps_api_get_handle(*key,handle)) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","No Service");
        return cps_api_ret_code_NO_SERVICE;
    }

    cps_api_channel_handle_guard hg(handle);

    rc = cps_api_ret_code_ERR;

    do {
        if (!cps_api_send_one_object(handle,cps_api_msg_o_REVERT,obj)) {
            EV_LOG(ERR,DSAPI,0,"CPS IPC","Could not send REVERT header");
            break;
        }

        uint32_t op;
           size_t len;
           if (!cps_api_receive_header(handle,op,len)) {
               EV_LOG(ERR,DSAPI,0,"CPS IPC","Failed to read the receive header for revert object");
               break;
           }

           if (op == cps_api_msg_o_RETURN_CODE) {
               if (!cps_api_receive_data(handle,&rc,sizeof(rc))) break;
           }

    } while (0);

    cps_api_disconnect_owner(handle);

    return rc;
}
Ejemplo n.º 10
0
/*----------------------------------------------------------------------------------------------
	With no scroll bar, the only way this happens is when the user drags outside the window.
	We need to override because the superclass does nothing when there is no scroll bar.
----------------------------------------------------------------------------------------------*/
bool TssEdit::OnHScroll(int nSBCode, int nPos, HWND hwndSbar)
{
	// NB - DON'T use nPos; it has only a 16-bit range.
	int dxdPos = m_dxpScrollOffset; // Where the window thinks it is now.
	// ENHANCE JohnT: use actual resolution.
	int dxdLine = 30 * 96/72; // 30 points seems a useful size increment.

	switch (nSBCode)
	{
	case SB_LINELEFT:
		dxdPos -= dxdLine;
		break;
	case SB_LINERIGHT:
		dxdPos += dxdLine;
		break;
	default:
		dxdPos = 0;
		Assert(false); // others should not happen
		break;
	}
	// Try to stop it scrolling too far. This is unfortunately not easy to do. Try getting
	// the width of a selection of the whole thing and limit it to a bit more than that.
	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->MakeSimpleSel(true, false, true, false, &qvwsel));
	HoldGraphics hg(this);
	Rect rdPrimary;
	Rect rdSecondary;
	ComBool fSplit;
	ComBool fEndBeforeAnchor;
	CheckHr(qvwsel->Location(hg.m_qvg, hg.m_rcSrcRoot, hg.m_rcDstRoot, &rdPrimary,
		&rdSecondary, &fSplit, &fEndBeforeAnchor));
	Rect rcClient;
	::GetClientRect(m_hwnd, &rcClient);
	int dxpMax = rdPrimary.Width() - rcClient.Width() + 20;
	if (dxdPos > dxpMax)
		dxdPos = dxpMax;

	// In this class we don't have to worry about a max.
	if (dxdPos < 0)
		dxdPos = 0;

	int dxdScrollBy = dxdPos - m_dxpScrollOffset;

	// Update the scroll position.
	m_dxpScrollOffset = dxdPos;

	ScrollBy(dxdScrollBy, 0);
	return true;
}
Ejemplo n.º 11
0
void engine::download(const std::set<std::string>& urls,
        const std::string& key,
        const std::string& path,
        report_level s,
        validate_cert v)
{
    init_curl(key, s, v);
    std::set<std::string>::const_iterator i = urls.begin();
    curl_header_guard hg(m_curl);
    while (i != urls.end()) {
        std::string filename = get_filename(*i);
        download_impl(*i, path, filename, s);
        ++i;
    }
}
Ejemplo n.º 12
0
std::string engine::get_filedrop_api_key(const std::string& url, report_level s, validate_cert v)
{
    init_curl("", s, v);
    curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str());
    curl_header_guard hg(m_curl);
    if (s >= VERBOSE) {
        io::mout << "Getting filedrop API key" << io::endl;
    }
    std::string r = perform();
    xml::document<> d;
    d.parse<xml::parse_fastest | xml::parse_no_utf8>(const_cast<char*>(r.c_str()));
    if (d.first_node() == 0) {
        throw request_error("filedrop info", r);
    }
    std::string h(d.first_node()->name(), d.first_node()->name_size());
    xml::node_iterator<> i(d.first_node());
    xml::node_iterator<> e;
    if (h == "error") {
        while(i != e) {
            std::string n(i->name(), i->name_size());
            if (n == "message") {
                std::string m = std::string(i->value(), i->value_size());
                throw request_error("filedrop info", m);
                break;
            }
            ++i;
        }
        throw request_error("filedrop info", r);
    }
    std::string q;
    while(i != e) {
        std::string n(i->name(), i->name_size());
        if (n == "api_key") {
            q = std::string(i->value(), i->value_size());
            if (s >= VERBOSE) {
                io::mout << "Got filedrop API key: " << q << io::endl;
            }
            break;
        }
        ++i;
    }
    if (q.empty()) {
        throw request_error("filedrop info", r);
    }
    return q;
}
Ejemplo n.º 13
0
void CSGUnion::procq(const gmVector3 & x, double* q)
{
	if( m_f != NULL && m_g != NULL ) {
		m_f->procq(x, q);
		m_g->procq(x, q	+ m_f->qlen());

		double fx = m_f->proc(x);
		double gx = m_g->proc(x);

		double dhdf = hf(fx, gx);
		unsigned int i;
		for(i = 0; i < m_f->qlen(); i++)
			q[i] *= dhdf;
		double dhdg = hg(fx, gx);
		for(; i < m_f->qlen() + m_g->qlen(); i++)
			q[i] *= dhdg;
	}
}
Ejemplo n.º 14
0
std::string engine::messages_impl(std::string server, const std::string& key, std::string l,
        std::string f, report_level s, validate_cert v)
{
    init_curl(key, s, v);
    server += "/message";
    if (!l.empty()) {
        server += "?sent_in_the_last=";
        server += l;
    } else if (!f.empty()) {
        server += "?sent_after=";
        server += f;
    }
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    if (s >= NORMAL) {
        io::mout << "Getting messages from the server." << io::endl;
    }
    return perform();
}
Ejemplo n.º 15
0
gmMatrix3 CSGUnion::hess(const gmVector3 & x)
{
  if ((m_f!=NULL) && (m_g!=NULL))
    {
      double fx = m_f->proc(x); 
      double gx = m_g->proc(x);
      gmVector3 dfx = m_f->grad(x);
      gmVector3 dgx = m_g->grad(x);

      return hff(fx,gx) * outer(dfx,dfx) + 
             hfg(fx,gx) * outer(dfx,dgx) +
             hfg(fx,gx) * outer(dgx,dfx) + 
             hgg(fx,gx) * outer(dgx,dgx) +
             hf(fx,gx)  * m_f->hess(x)   + 
             hg(fx,gx)  * m_g->hess(x);
    }
  else
    return gmMatrix3();
}
Ejemplo n.º 16
0
void engine::delete_attachments(std::string server,
            const std::string& key,
            const std::string& id,
            report_level s,
            validate_cert v)
{
    init_curl(key, s, v);
    server += "/message/";
    server += id;
    server += "/delete_attachments";
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    if (s >= NORMAL) {
        io::mout << "Deleting attachments of the message." << io::endl;
    }
    perform();
    if (s >= NORMAL) {
        io::mout << "Deleted attachments successfully." << io::endl;
    }
}
Ejemplo n.º 17
0
void engine::filelinks(std::string server,
            const std::string& key,
            const std::string& limit,
            output_format of,
            report_level s,
            validate_cert v)
{
    init_curl(key, s, v);
    server += "/link";
    if (!limit.empty()) {
        server += "?limit=";
        server += limit;
    }
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    if (s >= NORMAL) {
        io::mout << "Getting filelinks from the server." << io::endl;
    }
    process_output_responce<filelinks_responce>(perform(), s, of);
}
Ejemplo n.º 18
0
std::string engine::filelink_impl(std::string server, const std::string& expire,
            const std::string& id, report_level s)
{
    server += "/link";
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    std::string data = std::string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  <link>\
    <attachment>") + id + "</attachment>\n";
    if (!expire.empty()) {
        data += std::string("<expires_at>") + expire + "</expires_at>\n";
    }
    data += "  </link>\n";
    curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 0);
    curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data.c_str());
    if (s >= NORMAL) {
        io::mout << "Creating filelink" << io::endl;
    }
    return process_create_filelink_responce(perform(), s);
}
Ejemplo n.º 19
0
void engine::delete_filelink(std::string server,
            const std::string& key,
            const std::string& id,
            report_level s,
            validate_cert v)
{
    init_curl(key, s, v);
    server += "/link/";
    server += id;
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, "DELETE");
    if (s >= NORMAL) {
        io::mout << "Deleting filelink with id '" << id << "'" << io::endl;
    }
    std::string r = perform();
    if (r.find_first_not_of(' ') != r.npos) {
        throw request_error("delete_filelink", r);
    }
    io::mout << "Filelink deleted successfully." << io::endl;
}
Ejemplo n.º 20
0
    void PyGtkBackend::generate(ostream &os,
                                const vector<symbol::Argument *> &args,
                                ast::Statements *body)
    {
        if (body) {
            check_cmd(args);

            PyHeader h(os);
            h.generate();

            PyGtkHeader hg(os);
            hg.generate(args);

            PyGuiWriter g(os);
            g.generate(args);

            PyBody b(os);
            b.generate(body);

            PyGtkMain m(os);
            m.generate(args);
        }
    }
Ejemplo n.º 21
0
void engine::delete_attachments(std::string server,
            const std::string& key,
            const std::set<std::string>& ids,
            report_level s,
            validate_cert v)
{
    init_curl(key, s, v);
    server += "/attachment/";
    curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_header_guard hg(m_curl);
    std::set<std::string>::const_iterator i = ids.begin();
    for (; i != ids.end(); ++i) {
        std::string x = server + (*i);
        curl_easy_setopt(m_curl, CURLOPT_URL, x.c_str());
        if (s >= NORMAL) {
            io::mout << "Deleting attachment '" << *i << "'" << io::endl;
        }
        perform();
        if (s >= NORMAL) {
            io::mout << "Deleted successfully." << io::endl;
        }
    }
}
Ejemplo n.º 22
0
std::string engine::get_api_key(std::string server,
        const std::string& user,
        const std::string& password,
        report_level s,
        validate_cert v)
{
    if (m_curl == 0) {
        m_curl = curl_easy_init();
    }
    if (m_curl == 0) {
        throw curl_error("Failed to initialize CURL");
    }
    curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &data_get);
    curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, 0);
    if (v == NOT_VALIDATE) {
        curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, false);
    }
    if (s == VERBOSE) {
        curl_easy_setopt(m_curl, CURLOPT_VERBOSE, 1L);
    }
    server += "/login";
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    std::string data = std::string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  <user>\
    <email>") + user + std::string("</email>\
    <password>") + password + std::string("</password>\
");
    data += "</user>\n";
    curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 0);
    curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data.c_str());
    if (s >= NORMAL) {
        io::mout << "Getting API key for user '" << user << "'" << io::endl;
    }
    return process_get_api_key_responce(perform(), s);
}
Ejemplo n.º 23
0
std::string engine::send_attachments_impl(std::string server,
        const std::string& user,
        const std::string& subject,
        const std::string& message,
        const strings& fs,
        report_level s)
{
    server += "/message";
    curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
    curl_header_guard hg(m_curl);
    std::string data = std::string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  <message>\
    <recipients type=\"array\">\
      <recipient>") + user + std::string("</recipient>\
    </recipients>\
    <subject>") + subject + std::string("</subject>\
    <message>") + message + std::string("</message>\
    <send_email>true</send_email>\
    <authorization>3</authorization>\
    <attachments type='array'>\
");
    for (strings::const_iterator i = fs.begin(); i != fs.end(); ++i) {
        data += "      <attachment>";
        data += *i;
        data += "</attachment>\n";
    }
    data += "    </attachments>\
  </message>\n";
    curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 0);
    curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data.c_str());
    if (s >= NORMAL) {
        io::mout << "Sending message to user '" << user << "'" << io::endl;
    }
    return process_send_responce(perform(), s);
}
Ejemplo n.º 24
0
 Matches arcsMatchingInput(StateId s, Sym in) const {
   return Matches(hg().outArcsMatchingInput(s, in), this->arcFn);
 }
Ejemplo n.º 25
0
int main(int argc,char** argv) {

#ifdef INLIB_MEM
  inlib::mem::set_check_by_class(true);{
#endif //INLIB_MEM

  inlib::args args(argc,argv);

  std::string file;
  if(!args.file(file)) {
    std::cout << " give a root file." << std::endl;
    return EXIT_FAILURE;
  }

  bool verbose = args.is_arg("-verbose");
  bool ls = args.is_arg("-ls");
  bool dump = args.is_arg("-dump");

 {bool is;
  inlib::file::is_root(file,is);
  if(!is) {
    std::cout << " file is not a root file." << std::endl;
    return EXIT_FAILURE;
  }}

  inlib::rroot::file rfile(std::cout,file,verbose);
#ifdef EXLIB_DONT_HAVE_ZLIB
#else
  rfile.add_unziper('Z',exlib::decompress_buffer);
#endif

  if(ls) {
    std::cout << "format version " << rfile.version() << std::endl;
  }
      
  const std::vector<inlib::rroot::key*>& keys = rfile.dir().keys();
  inlib::rroot::read(std::cout,rfile,keys,true,ls,dump,0);

  ///////////////////////////////////////////////////////////////
  /// if reading the wroot.root produced with wroot.cpp : ///////
  ///////////////////////////////////////////////////////////////
 {inlib::rroot::TDirectory* dir = inlib::rroot::find_dir(rfile.dir(),"histo");
  if(dir) {
   {inlib::rroot::key* key = dir->find_key("rg");
    if(key) {
      inlib::histo::h1d* h = inlib::rroot::key_to_h1d(*key);
      if(h) {
        std::cout << "h1d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean " << h->mean() << ", rms " << h->rms()
                  << std::endl;
        delete h;
      }
    }}
   {inlib::rroot::key* key = dir->find_key("rf");
    if(key) {
      inlib::histo::h1d* h = inlib::rroot::key_to_h1d(*key);
      if(h) {
        std::cout << "h1d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean " << h->mean() << ", rms " << h->rms()
                  << std::endl;
        delete h;
      }
    }}
   {inlib::rroot::key* key = dir->find_key("rgbw");
    if(key) {
      inlib::histo::h2d* h = inlib::rroot::key_to_h2d(*key);
      if(h) {
        std::cout << "h2d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
                  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
                  << std::endl;
        delete h;
      }
    }}
   {inlib::rroot::key* key = dir->find_key("prof");
    if(key) {
      inlib::histo::p1d* h = inlib::rroot::key_to_p1d(*key);
      if(h) {
        std::cout << "p1d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean " << h->mean() << ", rms " << h->rms()
                  << std::endl;
        delete h;
      }
    }}
   {inlib::rroot::key* key = dir->find_key("prof2D");
    if(key) {
      inlib::histo::p2d* h = inlib::rroot::key_to_p2d(*key);
      if(h) {
        std::cout << "p2d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
                  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
                  << std::endl;
        delete h;
      }
    }}
   {inlib::rroot::key* key = dir->find_key("rggbw");
    if(key) {
      inlib::histo::h3d* h = inlib::rroot::key_to_h3d(*key);
      if(h) {
        std::cout << "h3d : " << h->title()
                  << ", all_entries " << h->all_entries()
                  << ", entries " << h->entries()
                  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
                  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
                  << ", mean_z " << h->mean_z() << ", rms_z " << h->rms_z()
                  << std::endl;
        delete h;
      }
    }}
    delete dir; 
  }}
  // read an ntuple :
 {inlib::rroot::key* key = rfile.dir().find_key("rg_rbw");
  if(key) {
    unsigned int sz;
    char* buf = key->get_object_buffer(sz);
    if(!buf) {
      std::cout << "can't get data buffer for ntuple." << std::endl;
      return EXIT_FAILURE;
    }
    inlib::rroot::buffer b(std::cout,rfile.byte_swap(),sz,buf,key->key_length(),verbose);
    inlib::rroot::fac fac(rfile);
    inlib::rroot::tree tree(rfile,fac);
    if(!tree.stream(b)) {
      std::cout << "TTree streaming failed." << std::endl;
      return EXIT_FAILURE;
    }
    tree.dump(std::cout,"","  ");
    //inlib::uint64 entries = tree.entries();
   {for(inlib::uint32 i=0;i<5;i++){
      if(!tree.show(std::cout,i)) {
        std::cout << "show failed for entry " << i << std::endl;
        return EXIT_FAILURE;
      }
    }}

    // read with the flat ntuple API :
   {inlib::rroot::ntuple ntu(tree); //use the flat ntuple API.
    inlib::ntuple_binding nbd;
    double v_rgauss;
    nbd.add_column("rgauss",v_rgauss);
    std::string v_string;
    nbd.add_column("strings",v_string);
    if(!ntu.initialize(std::cout,nbd)) {
      std::cout << "can't initialize ntuple with ntuple_binding." << std::endl;
      return EXIT_FAILURE;
    }
    inlib::histo::h1d hg("rgauss",100,-5,5);
    ntu.start();
    unsigned int count = 0;
    while(ntu.next()){
      if(!ntu.get_row()) {
        std::cout << "get_row() failed." << std::endl;
        return EXIT_FAILURE;
      }
      hg.fill(v_rgauss);
      if(count<5) std::cout << "v_string " << v_string << std::endl;
      count++;
    }
    std::cout << "ntuple_binding(rgauss) : " << hg.mean() << " " << hg.rms() << std::endl;}

  }}

  ///////////////////////////////////////////////////////////////
  /// if reading the pawdemo.root : /////////////////////////////
  ///////////////////////////////////////////////////////////////
 {inlib::rroot::key* key = rfile.dir().find_key("h10");
  if(key) {
    inlib::histo::h1d* h = inlib::rroot::key_to_h1d(*key);
    if(h) {
      std::cout << "h1d : h10"
                << ", all_entries " << h->all_entries()
                << ", entries " << h->entries()
                << ", mean " << h->mean() << ", rms " << h->rms()
                << std::endl;
      delete h;
    }
  }}

  /////////////////////////////////////////////////////////////////////
  /// if reading the prof.root produced with croot_TProfile.cpp : /////
  /////////////////////////////////////////////////////////////////////
 {inlib::rroot::key* key = rfile.dir().find_key("prof");
  if(key) {
    inlib::histo::p1d* h = inlib::rroot::key_to_p1d(*key);
    if(h) {
      std::cout << "p1d : prof"
                << ", all_entries " << h->all_entries()
                << ", entries " << h->entries()
                << ", mean " << h->mean() << ", rms " << h->rms()
                << std::endl;
      delete h;
    }
  }}
 {inlib::rroot::key* key = rfile.dir().find_key("prof2D");
  if(key) {
    inlib::histo::p2d* h = inlib::rroot::key_to_p2d(*key);
    if(h) {
      std::cout << "p2d : prof"
                << ", all_entries " << h->all_entries()
                << ", entries " << h->entries()
                << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
                << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
                << std::endl;
      delete h;
    }
  }}

#ifdef INLIB_MEM
  }inlib::mem::balance(std::cout);
#endif //INLIB_MEM

  return EXIT_SUCCESS;
}
Ejemplo n.º 26
0
/*----------------------------------------------------------------------------------------------
	Scroll to make the selection visible.
	In general, scroll the minimum distance to make it entirely visible.
	If the selection is higher than the window, scroll the minimum distance to make it
	fill the window.
	If the window is too small to show both primary and secondary, show primary.
	Note: subclasses for which scrolling is disabled should override.
	If psel is null, make the current selection visible.
----------------------------------------------------------------------------------------------*/
void TssEdit::MakeSelectionVisible1(IVwSelection * psel)
{
	//Assert(m_fVScrollEnabled);
	IVwSelectionPtr qvwsel;
	if (!m_qrootb)
	{
		return; // For paranoia.
	}
	if (psel)
		qvwsel = psel;
	else
	{
		CheckHr(m_qrootb->get_Selection(&qvwsel));
		if (!qvwsel)
		{
			return; // Nothing we can do.
		}
	}
	Rect rdPrimary;
	Rect rdSecondary;
	ComBool fSplit;
	ComBool fEndBeforeAnchor;
	Rect rcSrcRoot;
	Rect rcDstRoot;
	Rect rdIdeal;
	HoldGraphics hg(this);
	GetCoordRects(m_qvg, &rcSrcRoot, &rcDstRoot);
	CheckHr(qvwsel->Location(m_qvg, rcSrcRoot, rcDstRoot, &rdPrimary, &rdSecondary, &fSplit,
		&fEndBeforeAnchor));
	rdIdeal = rdPrimary;

	Rect rcClient;
	m_pwndSubclass->GetClientRect(rcClient);
	if (fSplit)
	{
		rdIdeal.Sum(rdSecondary);
		if (rdIdeal.Width() > rcClient.Width())
			rdIdeal = rdPrimary;
	}
	// OK, we want rdIdeal to be visible.

	// dx gets added to the scroll offset. This means a positive dx causes there to be more
	// of the view hidden left of the screen. This is the same effect as clicking a
	// right arrow, which paradoxically causes the window contents to move left.
	int dx = 0;
	int xdLeft = m_dxpScrollOffset; // Where the window thinks it is now.
	rdIdeal.Offset(xdLeft, 0); // Was in drawing coords, adjusted by left.
	int xdRight = xdLeft + rcClient.Width();

	// Is the selection partly off the left of the screen?
	if (rdIdeal.left < xdLeft)
	{
		// Is it bigger than the screen?
		if (rdIdeal.Width() > rcClient.Width() && !fEndBeforeAnchor)
		{
			// Left is off, and though it is too big to show entirely, we can show
			// more. Move the window contents right (negative dx).
			dx = rdIdeal.right - xdRight;
		}
		else
		{
			// Partly off left, and fits: move window contents right (less is hidden,
			// neg dx).
			dx = rdIdeal.left - xdLeft;
		}
	}
	else
	{
		// Left of selection is right of (or at) the left side of the screen.
		// Is right of selection right of the right side of the screen?
		if (rdIdeal.right > xdRight)
		{
			if (rdIdeal.Width() > rcClient.Width() && fEndBeforeAnchor)
			{
				// Left is visible, right isn't: move until lefts coincide to show as much
				// as possible. This is hiding more text left of the window: positive dx.
				dx = rdIdeal.left - xdLeft;
			}
			else
			{
				// Fits entirely: scroll left minimum to make right visible. This involves
				// hiding more text at the left: positive dx.
				dx = rdIdeal.right - xdRight;
			}
		}
		// Else it is already entirely visible, do nothing.
	}
	if (dx + m_dxpScrollOffset < 0)
		dx = -m_dxpScrollOffset; // make offset 0 if it would have been less than that
	if (dx)
	{
		// Update the actual position.
		m_dxpScrollOffset += dx;
	}
	ScrollBy(dx, 0);
}