Strange beahviour of Option_t type

Hello,

I have found some weird behaviour of Option_t * type (which as far as I know is simply const char *). Here is part of the code I’ using (unfortunately whole code is to big and without specific samples and config files is useless)

const Option_t * drawOpt = drawOp.getDrawOptions( otherHistos[i].getName(), same ).c_str();
cout << "TEST1: " << drawOpt << endl;
otherHistos[i].getHisto(k)->Draw( drawOpt );
cout << "TEST2: " << drawOpt << endl;

So first line obtains drawing options depending on histogram name and if it is first histogram drawn on canvas or not. otherHistos[i].getHisto(k) is just a pointer to TH1D.

Below you can find output in ROOT 5.27/06b on cmslpc corresponding to that piece of code:

TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MT.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/MT.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MT_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZMASS.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/ZMASS.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZMASS_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZPT.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/ZPT.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZPT_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1PT.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L1PT.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1PT_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2PT.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L2PT.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2PT_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZETA.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/ZETA.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZETA_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1ETA.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L1ETA.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1ETA_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2ETA.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L2ETA.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2ETA_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZPHI.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/ZPHI.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/ZPHI_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/METPHI.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/METPHI.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/METPHI_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1PHI.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L1PHI.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L1PHI_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2PHI.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/L2PHI.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/L2PHI_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMET.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/PFMET.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMET_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMETSIGN.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/PFMETSIGN.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMETSIGN_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: p�
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMETSUMET.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/PFMETSUMET.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/PFMETSUMET_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NVTX.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/NVTX.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NVTX_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: 0�
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NJET.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/NJET.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NJET_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: @�
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NELE.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/NELE.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NELE_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: ��
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NMU.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/NMU.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/NMU_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: �#�
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MAXJETPT.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/MAXJETPT.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MAXJETPT_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: samepe1x0
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MAXJETBTAG.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/MAXJETBTAG.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MAXJETBTAG_ratio.ps has been created
TEST1: SAMEPE1X0
TEST2: �.�
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MINJETDPM.ps has been created
Info in <TCanvas::SaveSource>: C++ Macro file: ./Plots_All/Selection/MINJETDPM.C has been generated
Info in <TCanvas::Print>: ps file ./Plots_All/Selection/MINJETDPM_ratio.ps has been created

First of all for some reason in most cases upper case string becomes lower case. This is strange since this const char *. second, in some cases string becomes broken.

I tested this code also on my personal computer with ROOT 5.30 and it looks like first issues is fixed, but still sometimes string becomes garbled.

Is this a bug or my lack of understanding of ROOT?

I tried to trace the issue and find out what causes problem, but failed. Basically in TList::NewOptLink(TObject *obj, Option_t *opt, TObjLink *prev) option is still correct but than during creating TObjOptLink(obj, prev, opt) the text becomes broken.

Maybe some experts could clarify that.

Thank you for help.

[quote]const Option_t * drawOpt = drawOp.getDrawOptions( otherHistos[i].getName(), same ).c_str();[/quote]What the return type of drawOp.getDrawOptions. Unless it returns a reference to an std::string, this code is invalid as it would record in drawOpt an internal address (c_str()) of a temporary object that is deleted at the end of the statement.

Cheers,
Philippe.

Hello,

excuse me for answering so late, I was on vacation.

So indeed I return there string and then drawOpt would point to temporary object. I fixed that and now this seems to work. Stupid mistake. Thank you for pointing it.