Changeset 18838 for trunk/FACT++/src


Ignore:
Timestamp:
04/18/17 20:41:25 (8 years ago)
Author:
tbretz
Message:
Fixed updating of existing branches.
File:
1 edited

Legend:

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

    r18837 r18838  
    406406
    407407
     408#ifdef HAVE_ROOT
     409template<typename T>
     410void SetBranch(TTree *ttree, const string &bname, const MyColumn &col)
     411{
     412    TBranch *b = ttree->GetBranch(bname.c_str());
     413
     414    T *address = reinterpret_cast<T*>(col.ptr)+col.first;
     415    if (b)
     416        b->SetAddress(address);
     417    else
     418        ttree->Branch(bname.c_str(), address);
     419}
     420#endif
     421
    408422// --------------------------------------------------------------------------
    409423//
     
    455469
    456470    // FIXME: Add header values
    457     TTree *ttree = tfile ? new TTree(fKeyMap.find("EXTNAME")->second.value.c_str(), Tools::Form("From N=%d [cnt=%d] {filter=%s}", first, limit, filter.c_str()).c_str()) : 0;
     471    TTree *ttree = 0;
     472    if (tfile)
     473    {
     474        const string tname = fKeyMap.find("EXTNAME")->second.value;
     475        tfile->GetObject(tname.c_str(), ttree);
     476        if (!ttree)
     477            ttree = new TTree(tname.c_str(), Tools::Form("From N=%d [cnt=%d] {filter=%s}", first, limit, filter.c_str()).c_str());
     478    }
    458479#endif
    459480
     
    501522            {
    502523            case 'B':
    503                 ttree->Branch(branch.c_str(), reinterpret_cast<unsigned char*>(it->ptr)+it->first);
     524                SetBranch<unsigned char>(ttree, branch, *it);
    504525                break;
    505526            case 'L':
    506                 ttree->Branch(branch.c_str(), reinterpret_cast<bool*>(it->ptr)+it->first);
     527                SetBranch<bool>(ttree, branch, *it);
    507528                break;
    508529            case 'I':
    509                 ttree->Branch(branch.c_str(), reinterpret_cast<int16_t*>(it->ptr)+it->first);
     530                SetBranch<int16_t>(ttree, branch, *it);
    510531                break;
    511532            case 'J':
    512                 ttree->Branch(branch.c_str(), reinterpret_cast<int32_t*>(it->ptr)+it->first);
     533                SetBranch<int32_t>(ttree, branch, *it);
    513534                break;
    514535            case 'K':
    515                 ttree->Branch(branch.c_str(), reinterpret_cast<int64_t*>(it->ptr)+it->first);
     536                SetBranch<int64_t>(ttree, branch, *it);
    516537                break;
    517538            case 'E':
    518                 ttree->Branch(branch.c_str(), reinterpret_cast<float*>(it->ptr)+it->first);
     539                SetBranch<float>(ttree, branch, *it);
    519540                break;
    520541            case 'D':
    521                 ttree->Branch(branch.c_str(), reinterpret_cast<double*>(it->ptr)+it->first);
     542                SetBranch<double>(ttree, branch, *it);
    522543                break;
    523544            default:
     
    630651        fout << endl;
    631652
    632         ttree->Write();
     653        ttree->Write("", TObject::kWriteDelete);
    633654        delete tfile;
    634655    }
     
    12731294        ("filter,f",    var<string>(""),        "Filter to restrict the selection of events (e.g. '[0]>10 && [0]<20';  does not work with stat and minmax yet)")
    12741295        ("overwrite",   po_switch(),            "Force overwriting an existing root file ('RECREATE')")
    1275         ("update",      po_switch(),            "Update an existing root file with the new tree ('UPDATE')")
     1296        ("update",      po_switch(),            "Update an existing root file ('UPDATE') or an existing tree with more data.")
    12761297        ("compression", var<uint16_t>(1),       "zlib compression level for the root file")
    12771298#endif
Note: See TracChangeset for help on using the changeset viewer.