So I’m continuing to have a bit of trouble.
charReplaceAll function is:
void charReplaceAll(char* cstr, const string& from, const string& to)
{
string str = cstr;
if(from.empty())
{return;}
string wsRet;
wsRet.reserve(str.length());
size_t start_pos = 0, pos;
while((pos = str.find(from, start_pos)) != string::npos)
{
wsRet += str.substr(start_pos, pos - start_pos);
wsRet += to;
pos += from.length();
start_pos = pos;
}
wsRet += str.substr(start_pos);
str.swap(wsRet); // faster than str = wsRet;
strcpy(cstr, str.c_str());
}
Using this code:
Output:
Result:
name is cut off after using (
Using code:
sprintf(savePlotFilename, "/local_data0/Data/GAIN/%s_%iC_%.1fV/%s_%iC_Template-%.1fV_%.1fV_%s_maxamp.pdf", deviceNameExtendedU.c_str(), temperature, HVTemplate, deviceNameExtendedU.c_str(), temperature, HVTemplate, HV, todaysDate);
cout<<savePlotFilename<<endl;
charReplaceAll(savePlotFilename, "(", "\(");
cout<<savePlotFilename<<endl;
cMaxAmpDistribution->SaveAs(savePlotFilename);
Output:
/local_data0/Data/GAIN/test_with_Shaper(47pF)_5C_71.0V/test_with_Shaper(47pF)_5C_Template-71.0V_70.6V_Jul242013_maxamp.pdf
/local_data0/Data/GAIN/test_with_Shaper(47pF)_5C_71.0V/test_with_Shaper(47pF)_5C_Template-71.0V_70.6V_Jul242013_maxamp.pdf
Info in <TCanvas::Print>: Current canvas added to pdf file /local_data0/Data/GAIN/test_with_Shaper
Result:
Seems like there’s a weird conversion that gets eaten up, resulting in failure to save file. ( seems to be eaten up by the compiler. So I would need to use “\(” in order to get “(” in the filename.
Using code:
sprintf(savePlotFilename, "/local_data0/Data/GAIN/%s_%iC_%.1fV/%s_%iC_Template-%.1fV_%.1fV_%s_maxamp.pdf", deviceNameExtendedU.c_str(), temperature, HVTemplate, deviceNameExtendedU.c_str(), temperature, HVTemplate, HV, todaysDate);
cout<<savePlotFilename<<endl;
charReplaceAll(savePlotFilename, "(", "\\\(");
cout<<savePlotFilename<<endl;
cMaxAmpDistribution->SaveAs(savePlotFilename);
Output:
/local_data0/Data/GAIN/test_with_Shaper(47pF)_5C_71.0V/test_with_Shaper(47pF)_5C_Template-71.0V_70.6V_Jul242013_maxamp.pdf
/local_data0/Data/GAIN/test_with_Shaper\(47pF)_5C_71.0V/test_with_Shaper\(47pF)_5C_Template-71.0V_70.6V_Jul242013_maxamp.pdf
Info in <TCanvas::Print>: Current canvas added to pdf file /local_data0/Data/GAIN/test_with_Shaper\
Result:
The cout after replacing ( with ( looks good, but SaveAs still does not work, still gets cut off at (.