Use of templates for dimensional analysis

Hi,

I’d like to automate units checking and dimansional analysis, for which I’d like to use template classes of the form

template<class T, int i1, int i2, int i3,…,int iN>

with N the number of fundamental units in terms of which composite units are to be expressed. Instances with a 1 in a slot and 0’s elsewhere would be fundamental units, powers ^(+/-k) of fundamental units would have +/-k in the corresponding slot, and composite units could have any positive or negative integer in any slot.

The problem is that every combination (int i1, int i2, int i3,…,int iN) that is realizable algebraically currently has to be explicitly included as a “#pragma link” statement , which effectively makes this implementation unfeasible.

Is there any way around this, or an alternative way people have thought of how to deal with this sort of issue?

Thanks,
Marios

Hi,

you could simply not use templates but pass the dimension “coordinates” into the constructor. At least I don’t see why this needs to be fixed at compile time (and actually you might gain in having much more dynamic code if you can define the values for each dimension at runtime). If this answer doesn’t make sense then please elaborate a bit what exactly you’re trying to do and why you would need templates for it.

Cheers, Axel.

Hi,

This is precisely the point, I’d like to use templates AND not have to fix them at compile time. The benefit of templates in the context I want to use them is the ability to generate objects that are different types, which enforces consistency in certain operations for free instead of having to implement explicit algorithms.

One way I am experimenting with is having the template classes be invisible to ROOT and inherit from wrapper parent classes which are not templates and visible to ROOT. This works in some respects but it isn’t entirely satisfactory.

So I guess the my question is whether there is any way around fixing the templates at compile time in ROOT, and allowing for a dynamic use of templates at run time.

Thanks for any insights,

Marios

[quote]and allowing for a dynamic use of templates at run time. [/quote]Somewhat … the dictionary can be compiled and loaded at run-time when needed (For example via ACLiC).

Cheers,
Philippe.

Can ACLiC be invoked from inside compiled code with MS VC++, either an executable or a dll loaded in CINT in a Windows environment?

Is there an example posted anywhere on how to do this?

Thanks

Hi,

Yes, assuming that you set the C++ compiler environment (vcvars32.bat or similar) before starting root.exe, then you can do:gROOT->ProcessLine(".L myscript.C+").

Cheers,
Philippe.

PS. Also see TSystem::CompileMacro for finer grain control.