6 #include <nlohmann/json.hpp>
12 #include <TObjString.h>
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";
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);
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);
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);
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") {
275 const TCollection* next_coll =
next.GetCollection();
276 Int_t level_size = next_coll->Capacity();
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));