Skip to content

Commit 72d1501

Browse files
authored
Merge pull request #453 from rest-for-physics/issue452
Adding TRestEvent ptr while opening input file
2 parents e9db0dc + a9799a9 commit 72d1501

4 files changed

Lines changed: 62 additions & 29 deletions

File tree

macros/REST_OpenInputFile.C

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
1-
TRestRun* run0 = nullptr;
2-
TRestAnalysisTree* ana_tree0 = nullptr;
3-
TTree* ev_tree0 = nullptr;
4-
TRestDataSet* dSet0 = nullptr;
5-
std::map<std::string, TRestMetadata*> metadata0;
1+
TRestRun* run = nullptr;
2+
TRestAnalysisTree* ana_tree = nullptr;
3+
TTree* ev_tree = nullptr;
4+
TRestDataSet* dSet = nullptr;
65

76
void REST_OpenInputFile(const std::string& fileName) {
87
if (TRestTools::isRunFile(fileName)) {
9-
printf("\n%s\n", "REST processed file identified. It contains a valid TRestRun.");
10-
run0 = new TRestRun(fileName);
11-
printf("\nAttaching TRestRun %s as run0...\n", fileName.c_str());
12-
ana_tree0 = run0->GetAnalysisTree();
13-
printf("\nAttaching TRestAnalysisTree as ana_tree0...\n");
14-
ev_tree0 = run0->GetEventTree();
15-
printf("\nAttaching event tree as ev_tree0...\n");
16-
std::map<std::string, int> metanames;
17-
for (auto& [name, meta] : metadata0) delete meta;
18-
metadata0.clear();
19-
for (int n = 0; n < run0->GetNumberOfMetadata(); n++) {
20-
std::string metaName = run0->GetMetadataNames()[n];
8+
printf("\n%s\n\n", "REST processed file identified. It contains a valid TRestRun.");
9+
run = new TRestRun(fileName);
10+
printf("\nAttaching TRestRun %s as run...\n", fileName.c_str());
11+
ana_tree = run->GetAnalysisTree();
12+
printf("Attaching TRestAnalysisTree as ana_tree...\n");
13+
ev_tree = run->GetEventTree();
14+
printf("Attaching event tree as ev_tree...\n");
15+
std::string eventType = run->GetInputEvent()->ClassName();
16+
std::string evcmd = Form("%s* ev = (%s*)run->GetInputEvent();", eventType.c_str(), eventType.c_str());
17+
gROOT->ProcessLine(evcmd.c_str());
18+
run->GetEntry(0);
19+
printf("Attaching input event %s as ev...\n", eventType.c_str());
20+
for (int n = 0; n < run->GetNumberOfMetadata(); n++) {
21+
if (n == 0) printf("Attaching Metadata classes:\n");
22+
std::string metaName = run->GetMetadataNames()[n];
2123
if (metaName.find("Historic") != string::npos) continue;
22-
TRestMetadata* md = run0->GetMetadata(metaName);
23-
metadata0[metaName] = md;
24-
printf("\nAttaching Metadata class %s as metadata0[\"%s\"]...\n", md->ClassName(),
25-
metaName.c_str());
24+
TRestMetadata* md = run->GetMetadata(metaName);
25+
if (md == nullptr) {
26+
printf("\nERROR Cannot get metadata pointer for class %s and name%s\n", md->ClassName(),
27+
metaName.c_str());
28+
continue;
29+
}
30+
std::string mName = Replace(metaName, " ", "");
31+
mName = Replace(mName, ".", "_");
32+
std::string mdcmd = Form("%s* %s = (%s*)run->GetMetadata(\"%s\");", md->ClassName(),
33+
mName.c_str(), md->ClassName(), metaName.c_str());
34+
gROOT->ProcessLine(mdcmd.c_str());
35+
printf("- %s as %s\n", md->ClassName(), mName.c_str());
2636
}
37+
printf("\n");
2738

2839
} else if (TRestTools::isDataSet(fileName)) {
2940
printf("\n%s\n", "REST dataset file identified. It contains a valid TRestDataSet.");
30-
printf("\nImporting dataset %s as `dSet0`\n", fileName.c_str());
41+
printf("\nImporting dataset %s as `dSet`\n", fileName.c_str());
3142
printf("\n%s\n", "The dataset is ready. You may now access the dataset using:");
32-
printf("\n%s\n", " - dSet0->PrintMetadata()");
33-
printf("%s\n", " - dSet0->GetDataFrame().GetColumnNames()");
34-
printf("%s\n\n", " - dSet0->GetTree()->GetEntries()");
35-
if (dSet0) delete dSet0;
36-
dSet0 = new TRestDataSet();
37-
dSet0->Import(fileName);
43+
printf("\n%s\n", " - dSet->PrintMetadata()");
44+
printf("%s\n", " - dSet->GetDataFrame().GetColumnNames()");
45+
printf("%s\n\n", " - dSet->GetTree()->GetEntries()");
46+
if (dSet) delete dSet;
47+
dSet = new TRestDataSet();
48+
dSet->Import(fileName);
3849
} else {
3950
printf("\n%s is not a valid TRestRun or TRestDataSet\n", fileName.c_str());
4051
}

source/framework/core/inc/TRestRun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class TRestRun : public TRestMetadata {
167167
inline TTree* GetEventTree() const { return fEventTree; }
168168
inline Int_t GetInputFileNumber() const { return fFileProcess == nullptr ? fInputFileNames.size() : 1; }
169169

170+
std::vector<std::string> GetEventTypesList();
171+
170172
TRestMetadata* GetMetadata(const TString& name, TFile* file = nullptr);
171173
TRestMetadata* GetMetadataClass(const TString& type, TFile* file = nullptr);
172174
std::vector<std::string> GetMetadataNames();

source/framework/core/src/TRestRun.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,25 @@ Int_t TRestRun::GetNextEvent(TRestEvent* targetEvent, TRestAnalysisTree* targetT
887887
return 0;
888888
}
889889

890+
///////////////////////////////////////////////
891+
/// \brief It returns a list of available event types inside the file
892+
///
893+
std::vector<std::string> TRestRun::GetEventTypesList() {
894+
std::vector<std::string> list;
895+
TObjArray* branches = GetEventTree()->GetListOfBranches();
896+
for (int i = 0; i <= branches->GetLast(); i++) {
897+
auto branch = (TBranch*)branches->At(i);
898+
if (((std::string)branch->GetName()).find("EventBranch") != string::npos) {
899+
std::string eventType = Replace((string)branch->GetName(), "Branch", "");
900+
list.emplace_back(eventType);
901+
}
902+
}
903+
return list;
904+
}
905+
890906
///////////////////////////////////////////////
891907
/// \brief Calls GetEntry() for both AnalysisTree and EventTree
908+
///
892909
void TRestRun::GetEntry(Long64_t entry) {
893910
if (entry >= GetEntries()) {
894911
RESTWarning << "TRestRun::GetEntry. Entry requested out of limits" << RESTendl;

source/framework/tools/src/TRestTools.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,10 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) {
11371137
return 0;
11381138
}
11391139
} else {
1140-
RESTError << "unknown protocol!" << RESTendl;
1140+
if (!TRestTools::fileExists(remoteFile)) {
1141+
RESTWarning << "Trying to download: " << remoteFile << RESTendl;
1142+
RESTWarning << "Unknown protocol!" << RESTendl;
1143+
}
11411144
}
11421145

11431146
return -1;

0 commit comments

Comments
 (0)