51 TLeaf::TLeaf(TBranch *parent,
const char* name,
const char *)
63 fLeafCount = GetLeafCounter(fLen);
70 const char *bracket = strchr(name,
'[');
71 if (bracket) fName.ReplaceAll(bracket,
"");
77 TLeaf::TLeaf(
const TLeaf& lf) :
81 fLenType(lf.fLenType),
83 fIsRange(lf.fIsRange),
84 fIsUnsigned(lf.fIsUnsigned),
85 fLeafCount(lf.fLeafCount),
87 fLeafCountValues(nullptr)
94 TLeaf& TLeaf::operator=(
const TLeaf& lf)
97 TNamed::operator=(lf);
100 fLenType=lf.fLenType;
102 fIsRange=lf.fIsRange;
103 fIsUnsigned=lf.fIsUnsigned;
104 fLeafCount=lf.fLeafCount;
106 if (fLeafCountValues) {
107 fLeafCountValues->fStartEntry = -1;
108 fLeafCountValues->fValues.resize(0);
120 TTree* tree = fBranch->GetTree();
123 TObjArray *lst = tree->GetListOfLeaves();
124 if (lst->GetLast()!=-1) lst->Remove(
this);
128 delete fLeafCountValues;
134 void TLeaf::Browse(TBrowser* b)
136 if (strchr(GetName(),
'.')) {
137 fBranch->GetTree()->Draw(GetName(),
"", b ? b->GetDrawOption() :
"");
139 if ((fBranch->GetListOfLeaves()->GetEntries() > 1) ||
140 (strcmp(fBranch->GetName(), GetName()) != 0)) {
141 TString name(fBranch->GetName());
142 if (!name.EndsWith(
".")) name +=
".";
144 fBranch->GetTree()->Draw(name,
"", b ? b->GetDrawOption() :
"");
146 fBranch->GetTree()->Draw(GetName(),
"", b ? b->GetDrawOption() :
"");
157 void TLeaf::FillBasket(TBuffer &)
165 Int_t *TLeaf::GenerateOffsetArrayBase(Int_t base, Int_t events)
const
170 Int_t *retval =
new Int_t[events];
171 if (R__unlikely(!retval || !fLeafCount)) {
175 Long64_t orig_entry = std::max(fBranch->GetReadEntry(), 0LL);
176 const std::vector<Int_t> *countValues = fLeafCount->GetLeafCountValues(orig_entry, events);
178 if (!countValues || ((Int_t)countValues->size()) < events) {
179 Error(
"GenerateOffsetArrayBase",
"The leaf %s could not retrieve enough entries from its branch count (%s), ask for %d and got %ld",
180 GetName(), fLeafCount->GetName(), events, (long)(countValues ? countValues->size() : -1));
184 Int_t header = GetOffsetHeaderSize();
186 for (Int_t idx = 0, offset = base; idx < events; idx++) {
187 retval[idx] = offset;
188 len = (*countValues)[idx];
189 offset += fLenType * len + header;
211 TLeaf* TLeaf::GetLeafCounter(Int_t& countval)
const
214 const char* name = GetTitle();
215 char* bleft = (
char*) strchr(name,
'[');
220 Int_t nch = strlen(bleft);
221 char* countname =
new char[nch+1];
222 strcpy(countname, bleft);
223 char* bright = (
char*) strchr(countname,
']');
230 char *bleft2 = (
char*) strchr(countname,
'[');
232 nch = strlen(countname);
236 Error(
"GetLeafCounter",
"TLeaf %s is not setup properly, fBranch is null.",GetName());
240 if (fBranch->GetTree() == 0) {
241 Error(
"GetLeafCounter",
"For Leaf %s, the TBranch %s is not setup properly, fTree is null.",GetName(),fBranch->GetName());
245 TTree* pTree = fBranch->GetTree();
247 TLeaf* leaf = (TLeaf*) GetBranch()->GetListOfLeaves()->FindObject(countname);
250 leaf = (TLeaf*) pTree->GetListOfLeaves()->FindObject(countname);
253 if (!leaf && strchr(GetName(),
'.')) {
254 char* withdot =
new char[strlen(GetName())+strlen(countname)+1];
255 strcpy(withdot, GetName());
256 char* lastdot = strrchr(withdot,
'.');
257 strcpy(lastdot, countname);
258 leaf = (TLeaf*) pTree->GetListOfLeaves()->FindObject(countname);
262 if (!leaf && strchr(countname,
'.')) {
265 leaf = pTree->FindLeaf(countname);
272 sscanf(bleft2,
"[%d]", &i);
278 bleft = (
char*) strchr(bleft2,
'[');
282 sscanf(bleft,
"[%d]", &i);
291 for (i = 0; i < nch; i++) {
292 if (!isdigit(countname[i])) {
299 sscanf(countname,
"%d", &countval);
301 sscanf(bleft2,
"[%d]", &i);
307 bleft = (
char*) strchr(bleft2,
'[');
311 sscanf(bleft,
"[%d]", &i);
326 const TLeaf::Counts_t *TLeaf::GetLeafCountValues(Long64_t start, Long64_t len)
328 if (len <= 0 || !IsRange())
331 if (fLeafCountValues) {
332 if (fLeafCountValues->fStartEntry == start && len < (Long64_t)fLeafCountValues->fValues.size())
334 return &fLeafCountValues->fValues;
336 if (start >= fLeafCountValues->fStartEntry &&
337 (start+len) <= (Long64_t)(fLeafCountValues->fStartEntry + fLeafCountValues->fValues.size()))
339 auto &values(fLeafCountValues->fValues);
340 values.erase(values.begin(), values.begin() + start-fLeafCountValues->fStartEntry);
344 fLeafCountValues =
new LeafCountValues();
348 fLeafCountValues->fValues.clear();
349 fLeafCountValues->fValues.reserve(len);
350 fLeafCountValues->fStartEntry = start;
352 auto branch = GetBranch();
353 Long64_t orig_leaf_entry = branch->GetReadEntry();
354 for (Long64_t idx = 0; idx < len; ++idx) {
355 branch->GetEntry(start + idx);
356 auto size =
static_cast<Int_t
>(GetValue());
357 fLeafCountValues->fValues.push_back( size );
359 branch->GetEntry(orig_leaf_entry);
360 return &(fLeafCountValues->fValues);
366 Int_t TLeaf::GetLen()
const
370 Int_t len = Int_t(fLeafCount->GetValue());
371 if (len > fLeafCount->GetMaximum()) {
372 Error(
"GetLen",
"Leaf counter is greater than maximum! leaf: '%s' len: %d max: %d", GetName(), len, fLeafCount->GetMaximum());
373 len = fLeafCount->GetMaximum();
391 Int_t TLeaf::ResetAddress(
void* addr, Bool_t calledFromDestructor)
396 Bool_t deleteValue = kFALSE;
397 if (TestBit(kNewValue)) {
403 if (!calledFromDestructor) {
407 fNdata = (fLeafCount->GetMaximum() + 1) * fLen;
427 void TLeaf::SetLeafCount(TLeaf *leaf)
429 if (IsZombie() && (fLen == -1) && leaf) {
442 void TLeaf::Streamer(TBuffer &b)
446 Version_t R__v = b.ReadVersion(&R__s, &R__c);
448 b.ReadClassBuffer(TLeaf::Class(),
this, R__v, R__s, R__c);
458 b.CheckByteCount(R__s, R__c, TLeaf::IsA());
467 b.WriteClassBuffer(TLeaf::Class(),
this);