Error in running macro in ROOT

Hi,

I tried running this macro named MyAutoFit.C on the rootfile named 6_000.root however I am getting errors related to the char variables which I could not solve. Please help me out. I am attaching the root file, the macro and the error message that I am getting.

Thank you for your help in advance.

MyAutoFit.C (4.2 KB)

https://drive.google.com/file/d/1pBUR_ZsISc8OC70JkbD90vTkvJJA-B6O/view?usp=sharing


ROOT Version: 6
Platform: Ubuntu 16.04
Compiler: Not Provided


Hi,
the error messages are correct, there are some mistakes in the code:

  1. “initializer string for char array is too long”:
    Char_t E[2] is an array of two characters, but you are filling it with two strings. Probably you want a std::array<std::string, 2> or a std::vector<std::string> instead of a Char_t[2]

  2. "calling a private constructor of class TChain:
    TChain ch = TChain("h101") constructs a TChain on the right side of the assignment and then assigns it to a new TChain (the one on the left side of the assignment), but copy-constructing TChains is not allowed. You probably want to do TChain ch("h101")

  3. “use of undeclare identifier ‘h101’”
    My guess is that you don’t have any variable named h101, you maybe mean to use your chain ch there

C++ compilation errors are not the most friendly but usually all the information is there!
Cheers,
Enrico

Hi,

After making the changes I am getting these errors

root [3] .L MyAutoFit.C
In file included from input_line_82:1:
/home/user/javi/calib (copy)/MyAutoFit.C:79:5: error: member reference type
‘TChain’ is not a pointer; maybe you meant to use ‘.’?
ch->Draw(E[k],strip);
~~^~
.
/home/user/javi/calib (copy)/MyAutoFit.C:79:7: error: no matching member
function for call to ‘Draw’
ch->Draw(E[k],strip);
~~^~
/home/user/root-6.06.08/include/TChain.h:87:22: note: candidate function not
viable: no known conversion from ‘value_type’ (aka
‘std::__cxx11::basic_string’) to 'const char ’ for 1st argument
virtual Long64_t Draw(const char
varexp, const char* selection, Opt…
^
/home/user/root-6.06.08/include/TChain.h:86:22: note: candidate function not
viable: no known conversion from ‘value_type’ (aka
‘std::__cxx11::basic_string’) to 'const char ’ for 1st argument
virtual Long64_t Draw(const char
varexp, const TCut& selection, Opt…
^
/home/user/root-6.06.08/include/TChain.h:88:22: note: candidate function not
viable: requires single argument ‘opt’, but 2 arguments were provided
virtual void Draw(Option_t* opt) { Draw(opt, “”, “”, kMaxEntries, 0); }
^

I don’t think it gets clearer than that :smile: ch is not a pointer, and you need to use . instead of ->.

The other errors look like they are at the same exact point and probably follow from this one.

But again these are more C++ compilation errors than ROOT-specific problems: for these kind of issues you might be better off on stackoverflow.

Cheers,
Enrico

well I am sorry if its too obvious but replacing -> with . doesn’t do much help either.

In file included from input_line_50:1:
/home/user/javi/calib (copy)/MyAutoFit.C:79:6: error: no matching member
function for call to ‘Draw’
ch.Draw(E[k],strip);
~^~
/home/user/root-6.06.08/include/TChain.h:87:22: note: candidate function not
viable: no known conversion from ‘value_type’ (aka
‘std::__cxx11::basic_string’) to 'const char ’ for 1st argument
virtual Long64_t Draw(const char
varexp, const char* selection, Opt…
^
/home/user/root-6.06.08/include/TChain.h:86:22: note: candidate function not
viable: no known conversion from ‘value_type’ (aka
‘std::__cxx11::basic_string’) to 'const char ’ for 1st argument
virtual Long64_t Draw(const char
varexp, const TCut& selection, Opt…
^
/home/user/root-6.06.08/include/TChain.h:88:22: note: candidate function not
viable: requires single argument ‘opt’, but 2 arguments were provided
virtual void Draw(Option_t* opt) { Draw(opt, “”, “”, kMaxEntries, 0); }
^

Well it got rid of an error message! :smile:
These other error messages are saying that you are passing a std::string (std::__cxx11::basic_string is a std::string) where the function expects a const char *.
You can convert the former to the latter:

ch.Draw(E[k].c_str(), strip)

Now this :tired_face:

In file included from input_line_50:1:
/home/user/javi/calib (copy)/MyAutoFit.C:152:1: error: control reaches end of
non-void function [-Werror,-Wreturn-type]
}
^

Your function is meant to return something but it doesn’t return anything.
Did you forget a return 0?

EDIT: these are really common C++ compilation errors!

I am really sorry thanks for bearing with me so long!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.