Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating restRoot behaviour #441

Merged
merged 32 commits into from
Jun 19, 2023
Merged

Updating restRoot behaviour #441

merged 32 commits into from
Jun 19, 2023

Conversation

jgalan
Copy link
Member

@jgalan jgalan commented Jun 9, 2023

jgalan Medium: 194

Updates brought by this PR:

Now restRoot will be able to open 2 different ROOT files on-the-fly: TRestRun based files, TRestDataSet based files and standard ROOT files.

When it is a TRestRun it will create instances for all metadata objects accessible to TRestRun together with the analysisTree and the eventTree if available.

When it is a TRestDataSet it will call to TRestDataSet::Import to make the dataset readily accessible.

When we open a dataset we get:

Screenshot 2023-06-15 at 11 49 37

@lobis @juanangp @nkx111 I would prefer to remove the last line about attaching _file0 but not idea how or if it is possible.

It seems that when doing it using a TRestRun file it does not prompt this _file0 line.

Main changes are happening in restRoot. Remains are just re-factoring.

@lobis lobis self-requested a review June 12, 2023 11:46
@juanangp
Copy link
Member

@lobis @juanangp @nkx111 I would prefer to remove the last line about attaching _file0 but not idea how or if it is possible.

It seems that when doing it using a TRestRun file it does not prompt this _file0 line.

I think that _file0 is created by root, so I don't understand why you don't have it while opening a TRestRun, I guess it should be done here TRint theApp("App", &argc, argv);
I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this:

   string evcmd = Form("TRestAnalysisTree* ana_tree%i = (TRestAnalysisTree*)%s;", nFile,
                         (PTR_ADDR_PREFIX + ToString(runTmp->GetAnalysisTree())).c_str());
                if (debug) printf("%s\n", evcmd.c_str());
                gROOT->ProcessLine(evcmd.c_str());

I guess this should work:

TRestRun *_run0=nullptr;
TRestDataSet *_dS0 = nullptr;
...
if (TRestTools::isTRestRun(opt)){
_run0 = new TRestRun (opt);
std::cout <<"Attaching TRestRun " << opt <<" as _run0"<<std::endl;
} if (TRestTools::isDataSet(opt)) {
_dS0 = new TRestDataSet();
_dS0->Import(opt);
std::cout <<"Attaching TRestDataSet " << opt <<" as _dS0"<<std::endl;
} else ...

@jgalan
Copy link
Member Author

jgalan commented Jun 15, 2023

@lobis @juanangp @nkx111 I would prefer to remove the last line about attaching _file0 but not idea how or if it is possible.
It seems that when doing it using a TRestRun file it does not prompt this _file0 line.

I think that _file0 is created by root, so I don't understand why you don't have it while opening a TRestRun, I guess it should be done here TRint theApp("App", &argc, argv); I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this:

   string evcmd = Form("TRestAnalysisTree* ana_tree%i = (TRestAnalysisTree*)%s;", nFile,
                         (PTR_ADDR_PREFIX + ToString(runTmp->GetAnalysisTree())).c_str());
                if (debug) printf("%s\n", evcmd.c_str());
                gROOT->ProcessLine(evcmd.c_str());

I guess this should work:

TRestRun *_run0=nullptr;
TRestDataSet *_dS0 = nullptr;
...
if (TRestTools::isTRestRun(opt)){
_run0 = new TRestRun (opt);
std::cout <<"Attaching TRestRun " << opt <<" as _run0"<<std::endl;
} if (TRestTools::isDataSet(opt)) {
_dS0 = new TRestDataSet();
_dS0->Import(opt);
std::cout <<"Attaching TRestDataSet " << opt <<" as _dS0"<<std::endl;
} else ...

However we need to call ProcessLine at some point so that the instance is available inside the ROOT interactive shell.

So I don't really see how to solve this. We need to provide the C-command to the ROOT shell.

We could avoid using the instance of analysisTree since we can always access it using run0->GetAnalysisTree().

Also there was some issues while using std::cout for some reason I am not aware of, but @nkx111 knows more about.

@nkx111
Copy link
Member

nkx111 commented Jun 15, 2023

I think the line is shown when you propagate the file name argument to TRint. TRint will just handle those arguments as the command line root does. You need to remove the corresponding item in the arguments.

@nkx111
Copy link
Member

nkx111 commented Jun 15, 2023

I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this

Constructing such complicated command and calling it through gROOT is because we can therefore use those objects in ROOT prompt. I don't know if it is possible to initialize objects outside ROOT environment but still accessible through its prompt. Perhaps by adding it to some global list?

@jgalan
Copy link
Member Author

jgalan commented Jun 15, 2023

I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this

Constructing such complicated command and calling it through gROOT is because we can therefore use those objects in ROOT prompt. I don't know if it is possible to initialize objects outside ROOT environment but still accessible through its prompt. Perhaps by adding it to some global list?

Ah, right! I see it now that is done for the TRestRun case!

@juanangp
Copy link
Member

I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this
Constructing such complicated command and calling it through gROOT is because we can therefore use those objects in ROOT prompt. I don't know if it is possible to initialize objects outside ROOT environment but still accessible through its prompt. Perhaps by adding it to some global list?

Ah, right! I see it now that is done for the TRestRun case!

I have simplified the opening of TRestRun and TRestDataSet in this PR #447 to this branch, please merge into this branch if you think is a better approach.

I think is possible to add global variables by defining them between the declaration of TRint theApp... and theApp.Run();. However, it would be not possible to add multiple files as it is done now, in fact the generation of the _file0 in root is done in a similar way using the interpreter.

@jgalan
Copy link
Member Author

jgalan commented Jun 16, 2023

I found restRoot rather complicated. I would suggest to create a TRestRun *_run0=nullptr; pointer and a TRestDataSet *_dS0 = nullptr; then you can avoid complicated stuff like this
Constructing such complicated command and calling it through gROOT is because we can therefore use those objects in ROOT prompt. I don't know if it is possible to initialize objects outside ROOT environment but still accessible through its prompt. Perhaps by adding it to some global list?

Ah, right! I see it now that is done for the TRestRun case!

I have simplified the opening of TRestRun and TRestDataSet in this PR #447 to this branch, please merge into this branch if you think is a better approach.

I think is possible to add global variables by defining them between the declaration of TRint theApp... and theApp.Run();. However, it would be not possible to add multiple files as it is done now, in fact the generation of the _file0 in root is done in a similar way using the interpreter.

I never used the function opening multi files. I use it for quick inspection of the input file. So, perhaps the multi can be removed

@jgalan jgalan marked this pull request as ready for review June 16, 2023 13:49
@jgalan jgalan closed this Jun 19, 2023
Simplifying opening of TRestRun and TRestDataSet files
@jgalan jgalan reopened this Jun 19, 2023
@jgalan jgalan marked this pull request as draft June 19, 2023 12:06
@jgalan jgalan marked this pull request as ready for review June 19, 2023 12:06
@jgalan jgalan added the enhancement New feature or request label Jun 19, 2023
@jgalan jgalan merged commit 29c2c59 into master Jun 19, 2023
63 checks passed
@jgalan jgalan deleted the jgalan-restRoot branch June 19, 2023 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants