#include <iostream>
#include <nlohmann/json.hpp>
#include <TFile.h>
#include <TFolder.h>
#include <TH1.h>
#include <TKey.h>
#include <TObjString.h>
#include <TROOT.h>
#include <unistd.h>
#include <chrono>
#include <cstring>
Go to the source code of this file.
◆ convert_file()
int convert_file |
( |
TObject * |
obj_in, |
|
|
TObject * |
obj_to |
|
) |
| |
Definition at line 134 of file HanOutputFile_translation.cxx.
135 TString obj_input_type = obj_input->ClassName();
138 if (obj_input_type ==
"TFile") {
145 TDirectory* save_to =
dynamic_cast<TDirectory*
>(obj_outout);
146 TString
name = obj_input->GetName();
148 if (
dir =
dynamic_cast<TDirectory*
>(obj_input)) {
150 if (
name ==
"Results") {
153 }
else if (
name ==
"Config") {
159 if (is_file ==
false) {
167 TIter
next(
dir->GetListOfKeys());
170 while ((
key = (TKey*)
next())) {
171 TObject* next_level_obj;
172 TString key_name =
key->GetName();
173 next_level_obj =
dir->GetKey(key_name)->ReadObj();
180 obj_input->Write(
name);
◆ include_hist()
int include_hist |
( |
TObject * |
obj | ) |
|
Instructions: COMPILE g++ -std=c++11 HanOutputFile_translation.cxx -O2 root-config --cflags
root-config --libs --glibs
-o HanOutputFile_translation.
RUN ./HanOutputFile_translation or ./HanOutputFile_translation <input_file_name> or ./HanOutputFile_translation <input_file_name> <output_dir_path> or ./HanOutputFile_translation <input_dir_path> <input_file_name> <output_dir_path> Declarations of functions protoypes
Definition at line 241 of file HanOutputFile_translation.cxx.
244 TDirectory*
dir = (TDirectory*)
obj;
250 TIter
next(
dir->GetListOfKeys());
251 while ((
key = (TKey*)
next())) {
253 key_name =
key->GetName();
255 dir->GetKey(key_name)->ReadObj();
257 key_type = obj_inside->ClassName();
259 if (key_type ==
"TH1I" || key_type ==
"TH2I" || key_type ==
"TH1F" || key_type ==
"TH2F" ||
260 key_type ==
"TProfile2D" || key_type ==
"TProfile" || key_type ==
"TGraphAsymmErrors" ||
261 key_type ==
"TGraphErrors" || key_type ==
"TH1D" || key_type ==
"TH2S") {
265 if (key_type ==
"TDirectoryFile") {
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 60 of file HanOutputFile_translation.cxx.
63 TString input_file_path =
"/eos/atlas/atlascerngroupdisk/data-dqm/examples/han_output_translation_example/";
65 TString output_file_path =
"./";
72 output_file_path =
argv[2];
75 input_file_path =
argv[1];
77 output_file_path =
argv[3];
85 TFile* f_output =
new TFile(output_file_path +
input_file_name,
"recreate");
88 std::chrono::duration<double> elapsed_seconds =
end -
start;
89 std::cout <<
"elapsed time to open files: " << elapsed_seconds.count() <<
"s\n";
97 f_output->cd(
"HanMetadata_");
98 TDirectory* version_dir =
gDirectory->mkdir(
"File");
100 TDirectory* version_sub_dir =
gDirectory->mkdir(
"Version_name");
101 version_sub_dir->cd();
102 TObjString file_version;
103 file_version.Write(
"V.2.3");
107 std::cout <<
"elapsed time for algorythm implementation: " << elapsed_seconds.count() <<
"s\n";
120 gROOT->GetListOfFiles()->Remove(f_input);
122 gROOT->GetListOfFiles()->Remove(f_output);
129 std::cout <<
"elapsed time to close files: " << elapsed_seconds.count() <<
"s\n";
◆ number_of_objects_in_dir()
int number_of_objects_in_dir |
( |
TIter |
next | ) |
|
◆ to_JSON()
nlohmann::ordered_json to_JSON |
( |
TObject * |
obj | ) |
|
Definition at line 281 of file HanOutputFile_translation.cxx.
282 using json = nlohmann::ordered_json;
283 TString obj_type =
obj->ClassName();
286 if (obj_type ==
"TObjString") {
290 std::cout <<
"WARNING: Strange case: TObjString is not a single object in a dir" << std::endl;
291 }
else if (obj_type !=
"TDirectoryFile" && obj_type !=
"TFile") {
293 std::cout <<
"WARNING: Strange type: " << obj_type << std::endl;
296 TDirectory*
dir = (TDirectory*)
obj;
297 TString dir_name =
dir->GetName();
298 TIter
next(
dir->GetListOfKeys());
305 while ((
key = (TKey*)
next())) {
306 TObject* next_level_obj;
307 key_name =
key->GetName();
309 dir->GetKey(key_name)->ReadObj();
311 TString key_type = next_level_obj->ClassName();
313 if (size_next == 1 && key_type ==
"TObjString") {
316 if (key_name == dir_name) {
317 std::cout <<
"WARNING: The names of Directory and TObjstring inside this directory are the same: " << dir_name
322 else if ((dir_name ==
"Results") &&
323 (key_type ==
"TH1I" || key_type ==
"TH2I" || key_type ==
"TH1F" || key_type ==
"TH2F" ||
324 key_type ==
"TProfile2D" || key_type ==
"TProfile" || key_type ==
"TGraphAsymmErrors" ||
325 key_type ==
"TGraphErrors" || key_type ==
"TH1D" || key_type ==
"TH2S")) {
331 std::string key_name_string(key_name.Data());
333 j.emplace(key_name_string,
to_JSON(next_level_obj));
◆ work_with_no_hist_dir()
int work_with_no_hist_dir |
( |
TObject * |
obj, |
|
|
TObject * |
destination_to_save |
|
) |
| |
Definition at line 217 of file HanOutputFile_translation.cxx.
218 TDirectory* save_place = (TDirectory*) destination_to_save;
226 std::string
string = j.dump(4);
229 TObjString string_to_tfile;
232 string_to_tfile.SetString(
"{}");
234 string_to_tfile.SetString(
string.
data());
236 TString key_name =
obj->GetName();
237 string_to_tfile.Write(key_name);
◆ work_with_results_dir()
int work_with_results_dir |
( |
TObject * |
obj_in, |
|
|
TObject * |
obj_to |
|
) |
| |
Definition at line 185 of file HanOutputFile_translation.cxx.
186 TDirectory*
dir = (TDirectory*) obj_input;
187 TDirectory* save_to = (TDirectory*) obj_outout;
193 TIter
next(
dir->GetListOfKeys());
194 while ((
key = (TKey*)
next())) {
196 key_name =
key->GetName();
197 obj_inside =
dir->GetKey(key_name)->ReadObj();
198 key_type = obj_inside->ClassName();
200 if (key_type ==
"TH1I" || key_type ==
"TH2I" || key_type ==
"TH1F" || key_type ==
"TH2F" ||
201 key_type ==
"TProfile2D" || key_type ==
"TProfile" || key_type ==
"TGraphAsymmErrors" ||
202 key_type ==
"TGraphErrors" || key_type ==
"TH1D" || key_type ==
"TH2S") {
204 obj_inside->Write(key_name);