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

Adding TRestEvent ptr while opening input file #453

Merged
merged 11 commits into from
Jul 5, 2023
54 changes: 29 additions & 25 deletions macros/REST_OpenInputFile.C
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
TRestRun* run0 = nullptr;
TRestAnalysisTree* ana_tree0 = nullptr;
TTree* ev_tree0 = nullptr;
TRestDataSet* dSet0 = nullptr;
std::map<std::string, TRestMetadata*> metadata0;
TRestRun* run = nullptr;
TRestAnalysisTree* ana_tree = nullptr;
TTree* ev_tree = nullptr;
TRestEvent* ev = nullptr;
TRestDataSet* dSet = nullptr;
std::map<std::string, TRestMetadata*> metadata;

void REST_OpenInputFile(const std::string& fileName) {
if (TRestTools::isRunFile(fileName)) {
printf("\n%s\n", "REST processed file identified. It contains a valid TRestRun.");
run0 = new TRestRun(fileName);
printf("\nAttaching TRestRun %s as run0...\n", fileName.c_str());
ana_tree0 = run0->GetAnalysisTree();
printf("\nAttaching TRestAnalysisTree as ana_tree0...\n");
ev_tree0 = run0->GetEventTree();
printf("\nAttaching event tree as ev_tree0...\n");
run = new TRestRun(fileName);
printf("\nAttaching TRestRun %s as run...\n", fileName.c_str());
ana_tree = run->GetAnalysisTree();
printf("\nAttaching TRestAnalysisTree as ana_tree...\n");
ev_tree = run->GetEventTree();
printf("\nAttaching event tree as ev_tree...\n");
ev = run->GetInputEvent();
jgalan marked this conversation as resolved.
Show resolved Hide resolved
run->GetEntry(0);
printf("\nAttaching input event %s as ev...\n", ev->ClassName());
std::map<std::string, int> metanames;
for (auto& [name, meta] : metadata0) delete meta;
metadata0.clear();
for (int n = 0; n < run0->GetNumberOfMetadata(); n++) {
std::string metaName = run0->GetMetadataNames()[n];
for (auto& [name, meta] : metadata) delete meta;
metadata.clear();
for (int n = 0; n < run->GetNumberOfMetadata(); n++) {
std::string metaName = run->GetMetadataNames()[n];
if (metaName.find("Historic") != string::npos) continue;
TRestMetadata* md = run0->GetMetadata(metaName);
metadata0[metaName] = md;
printf("\nAttaching Metadata class %s as metadata0[\"%s\"]...\n", md->ClassName(),
TRestMetadata* md = run->GetMetadata(metaName);
metadata[metaName] = md;
printf("\nAttaching Metadata class %s as metadata[\"%s\"]...\n", md->ClassName(),
metaName.c_str());
}

} else if (TRestTools::isDataSet(fileName)) {
printf("\n%s\n", "REST dataset file identified. It contains a valid TRestDataSet.");
printf("\nImporting dataset %s as `dSet0`\n", fileName.c_str());
printf("\nImporting dataset %s as `dSet`\n", fileName.c_str());
printf("\n%s\n", "The dataset is ready. You may now access the dataset using:");
printf("\n%s\n", " - dSet0->PrintMetadata()");
printf("%s\n", " - dSet0->GetDataFrame().GetColumnNames()");
printf("%s\n\n", " - dSet0->GetTree()->GetEntries()");
if (dSet0) delete dSet0;
dSet0 = new TRestDataSet();
dSet0->Import(fileName);
printf("\n%s\n", " - dSet->PrintMetadata()");
printf("%s\n", " - dSet->GetDataFrame().GetColumnNames()");
printf("%s\n\n", " - dSet->GetTree()->GetEntries()");
if (dSet) delete dSet;
dSet = new TRestDataSet();
dSet->Import(fileName);
} else {
printf("\n%s is not a valid TRestRun or TRestDataSet\n", fileName.c_str());
}
Expand Down