Skip to content
Snippets Groups Projects
Commit 80510bf6 authored by Pierre-Alain Loizeau's avatar Pierre-Alain Loizeau Committed by Pierre-Alain Loizeau
Browse files

Change TOF tag in mCBM run 2391 alignment file + macro to do it

parent 2853fe5b
No related branches found
No related tags found
1 merge request!126Change TOF tag in mCBM run 2391 alignment file + macro to do it
Pipeline #21774 passed
No preview for this file type
bool align_matrix_update_tag(std::string sInFile, std::string sTagOld, std::string sTagNew, std::string sOutFile)
{
std::cout << "Updating tag in alignment file " << sInFile << " from " << sTagOld << " to " << sTagNew
<< " and saving results as " << sOutFile << std::endl;
// Define the basic structure which needs to be filled with information
// This structure is stored in the output file and later passed to the
// FairRoot framework to do the (miss)alignment
std::map<std::string, TGeoHMatrix>* matrices = nullptr;
// read matrices from disk
TFile* misalignmentMatrixRootfile = new TFile(sInFile.data(), "READ");
if (misalignmentMatrixRootfile->IsOpen()) {
gDirectory->GetObject("MisalignMatrices", matrices);
misalignmentMatrixRootfile->Close();
}
else {
std::cerr << "Could not open file " << sInFile << "\n Exiting" << std::endl;
return false;
}
std::map<std::string, TGeoHMatrix> matricesOut = {};
for (auto entry = matrices->begin(); entry != matrices->end(); ++entry) {
std::cout << entry->first << std::endl;
std::string copy = entry->first;
bool bChangesDone = false;
std::size_t pos = copy.find(sTagOld);
while (std::string::npos != pos) {
bChangesDone = true;
copy.replace(pos, sTagOld.size(), sTagNew);
pos = copy.find(sTagOld, pos + sTagNew.size());
}
if (bChangesDone) {
std::cout << "=> " << copy << std::endl;
}
matricesOut[copy] = entry->second;
}
TFile* fileUpdated = new TFile(sOutFile.data(), "RECREATE");
if (fileUpdated->IsOpen()) {
gDirectory->WriteObject(&matricesOut, "MisalignMatrices");
fileUpdated->Close();
}
else {
std::cerr << "Could not open file " << sOutFile << "\n Exiting" << std::endl;
return false;
}
return true;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment