test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWOverlapTableManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWOverlapTableManager
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Jan 4 20:31:32 CET 2012
11 //
12 
13 // system include files
14 
15 // user include files
21 
22 #include "TEveQuadSet.h"
23 #include "TGeoVolume.h"
24 #include "TGeoMatrix.h"
25 #include "TGeoShape.h"
26 #include "TGeoBBox.h"
27 #include "TGeoMatrix.h"
28 #include "TEveUtil.h"
29 #include "TObjString.h"
30 #include "TGeoNode.h"
31 #include "TGeoOverlap.h"
32 #include "TGeoManager.h"
33 #include "TPolyMarker3D.h"
34 
35 #include "TStopwatch.h"
36 #include "TTimer.h"
37 #include "TGeoPainter.h"
38 #include "TPRegexp.h"
39 
42  m_browser(v)
43 {
44 }
45 
47 {
48 }
49 
50 
51 
52 std::vector<std::string> FWOverlapTableManager::getTitles() const
53 {
54  std::vector<std::string> returnValue;
55  returnValue.reserve(numberOfColumns());
56 
57  returnValue.push_back("Name");
58  returnValue.push_back("Color");
59  returnValue.push_back("Opcty");
60  returnValue.push_back("RnrSelf");
61  returnValue.push_back("RnrChildren");
62  returnValue.push_back("Overlap");
63  returnValue.push_back("RnrMarker");
64  return returnValue;
65 }
66 
67 
68 
69 
70 //---------------------------------------------------------------------------------
71 void FWOverlapTableManager::importOverlaps(std::string iPath, double iPrecision)
72 {
73  m_entries.clear();
74  m_mapNodeOverlaps.clear();
75  m_browser->getMarker()->Reset(TEveQuadSet::kQT_FreeQuad, kFALSE, 32 );
76 
77  TEveGeoManagerHolder mangeur( FWGeometryTableViewManager::getGeoMangeur());
78  // gGeoManager->cd();
79  NodeInfo topNodeInfo;
80  topNodeInfo.m_node = gGeoManager->GetTopNode();
81  topNodeInfo.m_level = 0;
82  topNodeInfo.m_color = gGeoManager->GetTopNode()->GetVolume()->GetLineColor();
83  topNodeInfo.m_transparency = gGeoManager->GetTopNode()->GetVolume()->GetTransparency();
84  topNodeInfo.m_parent = -1;
85  topNodeInfo.resetBit(kVisNodeSelf);
86 
87  m_entries.resize(gGeoManager->GetNNodes());
88  m_entries[0] = topNodeInfo;
89 
90  m_entries.resize( gGeoManager->GetNNodes());
91 
92  TGeoVolume* topVol = topNodeInfo.m_node->GetVolume();
93  Int_t icheck = 0;
94  Int_t ncheck = 0;
95  TStopwatch *timer;
96  Int_t i;
97  bool checkingOverlaps = false;
98  TGeoManager *geom = topVol->GetGeoManager();
99  ncheck = topNodeInfo.m_node->CountDaughters(kFALSE);
100  timer = new TStopwatch();
101  geom->ClearOverlaps();
102  geom->SetCheckingOverlaps(kTRUE);
103 
104  int oldS = 0;
105  timer->Start();
106  geom->GetGeomPainter()->OpProgress(topVol->GetName(),icheck,ncheck,timer,kFALSE);
107 // topVol->CheckOverlaps(iPrecision);
108  icheck++;
109  TGeoIterator git(topVol);
110  Entries_i eit = m_entries.begin();
111  /*
112  if (gGeoManager->GetListOfOverlaps()->GetEntriesFast()) {
113  int newCnt = gGeoManager->GetListOfOverlaps()->GetEntriesFast();
114  for (int i=0; i<newCnt; ++i) {
115  addOverlapEntry((TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At(i), new TGeoHMatrix(*geom->GetCurrentMatrix()), topNode, next);
116  }
117  oldS= newCnt;
118  }*/
119  eit++;
120  TGeoNode *node;
121  icheck = 1;
122 
123  int topNodeIdx = m_browser->getTopNodeIdx();
124 
125  while ((node=git())) {
126  if (!eit->testBit(kOverlap)) eit->resetBit(kVisNodeSelf);
127  eit->m_node = node;
128  eit->m_color = node->GetVolume()->GetLineColor();
129  eit->m_transparency = node->GetVolume()->GetTransparency();
130  eit->m_level = git.GetLevel();
131  eit->m_parent = icheck;
132 
133  if ((topNodeIdx )== icheck || !topNodeIdx ) {
134  // printf("start to check overlaps on topNodeIdx %s \n", eit->name());
135  checkingOverlaps=true;
136  }
137  else if (checkingOverlaps && ( eit->m_level <= m_entries[m_browser->getTopNodeIdx()].m_level))
138  {
139  checkingOverlaps=false;
140  }
141  // parent index
142  Entries_i pit = eit;
143  do
144  {
145  --pit;
146  --(eit->m_parent);
147  if (pit->m_level < eit->m_level)
148  break;
149  } while (pit != m_entries.begin());
150 
151  // overlap bits
152  if ( checkingOverlaps) {
153  if (!node->GetVolume()->IsSelected()) {
154  geom->GetGeomPainter()->OpProgress(node->GetVolume()->GetName(),icheck+1,ncheck,timer,kFALSE);
155  node->GetVolume()->SelectVolume(kFALSE);
156 
157  node->GetVolume()->CheckOverlaps(iPrecision);
158 
159  if (oldS != gGeoManager->GetListOfOverlaps()->GetEntriesFast()) {
160  // printf("mother %s overlaps \n", node->GetName());
161 
162  eit->setBit(kOverlapChild);
163  eit->setBit(kVisNodeChld);
164  eit->setBit(kVisMarker);
165 
166  TGeoHMatrix* motherm = new TGeoHMatrix(*geom->GetCurrentMatrix());
167  {
168  TGeoNode* ni = topNodeInfo.m_node;
169  for (Int_t i=1; i<=git.GetLevel(); i++) {
170  ni = ni->GetDaughter(git.GetIndex(i));
171  motherm->Multiply(ni->GetMatrix());
172  }
173  }
174 
175  int newCnt = gGeoManager->GetListOfOverlaps()->GetEntriesFast();
176 
177  for (int i=oldS; i<newCnt; ++i)
178  {
179  // printf("add %p %p \n", (void*)node->GetVolume(), (void*)m_entries[icheck].m_node->GetVolume());
180  addOverlapEntry((TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At(i), i, icheck, motherm);
181  }
182 
183  oldS = newCnt;
184  }
185  }
186  }
187  eit++;
188  icheck ++;
189  }
190 
191  m_browser->getMarker()->RefitPlex();
192 
193  topVol->SelectVolume(kTRUE);
194  geom->SetCheckingOverlaps(kFALSE);
195  // geom->SortOverlaps();
196  TObjArray *overlaps = geom->GetListOfOverlaps();
197  Int_t novlps = overlaps->GetEntriesFast();
198  TNamed *obj;
199  for (i=0; i<novlps; i++) {
200  obj = (TNamed*)overlaps->At(i);
201  obj->SetName(Form("ov%05d",i));
202  }
203  geom->GetGeomPainter()->OpProgress("Check overlaps:",icheck,ncheck,timer,kTRUE);
204  Info("CheckOverlaps", "Number of illegal overlaps/extrusions : %d\n", novlps);
205  delete timer;
206 }
207 
208 
209 //______________________________________________________________________________
210 
211 
212 void FWOverlapTableManager::addOverlapEntry(TGeoOverlap* ovl, int ovlIdx, Int_t parentIdx, TGeoHMatrix* motherm)
213 {
214 
215  // printf("add %s \n", ovl->GetTitle());
216  // get doughter indices of overlaps
217  /*
218  TPMERegexp re(" ", "o");
219  re.Split(TString(ovl->GetTitle()));
220  printf("add title %s \n", ovl->GetTitle());
221  */
222  int pcnt = parentIdx+1;
223  int dOff =0;
224  TGeoNode* mothern = m_entries[parentIdx].m_node;
225 
226  QuadId* quid = new QuadId(ovl, parentIdx);
227 
228  for (int i = 0; i < mothern->GetNdaughters(); ++i)
229  {
230  TGeoNode* n = mothern->GetDaughter(i);
231 
232  int cnt = pcnt + i+dOff;
233 
234  if (ovl->IsOverlap()) {
235  if (n->GetVolume() == ovl->GetFirstVolume() && (*(ovl->GetFirstMatrix()) == *(n->GetMatrix())))
236  {
237  // std::string x = re[0].Data();
238  //if (x.find(n->GetName()) == std::string::npos) printf("ERROT \n");
239 
240  m_entries[cnt].setBit(kOverlap);
241  m_entries[cnt].setBit(kVisNodeSelf);
242  m_mapNodeOverlaps.insert(std::pair<int, int>(cnt, ovlIdx));
243  int nno; n->GetOverlaps(nno);
244  nno |= BIT(1); n->SetOverlaps(0, nno);
245  quid->m_nodes.push_back(cnt);
246  }
247  }
248 
249  if (n->GetVolume() == ovl->GetSecondVolume() && (*(ovl->GetSecondMatrix()) == *(n->GetMatrix())))
250  {
251  //printf("-----------------------------------------------\n");
252  // std::string x = re[2].Data();
253  // if (x.find(n->GetName()) == std::string::npos) printf("ERROT \n");
254 
255  m_entries[cnt].setBit(kOverlap);
256  m_entries[cnt].setBit(kVisNodeSelf);
257 
258  m_mapNodeOverlaps.insert(std::pair<int, int>(cnt, ovlIdx));
259  int nno; n->GetOverlaps(nno);
260  nno |= (ovl->IsOverlap() ? BIT(1) : BIT(2));
261  n->SetOverlaps(0, nno);
262 
263  quid->m_nodes.push_back(cnt);
264 
265  }
266 
267 
269  }
270 
271  TPolyMarker3D* pm = ovl->GetPolyMarker();
272  for (int j=0; j<pm->GetN(); ++j )
273  {
274  double pl[3];
275  double pg[3];
276  pm->GetPoint(j, pl[0], pl[1], pl[2]);
277  motherm->LocalToMaster(pl, pg);
278 
279  float dx = TMath::Abs(ovl->GetOverlap());
280  if (dx > 1e5)
281  {
282  fwLog(fwlog::kInfo) << Form("WARNING [%s], overlap size = %.1f \n", ovl->GetTitle(), dx);
283  dx = 10;
284  }
285  float dy = dx, dz = 0;
286  float fp[3]; fp[0] = pg[0];fp[1] = pg[1];fp[2] = pg[2];
287  float bb[12] = {
288  fp[0] +dx, fp[1] -dy, fp[2] -dz,
289  fp[0] +dx, fp[1] +dy, fp[2] +dz,
290  fp[0] -dx, fp[1] +dy, fp[2] +dz,
291  fp[0] -dx, fp[1] -dy, fp[2] -dz
292  };
293  m_browser->getMarker()->AddQuad(&bb[0]);
294  m_browser->getMarker()->QuadId(quid);
295  }
296 
297 
298  int aIdx = parentIdx; int aLev = m_entries[aIdx].m_level;
299  int topNodeIdx = m_browser->getTopNodeIdx();
300 
301  while(aIdx > topNodeIdx)
302  {
303  aIdx--;
304  if (m_entries[aIdx].m_level < aLev)
305  {
306  m_entries[aIdx].setBit(kOverlapChild);
307  m_entries[aIdx].setBit(kVisNodeChld);
308  // printf("stamp %s \n", m_entries[aIdx].name());
309  aLev--;
310  }
311  }
312 }
313 
314 
315 //_____________________________________________________________________________
316 
318 {
319  // printf("overlap recalcuate vis \n");
320  m_row_to_index.clear();
321  int i = m_browser->getTopNodeIdx();
322  m_row_to_index.push_back(i);
323 
324  if (m_entries[i].testBit(kExpanded) )
326 }
327 
329 {
330  TGeoNode* parentNode = m_entries[pIdx].m_node;
331  int nD = parentNode->GetNdaughters();
332  int dOff=0;
333  for (int n = 0; n != nD; ++n)
334  {
335  int idx = pIdx + 1 + n + dOff;
337 
338 
340  m_row_to_index.push_back(idx);
341 
342  if ((m_browser->listAllNodes() || data.testBit(kOverlapChild)) && data.testBit(kExpanded) )
344 
345  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
346  }
347 }
348 
349 
350 //______________________________________________________________________________
351 
353 {
354  return m_browser->listAllNodes() ? data.m_node->GetNdaughters() : data.testBit(kOverlapChild) ;
355 }
356 
358 {
359 
360  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
361  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
362  ppp = m_mapNodeOverlaps.equal_range(idx);
363  for (std::multimap<int, int>::const_iterator it2 = ppp.first;it2 != ppp.second;++it2) {
364  const TGeoOverlap* ovl = (const TGeoOverlap*) gGeoManager->GetListOfOverlaps()->At((*it2).second);
365  if (ovl) ovl->Print();
366  }
367 }
368 
369 void FWOverlapTableManager::getOverlapTitles(int idx, TString& txt) const
370 {
371 
372  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
373  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
374  ppp = m_mapNodeOverlaps.equal_range(idx);
375  for (std::multimap<int, int>::const_iterator it2 = ppp.first;it2 != ppp.second;++it2) {
376  const TGeoOverlap* ovl = (const TGeoOverlap*) gGeoManager->GetListOfOverlaps()->At((*it2).second);
377  {
378  txt += "\n";
379 
380  if (ovl) {
381  txt += Form("%s: %g, ", ovl->IsOverlap() ? "Ovl" : "Extr", ovl->GetOverlap());
382  txt += ovl->GetTitle();
383  }
384  }
385  }
386 }
387 //______________________________________________________________________________
388 /*
389  const char* FWOverlapTableManager::cellName(const NodeInfo& data) const
390  {
391  if (data.m_parent == -1)
392  {
393  int ne = 0;
394  int no = 0;
395  TGeoOverlap* ovl;
396  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
397  TIter next_ovl(gGeoManager->GetListOfOverlaps());
398  while((ovl = (TGeoOverlap*)next_ovl()))
399  ovl->IsOverlap() ? no++ : ne++;
400 
401  return Form("%s Ovl[%d] Ext[%d]", data.m_node->GetName(), no, ne);
402  }
403  else
404  {
405  return data.name();
406  }
407  }*/
408 
409 //______________________________________________________________________________
410 
411 FWTableCellRendererBase* FWOverlapTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
412 {
413  if (m_row_to_index.empty()) return &m_renderer;
414 
415  int unsortedRow = m_row_to_index[iSortedRowNumber];
416 
417  if (unsortedRow < 0) printf("!!!!!!!!!!!!!!!! error %d %d \n",unsortedRow, iSortedRowNumber);
418 
419  // editor state
420  //
421  m_renderer.showEditor(unsortedRow == m_editTransparencyIdx && iCol == 2);
422 
423 
424  // selection state
425  //
426  const NodeInfo& data = m_entries[unsortedRow];
427 
428  bool isSelected = data.testBit(kHighlighted) || data.testBit(kSelected);
429  if (m_browser->listAllNodes()) isSelected = isSelected || data.testBit(kOverlap);
430 
431  if (data.testBit(kSelected))
432  {
433  m_highlightContext->SetBackground(0xc86464);
434  }
435  else if (data.testBit(kHighlighted) )
436  {
437  m_highlightContext->SetBackground(0x6464c8);
438  }
439  else if (m_browser->listAllNodes() && data.testBit(kOverlap) )
440  {
441  m_highlightContext->SetBackground(0xdddddd);
442  }
443 
444 
445  // set column content
446  //
447  if (iCol == 0)
448  {
449  if (unsortedRow == m_browser->getTopNodeIdx())
450  {
451  int no = 0, ne =0;
452  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
453  TIter next_ovl(gGeoManager->GetListOfOverlaps());
454  const TGeoOverlap* ovl;
455  while((ovl = (TGeoOverlap*)next_ovl()))
456  ovl->IsOverlap() ? no++ : ne++;
457 
458  m_renderer.setData(Form("%s Ovl[%d] Ext[%d]", data.m_node->GetName(), no, ne), isSelected);
459  }
460  else {
461  m_renderer.setData(data.name(), isSelected);
462  }
464 
466 
467  int level = data.m_level - m_levelOffset;
468  if (nodeIsParent(data))
469  m_renderer.setIndentation(20*level);
470  else
472  }
473  else
474  {
475  m_renderer.setIsParent(false);
477 
478  if (iCol == 5)
479  {
480  if (data.testBit(kOverlap) )
481  {
482  std::string x;
483  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
484  ppp = m_mapNodeOverlaps.equal_range(unsortedRow);
485 
486  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
487 
488  for (std::multimap<int, int>::const_iterator it2 = ppp.first;it2 != ppp.second;++it2) {
489  const TGeoOverlap* ovl = (const TGeoOverlap*) gGeoManager->GetListOfOverlaps()->At((*it2).second);
490  if (ovl)
491  x += Form("%s: %g ", ovl->IsOverlap() ? "Ovl" : "Extr", ovl->GetOverlap());
492  else
493  x += "err";
494 
495  }
496  m_renderer.setData(x, isSelected);
497  }
498  else
499  {
500  m_renderer.setData("", isSelected);
501  }
502  }
503  if (iCol == 1)
504  {
505  m_colorBoxRenderer.setData(data.m_color, isSelected);
506  return &m_colorBoxRenderer;
507  }
508  else if (iCol == 2 )
509  {
510  m_renderer.setData(Form("%d", 100 -data.m_transparency), isSelected);
511  }
512  else if (iCol == 3 )
513  {
514  m_renderer.setData(data.testBit(kVisNodeSelf) ? "On" : "-", isSelected );
515 
516  }
517  else if (iCol == 4 )
518  {
519  m_renderer.setData(data.testBit(kVisNodeChld) ? "On" : "-", isSelected);
520 
521  }
522  else if (iCol == 6)
523  {
524  std::cerr << "This shoud not happen! \n" ;
525  }
526  }
527  return &m_renderer;
528 }
529 
530 
531 
532 //______________________________________________________________________________
533 
535 {
536  int dOff = 0;
537  TGeoNode* parentNode = m_entries[selectedIdx].m_node;
538  int nD = parentNode->GetNdaughters();
539  for (int n = 0; n != nD; ++n)
540  {
541  int idx = selectedIdx + 1 + n + dOff;
543 
546 
547 
548  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
549  }
550 }
int i
Definition: DBlmapReader.cc:9
std::multimap< int, int > m_mapNodeOverlaps
FWEveDigitSetScalableMarker * getMarker()
tuple node
Definition: Node.py:50
void addOverlapEntry(TGeoOverlap *, int, int, TGeoHMatrix *)
bool listAllNodes() const
virtual void recalculateVisibilityNodeRec(int)
void getOverlapTitles(int, TString &) const
virtual std::vector< std::string > getTitles() const
returns the title names for each column
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const
T Abs(T a)
Definition: MathUtil.h:49
int j
Definition: DBlmapReader.cc:9
FWOverlapTableManager(FWOverlapTableView *)
virtual void setIndentation(int indentation=0)
static void getNNodesTotal(TGeoNode *geoNode, int &off)
void setData(const std::string &, bool isSelected)
virtual void recalculateVisibility()
#define fwLog(_level_)
Definition: fwLog.h:50
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void setDaughtersSelfVisibility(int i, bool v)
virtual int numberOfColumns() const
Number of columns in the table.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple level
Definition: testEve_cfg.py:34
Definition: DDAxes.h:10
virtual bool nodeIsParent(const NodeInfo &) const
void importOverlaps(std::string path, double precision)
FWOverlapTableView * m_browser
virtual void showEditor(bool value)