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?