CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Fireworks/Core/src/FWEveViewManager.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWEveViewManager
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Chris Jones, Alja Mrak-Tadel
00010 //         Created:  Thu Mar 18 14:11:32 CET 2010
00011 // $Id: FWEveViewManager.cc,v 1.46 2013/01/21 20:33:28 chrjones Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "TEveManager.h"
00018 #include "TEveSelection.h"
00019 #include "TEveScene.h"
00020 #include "TEveViewer.h"
00021 #include "TEveCalo.h"
00022 #include "TGLViewer.h"
00023 
00024 #include "Fireworks/Core/interface/FWEveViewManager.h"
00025 #include "Fireworks/Core/interface/FWSelectionManager.h"
00026 #include "Fireworks/Core/interface/FWColorManager.h"
00027 #include "Fireworks/Core/interface/Context.h"
00028 #include "Fireworks/Core/interface/FWInteractionList.h"
00029 #include "Fireworks/Core/interface/CmsShowCommon.h"
00030 #include "Fireworks/Core/interface/fwLog.h"
00031 
00032 // PB
00033 #include "Fireworks/Core/interface/FWEDProductRepresentationChecker.h"
00034 #include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"
00035 #include "Fireworks/Core/interface/FWTypeToRepresentations.h"
00036 #include "Fireworks/Core/interface/FWEventItem.h"
00037 #include "Fireworks/Core/interface/FWProxyBuilderFactory.h"
00038 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
00039 
00040 // viewes
00041 #include "Fireworks/Core/interface/FWGUIManager.h"
00042 #include "Fireworks/Core/interface/FWISpyView.h"
00043 #include "Fireworks/Core/interface/FW3DView.h"
00044 #include "Fireworks/Core/interface/FWGlimpseView.h"
00045 #include "Fireworks/Core/interface/FWEveLegoView.h"
00046 #include "Fireworks/Core/interface/FWHFView.h"
00047 #include "Fireworks/Core/interface/FWRPZView.h"
00048 
00049 #include <boost/bind.hpp>
00050 
00051 class FWViewContext;
00052 
00053 // sentry class block TEveSelection signals when call TEveSelection::Remove/AddElement and
00054 // when process its callbacks
00055 class EveSelectionSentry {
00056 public:
00057    EveSelectionSentry()
00058    {
00059       m_blocked = gEve->GetSelection()->BlockSignals(true);
00060    }
00061    ~EveSelectionSentry()
00062    {
00063      gEve->GetSelection()->BlockSignals(m_blocked);
00064    }
00065 private:
00066    bool m_blocked;
00067 };
00068 
00069 //
00070 //
00071 // constants, enums and typedefs
00072 //
00073 //
00074 // constructors and destructor
00075 //
00076 FWEveViewManager::FWEveViewManager(FWGUIManager* iGUIMgr) :
00077    FWViewManagerBase()
00078 {
00079      
00080    // builders
00081    std::set<std::string> builders;
00082    
00083    std::vector<edmplugin::PluginInfo> available = FWProxyBuilderFactory::get()->available();
00084    std::transform(available.begin(),
00085                   available.end(),
00086                   std::inserter(builders,builders.begin()),
00087                   boost::bind(&edmplugin::PluginInfo::name_,_1));
00088    
00089    if(edmplugin::PluginManager::get()->categoryToInfos().end()!=edmplugin::PluginManager::get()->categoryToInfos().find(FWProxyBuilderFactory::get()->category())) {
00090       available = edmplugin::PluginManager::get()->categoryToInfos().find(FWProxyBuilderFactory::get()->category())->second;
00091       std::transform(available.begin(),
00092                      available.end(),
00093                      std::inserter(builders,builders.begin()),
00094                      boost::bind(&edmplugin::PluginInfo::name_,_1));
00095    }
00096    
00097    
00098    for(std::set<std::string>::iterator it = builders.begin(), itEnd=builders.end();
00099        it!=itEnd;
00100        ++it) {
00101       std::string::size_type first = it->find_first_of('@')+1;
00102       std::string purpose = it->substr(first,it->find_last_of('@')-first);
00103       
00104       first = it->find_last_of('@')+1;
00105       std::string view_str =  it->substr(first,it->find_last_of('#')-first);
00106       int viewTypes = atoi(view_str.c_str());
00107       std::string fullName = *it;
00108       m_typeToBuilder[purpose].push_back(BuilderInfo(*it, viewTypes));
00109    }
00110    
00111    
00112    m_views.resize(FWViewType::kTypeSize); 
00113    
00114    
00115    // view construction called via GUI mng
00116    FWGUIManager::ViewBuildFunctor f =  boost::bind(&FWEveViewManager::buildView, this, _1, _2);
00117    for (int i = 0; i < FWViewType::kTypeSize; i++)
00118    {
00119       if ( i == FWViewType::kTable || i == FWViewType::kTableHLT || i == FWViewType::kTableL1)
00120          continue;
00121       iGUIMgr->registerViewBuilder(FWViewType::idToName(i), f);
00122    }
00123    
00124    // signal
00125    gEve->GetHighlight()->SetPickToSelect(TEveSelection::kPS_Master);
00126    TEveSelection* eveSelection = gEve->GetSelection();
00127    eveSelection->SetPickToSelect(TEveSelection::kPS_Master);  
00128    eveSelection->Connect("SelectionAdded(TEveElement*)","FWEveViewManager",this,"selectionAdded(TEveElement*)");
00129    eveSelection->Connect("SelectionRepeated(TEveElement*)","FWEveViewManager",this,"selectionAdded(TEveElement*)");
00130    eveSelection->Connect("SelectionRemoved(TEveElement*)","FWEveViewManager",this,"selectionRemoved(TEveElement*)");
00131    eveSelection->Connect("SelectionCleared()","FWEveViewManager",this,"selectionCleared()");
00132 
00133    gEve->GetHighlight()->Connect("SelectionAdded(TEveElement*)","FWEveViewManager",this,"highlightAdded(TEveElement*)");
00134    gEve->GetHighlight()->Connect("SelectionRepeated(TEveElement*)","FWEveViewManager",this,"highlightAdded(TEveElement*)");
00135 }
00136 
00137 FWEveViewManager::~FWEveViewManager()
00138 {
00139 }
00140 
00141 //
00142 // member functions
00143 //
00144 
00145 //______________________________________________________________________________
00146 
00152 void
00153 addElements(const FWEventItem *item, FWEveView *view, 
00154             int viewType, TEveElementList* product)
00155 {
00156    if (FWViewType::isProjected(viewType))
00157    {
00158       FWRPZView* rpzView = dynamic_cast<FWRPZView*>(view);
00159       assert(rpzView);
00160       rpzView->importElements(product, item->layer(), rpzView->eventScene());
00161    }
00162    else
00163    {
00164       view->eventScene()->AddElement(product);
00165    }
00166 }
00167 
00181 void
00182 FWEveViewManager::newItem(const FWEventItem* iItem)
00183 {
00184    TypeToBuilder::iterator itFind = m_typeToBuilder.find(iItem->purpose());
00185    
00186    if (itFind == m_typeToBuilder.end())
00187       return;
00188 
00189    std::vector<BuilderInfo>& blist = itFind->second;
00190 
00191    for (size_t bii = 0, bie = blist.size(); bii != bie; ++bii)
00192    {
00193       // 1.
00194       BuilderInfo &info = blist[bii];
00195       std::string builderName = info.m_name;
00196       int builderViewBit =  info.m_viewBit;
00197       
00198       FWProxyBuilderBase* builder = 0;
00199       try
00200       {
00201          builder = FWProxyBuilderFactory::get()->create(builderName);
00202 
00203       }
00204       catch (std::exception& exc)
00205       {
00206          fwLog(fwlog::kWarning) << "FWEveViewManager::newItem ignoring the following exception (probably edmplugincache mismatch):"
00207                                 << std::endl << exc.what();
00208       }
00209       if (!builder)
00210          continue;
00211 
00212       // 2.
00213       // printf("FWEveViewManager::makeProxyBuilderFor NEW builder %s \n", builderName.c_str());
00214       
00215       boost::shared_ptr<FWProxyBuilderBase> pB(builder);
00216       builder->setItem(iItem);
00217       iItem->changed_.connect(boost::bind(&FWEveViewManager::modelChanges,this,_1));
00218       iItem->goingToBeDestroyed_.connect(boost::bind(&FWEveViewManager::removeItem,this,_1));
00219       iItem->itemChanged_.connect(boost::bind(&FWEveViewManager::itemChanged,this,_1));
00220 
00221       // 3.
00222       // This calud be opaque to the user. I would pass a reference to the m_interactionLists to
00223       // FWProxyBuilderBase::setInteractionList and handle different case differently.
00224       if (builder->willHandleInteraction() == false)
00225       {
00226          typedef std::map<const FWEventItem*, FWInteractionList*>::iterator Iterator;
00227          std::pair<Iterator, bool> t = m_interactionLists.insert(std::make_pair(iItem,
00228                                                                                 (FWInteractionList*)0));
00229 
00230          if (t.second == true)
00231             t.first->second = new FWInteractionList(iItem);
00232          //  printf(">>> builder %s add list %p \n", iItem->name().c_str(), il); fflush(stdout);
00233          builder->setInteractionList(t.first->second, iItem->purpose());
00234       }
00235       
00236       builder->setHaveWindow(haveViewForBit(builderViewBit));
00237       
00238       // 4.
00239       for (size_t viewType = 0; viewType < FWViewType::kTypeSize; ++viewType)
00240       {
00241          if (((1 << viewType) & builderViewBit) == 0)
00242             continue;
00243          
00244          FWViewType::EType type = (FWViewType::EType) viewType;
00245          
00246          // printf("%s builder %s supportsd view %s \n",  iItem->name().c_str(), builderName.c_str(), FWViewType::idToName(viewType).c_str());
00247          if (builder->havePerViewProduct((FWViewType::EType) viewType))
00248          { 
00249             for (size_t i = 0, e = m_views[viewType].size(); i != e; ++i)
00250             {
00251                FWEveView *view = m_views[viewType][i].get();
00252                TEveElementList* product = builder->createProduct(type, 
00253                                                                  view->viewContext());
00254                addElements(iItem, view, viewType, product);
00255             }
00256          }
00257          else 
00258          {
00259             TEveElementList* product = builder->createProduct(type, 0);
00260          
00261             for (size_t i = 0, e = m_views[viewType].size(); i != e; ++i)
00262                addElements(iItem, m_views[viewType][i].get(), viewType, product);
00263          }
00264       }
00265       
00266       m_builders[builderViewBit].push_back(pB);
00267    } // loop views
00268 }
00269 
00270 //______________________________________________________________________________
00271 FWViewBase*
00272 FWEveViewManager::buildView(TEveWindowSlot* iParent, const std::string& viewName)
00273 {
00274    FWViewType::EType type = FWViewType::kTypeSize;
00275    for (int i = 0; i < FWViewType::kTypeSize; ++i)
00276    {
00277       if (viewName == FWViewType::idToName(i))
00278       {
00279          type = FWViewType::EType(i);
00280          break;
00281       }
00282    }
00283 
00284    boost::shared_ptr<FWEveView> view;
00285    switch(type)
00286    {
00287       case FWViewType::k3D:
00288          view.reset(new FW3DView(iParent, type));
00289          break;
00290       case FWViewType::kISpy:
00291          view.reset(new FWISpyView(iParent, type));
00292          break;
00293       case FWViewType::kRhoPhi:
00294       case FWViewType::kRhoZ:
00295       case FWViewType::kRhoPhiPF:
00296          view.reset(new FWRPZView(iParent, type));
00297          break;
00298       case FWViewType::kLego:
00299       case FWViewType::kLegoPFECAL:
00300          view.reset(new FWEveLegoView(iParent, type));
00301          break;
00302       case FWViewType::kLegoHF:
00303          view.reset(new FWHFView(iParent, type));
00304          break;
00305       case FWViewType::kGlimpse:
00306          view.reset(new FWGlimpseView(iParent, type));
00307          break;
00308       default:
00309          break;
00310    }
00311 
00312    m_views[type].push_back(boost::shared_ptr<FWEveView> (view));
00313    return finishViewCreate(m_views[type].back());
00314 }
00315 
00316 FWEveView*
00317 FWEveViewManager::finishViewCreate(boost::shared_ptr<FWEveView> view)
00318 {
00319    // printf("new view %s added \n", view->typeName().c_str());
00320    gEve->DisableRedraw();
00321 
00322    // set geometry and calo data
00323    view->setContext(context()); 
00324 
00325    FWColorManager::setColorSetViewer(view->viewerGL(),  context().colorManager()->background());
00326 
00327    // set proxies have a window falg
00328    int viewerBit = 1 << view->typeId();   
00329    if (m_views[view->typeId()].size() == 1)
00330    {
00331       for ( std::map<int, BuilderVec>::iterator i = m_builders.begin(); i!=  m_builders.end(); ++i)
00332       {
00333          int builderViewBit = i->first;
00334          BuilderVec& bv =  i->second;
00335          if (viewerBit == (builderViewBit & viewerBit))
00336          {
00337             for(BuilderVec_it bIt = bv.begin(); bIt != bv.end(); ++bIt)
00338             {
00339                (*bIt)->setHaveWindow(true);
00340             }
00341          }
00342       }
00343    }
00344     
00345    FWRPZView* rpzView = dynamic_cast<FWRPZView*>(view.get());
00346    for ( std::map<int, BuilderVec>::iterator i = m_builders.begin(); i!=  m_builders.end(); ++i)
00347    {
00348       int builderViewBit = i->first;
00349       BuilderVec& bv =  i->second;
00350       if (viewerBit == (builderViewBit & viewerBit))
00351       { 
00352          for(BuilderVec_it bIt = bv.begin(); bIt != bv.end(); ++bIt)
00353          {
00354             // it is ok to call create even for shared productsm since
00355             // builder map key garanties that
00356             TEveElementList* product = (*bIt)->createProduct(view->typeId(), view->viewContext());
00357 
00358             if ((*bIt)->havePerViewProduct((FWViewType::EType)view->typeId()))
00359             {
00360                // view owned
00361                (*bIt)->build();
00362                if (rpzView)
00363                {
00364                   rpzView->importElements(product, (*bIt)->item()->layer(), rpzView->ownedProducts());
00365                }
00366                else
00367                {
00368                   view->ownedProducts()->AddElement(product);
00369                }
00370             }
00371             else
00372             {
00373                // shared
00374                if (rpzView)
00375                {
00376                   rpzView->importElements(product, (*bIt)->item()->layer(), rpzView->eventScene());
00377                }
00378                else
00379                {
00380                   view->eventScene()->AddElement(product);
00381                }
00382                  
00383             }
00384          }
00385       }
00386    }
00387 
00388    view->beingDestroyed_.connect(boost::bind(&FWEveViewManager::beingDestroyed,this,_1));
00389 
00390    view->setupEnergyScale(); // notify PB for energy scale
00391 
00392    gEve->EnableRedraw();
00393    view->viewerGL()->UpdateScene();
00394    gEve->Redraw3D();   
00395 
00396    return view.get();
00397 }
00398 
00399 void
00400 FWEveViewManager::beingDestroyed(const FWViewBase* vb)
00401 {
00402    FWEveView* view = (FWEveView*) vb;
00403    int typeId = view->typeId();
00404   
00405    int viewerBit = 1 << typeId;
00406    int nviews = m_views[typeId].size(); 
00407    for ( std::map<int, BuilderVec>::iterator i = m_builders.begin(); i!= m_builders.end(); ++i)
00408    {
00409       int builderBit = i->first;
00410       if (viewerBit == (builderBit & viewerBit)) // check only in case if connected
00411       {
00412          BuilderVec& bv =  i->second;
00413 
00414          // remove view-owned product
00415          if (viewerBit == (builderBit & viewerBit))
00416          {
00417             for(BuilderVec_it bIt = bv.begin(); bIt != bv.end(); ++bIt)
00418                (*bIt)->removePerViewProduct(view->typeId(), view->viewContext());
00419          }
00420 
00421          // and setup proxy builders have-a-window flag
00422          if (nviews == 1)
00423          {
00424             if (!haveViewForBit(builderBit))
00425             {
00426                if (viewerBit == (builderBit & viewerBit))
00427                {
00428                   for(BuilderVec_it bIt = bv.begin(); bIt != bv.end(); ++bIt)
00429                      (*bIt)->setHaveWindow(false);
00430                }
00431             }
00432          }
00433       }
00434    }
00435   
00436 
00437    for(EveViewVec_it i= m_views[typeId].begin(); i != m_views[typeId].end(); ++i) {
00438       if(i->get() == vb) {
00439          m_views[typeId].erase(i);
00440          break;
00441       }
00442    }
00443 }
00444 
00445 //______________________________________________________________________________
00446 
00447 void
00448 FWEveViewManager::modelChangesComing()
00449 {
00450    gEve->DisableRedraw();
00451 }
00452 
00453 void
00454 FWEveViewManager::modelChangesDone()
00455 {
00456    gEve->EnableRedraw();
00457 }
00458 
00460 void
00461 FWEveViewManager::modelChanges(const FWModelIds& iIds)
00462 {
00463    FWModelId id = *(iIds.begin());
00464    const FWEventItem* item = id.item();
00465 
00466    // in standard case new elements can be build in case of change of visibility
00467    // and in non-standard case (e.g. calo towers) PB's modelChages handles all changes
00468    bool itemHaveWindow = false;
00469    for (std::map<int, BuilderVec>::iterator i = m_builders.begin(); 
00470         i != m_builders.end(); ++i)
00471    {
00472       for (size_t bi = 0, be = i->second.size(); bi != be; ++bi)
00473       {
00474          FWProxyBuilderBase *builder = i->second[bi].get();
00475          if (builder->getHaveWindow() && builder->item() == item)
00476          {
00477             builder->modelChanges(iIds);
00478             itemHaveWindow = true;
00479          }
00480       }
00481    }
00482 
00483    if (!itemHaveWindow)
00484       return;
00485 
00486    EveSelectionSentry();
00487 
00488    std::map<const FWEventItem*, FWInteractionList*>::iterator it = m_interactionLists.find(item);
00489    if (it != m_interactionLists.end())
00490    {
00491       if (!it->second->empty())
00492          it->second->modelChanges(iIds);
00493    }
00494 }
00495 
00501 void
00502 FWEveViewManager::itemChanged(const FWEventItem* item)
00503 {
00504    if (!item)
00505       return;
00506 
00507    bool itemHaveWindow = false;
00508 
00509    for (std::map<int, BuilderVec>::iterator i = m_builders.begin(); 
00510         i != m_builders.end(); ++i)
00511    {
00512       for(size_t bi = 0, be = i->second.size(); bi != be; ++bi)
00513       {
00514          FWProxyBuilderBase *builder = i->second[bi].get();
00515          
00516          if (builder->item() != item)
00517             continue;
00518 
00519          builder->itemChanged(item);
00520          itemHaveWindow |= builder->getHaveWindow();
00521       }
00522    }
00523    
00524    if (!itemHaveWindow)
00525       return;
00526 
00527    std::map<const FWEventItem*, FWInteractionList*>::iterator it = m_interactionLists.find(item);
00528    if (it != m_interactionLists.end())
00529    {
00530       if (!it->second->empty())
00531          it->second->itemChanged();
00532    }
00533 }
00534 
00537 void
00538 FWEveViewManager::removeItem(const FWEventItem* item)
00539 {
00540    EveSelectionSentry();
00541 
00542    std::map<const FWEventItem*, FWInteractionList*>::iterator it =  m_interactionLists.find(item);
00543    if (it != m_interactionLists.end())
00544    {
00545       delete it->second;
00546       m_interactionLists.erase(it);
00547    }
00548   
00549    for (std::map<int, BuilderVec>::iterator i = m_builders.begin();
00550         i != m_builders.end(); ++i)
00551    {
00552       BuilderVec_it bIt = i->second.begin();
00553       while( bIt != i->second.end() )
00554       {
00555          if ((*bIt)->item() == item)
00556          { 
00557             // TODO caching of proxy builders
00558             (*bIt)->itemBeingDestroyed(item);
00559             bIt = i->second.erase(bIt);
00560          }
00561          else
00562          {
00563             ++bIt;
00564          }
00565       }
00566    }
00567 }
00568 
00569 void
00570 FWEveViewManager::setContext(const fireworks::Context* x)
00571 {
00572    FWViewManagerBase::setContext(x);
00573    x->commonPrefs()->getEnergyScale()->parameterChanged_.connect(boost::bind(&FWEveViewManager::globalEnergyScaleChanged,this));
00574 
00575 }
00576 
00577 void
00578 FWEveViewManager::globalEnergyScaleChanged()
00579 {
00580    for (int t = 0 ; t < FWViewType::kTypeSize; ++t)
00581    {
00582       for(EveViewVec_it i = m_views[t].begin(); i != m_views[t].end(); ++i) 
00583       {
00584          if ((*i)->isEnergyScaleGlobal())
00585          {
00586             (*i)->setupEnergyScale();
00587          }
00588       }
00589 
00590    }
00591 }
00592 
00593 void
00594 FWEveViewManager::colorsChanged()
00595 {
00596    for (int t = 0 ; t < FWViewType::kTypeSize; ++t)
00597    {
00598       for(EveViewVec_it i = m_views[t].begin(); i != m_views[t].end(); ++i) 
00599          (*i)->setBackgroundColor(colorManager().background());
00600    }
00601 }
00602 
00603 //______________________________________________________________________________
00604 void
00605 FWEveViewManager::eventBegin()
00606 {
00607    gEve->DisableRedraw();
00608 
00609    context().resetMaxEtAndEnergy();
00610 
00611    for (int t = 0 ; t < FWViewType::kTypeSize; ++t)
00612    {
00613       for(EveViewVec_it i = m_views[t].begin(); i != m_views[t].end(); ++i)   
00614          (*i)->eventBegin();
00615    }
00616 }
00617 
00618 void
00619 FWEveViewManager::eventEnd()
00620 {
00621    for (int t = 0 ; t < FWViewType::kTypeSize; ++t)
00622    {
00623       for(EveViewVec_it i = m_views[t].begin(); i != m_views[t].end(); ++i)   
00624          (*i)->eventEnd();
00625    }
00626    gEve->EnableRedraw();
00627 }
00628 
00629 //______________________________________________________________________________
00630 
00633 FWFromEveSelectorBase *getSelector(TEveElement *iElement)
00634 {
00635    if (!iElement)
00636       return 0;
00637 
00638    //std::cout <<"  non null"<<std::endl;
00639    void* userData = iElement->GetUserData();
00640    //std::cout <<"  user data "<<userData<<std::endl;
00641    if (!userData)
00642       return 0;
00643 
00644    //std::cout <<"    have userData"<<std::endl;
00645    //std::cout <<"      calo"<<std::endl;
00646    EveSelectionSentry();
00647    return reinterpret_cast<FWFromEveSelectorBase*> (userData);   
00648 }
00649 
00650 void
00651 FWEveViewManager::selectionAdded(TEveElement* iElement)
00652 {
00653    FWFromEveSelectorBase* selector = getSelector(iElement);
00654    if (selector)
00655       selector->doSelect();
00656 }
00657 
00658 void
00659 FWEveViewManager::selectionRemoved(TEveElement* iElement)
00660 {
00661    FWFromEveSelectorBase* selector = getSelector(iElement);
00662    if (selector)
00663       selector->doUnselect();
00664 }
00665 
00666 void
00667 FWEveViewManager::selectionCleared()
00668 {
00669    context().selectionManager()->clearSelection();
00670 }
00671 
00672 
00673 //
00674 // const member functions
00675 //
00676 
00677 FWTypeToRepresentations
00678 FWEveViewManager::supportedTypesAndRepresentations() const
00679 {
00680    // needed for add collection GUI
00681    FWTypeToRepresentations returnValue;
00682    const std::string kSimple("simple#");
00683    for(TypeToBuilder::const_iterator it = m_typeToBuilder.begin(), itEnd = m_typeToBuilder.end();
00684        it != itEnd;
00685        ++it) 
00686    {
00687       std::vector<BuilderInfo> blist = it->second;
00688       for (size_t bii = 0, bie = blist.size(); bii != bie; ++bii)
00689       {
00690          BuilderInfo &info = blist[bii];
00691          std::string name = info.m_name;
00692          unsigned int bitPackedViews = info.m_viewBit;
00693          bool representsSubPart = (name.substr(name.find_first_of('@')-1, 1)=="!");
00694      
00695          if(name.substr(0,kSimple.size()) == kSimple)
00696          {
00697             name = name.substr(kSimple.size(), name.find_first_of('@')-kSimple.size()-1);
00698             returnValue.add(boost::shared_ptr<FWRepresentationCheckerBase>(new FWSimpleRepresentationChecker(name, it->first,bitPackedViews,representsSubPart)) );
00699          }
00700          else
00701          {
00702             name = name.substr(0, name.find_first_of('@')-1);
00703             returnValue.add(boost::shared_ptr<FWRepresentationCheckerBase>(new FWEDProductRepresentationChecker(name, it->first,bitPackedViews,representsSubPart)) );
00704          }
00705       }
00706    }
00707    return returnValue;
00708 }
00709 
00710 
00712 bool
00713 FWEveViewManager::haveViewForBit(int bit) const
00714 {
00715    for (int t = 0; t < FWViewType::kTypeSize; ++t)
00716    {
00717       if ((bit & (1 << t)) && m_views[t].size())
00718          return true;
00719    }
00720    // printf("have %d view for bit %d \n", haveView, bit);
00721    return false;
00722 }
00723 
00724 
00725 /*
00726 AMT: temporary workaround for using TEveCaloDataHist instead of
00727 TEveCaloDataVec. 
00728 
00729  */
00730 
00731 #include "TH2F.h"
00732 #include "TAxis.h"
00733 #include "TEveCaloData.h"
00734 
00735 void
00736 FWEveViewManager::highlightAdded(TEveElement* iElement)
00737 {
00738 
00739    bool blocked = gEve->GetHighlight()->BlockSignals(true);
00740 
00741 
00742    if (iElement == context().getCaloData())
00743    {
00744       TEveCaloData::vCellId_t& hlist =  context().getCaloData()->GetCellsHighlighted();
00745       std::set<TEveCaloData::CellId_t> hset;
00746 
00747       int etaBin, phiBin, w, newPhiBin, tower;
00748       TH2F* hist =  context().getCaloData()->GetHist(0);
00749       TAxis* etaAxis = hist->GetXaxis();
00750       int nBinsX = etaAxis->GetNbins() + 2;
00751 
00752       for (TEveCaloData::vCellId_i i = hlist.begin(); i != hlist.end(); ++i)
00753       {
00754          hist->GetBinXYZ((*i).fTower, etaBin, phiBin, w);
00755          if (TMath::Abs(etaAxis->GetBinCenter(etaBin)) > 4.71475)
00756          {
00757             newPhiBin = ((phiBin + 1) / 4) * 4 - 1;
00758             if (newPhiBin <= 0) newPhiBin = 71;
00759                
00760             tower = etaBin + newPhiBin*nBinsX;
00761             hset.insert(TEveCaloData::CellId_t( tower, (*i).fSlice, (*i).fFraction));
00762             tower += nBinsX;
00763             hset.insert(TEveCaloData::CellId_t(tower, (*i).fSlice, (*i).fFraction));
00764             tower += nBinsX;
00765 
00766             if (newPhiBin == 71)
00767                tower = etaBin + 1*nBinsX;
00768 
00769             hset.insert(TEveCaloData::CellId_t(tower, (*i).fSlice, (*i).fFraction));
00770             tower += nBinsX;
00771             hset.insert(TEveCaloData::CellId_t(tower, (*i).fSlice, (*i).fFraction));
00772          }
00773          else if (TMath::Abs(etaAxis->GetBinCenter(etaBin)) > 1.747650)
00774          {  
00775             newPhiBin =  ((phiBin + 1)/2)*2 - 1;
00776             tower = etaBin + newPhiBin*nBinsX;
00777             hset.insert(TEveCaloData::CellId_t( tower, (*i).fSlice, (*i).fFraction));
00778             tower += nBinsX;
00779             hset.insert(TEveCaloData::CellId_t(tower, (*i).fSlice, (*i).fFraction));
00780          }
00781          else
00782          {
00783             hset.insert(*i);
00784          }
00785       }
00786  
00787       // edit calo data list
00788       hlist.clear();
00789       for(std::set<TEveCaloData::CellId_t>::iterator it = hset.begin(); it != hset.end(); ++it)
00790       {
00791          hlist.push_back(*it);
00792       }    
00793       context().getCaloData()->CellSelectionChanged();
00794 
00795    }
00796 
00797    gEve->GetHighlight()->BlockSignals(blocked);
00798 }