Error in <TClass::New>: cannot create object of class


I have a weird problem.
I write a custom class with dictionary generated into a TTree. This class also has vectors inside. When I try to read the data from the TTree I get:


[code]#ifndef MODDATA_H
#define MODDATA_H

#include “Rtypes.h”
#include “datastructure/ModPropVector2D.h”
#include “Constants.h”

class ModData


std::vector pedestal;
std::vector cmnoise;
std::vector rawnoise; //noise without CMC
std::vector snoise; //noise after CMC
std::vector gnoise; //noise after CMC
std::vector noise; //noise after CMC
std::vector noisecal; //noise after CMC
std::vector clwid; //cluster width histograms
std::vector hits;
std::vector hitsperevent;
std::vector<std::vector > hitspersubevent;
std::vector stripok; //noisy strips are masked with 0, others 1
unsigned short number_strips;
unsigned short number_strips_zone; //number of strips in current zone
unsigned short number_stripsok;
double perc_stripsok;
double tm_noise; //Truncated Mean Noise
double gf_noise; //Gauss Fit Noise
double mpsignal;
double mpsignalcal;
double meansignal;
unsigned int hitentries; //all unsigned long changed to unsigned int by Erik 1611101616
double mpsnr;
double meanclwid;

ModData(int the_max_apv_per_mod,
int the_apv_channels,
int the_max_subevents,
int the_max_hits_per_event);

ModData(const hat::ModProp* readmodprop);

ModData(const ModData& other);

virtual ~ModData();





[code]#include “ModData.h”


using namespace std;

ModData::ModData(int the_max_apv_per_mod,
int the_apv_channels,
int the_max_subevents,
int the_max_hits_per_event) :
pedestal( vector(the_max_apv_per_modthe_apv_channels, 0) ),
cmnoise( vector(the_max_apv_per_mod
the_apv_channels/32, 0) ),
rawnoise( vector(the_max_apv_per_modthe_apv_channels, 0) ),
snoise( vector(the_max_apv_per_mod
the_apv_channels, 0) ),
gnoise( vector(the_max_apv_per_modthe_apv_channels, 0) ),
noise( vector(the_max_apv_per_mod
the_apv_channels, 0) ),
noisecal( vector(the_max_apv_per_modthe_apv_channels, 0) ),
clwid( vector(the_max_apv_per_mod
the_apv_channels, 0) ),
hits( vector(the_max_apv_per_modthe_apv_channels, 0) ),
hitsperevent( vector(the_max_apv_per_mod
the_apv_channels, 0) ),
hitspersubevent( vector<vector >(the_max_subevents, vector(the_max_hits_per_event, 0) ) ),
stripok( vector(the_max_apv_per_mod*the_apv_channels, 0) ),
number_strips_zone(0), //number of strips in current zone
tm_noise(0), //Truncated Mean Noise
gf_noise(0), //Gauss Fit Noise

ModData::ModData(const hat::ModProp* readmodprop) :
pedestal( readmodprop->pedestal ),
cmnoise( readmodprop->cmnoise ),
rawnoise( readmodprop->rawnoise ),
snoise( readmodprop->snoise ),
gnoise( readmodprop->gnoise ),
noise( readmodprop->noise ),
noisecal( readmodprop->noisecal ),
clwid( readmodprop->clwid ),
hits( readmodprop->hits ),
hitsperevent( readmodprop->hitsperevent ),
hitspersubevent( readmodprop->hitspersubevent ),
stripok( readmodprop->stripok ),
number_strips( readmodprop->number_strips ),
number_strips_zone( readmodprop->number_strips_zone ), //number of strips in current zone
number_stripsok( readmodprop->number_stripsok ),
perc_stripsok( readmodprop->perc_stripsok ),
tm_noise( readmodprop->tm_noise ), //Truncated Mean Noise
gf_noise( readmodprop->gf_noise ), //Gauss Fit Noise
mpsignal( readmodprop->mpsignal ),
mpsignalcal( readmodprop->mpsignalcal ),
meansignal( readmodprop->meansignal ),
hitentries( readmodprop->hitentries ),
mpsnr( readmodprop->mpsnr ),
meanclwid( readmodprop->meanclwid )

ModData::ModData(const ModData& other) :
pedestal( other.pedestal ),
cmnoise( other.cmnoise ),
rawnoise( other.rawnoise ),
snoise( other.snoise ),
gnoise( other.gnoise ),
noise( other.noise ),
noisecal( other.noisecal ),
clwid( other.clwid ),
hits( other.hits ),
hitsperevent( other.hitsperevent ),
hitspersubevent( other.hitspersubevent ),
stripok( other.stripok ),
number_strips( other.number_strips ),
number_strips_zone( other.number_strips_zone ), //number of strips in current zone
number_stripsok( other.number_stripsok ),
perc_stripsok( other.perc_stripsok ),
tm_noise( other.tm_noise ), //Truncated Mean Noise
gf_noise( other.gf_noise ), //Gauss Fit Noise
mpsignal( other.mpsignal ),
mpsignalcal( other.mpsignalcal ),
meansignal( other.meansignal ),
hitentries( other.hitentries ),
mpsnr( other.mpsnr ),
meanclwid( other.meanclwid )

ModData::~ModData() {}[/code]

I am reading the data like:

TFile *f = new TFile; TTree *tmodprop = new TTree; int tmodpropentr; ModData* mprop = 0; f = new TFile(filename,"READ"); tmodprop = dynamic_cast<TTree*>(f->Get("TCluster2DCNM_Module_4_Zone_1_tmodprop")); tmodpropentr = tmodprop->GetEntries(); tmodprop->SetBranchAddress("mprops",&mprop);

Any ideas?

BR Erik

Could it be because ModData has no empty default constructor? Like


Yes, this is the reason. For I/O you need to either have a default constructor (i.e. a constructor without any argument or with defaults for all its arguments) or a constructor taking exactly one argument of type TRootIOCtor*


Figured it out myself just a moment ago.
But nevertheless thank you very much.

so long

Considering the default constructor of TH1 is protected, what’s the best way to have a TH1* in a custom class that will be written out to a root file as a branch of such a type? Having the TH1* in CustomClass just causes:

Error in TClass::New: cannot create object of class TH1

when writing the file.


– Nil

Nevermind. This can be done by having a pointer to a TH1 and setting it to NULL in the default constructor.

– Nil