Skip to content

Removing and adding elements with dec deny destroy has client errors #39

@alja

Description

@alja

#include "ROOT/REvePointSet.hxx"
#include "ROOT/REveStraightLineSet.hxx"
#include "ROOT/REveCompound.hxx"
#include "ROOT/REveDataSimpleProxyBuilder.hxx"
#include "ROOT/REveGeoShape.hxx"
#include "ROOT/REveLine.hxx"
#include "FireworksWeb/Core/interface/FWProxyBuilderFactory.h"
#include "FireworksWeb/Core/interface/FWWebEventItem.h"
#include "FireworksWeb/Core/interface/FWGeometry.h"
#include "FireworksWeb/Core/interface/fwLog.h"
#include "FireworksWeb/Core/interface/FWWebEventItem.h"
#include "FireworksWeb/Tracks/interface/TrackUtils.h"

#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"

using namespace ROOT::Experimental;

class FWSiStripClusterProxyBuilder: public REveDataSimpleProxyBuilder
{
private:
std::vector<REveGeoShape*> m_shapeList;

public:
REGISTER_FWPB_METHODS();
FWSiStripClusterProxyBuilder(void) {}

using REveDataSimpleProxyBuilder::BuildItem;
void BuildItem(const void *, int, REveElement *, const REveViewContext *) {}

using REveDataSimpleProxyBuilder::BuildItemViewType;
void BuildItemViewType(const void *, int, REveElement *, const std::string &, const REveViewContext *) {}

// reuse shapes
using REveDataSimpleProxyBuilder::Clean;
void Clean()
{
printf("virutal clean \n");
REveDataSimpleProxyBuilder::Clean();

  for (auto &i : m_shapeList)i->SetRnrSelf(false);

}

using REveDataSimpleProxyBuilder::CollectionBeingDestroyed;
void CollectionBeingDestroyed(const REveDataCollection* iItem)
{
REveDataSimpleProxyBuilder::CollectionBeingDestroyed(iItem);
for (auto &i : m_shapeList)i->DecDenyDestroy();
}

using REveDataSimpleProxyBuilder::BuildProduct;
void BuildProduct(const REveDataCollection *collection, REveElement *product, const REveViewContext *) override
{
int index = 0;
auto context = fireworks::Context::getInstance();
FWWebEventItem item = dynamic_cast<FWWebEventItem>(Collection());

item->SetMainTransparency(70);

const edmNew::DetSetVector<SiStripCluster>* clusters = nullptr;
item->get(clusters);
if (!clusters)
{
  return;
}

// check if need to create more shapes
int sdiff = clusters->size() - m_shapeList.size();
for (int i = 0; i <= sdiff; ++i) {
m_shapeList.push_back(new REveGeoShape("Det"));
m_shapeList.back()->IncDenyDestroy();
m_shapeList.back()->SetPickable(false);
m_shapeList.back()->SetMainTransparency(80);
}

auto shapeIt = m_shapeList.begin();

const FWGeometry *geom = context->getGeom();
for (edmNew::DetSetVector<SiStripCluster>::const_iterator set = clusters->begin(), setEnd = clusters->end(); set != setEnd;
     ++set)
{
     unsigned int id = set->detId();
     if (!geom->contains(id))
     {
        fwLog(fwlog::kWarning) << "failed get geometry of SiStripCluster with detid: " << id << std::endl;
        continue;
     }
     const FWGeometry::GeomDetInfo& info = *geom->find(id);

     double array[16] = {info.matrix[0],
                       info.matrix[3],
                       info.matrix[6],
                       0.,
                       info.matrix[1],
                       info.matrix[4],
                       info.matrix[7],
                       0.,
                       info.matrix[2],
                       info.matrix[5],
                       info.matrix[8],
                       0.,
                       info.translation[0],
                       info.translation[1],
                       info.translation[2],
                       1.};

     // note REveGeoShape owns shape
     REveGeoShape *shape = *shapeIt;
     delete shape->GetShape();

     try {
        shape->SetShape(geom->getShape(info));
        shape->SetTransMatrix(array);
        shape->SetRnrSelf(true);
        shapeIt++;
     }
     catch (std::exception& e) { std::cout << e.what(); }
     bool addGeoShape = false;

     for (edmNew::DetSet<SiStripCluster>::const_iterator ic = set->begin(); ic != set->end(); ++ic )
     {
        REveElement *itemHolder = GetHolder(product, index);

        if (!addGeoShape)
        {
           SetupAddElement(shape, itemHolder);
           addGeoShape = true;
        }
        
        REveLine* line = new REveLine();
        SetupAddElement(line, itemHolder);
        float localTop[3] = {0.0, 0.0, 0.0};
        float localBottom[3] = {0.0, 0.0, 0.0};
        fireworks::localSiStrip((*ic).firstStrip(), localTop, localBottom, geom->getParameters(id), id);
        float globalTop[3];
        float globalBottom[3];
        geom->localToGlobal(id, localTop, globalTop, localBottom, globalBottom);
        line->SetPoint(0, globalTop[0], globalTop[1], globalTop[2]);
        line->SetPoint(1, globalBottom[0], globalBottom[1], globalBottom[2]);

        index++;

     }
     if (product)
       printf("product children %d \n", product->NumChildren());
   }

}

};

REGISTER_FW2PROXYBUILDER_BASE(FWSiStripClusterProxyBuilder, edmNew::DetSetVector, "SiStripCluster");
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions