diff --git a/macros/REST_OpenInputFile.C b/macros/REST_OpenInputFile.C index 982cf46cc..1bf55e0a5 100644 --- a/macros/REST_OpenInputFile.C +++ b/macros/REST_OpenInputFile.C @@ -7,6 +7,8 @@ void REST_OpenInputFile(const std::string& fileName) { if (TRestTools::isRunFile(fileName)) { printf("\n%s\n\n", "REST processed file identified. It contains a valid TRestRun."); run = new TRestRun(fileName); + // print number of entries in the run + printf("\nThe run has %lld entries.\n", run->GetEntries()); printf("\nAttaching TRestRun %s as run...\n", fileName.c_str()); ana_tree = run->GetAnalysisTree(); printf("Attaching TRestAnalysisTree as ana_tree...\n"); diff --git a/source/framework/core/inc/TRestHits.h b/source/framework/core/inc/TRestHits.h index 654b88736..3e6e8c0e3 100644 --- a/source/framework/core/inc/TRestHits.h +++ b/source/framework/core/inc/TRestHits.h @@ -63,7 +63,7 @@ class TRestHits { public: void Translate(Int_t n, Double_t x, Double_t y, Double_t z); - void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& vMean); + void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& center); void Rotate(Int_t n, Double_t alpha, const TVector3& vAxis, const TVector3& vMean); void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t = 0, REST_HitType type = XYZ); diff --git a/source/framework/core/inc/TRestRun.h b/source/framework/core/inc/TRestRun.h index ffaf56b41..c927d5880 100644 --- a/source/framework/core/inc/TRestRun.h +++ b/source/framework/core/inc/TRestRun.h @@ -84,7 +84,9 @@ class TRestRun : public TRestMetadata { void GetEntry(Long64_t entry); void GetNextEntry() { - if (fCurrentEvent + 1 >= GetEntries()) fCurrentEvent = -1; + if (fCurrentEvent + 1 >= GetEntries()) { + fCurrentEvent = -1; + } GetEntry(fCurrentEvent + 1); } @@ -246,7 +248,7 @@ class TRestRun : public TRestMetadata { // Constructor & Destructor TRestRun(); - TRestRun(const std::string& filename); + explicit TRestRun(const std::string& filename); ~TRestRun(); ClassDefOverride(TRestRun, 6); diff --git a/source/framework/core/src/TRestHits.cxx b/source/framework/core/src/TRestHits.cxx index b2c4900a8..1e2a642ab 100644 --- a/source/framework/core/src/TRestHits.cxx +++ b/source/framework/core/src/TRestHits.cxx @@ -169,7 +169,9 @@ Bool_t TRestHits::isNaN(Int_t n) const { /// Double_t TRestHits::GetEnergyIntegral() const { Double_t sum = 0; - for (unsigned int i = 0; i < GetNumberOfHits(); i++) sum += GetEnergy(i); + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { + sum += GetEnergy(i); + } return sum; } @@ -207,8 +209,11 @@ Double_t TRestHits::GetEnergyInPrism(const TVector3& x0, const TVector3& x1, Dou Double_t theta) const { Double_t energy = 0.; - for (unsigned int n = 0; n < GetNumberOfHits(); n++) - if (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) energy += this->GetEnergy(n); + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { + if (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) { + energy += this->GetEnergy(n); + } + } return energy; } @@ -416,17 +421,17 @@ void TRestHits::Translate(Int_t n, double x, double y, double z) { /// \brief It rotates hit `n` following rotations in Z, Y and X by angles gamma, beta and alpha. The /// rotation is performed with center at `vMean`. /// -void TRestHits::RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& vMean) { - TVector3 position = GetPosition(n); - TVector3 vHit = position - vMean; +void TRestHits::RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& center) { + const TVector3 position = GetPosition(n); + TVector3 vHit = position - center; vHit.RotateZ(gamma); vHit.RotateY(beta); vHit.RotateX(alpha); - fX[n] = vHit[0] + vMean[0]; - fY[n] = vHit[1] + vMean[1]; - fZ[n] = vHit[2] + vMean[2]; + fX[n] = vHit.X() + center.X(); + fY[n] = vHit.Y() + center.Y(); + fZ[n] = vHit.Z() + center.Z(); } /////////////////////////////////////////////// diff --git a/source/framework/core/src/TRestRun.cxx b/source/framework/core/src/TRestRun.cxx index 3f533206b..d08dba6b2 100644 --- a/source/framework/core/src/TRestRun.cxx +++ b/source/framework/core/src/TRestRun.cxx @@ -1617,8 +1617,11 @@ TRestMetadata* TRestRun::GetMetadata(const TString& name, TFile* file) { } } } else { - for (unsigned int i = 0; i < fMetadata.size(); i++) - if (fMetadata[i]->GetName() == name) return fMetadata[i]; + for (unsigned int i = 0; i < fMetadata.size(); i++) { + if (fMetadata[i]->GetName() == name) { + return fMetadata[i]; + } + } } return nullptr; diff --git a/source/framework/core/src/startup.cpp b/source/framework/core/src/startup.cpp index 259956073..a4f7e7f41 100644 --- a/source/framework/core/src/startup.cpp +++ b/source/framework/core/src/startup.cpp @@ -295,6 +295,7 @@ vector StringToVector(string vec) { return result; } AddConverter(VectorToString, StringToVector, vector); +AddConverter(VectorToString, StringToVector, vector); AddConverter(VectorToString, StringToVector, vector); AddConverter(VectorToString, StringToVector, vector); AddConverter(VectorToString, StringToVector, vector); @@ -433,3 +434,254 @@ AddConverter(MapToString, StringToMap, map); AddConverter(MapToString, StringToMap, map); AddConverter(MapToString, StringToMap, map); + +template +string PairToString(pair p) { + string result = "{"; + result += Converter::thisptr->ToStringFunc(p.first); + result += ","; + result += Converter::thisptr->ToStringFunc(p.second); + result += "}"; + return result; +} +template +pair StringToPair(string vec) { + pair result; + if (vec[0] == '{' && vec[vec.size() - 1] == '}') { + vec.erase(vec.begin()); + vec.erase(vec.end() - 1); + vector parts = Split(vec, ","); + + if (parts.size() == 2) { + while (parts[0][0] == ' ') { + parts[0].erase(parts[0].begin()); + } + while (parts[0][parts[0].size() - 1] == ' ') { + parts[0].erase(parts[0].end() - 1); + } + while (parts[1][0] == ' ') { + parts[1].erase(parts[1].begin()); + } + while (parts[1][parts[1].size() - 1] == ' ') { + parts[1].erase(parts[1].end() - 1); + } + result.first = Converter::thisptr->ParseStringFunc(parts[0]); + result.second = Converter::thisptr->ParseStringFunc(parts[1]); + } else { + cout << "illegal format!" << endl; + return pair{}; + } + + } else { + cout << "illegal format!" << endl; + return pair{}; + } + return result; +} +AddConverter(PairToString, StringToPair, pair); +AddConverter(PairToString, StringToPair, pair); +AddConverter(PairToString, StringToPair, pair); +AddConverter(PairToString, StringToPair, pair); +AddConverter(PairToString, StringToPair, pair); + +// a vector of pairs +template +string PairVectorToString(vector> vec) { + stringstream ss; + ss << "{"; + int cont = 0; + for (auto const& x : vec) { + if (cont > 0) ss << ","; + cont++; + + ss << "["; + ss << Converter::thisptr->ToStringFunc(x.first); + ss << ":"; + ss << Converter::thisptr->ToStringFunc(x.second); + ss << "]"; + } + ss << "}"; + return ss.str(); +} +template +vector> StringToPairVector(string vec) { + vector> result; + // input string format: {[dd:7],[aa:8],[ss:9]} + if (vec[0] == '{' && vec[vec.size() - 1] == '}') { + vec.erase(vec.begin()); + vec.erase(vec.end() - 1); + vector parts = Split(vec, ","); + + for (string part : parts) { + while (part[0] == ' ') { + part.erase(part.begin()); + } + while (part[part.size() - 1] == ' ') { + part.erase(part.end() - 1); + } + + if (part[0] == '[' && part[part.size() - 1] == ']') { + part.erase(part.begin()); + part.erase(part.end() - 1); + vector key_value = Split(part, ":"); + if (key_value.size() == 2) { + T key = Converter::thisptr->ParseStringFunc(key_value[0]); + U value = Converter::thisptr->ParseStringFunc(key_value[1]); + result.push_back(pair(key, value)); + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + } + + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + + return result; +} +AddConverter(PairVectorToString, StringToPairVector, vector>); +AddConverter(PairVectorToString, StringToPairVector, vector>); +AddConverter(PairVectorToString, StringToPairVector, vector>); +AddConverter(PairVectorToString, StringToPairVector, vector>); +AddConverter(PairVectorToString, StringToPairVector, vector>); + +// Implement for triple (tuple) +template +string TripleToString(tuple t) { + string result = "{"; + result += Converter::thisptr->ToStringFunc(get<0>(t)); + result += ","; + result += Converter::thisptr->ToStringFunc(get<1>(t)); + result += ","; + result += Converter::thisptr->ToStringFunc(get<2>(t)); + result += "}"; + return result; +} + +template +tuple StringToTriple(string vec) { + tuple result; + if (vec[0] == '{' && vec[vec.size() - 1] == '}') { + vec.erase(vec.begin()); + vec.erase(vec.end() - 1); + vector parts = Split(vec, ","); + + if (parts.size() == 3) { + while (parts[0][0] == ' ') { + parts[0].erase(parts[0].begin()); + } + while (parts[0][parts[0].size() - 1] == ' ') { + parts[0].erase(parts[0].end() - 1); + } + while (parts[1][0] == ' ') { + parts[1].erase(parts[1].begin()); + } + while (parts[1][parts[1].size() - 1] == ' ') { + parts[1].erase(parts[1].end() - 1); + } + while (parts[2][0] == ' ') { + parts[2].erase(parts[2].begin()); + } + while (parts[2][parts[2].size() - 1] == ' ') { + parts[2].erase(parts[2].end() - 1); + } + get<0>(result) = Converter::thisptr->ParseStringFunc(parts[0]); + get<1>(result) = Converter::thisptr->ParseStringFunc(parts[1]); + get<2>(result) = Converter::thisptr->ParseStringFunc(parts[2]); + } else { + cout << "illegal format!" << endl; + return tuple{}; + } + + } else { + cout << "illegal format!" << endl; + return tuple{}; + } + return result; +} + +AddConverter(TripleToString, StringToTriple, tuple); +AddConverter(TripleToString, StringToTriple, tuple); +AddConverter(TripleToString, StringToTriple, tuple); +AddConverter(TripleToString, StringToTriple, tuple); +AddConverter(TripleToString, StringToTriple, tuple); +AddConverter(TripleToString, StringToTriple, tuple); + +// vector of triple +template +string TripleVectorToString(vector> vec) { + stringstream ss; + ss << "{"; + int cont = 0; + for (auto const& x : vec) { + if (cont > 0) ss << ","; + cont++; + + ss << "["; + ss << Converter::thisptr->ToStringFunc(get<0>(x)); + ss << ":"; + ss << Converter::thisptr->ToStringFunc(get<1>(x)); + ss << ":"; + ss << Converter::thisptr->ToStringFunc(get<2>(x)); + ss << "]"; + } + ss << "}"; + return ss.str(); +} + +template +vector> StringToTripleVector(string vec) { + vector> result; + // input string format: {[dd:7],[aa:8],[ss:9]} + if (vec[0] == '{' && vec[vec.size() - 1] == '}') { + vec.erase(vec.begin()); + vec.erase(vec.end() - 1); + vector parts = Split(vec, ","); + + for (string part : parts) { + while (part[0] == ' ') { + part.erase(part.begin()); + } + while (part[part.size() - 1] == ' ') { + part.erase(part.end() - 1); + } + + if (part[0] == '[' && part[part.size() - 1] == ']') { + part.erase(part.begin()); + part.erase(part.end() - 1); + vector key_value = Split(part, ":"); + if (key_value.size() == 3) { + T key = Converter::thisptr->ParseStringFunc(key_value[0]); + U value = Converter::thisptr->ParseStringFunc(key_value[1]); + V value2 = Converter::thisptr->ParseStringFunc(key_value[2]); + result.push_back(tuple(key, value, value2)); + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + } + + } else { + cout << "illegal format!" << endl; + return vector>{}; + } + + return result; +} + +AddConverter(TripleVectorToString, StringToTripleVector, vector>); +AddConverter(TripleVectorToString, StringToTripleVector, vector>); +AddConverter(TripleVectorToString, StringToTripleVector, vector>); +AddConverter(TripleVectorToString, StringToTripleVector, vector>); +AddConverter(TripleVectorToString, StringToTripleVector, vector>); +AddConverter(TripleVectorToString, StringToTripleVector, vector>);