Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:57:12+00:00 2026-05-16T14:57:12+00:00

I’m generating automatic C++ code from python, in particular I need to select some

  • 0

I’m generating automatic C++ code from python, in particular I need to select some events for a list of events. I declare some selections:

selectionA = Selection(name="selectionA", formula="A>10")
selectionB = Selection(name="selectionB", formula="cobject->f()>50")
selectionC = selectionA * selectionB # * means AND

this generate the C++ code:

for(...) { // cicle on events
  event = GetEvent(i);

  bool selectionA = A>10;
  bool selectionB = cobject->f()>50;
  bool selectionC = (A>10) and (cobject->f()>50);

  if (selectionA) { histo_selectionA->Fill(event); }
  if (selectionB) { histo_selectionB->Fill(event); }
  if (selectionC) { histo_selectionC->Fill(event); }
}

This is not very smart, because the smartest code will be:

bool selectionC = selectionA and selectionB

This problem seems to be simple, but it is not, because I have 100+ base selections (as selectionA or selectionB) and 300+ derived selections, and of course a derived selection can be derived from derived selection. Obvious derived selections are not derived from base selections using a regular pattern.

I understand that it is diffult to answer, but can someone give me some hints? For example: is it really necessary to write smart code? I mean, compilers are not able to optimize this code?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:57:12+00:00Added an answer on May 16, 2026 at 2:57 pm

    It’s unlikely that a compiler could optimize this code. Partly because cobject->f() might have side effects the compiler can’t see.

    You could help in a minor way by declaring your bools as const.

    Otherwise, it looks like you’re already overloading operators to compose selections. So it shouldn’t be too hard to make a composed selection use the names of the selections its composed from instead of the expressions. This does some optimization for you and will allow the compiler to optimize further if possible, especially if you declare your selection bools as const.

    You will also have to be careful to emit the code to initialize the bool flags in the same order the selection objects are created in Python. This will make sure a bool is always declared and initialized before its used later. You can do this by having a list in the Python Selection class and have the __init__ method add the new Selection to that list. Of course, if you create Selection objects that you then throw away that might be a problem. But if you keep them all, it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.