FairRoot/PandaRoot
Typedefs | Functions
convertRootMatricesToJSON.C File Reference
#include "json.hpp"

Go to the source code of this file.

Typedefs

using json = nlohmann::json
 

Functions

std::map< std::string,
TGeoHMatrix > * 
readRootMatrices (std::string filename)
 
void saveMatricesToJson (std::map< std::string, TGeoHMatrix > matrices, std::string outfilename)
 
void convertRootMatricesToJSON (std::string filename)
 main function More...
 
void convertRootMatricesToJSON ()
 

Typedef Documentation

using json = nlohmann::json

Definition at line 5 of file convertRootMatricesToJSON.C.

Function Documentation

void convertRootMatricesToJSON ( std::string  filename)

main function

Definition at line 46 of file convertRootMatricesToJSON.C.

References readRootMatrices(), and saveMatricesToJson().

46  {
47  cout << "starting...\n";
48 
49  // read root file, this will be a map<TString, TGeoHMatrix>
50  std::map<std::string, TGeoHMatrix> rootMatrices = *(readRootMatrices(filename));
51 
52  // save file to json
53  cout << "saving " << filename << " to json file!\n";
54  saveMatricesToJson(rootMatrices, filename + ".json");
55 }
std::map< std::string, TGeoHMatrix > * readRootMatrices(std::string filename)
void saveMatricesToJson(std::map< std::string, TGeoHMatrix > matrices, std::string outfilename)
const string filename
void convertRootMatricesToJSON ( )

Definition at line 58 of file convertRootMatricesToJSON.C.

References exit().

58  {
59  cout << "You must specify a file name!\n";
60  exit(1);
61 }
exit(0)
std::map<std::string, TGeoHMatrix>* readRootMatrices ( std::string  filename)

Definition at line 7 of file convertRootMatricesToJSON.C.

References exit().

Referenced by convertRootMatricesToJSON().

7  {
8  cout << "reding file: " << filename << "\n";
9  TFile *misalignmentMatrixRootfile = new TFile(filename.c_str(), "READ");
10  if (misalignmentMatrixRootfile->IsOpen()) {
11  std::map<std::string, TGeoHMatrix> *matrices;
12  gDirectory->GetObject("PndLmdMisalignMatrices", matrices);
13  misalignmentMatrixRootfile->Close();
14  cout << "read " << matrices->size() << " matrices from file.\n";
15  return matrices;
16  } else {
17  cout << "file could not be read\n";
18  exit(1);
19  }
20 }
exit(0)
const string filename
void saveMatricesToJson ( std::map< std::string, TGeoHMatrix >  matrices,
std::string  outfilename 
)

Definition at line 22 of file convertRootMatricesToJSON.C.

Referenced by convertRootMatricesToJSON().

22  {
23  // matrices is a map with string->TGeoHMatrix
24  json j;
25  double thisMatrixDoubles[16];
26  TGeoHMatrix thisMatrix;
27 
28  for (auto &path : matrices) {
29  thisMatrix = path.second;
30  thisMatrix.GetHomogenousMatrix(thisMatrixDoubles);
31 
32  j[path.first] = {
33  thisMatrixDoubles[0], thisMatrixDoubles[1], thisMatrixDoubles[2], thisMatrixDoubles[12],
34  thisMatrixDoubles[4], thisMatrixDoubles[5], thisMatrixDoubles[6], thisMatrixDoubles[13],
35  thisMatrixDoubles[8], thisMatrixDoubles[9], thisMatrixDoubles[10], thisMatrixDoubles[14],
36  thisMatrixDoubles[3], thisMatrixDoubles[7], thisMatrixDoubles[11], thisMatrixDoubles[15]};
37  }
38 
39  // save!
40  cout << "save " << j.size() << " matrices to json!\n";
41  std::ofstream o(outfilename.c_str());
42  o << std::setw(2) << j << std::endl;
43 }
nlohmann::json json