2 #include <nlohmann/json.hpp>
8 #include <TObjString.h>
10 #include <gperftools/profiler.h>
27 TFile*
f =
new TFile(
"run_364030_lowStat_LB121-140_han_converted.root");
28 TFile* f_output =
new TFile(
"run_364030_lowStat_LB121-140_han_converted_back.root",
"recreate");
34 std::chrono::duration<double> elapsed_seconds =
end -
start;
35 std::cout <<
"elapsed time: " << elapsed_seconds.count() <<
"s\n";
43 TObjString* TOS_w_JSON;
46 TString obj_input_type = obj_in->ClassName();
48 if (obj_input_type ==
"TFile") {
53 TDirectory* obj_in_dir = (TDirectory*) obj_in;
54 TDirectory* obj_to_dir = (TDirectory*) obj_to;
55 TString
name = obj_in->GetName();
57 if (is_file ==
false) {
64 TIter
next(obj_in_dir->GetListOfKeys());
66 while ((
key = (TKey*)
next())) {
68 TString key_name =
key->GetName();
69 TString key_type =
key->GetClassName();
70 if (key_type ==
"TObjString") {
71 if (key_name ==
"File_version") {
74 obj_in_dir->GetObject(key_name, TOS_w_JSON);
76 content = TOS_w_JSON->GetString();
83 idir =
new TDirectoryFile(key_name,
"");
98 else if (key_type ==
"TH1I" || key_type ==
"TH2I" || key_type ==
"TH1F" || key_type ==
"TH2F" ||
99 key_type ==
"TProfile2D" || key_type ==
"TProfile" || key_type ==
"TGraphAsymmErrors" ||
100 key_type ==
"TGraphErrors" || key_type ==
"TH1D" || key_type ==
"TH2S") {
101 obj_inside = obj_in_dir->GetKey(key_name)->ReadObj();
103 if (key_name ==
"Reference") {
109 obj_inside->Write(key_name);
112 }
else if (key_type ==
"TDirectoryFile") {
113 obj_inside = obj_in_dir->GetKey(key_name)->ReadObj();
123 int size = str_content.size();
127 TDirectory* nextLevelDirs[
size];
129 const char* keyname =
it.key().c_str();
130 auto valuestring =
it.value();
132 if (
dir_exists(keyname, place_to_save) == 0) {
133 place_to_save->mkdir(keyname);
135 place_to_save->cd(keyname);
137 if (strncmp(valuestring.type_name(),
"string", 6) == 0) {
139 nextLevelDirs[num_of_key]->cd();
140 TString string_name = valuestring.dump();
141 leaf.SetString(string_name);
142 nextLevelDirs[num_of_key]->WriteTObject(&leaf, string_name);
153 TDirectory* obj_in_dir = (TDirectory*) obj_in;
154 TList*
keys = obj_in_dir->GetListOfKeys();
157 if (
k && !strcmp(
k->GetClassName(),
"TDirectoryFile")) {