warning: Failed to call `main()` to execute the macro - c++

I am trying to learn ROOT and I have a few codes that I can work with. Sometimes codes work but sometimes they don't.
{
c1 = new TCanvas("c1", "My Root Plots",600, 400);
c1->Divide(2,2);
c1->cd(1);
f=new TF1("f","[0]*exp(-0.5*((x-[1])/[2])**2)/(sqrt(2.0*TMath::Pi())*[2])",-100,100); f->SetTitle("Gaus;X axis ;Y axis");
f->SetParameter(0,0.5*sqrt(2*TMath::Pi()));
f->SetParameter(1,8);
f->SetParameter(2,5);
f->SetLineColor(3);
f->SetMarkerColor(1);
f->SetMarkerStyle(kOpenStar);
f->SetMarkerSize(5);
f->Draw();
c1->cd(2);
f1 = new TF1("f1", "[0]*x+[1]", 0,50);
f1->SetParameters(10,4);
f1->SetLineColor(5);
f1->SetTitle("ax+b;x;y");
f1->Draw();
}
This is the code I am trying to do. Code is kinda working , ''what do you mean kinda working''. I mean it's giving me a graph but as you can see in the code I wrote ( f->SetMarkerColor(1);
f->SetMarkerStyle(kOpenStar);) But markers didn't appear on the graph. Terminal doesn't giving me any errors. Is it my ROOT library missing ? I cannot upload images because I am new here.
I have a another problem. I want to share it maybe it will help solving the problem that I have.
void testRandom(Int_t nrEvents=500000000)
{
TRandom *r1=new TRandom();
TRandom2 *r2=new TRandom2();
TRandom3 *r3=new TRandom3();
TCanvas* c1=new TCanvas("c1","TRandom Number Generators", 800,600); c1->Divide(3,1);
TH1D *h1=new TH1D("h1","TRandom",500,0,1); TH1D *h2=new TH1D("h2","TRandom2",500,0,1); TH1D *h3=new TH1D("h3","TRandom3",500,0,1); TStopwatch *st=new TStopwatch();
st->Start();
for (Int_t i=0; i<nrEvents; i++) { h1->Fill(r1->Uniform(0,1)); } st->Stop(); cout << "Random: " << st->CpuTime() << endl; st->Start();
c1->cd(1); h1->SetFillColor(kRed+1); h1->SetMinimum(0); h1->Draw();
for (Int_t i=0; i<nrEvents; i++) { h2->Fill(r2->Uniform(0,1)); } st->Stop(); cout << "Random2: " << st->CpuTime() << endl; st->Start();
c1->cd(2); h2->SetFillColor(kGreen+1); h2->SetMinimum(0); h2->Draw();
for (Int_t i=0; i<nrEvents; i++) { h3->Fill(r3->Uniform(0,1)); } st->Stop(); cout << "Random3:" << st->CpuTime() << endl;
c1->cd(3);
h3->Draw(); h3->SetFillColor(kBlue+1); h3->SetMinimum(0);
}
This is a another code I am trying to run. But this code doesn't work an it's giving me this error.
warning: Failed to call main() to execute the macro.
Add this function or rename the macro. Falling back to .L.
I tried different things. I tried ,
root [1] .x main.cpp
root [1] .L main.cpp
still giving me same error.

f->SetMarkerColor(1); f->SetMarkerStyle(kOpenStar);) But markers
didn't appear on the graph.
Try f->Draw("PL") instead of f->Draw() to make the markers visible.
warning: Failed to call main() to execute the macro.
Rename your file, it should be called testRandom.cpp instead of main.cpp
Then, you can execute it with .x testRandom.cpp.

Related

Locating bug triggering runtime error in Rcpp

I am using Rcpp to translate a model written in C++ to R, to take advantage of the visualization and fitting capabilities. I know the C++ code compiles and runs well. However, in Rcpp it triggers a runtime error that manifests as a fatal error and aborts the R session.
To try to locate where the error is triggered, I have written a wait_for_return() function and placed it along the code. This way I found the function that is triggering the error:
init = 0;
gammas[group[id_data_point]]*
(1 - pow(1 -
rel_abund_resid[id_data_point] -
rel_abund_visitors[id_data_point], 2)) / (1 - gammas[group[id_data_point]]);
draw(clientSet, int(sim_param["totRounds"]),
rel_abund_resid[id_data_point],
rel_abund_visitors[id_data_point]);
cout << id_data_point << '\t'<< group[id_data_point] << '\n';
wait_for_returnRcpp();
cleaners[agent[id_data_point]][group[id_data_point]]->rebirth(init);
wait_for_returnRcpp(); # This function is not reached
idClientSet = 0;
VisPref = 0, countRVopt = 0;
cleaners[agent[id_data_point]][group[id_data_point]]->
act(clientSet, idClientSet, prob_Vis_Leav[id_data_point],
double(sim_param["ResProbLeav"]), double(sim_param["VisReward"]),
sim_param["ResReward"], sim_param["inbr"], sim_param["outbr"],
learnScenario(int(sim_param["scenario"])));
wait_for_returnRcpp();
cleaners[agent[id_data_point]][group[id_data_point]]->update();
return 0;
While trying to understand how the function is triggering the error, I commented some parts of the code. Surprisingly, when I commented a function that is executed after the error-triggering function the error is not triggered anymore.
init = 0;
gammas[group[id_data_point]]*
(1 - pow(1 -
rel_abund_resid[id_data_point] -
rel_abund_visitors[id_data_point], 2)) / (1 - gammas[group[id_data_point]]);
draw(clientSet, int(sim_param["totRounds"]),
rel_abund_resid[id_data_point],
rel_abund_visitors[id_data_point]);
cout << id_data_point << '\t'<< group[id_data_point] << '\n';
wait_for_returnRcpp();
cleaners[agent[id_data_point]][group[id_data_point]]->rebirth(init);
wait_for_returnRcpp();
idClientSet = 0;
VisPref = 0, countRVopt = 0;
// cleaners[agent[id_data_point]][group[id_data_point]]->
// act(clientSet, idClientSet, prob_Vis_Leav[id_data_point],
// double(sim_param["ResProbLeav"]), double(sim_param["VisReward"]),
// sim_param["ResReward"], sim_param["inbr"], sim_param["outbr"],
// learnScenario(int(sim_param["scenario"])));
// wait_for_returnRcpp();
// cleaners[agent[id_data_point]][group[id_data_point]]->update();
return 0;
# Code runs until the end
I have a hard time understanding how this is possible. The code is lengthy, so I was not able to provide a reproducible example. Any ideas of what I am missing are very welcome.

Could not found the resource definition:BinOcaf.StoragePlugin?

I have the following code, and can be compiled, but when I run it, it fails with error of missing resource.
I have checked the cascade installer and everything is clicked and installed. How could I fix this?
#include <TDocStd_Application.hxx>
#include <TDataStd_Integer.hxx>
int main()
{
Handle(TDocStd_Application) app = new TDocStd_Application;
Handle(TDocStd_Document) doc;
app->NewDocument("BinOcaf", doc);
if (doc.IsNull())
{
std::cout << "Error: cannot create an OCAF document." << std::endl;
return 1;
}
// to access the main label, the transient data framework
TDF_Label mainLab = doc->Main();
// attach some integer value to this label
TDataStd_Integer::Set(mainLab, 1002);
// save document to file
PCDM_StoreStatus sstatus = app->SaveAs(doc, "C:/Users/Administrator/Desktop/test.cbf");
if (sstatus != PCDM_SS_OK)
{
app->Close(doc);
std::cout << "cannot write OCAF document." << std::endl;
return 1;
}
// release the data of doc
app->Close(doc);
return 0;
}
Ok, so after some head scratching I realized one thing. Forgot to define format.
just add the line of code to the main function would fix the problem.
BinDrivers::DefineFormate(app);

simplify combinatorial map using CGAL

I want to simplify or edge collapse a mesh read from .off file as a combinatorial map using CGAL
std::ifstream ifile(fileName.toStdString().c_str());
if (ifile)
{
CGAL::load_off(lcc, ifile);
lcc.display_characteristics(std::cout)<<", is_valid="<<CGAL::is_valid(lcc)<<std::endl;
}
namespace SMS = CGAL::Surface_mesh_simplification ;
SMS::Count_stop_predicate<LCC> stop(lcc.number_of_halfedges()/2 - 1);
int r = SMS::edge_collapse
(lcc
,stop
,CGAL::parameters::halfedge_index_map(get(CGAL::halfedge_index, lcc))
.vertex_index_map(get(boost::vertex_index, lcc))
.get_cost(SMS::Edge_length_cost<LCC>())
.get_placement(SMS::Midpoint_placement<LCC>())
);
std::cout << "\nFinished...\n" << r << " edges removed.\n"
<< (lcc.number_of_darts()/2) << " final edges.\n" ;
lcc.display_characteristics(std::cout)<<", is_valid="<<CGAL::is_valid(lcc)<<std::endl;
the output :
#Darts=16674, #0-cells=2775, #1-cells=8337, #2-cells=5558, #ccs=1, is_valid=1
Finished...
0 edges removed.
8337 final edges.
#Darts=16674, #0-cells=2775, #1-cells=8337, #2-cells=5558, #ccs=1, is_valid=1
the method do nothing , I tried more than .off file and it's preview it properly but it cannot simplify it
I appreciate any help .
See the example given here, it works perfectly.

Tensorflow C++ YOU_MADE_A_PROGRAMMING_MISTAKE

I train my NN-model in python and load it in VS2015 C++. The piece of code:
// The session will initialize the outputs
vector<Tensor> outputs;
// Run the session, evaluating our "c" operation from the graph
status = session->Run(inputs, { "y_pred" }, {}, &outputs);
// Convert the node to a scalar representation.
auto output_c = outputs[0].flat<float>();
The y_pred is a 2-element tensor, so I use flat to get it. However, I got an error, "YOU_MADE_A_PROGRAMMING_MISTAKE", from EIGEN_STATIC_ASSERT.
Anyone has this issue before? How should I solve it? Thanks!
Finally, I found a post in stackoverflow but I cannot make sure who is the original author. Indeed we need flat function.
session->Run(inputs, { "pred" }, {}, &outputs);
TTypes<float>::Flat indices_flat = outputs[0].flat<float>();
float coutput[6];
for (int i = 0; i<dataSize; i++) {
coutput[i] = indices_flat(i);
cout << "outptut[i]: " << indices_flat(i) << endl;
}

Accessing Iterator After Deletion Causes Crash

so I'm used to coding in C# and have just started using C++ again after a pretty substantial break. Essentially what I'm trying to do is to create a program that has lists of students with IDs, in courses.
I have this code that essentially prints out all available students in courses.
auto allCourses = WSUCourse::getAllCourses();
std::for_each(
allCourses.begin(),
allCourses.end(),
GetCoursePrinter());
The GetCoursePrinter() is called in this code in the constructor
struct GetCoursePrinter
{
void operator () (
MyCourse *coursePtr
)
{
std::cout << coursePtr->getIdentifier() <<
": " <<
coursePtr->getTitle() <<
std::endl;
}
};
My problem is after I delete an enrollment like so
MyEnrollment *enrollmentPtr = MyEnrollment::findEnrollment(
MyStudent::getStudentWithUniqueID(1000002),
MyCourse::getCourseWithIdentifier("CS 2800")
);
delete enrollmentPtr;
And then try to print it with GetCoursePrinter it crashes. I believe this is because it's trying to access something that doesn't exist. What I'm wondering is if there is a way to call something like this
if (allCourses.current() != null)
{
GetCoursePrinter();
}
else
{
//do nothing
}
when you call:
delete enrollmentPtr;
you need to remove this item in environment.