TSelector creation and member access

Hello,

I have a class derived from TSelector, and I am trying to instantiate it with GetSelector(), and then call some initalization methods before calling TChain->Process(). I am attempting to compile everything within root (i.e. root -b -q run.C+).

However, when I use this method to change myAnalysis->testvar = 10, it “works” (in run.C I can show that it changed), but when TTree->Process(mySelector) is called, my debug output shows that testvar is now at its default value of 3.

Do you have any suggestions?

Cheers,
Andrew

[code]/// run.C ///

#include “compileAll.C”
#include
#include
#include “TSelector.h”
#include “MyAnalysis.h”

void run(string infilename = “ZeeNp5.wzD3PD.root”, string outfilename = “testoutput.root”, int nevents = 10)
{
infilename.append("/physics");
TFile * outputFile = new TFile (outfilename.c_str(),“RECREATE”);

// chose compilation options
if ( !compileAll(“Ok”) ) {
std::cout << “ERROR: Problem compiling and/or loading code. Not running analysis.” << std::endl;
return;
}

// Instantiate TSelector object and try to set some methods
MyAnalysis * myAnalysis = (MyAnalysis*) TSelector::GetSelector(“MyAnalysis.C+O”);
myAnalysis->testvar = 10;

TChain f;
f.Add(infilename.c_str());
f.Process(myAnalysis,"",nevents,0);

outputFile->Write();

}[/code]

Hi,

Is testvar set anywhere else than the constructor? If not, can you send a complete running example showing the problem?

Cheers,
Philippe.

Here is an example, it should work on any tree you have lying around, because it doesn’t access any branches at all. (if you change the filename, of course). You have to run with the + option.

It is interesting that the address changes between the constructor and the pointer accessed in run_dummy.C. Here is the output:

pb-d-128-141-86-209:dummy ameade$ root -b -q run_dummy.C+

root [0]
Processing run_dummy.C+…
Info in TUnixSystem::ACLiC: creating shared library /Users/ameade/workarea/newAnalysis/dummy/./run_dummy_C.so
In constructor
This = 0x27cd210
Testvar in constructor: -999

In Macro after GetSelector
This = 0x27cd280
Testvar before Process: 10

testvar in Begin: -999

Thanks!
Andrew
run_dummy.C (724 Bytes)
dummy.h (2.58 KB)
dummy.C (440 Bytes)

Hi,

Due to an over-sight, when you useTSelector::GetSelector("MyAnalysis.C+O"); where you use the prefix +O, TSelector::GetSelector returns a TSelectorCint instead of directly returning your Selector. Until this oversight is fixed, you can use the following work around TSelector *sel = TSelector::GetSelector("dummy.C+O"); delete sel; dummy * mydummy = (dummy*)TSelector::GetSelector("dummy.C+");

Cheers,
Philippe.

Hi,

Please note that the problem is fixed in svn.

Cheers,
Philippe.

Thanks for the help, this seems to work.

Hello,

As an update, if I declare a static member of the TSelector, and change it with

mySelector::myStaticVariable = blah;

the change does not seem to “stick”, much like before, but in this case the trick offered does not fix this.

Any suggestions?

Cheers,
Andrew Meade

Hi,

Here the problem is that you must insure that the static variable is not re-initialize which happens if (and whenever) the library is reloaded.

In the example I showed there is one reload. So instead you will need to use the underlying interface of ACLiC. So rather than “TSelector::GetSelector(“dummy.C+O”);” try:gSystem->CompileMacro("dummy.C","kOc"); // k: keep, O: optimize, c: compile only (do not load)

Cheers,
Philippe.

Hello,

This didn’t seem to change the problem… I compiled as you suggested, changed MySelector::myVar, and the called Process(“MySelector.C+O”), and the value was not updated.

Cheers,
Andrew

Hi Andrew,

Can you send me a running example showing this problem?

Thanks,
Philippe

Hi Philippe,

So the problem goes away if you compile the selector and just create it with new, in an interpreted “run” macro…

I’m very sorry I’m having trouble reproducing the problem in a simple context. I appreciate all your help. I’ll have to come back to this later though.

Thank you,
Andrew