error: unknown type name 'JetProbaCalib'
JetProbaCalib* theanalyzer = new JetProbaCalib(&c);
the class JetProbaCalib, should be defined in JetProbaCalib.C, but the problem does not recognize the class , how to fix this problem? BTW, I am using root version 6.02/13.
Hi,
I tried the way you post,
it still shows the same error, unknown type name ‘JetProbaCalib’
looks like the root will “compile” the the main marcro (in the example is myMarco) first, before it run the ProcessLine to load the needed library even if I run the myMarco without adding ++.
by the way, the original marco I post, it can be run line by line within root interactively, the error appear when combining everything into a marco and run the marco by root marco.C.
JetProbaCalib.h :
#ifndef JetProbaCalib_h
#define JetProbaCalib_h
#include "CategoryDef.h"
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <iostream>
#include <fstream>
#include <TH1.h>
#include "CategoryDef.h"
#include "CategoriesDefinition.h"
#include "CategoryDefCollection.h"
#include "TList.h"
class JetProbaCalib {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Declaration of leaf types
Int_t nBitTrigger;
Int_t BitTrigger[3]; //[nBitTrigger]
Int_t Run;
Float_t Jet_pt[200]; //[nJet]
......
// List of branches
TBranch *b_Run; //!
TBranch *b_Evt; //!
.......
JetProbaCalib(TTree *tree=0);
virtual ~JetProbaCalib();
virtual Int_t Cut(Long64_t entry);
virtual Int_t GetEntry(Long64_t entry);
virtual Long64_t LoadTree(Long64_t entry);
virtual void Init(TTree *tree);
virtual void Loop();
virtual Bool_t Notify();
virtual void Show(Long64_t entry = -1);
#endif
#ifdef JetProbaCalib_cxx
JetProbaCalib::JetProbaCalib(TTree *tree) : fChain(0)
{
TChain *superTree = new TChain("btagana/ttree");
if (tree == 0) {
//superTree->Add("/opt/sbg/cms/ui8_data2/ccollard/BTAG/MC_Dan_2013April/PythiaQCD/QCD_Pt-800to1000_Inclusive_8TeV_pythia6_Summer12_DR53X-PU_S10_AODSIM/TrackTree_*.root");
Init(superTree);
} else Init(tree);
}
JetProbaCalib::~JetProbaCalib()
{
if (!fChain) return;
delete fChain->GetCurrentFile();
}
Int_t JetProbaCalib::GetEntry(Long64_t entry)
{
// Read contents of entry.
if (!fChain) return 0;
return fChain->GetEntry(entry);
}
Long64_t JetProbaCalib::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
if (!fChain) return -5;
Long64_t centry = fChain->LoadTree(entry);
if (centry < 0) return centry;
if (fChain->GetTreeNumber() != fCurrent) {
fCurrent = fChain->GetTreeNumber();
Notify();
}
return centry;
}
void JetProbaCalib::Init(TTree *tree)
{
if (!tree) return;
fChain = tree;
fCurrent = -1;
fChain->SetMakeClass(1);
fChain->SetBranchAddress("nBitTrigger", &nBitTrigger, &b_nBitTrigger);
fChain->SetBranchAddress("BitTrigger", BitTrigger, &b_BitTrigger);
fChain->SetBranchAddress("Run", &Run, &b_Run);
...
Notify();
}
Bool_t JetProbaCalib::Notify()
{
return kTRUE;
}
void JetProbaCalib::Show(Long64_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
if (!fChain) return;
fChain->Show(entry);
}
Int_t JetProbaCalib::Cut(Long64_t entry)
{
// This function may be called from Loop.
// returns 1 if entry is accepted.
// returns -1 otherwise.
return 1;
}
#endif // #ifdef JetProbaCalib_cxx
The #include should have helped, it contains the declaration of JetProbaCalib. Are you sure you ran the macro I suggested - with the same error message? Is the section surrounded by #ifdef JetProbaCalib_cxx part of the same file JetProbaCalib.h?
ah,the error is different , by following your suggestion, include the #include “JetProbaCalib.h” at beginning of marco, and the error is the now :
IncrementalExecutor::executeFunction: symbol ‘_ZN13JetProbaCalibC1EP5TTree’ unresolved while linking function’_Z15__cling_Un1Qu30Pv’!
this error is similar to that if I run gROOT->ProcessLine(".L JetProbaCalib.C+g") ; without adding gROOT->ProcessLine(".L CategoriesDefinition.C++"); I tried also add #include “CategoriesDefinition.h” at beginning but still the same.
// myMacro.C
// You can skip these #includes if you wish:
#include "JetProbaCalib.h"
#include <TROOT.h>
#include <TChain.h>
// This compiles / loads the library before running anything.
R__LOAD_LIBRARY(CategoriesDefinition.C++)
R__LOAD_LIBRARY(JetProbaCalib.C+g)
void myMacro() {
TChain c("btagana/ttree");
c.Add("ntuple.root")
JetProbaCalib* theanalyzer = new JetProbaCalib(&c);
theanalyzer->Loop();
}
I switch from root 6.02 to 6.08, since 6.02 does not recognize the R__LOAD_LIBRARY,
it now did load and compile the library first, but shows lots of error,
and in the end , it still shows error: unknown type name
’JetProbaCalib’
JetProbaCalib* theanalyzer = new JetProbaCalib();