如何在 C++ 中使用 Void 而不会出现关于参数的错误
How to use Void in C++ without getting an Error about Argument
我正在尝试使用 C++ 在 ROOT 中创建一个简单的树 运行 使用这里的教程:https://www.niser.ac.in/sercehep2017/notes/RootTutorial_TTree.pdf.
但是,为什么会出现此错误:
Processing examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")...
input_line_9:2:2: error: no matching function for call to 'tree_example1'
tree_example1("../trisignal/Events/run_01/tag_1_delphes_events.root") /* invoking function corresponding to '.x' */
^~~~~~~~~~~~~
/mnt/c/1/MG5_aMC_v2_6_6/Delphes/examples/tree_example1.C:12:6: note: candidate function not viable: requires 0 arguments, but 1 was provided
void tree_example1 ()
我只是想 运行 一个创建 TTree 的简单代码。
这是我的代码:
/*
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
#else
class ExRootTreeReader;
class ExRootResult;
#endif
*/
void tree_example1 ()
{
//gSystem->Load("libDelphes");
// Create chain of root trees
//TChain chain("Delphes");
//chain.Add(inputFile);
//Open the input file and Create a simple tree
TFile *f = new TFile("eventstrial.root", "RECREATE");
TTree *tree = new TTree("T", "simple tree");
//TTree *tree = &chain;
TRandom r;
//Filling Histograms
TH1F *hist = new TH1F("hist", "", 100, 0., 2.);
//Set up the variables
Float_t px, py, pz, pt;
Double_t random;
UShort_t i;
//Set Variables to Tree's Branches
tree->Branch("px", &px, "px/F");
tree->Branch("py", &py, "py/F");
tree->Branch("pz", &py, "py/F");
tree->Branch("pt", &pt, "pt/F");
tree->Branch("random", &random, "random/D");
for (i = 0; i < 10000; i++)
{
r.Rannor(px,py);
pt = std::sqrt(px*px + py*py);
tree->Fill();
}
f->Write();
f->Close();
tree->Draw("pt>>hist");
hist->SetLineColor(3);
hist->Draw("same");
}
我在我的 ROOT 终端中输入:root -l 'examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")'
如果我写
root -l tree_example1.C
我收到这个错误:
root [0]
Processing tree_example1.C...
*** Break *** segmentation violation
Generating stack trace...
0x00007fdcdda680a0 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const + 0x380 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fae77 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) + 0xa7 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fc4df in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x1df from /home/cucip/builddir/lib/libCling.so
0x00007fdcddac61f1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0x591 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad6084 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x194 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad7476 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0xa6 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddabf64b in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x10b from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd97b68e in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd98fe72 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd984537 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdce3112908 in TApplication::ExecuteFile(char const*, int*, bool) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1156 from /home/cucip/builddir/lib/libCore.so
0x00007fdce31120ac in TApplication::ProcessLine(char const*, bool, int*) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1007 from /home/cucip/builddir/lib/libCore.so
0x00007fdce35e18e2 in TRint::ProcessLineNr(char const*, char const*, int*) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:762 from /home/cucip/builddir/lib/libRint.so
0x00007fdce35e31d9 in TRint::Run(bool) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:421 from /home/cucip/builddir/lib/libRint.so
0x00007fdce3c00a0c in <unknown> from /home/cucip/builddir/bin/root.exe
0x00007fdce2571b97 in __libc_start_main + 0xe7 from /lib/x86_64-linux-gnu/libc.so.6
0x00007fdce3c00a6a in _start + 0x2a from /home/cucip/builddir/bin/root.exe
Root >
正如编译器所说:
需要 0 个参数,但提供了 1 个
void tree_example1 ()
您调用 tree_example1 时使用了一个参数而不是零。
重新定义函数以接受路径
我正在尝试使用 C++ 在 ROOT 中创建一个简单的树 运行 使用这里的教程:https://www.niser.ac.in/sercehep2017/notes/RootTutorial_TTree.pdf.
但是,为什么会出现此错误:
Processing examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")...
input_line_9:2:2: error: no matching function for call to 'tree_example1'
tree_example1("../trisignal/Events/run_01/tag_1_delphes_events.root") /* invoking function corresponding to '.x' */
^~~~~~~~~~~~~
/mnt/c/1/MG5_aMC_v2_6_6/Delphes/examples/tree_example1.C:12:6: note: candidate function not viable: requires 0 arguments, but 1 was provided
void tree_example1 ()
我只是想 运行 一个创建 TTree 的简单代码。 这是我的代码:
/*
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
#else
class ExRootTreeReader;
class ExRootResult;
#endif
*/
void tree_example1 ()
{
//gSystem->Load("libDelphes");
// Create chain of root trees
//TChain chain("Delphes");
//chain.Add(inputFile);
//Open the input file and Create a simple tree
TFile *f = new TFile("eventstrial.root", "RECREATE");
TTree *tree = new TTree("T", "simple tree");
//TTree *tree = &chain;
TRandom r;
//Filling Histograms
TH1F *hist = new TH1F("hist", "", 100, 0., 2.);
//Set up the variables
Float_t px, py, pz, pt;
Double_t random;
UShort_t i;
//Set Variables to Tree's Branches
tree->Branch("px", &px, "px/F");
tree->Branch("py", &py, "py/F");
tree->Branch("pz", &py, "py/F");
tree->Branch("pt", &pt, "pt/F");
tree->Branch("random", &random, "random/D");
for (i = 0; i < 10000; i++)
{
r.Rannor(px,py);
pt = std::sqrt(px*px + py*py);
tree->Fill();
}
f->Write();
f->Close();
tree->Draw("pt>>hist");
hist->SetLineColor(3);
hist->Draw("same");
}
我在我的 ROOT 终端中输入:root -l 'examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")'
如果我写 root -l tree_example1.C
我收到这个错误:
root [0]
Processing tree_example1.C...
*** Break *** segmentation violation
Generating stack trace...
0x00007fdcdda680a0 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const + 0x380 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fae77 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) + 0xa7 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fc4df in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x1df from /home/cucip/builddir/lib/libCling.so
0x00007fdcddac61f1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0x591 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad6084 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x194 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad7476 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0xa6 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddabf64b in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x10b from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd97b68e in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd98fe72 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd984537 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdce3112908 in TApplication::ExecuteFile(char const*, int*, bool) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1156 from /home/cucip/builddir/lib/libCore.so
0x00007fdce31120ac in TApplication::ProcessLine(char const*, bool, int*) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1007 from /home/cucip/builddir/lib/libCore.so
0x00007fdce35e18e2 in TRint::ProcessLineNr(char const*, char const*, int*) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:762 from /home/cucip/builddir/lib/libRint.so
0x00007fdce35e31d9 in TRint::Run(bool) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:421 from /home/cucip/builddir/lib/libRint.so
0x00007fdce3c00a0c in <unknown> from /home/cucip/builddir/bin/root.exe
0x00007fdce2571b97 in __libc_start_main + 0xe7 from /lib/x86_64-linux-gnu/libc.so.6
0x00007fdce3c00a6a in _start + 0x2a from /home/cucip/builddir/bin/root.exe
Root >
正如编译器所说:
需要 0 个参数,但提供了 1 个 void tree_example1 ()
您调用 tree_example1 时使用了一个参数而不是零。 重新定义函数以接受路径