BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnUtils.cxx
Go to the documentation of this file.
1#include "BmnUtils.h"
2
3#include "TCanvas.h"
4#include "TSystem.h"
5
6namespace lit
7{
8
9void SaveCanvasAsImage(TCanvas* c, const std::string& dir)
10{
11 if (dir == "")
12 return;
13 gSystem->mkdir(dir.c_str(), true); // create directory if it does not exist
14 c->SaveAs(std::string(dir + std::string(c->GetTitle()) + ".eps").c_str());
15 c->SaveAs(std::string(dir + std::string(c->GetTitle()) + ".png").c_str());
16 c->SaveAs(std::string(dir + std::string(c->GetTitle()) + ".gif").c_str());
17}
18
19string FindAndReplace(const string& name, const string& oldSubstr, const string& newSubstr)
20{
21 string newName = name;
22 Int_t startPos = name.find(oldSubstr);
23 newName.replace(startPos, oldSubstr.size(), newSubstr);
24 return newName;
25}
26
27vector<string> Split(const string& name, char delimiter)
28{
29 vector<string> result;
30 size_t begin = 0;
31 size_t end = name.find_first_of(delimiter);
32 while (end != string::npos) {
33 string str = name.substr(begin, end - begin);
34 if (str[0] == delimiter)
35 str.erase(0, 1);
36 result.push_back(str);
37 begin = end;
38 end = name.find_first_of(delimiter, end + 1);
39 }
40 result.push_back(name.substr(begin + 1));
41 return result;
42}
43
44} // namespace lit
int Int_t
R__EXTERN TSystem * gSystem
const char * GetTitle() const override
void SaveAs(const char *filename="", Option_t *option="") const override
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
Definition BmnUtils.cxx:19
void SaveCanvasAsImage(TCanvas *c, const std::string &dir)
Definition BmnUtils.cxx:9
vector< string > Split(const string &name, char delimiter)
Definition BmnUtils.cxx:27