My understanding is that if you create a variable using “new”, the memory is stored in a heap so you have to use delete command to free the space. However, I have defined the variable normally so it should be stored in stack memory and should be freed after the program ends.
How can I execute my code without getting the following error? Thank you.
I think I have the same issue even though I have the new root installed.
how to avoid getting redefinition error when running multiple macro with ProcessLine command in ROOT? All this macros have same variable definitions and names, but they are independent macros. When we link, I guess ROOT sees them as one. Thus, we get an error of redefinition.
All this macros have same variable definitions and names, but they are independent macros. When we link, I guess ROOT sees them as one. Thus, we get an error of redefinition.
`
In file included from input_line_58:1:
**/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/STPMediumSi.cpp:64:8:** **error:** **redefinition of 'PATH'**
string PATH ="/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/";
**^**
**/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/densityplot.cpp:55:8: note:** previous definition is here
string PATH ="/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/";
/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/STPprotonDifferentMediums1.cpp:51:17: error: redefinition of 'T_particle1'
vector <double> T_particle1; //take and read the list from an input file
^
/Users/spyhunter0066/Library/CloudStorage/OneDrive-harran.edu.tr/MacbookCplusplus/STOPPINGPOWERROOT/STOPPINGPOWERROOT/STPElectronPositron.cpp:49:17: note: previous definition is here
vector <double> T_particle1; //take and read the list from an input file
........
[EnergyList1.txt|attachment](upload://oBJ55y6xcGoBIC9I6zuFXBnJQx4.txt) (1.1 KB)
[STPprotonDifferentMediums1.cpp|attachment](upload://9cxpUfgktrxYwiy1J7DyEGVHEvy.cpp) (16.4 KB)
[STPElectronPositron.cpp|attachment](upload://zREIAwFH8ACnMtnrr5lvpk5kJxk.cpp) (13.7 KB)
[maincompilation.cpp|attachment](upload://hIj8Vm16lAQgniuTn90li6aGDbV.cpp) (1.5 KB)
I want to solve it without renaming all the variables.
root.exe(1766,0x1dff75000) malloc: double free for ptr 0x13c9cc400
root.exe(1766,0x1dff75000) malloc: *** set a breakpoint in malloc_error_break to debug
For some reason, it opens up XQuarts instead of ROOT to visualize. XQuarts opens empty canvas by the way. How can we make it open ROOT.
Plus, should we use -q because I want to see all plots at once on my screen.
THANKS. Sorry for the pain. It shouldn’t take that long to solve this.
I see your point, but that’s not what I wanted. I wanted to compile and see the files one by one indeed.
This code runs but it doesn’t plot anything. what’s wrong with it? I save each macro’s canvas in a root file separately.
#!/bin/bash
yourPath=“PATH/”
Start ROOT session and open the ROOT files within the ROOT interpreter
root -l -b << EOF
{
// Open the ROOT file
TFile *file = TFile::Open(“${yourPath}densityplot.root”);
if (!file) {
std::cerr << “Error: Could not open densityplot.root” << std::endl;
return 1;
}
// Get the canvas named "c1" from the file
TCanvas *c1 = (TCanvas*)file->Get("c1");
if (!c1) {
std::cerr << "Error: Could not find canvas c1 in densityplot.root" << std::endl;
return 1;
}
// Draw the canvas
c1->Draw();
}
EOF
root -l -b << EOF
{
// Open the ROOT file
TFile *file = TFile::Open(“${yourPath}STPElectronPositron.root”);
if (!file) {
std::cerr << “Error: Could not open STPElectronPositron.root” << std::endl;
return 1;
}
// Get the canvas named "c3" from the file
TCanvas *c3 = (TCanvas*)file->Get("c3");
if (!c3) {
std::cerr << "Error: Could not find canvas c3 in STPElectronPositron.root" << std::endl;
return 1;
}
// Draw the canvas
c3->Draw();
It worked alright after TFile and write() method.
I use this now. The weird thing is, plots show up only if I select the root file in the Browser and pick up one by one. Should I write the graphs I create instead of Canvas to see in the TBrowser?
#!/bin/bash
yourPath=“…”
root -l -b -q ${yourPath}macro1.cpp
root -l -b -q ${yourPath}macro2.cpp
root -l -b -q ${yourPath}macro3.cpp
root -l -b -q ${yourPath}macro4.cpp
root -l -b -q ${yourPath}macro5.cpp
root -l -b -q ${yourPath}macro6.cpp
#To see all at once
root -l ${yourPath}plots.root -e “new TBrowser”