Ignore:
Timestamp:
10/26/19 16:32:49 (5 years ago)
Author:
tbretz
Message:
Some fixed to be able to correctly update a tree.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/csv2root.cc

    r19796 r19798  
    398398        }
    399399
    400         ttree[index]->Fill();
     400        // Fill only branches for which an adress was set
     401        // If we fill the tree, we get empty entries at the
     402        // end of the already written branches
     403        TIter NextBranch(ttree[index]->GetListOfBranches());
     404        TBranch *b=0;
     405        while ((b=static_cast<TBranch*>(NextBranch())))
     406            if (b->GetAddress())
     407                b->Fill();
     408    }
     409
     410    for (auto it=ttree.begin(); it!=ttree.end(); it++)
     411    {
     412        if (update)
     413        {
     414            TIter NextBranch((*it)->GetListOfBranches());
     415            TBranch *b=0;
     416            while ((b=static_cast<TBranch*>(NextBranch())))
     417                if (b->GetAddress() && b->GetEntries()>0)
     418                {
     419                    (*it)->SetEntries(b->GetEntries());
     420                    break;
     421                }
     422        }
     423
     424        (*it)->Write("", TObject::kOverwrite);
    401425    }
    402426
     
    404428    {
    405429        cout << valid << " data rows found in " << line << " lines (excl. title)." << endl;
    406         if (!update || !entries)
    407         {
    408             for (size_t i=0; i<ttree.size(); i++)
    409                 cout << ttree[i]->GetEntries() << " rows filled into tree #" << i << "." << endl;
    410         }
     430        for (size_t i=0; i<ttree.size(); i++)
     431            cout << ttree[i]->GetEntries() << " rows filled into tree #" << i << "." << endl;
    411432    }
    412433
     
    414435        cerr << "\nWARNING - Number of updated entries does not match number of entries in tree!\n" << endl;
    415436
    416     for (auto it=ttree.begin(); it!=ttree.end(); it++)
    417         (*it)->Write("", TObject::kOverwrite);
    418437    tfile.Close();
    419438
Note: See TracChangeset for help on using the changeset viewer.