]> git.uio.no Git - u/mrichter/AliRoot.git/blame - GEODB/AliGNode.cxx
This commit was generated by cvs2svn to compensate for changes in r209,
[u/mrichter/AliRoot.git] / GEODB / AliGNode.cxx
CommitLineData
ab2f6604 1/**********************************************/
2/* */
3/* FILE: AliGNode.cxx */
4/* PURPOSE: Tree elemnt of the geometry */
5/* LANGUAGE: C++ */
6/* COMPILER: CC for HP-UX 9.x and 10. */
7/* AUTHOR: Joana && David */
8/* DATE: May 28, 1999 */
9/* ADDRESS: jesanto@cern.ch, dcollado@cern.ch */
10/* */
11/**********************************************/
12
13#include <TCanvas.h>
14#include <TView.h>
15#include <TPadView3D.h>
16#include <iostream.h>
17#include <TFile.h>
18#include <TROOT.h>
19#include "AliGeometry.h"
20#include "AliGBox.h"
21#include "AliGCone.h"
22#include "AliGPCone.h"
23#include "AliGSphere.h"
24#include "AliGNode.h"
25
26const Int_t kSonsInvisible = BIT(17);
27Text_t* ROOT_FILE = "AliGeoDB.root";
28
29ClassImp(AliGNode)
30
31//----------------------------------------------------------------------
32
33AliGNode::AliGNode( AliGNode* node )
34{
35
36 if( node ) {
37 /* Copy Constructor */
38 fConfig = new AliGConfig( node->fConfig );
39 fId = node->fId;
40 fMaterial = new AliGMaterial( node->fMaterial );
41 fName = node->fName;
42 fNcopy = new TArrayI( *(node->fNcopy) );
43 fNname = node->fNname;
44 fNnode = new TArrayI( *(node->fNnode) );
45 fNode = new TObjArray( *(node->fNode) );
46 fNsons = node->fNsons;
47 fNtrans = new TArrayI( *(node->fNtrans) );
48 fParent = node->fParent;
49 fVis = node->fVis;
50 fTitle = node->fTitle;
51 fTrans = new TObjArray(*(node->fTrans));
52 // fParent = new AliGNode(node->fParent);
53
54 if (node->fShape) {
55 if( !strcmp(node->fShape->ClassName(), "AliGBox") ) {
56 fShape = new AliGBox( (AliGBox*) node->fShape );
57 //fShape = new AliGBox(*(AliGBox*)node->fShape);
58 }
59 else {
60 if( !strcmp(node->fShape->ClassName(), "AliGSphere") )
61 fShape = new AliGSphere( (AliGSphere*) node->fShape );
62 else {
63 if( !strcmp(node->fShape->ClassName(), "AliGTube") )
64 fShape = new AliGTube( (AliGTube*) node->fShape );
65 else {
66 if( !strcmp(node->fShape->ClassName(), "AliGCone") )
67 fShape = new AliGCone( (AliGCone*) node->fShape );
68 else {
69 if( !strcmp(node->fShape->ClassName(), "AliGPCone") )
70 fShape = new AliGPCone( (AliGPCone*) node->fShape );
71 else {
72 if( !strcmp(node->fShape->ClassName(), "AliGTRD1") )
73 fShape = new AliGTRD1( (AliGTRD1*) node->fShape );
74 }
75 }
76 }
77 }
78 }
79 }
80 else
81 fShape = NULL;
82
83 /*cout << endl << " Comparacion." << endl;
84 cout << " El que paso por parametro:" << endl;
85 node->Dump();
86 cout << " El resultado de la copia:" << endl;
87 this->Dump();*/
88
89 }
90 else {
91 /* Default Constructor */
92 fConfig = NULL;
93 fId = 0;
94 fMaterial = NULL;
95 fName = "";
96 fNcopy = NULL;
97 fNname = "";
98 fNnode = NULL;
99 fNode = new TObjArray();
100 fNsons = 0;
101 fNtrans = NULL;
102 fParent = NULL;
103 fShape = NULL;
104 fTitle = "";
105 fTrans = new TObjArray();
106 fVis = 0;
107 }
108}
109
110//----------------------------------------------------------------------
111
112AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGBox* box, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
113{
114 /* AliGNode Constructor for AliGBox shape */
115
116 if( box )
117 fShape = new AliGBox(box); // Shape inside node
118 else
119 fShape = NULL;
120
121 EndConstructor( name, id, title, material, matrixname, config );
122}
123
124//----------------------------------------------------------------------
125
126AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGSphere* sphere, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
127{
128 /* AliGNode Constructor for AliGSphere shape */
129
130 if( sphere )
131 fShape = new AliGSphere(sphere); // Shape inside node
132 else
133 fShape = NULL;
134
135 EndConstructor( name, id, title, material, matrixname, config );
136}
137
138//----------------------------------------------------------------------
139
140AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGTube* tube, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
141{
142 /* AliGNode Constructor for AliGTube shape */
143
144 if( tube )
145 fShape = new AliGTube(tube); // Shape inside node
146 else
147 fShape = NULL;
148
149 EndConstructor( name, id, title, material, matrixname, config );
150}
151
152//----------------------------------------------------------------------
153
154AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGCone* cone, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
155{
156 /* AliGNode Constructor for AliGCone shape */
157
158 if( cone )
159 fShape = new AliGCone(cone); // Shape inside node
160 else
161 fShape = NULL;
162
163 EndConstructor( name, id, title, material, matrixname, config );
164}
165
166//----------------------------------------------------------------------
167
168
169AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGPCone* pcone, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
170{
171 /* AliGNode Constructor for AliGPCone shape */
172
173 if( pcone )
174 fShape = new AliGPCone(pcone); // Shape inside node
175 else
176 fShape = NULL;
177
178 EndConstructor( name, id, title, material, matrixname, config );
179}
180
181//----------------------------------------------------------------------
182
183
184AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGTRD1* trd1, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
185{
186 /* AliGNode Constructor for AliGTRD1 shape */
187
188 if( trd1 )
189 fShape = new AliGTRD1(trd1); // Shape inside node
190 else
191 fShape = NULL;
192
193 EndConstructor( name, id, title, material, matrixname, config );
194}
195
196//----------------------------------------------------------------------
197
198void AliGNode::EndConstructor( Text_t* name, Int_t id, Text_t* title, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
199{
200 /* Finish the construction of AliGNodes */
201
202 fConfig = new AliGConfig(config);
203 fId = id; // Node id number
204 fMaterial = new AliGMaterial(material); // Material inside shape
205
206 char* TmpName = new char[strlen(name)+int(TMath::Log10((double) id)+3)];
207 sprintf(TmpName,"%s_%d",name,id);
208 fName = TmpName; // Complete node name
209 delete [] TmpName;
210
211 fNcopy = new TArrayI(50); // Array of integers containing the copy number (by family name)
212 fNname = name; // Node family name
213 fNnode = new TArrayI(50); // Array of integers containing every node son index
214 fNode = new TObjArray(100,0); // Array containing every (different)node son
215 fNsons = 0;
216 fNtrans = new TArrayI(50); // Array of integers containing every transformation index
217 fParent = NULL;
218 fTitle = title;
219 fTrans = new TObjArray(100,0); // Array containing every (different)transformation used
220 fVis = 1;
221
222}
223
224//-----------------------------------------------------------------------
225
226AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGShape* shape, AliGMaterial* material, const Text_t* matrixname, AliGConfig* config )
227{
228 /* AliGNode Constructor for an AliGShape */
229
230 fShape = NULL;
231
232 EndConstructor( name, id, title, material, matrixname, config );
233}
234
235
236//----------------------------------------------------------------------
237
238AliGNode::~AliGNode()
239{
240 /* Destructor */
241
242 if(fConfig) delete fConfig;
243 if(fMaterial) delete fMaterial;
244 if(fNcopy) delete fNcopy;
245 if(fNnode) delete fNnode;
246 if(fNode) delete fNode;
247 if(fNtrans) delete fNtrans;
248 if(fShape) delete fShape;
249 if(fTrans) delete fTrans;
250}
251
252//----------------------------------------------------------------------
253
254AliGNode* AliGNode::operator=( const AliGNode* node )
255{
256 if( this == node ) return this; // special case.
257
258 fConfig = node->fConfig;
259 fId = node->fId;
260 fMaterial = node->fMaterial;
261 fName = node->fName;
262 fNcopy = node->fNcopy;
263 fNname = node->fNname;
264 fNnode = node->fNnode;
265
266 if( fNode ) fNode->Delete();
267
268 if( node->fNode ) {
269 //for( int i=0; i<node->fNode->GetSize(); i++ )
270 for( int i=0; i<node->fNode->GetSize(); i++ )
271 fNode->AddLast(node->fNode->At(i));
272 }
273
274 fNsons = node->fNsons;
275 fNtrans = node->fNtrans;
276 fParent = node->fParent;
277 fShape = node->fShape;
278 fTitle = node->fTitle;
279
280 if( fTrans ) fTrans->Delete();
281 if( node->fTrans ) {
282 for( int i=0; i<node->fTrans->GetSize(); i++ )
283 fTrans->AddLast(node->fTrans->At(i));
284 }
285 //fTrans = node->fTrans;
286
287 return this;
288}
289
290//----------------------------------------------------------------------
291
292void AliGNode::Add(AliGNode* son, AliGTransform* tran)
293{
294
295 Int_t index = fNode->IndexOf((TObject*)son);
296
297 if( index == -1 ) {
298 fNode->Add(son); // fNode is TObjArray
299 index = fNode->IndexOf((TObject*)son);
300 son->fParent = this;
301 }
302
303 Int_t tranumber = fTrans->IndexOf((TObject*)tran);
304 if( tranumber == -1 ) {
305 fTrans->Add( tran );
306 tranumber = fTrans->IndexOf((TObject*)tran);
307 }
308
309 Int_t Nsons = this->GetfNsons();
310 Int_t copy = 1;
311
312 for( Int_t i = 0; i<Nsons; i++ ) {
313 if( index == fNnode->At(i) ) {
314 if( fNtrans->At(i) == tranumber ) {
315 cout << "Error: Node already exists!";
316 return;
317 }
318 }
319
320
321 if( ((AliGNode*)fNode->At(fNnode->At(i)))->fNname == son->fNname )
322 copy++;
323
324 }
325
326 if( fNnode->GetSize() == Nsons ) {
327
328 IncreaseSize( Nsons+100, *fNnode );
329 IncreaseSize( Nsons+100, *fNtrans );
330 IncreaseSize( Nsons+100, *fNcopy );
331
332 }
333 fNnode->AddAt( index, Nsons ); // Add value of index at position Nsons
334
335 fNtrans->AddAt( tranumber, Nsons );
336 fNcopy->AddAt( copy, Nsons );
337 fNsons++; // Because we have added a new node
338
339}
340
341//----------------------------------------------------------------------
342
343void AliGNode::IncreaseSize(Int_t total,TArrayI &array)
344{
345 TArrayI *newarray = new TArrayI(array);
346 array.Set(total);
347
348 for( int i=0; i<newarray->GetSize(); i++ )
349 array[i] = (*newarray)[i];
350
351 delete newarray;
352}
353
354//----------------------------------------------------------------------
355
356Text_t* AliGNode::GetPath()
357{
358 const int kMAXDEPTH = 128;
359 const AliGNode* d[kMAXDEPTH];
360 AliGNode* node = this;
361 int depth = 0, len = 0;
362
363 d[depth++] = node;
364 len = strlen(node->GetName()) + 1;
365
366 while (node->fParent && depth < kMAXDEPTH) {
367 node = node->fParent;
368 d[depth++] = node;
369 len += strlen (node->GetName()) + 1;
370 }
371
372 char* path = new char[len + 2];
373
374 for (int i = depth-1; i>=0; i--) {
375 if (i == depth-1) { // file or TROOT name
376 strcpy(path, d[i]->GetName());
377 if (i == 0) strcat(path, "/");
378 }
379 else {
380 strcat(path, "/");
381 strcat(path, d[i]->GetName());
382 }
383 }
384
385 return path;
386}
387
388
389//----------------------------------------------------------------------
390
391void AliGNode::Save( TFile* file )
392{
393 if( fParent ) { // it's not the root node
394 // So I must check if the father node is in disk
395
396 if( file->cd(fParent->GetPath()) ) {
397
398 if( !gDirectory->Get(GetName()) )
399 file->mkdir( GetName() );
400
401 file->cd( GetPath() );
402
403 if( !gDirectory->Get( fShape->GetName() ) )
404 if ( fShape ) {
405/* const Text_t* shapetype = fShape->ClassName();
406 if( !strcmp(shapetype,"AliGBox") ) {
407 fShape->Write();
408 }
409 else {
410 if (!strcmp(shapetype,"AliGSphere")) {
411 fShape->Write();
412 }
413 else {
414 if (!strcmp(shapetype,"AliGTube")) {
415 fShape->Write();
416 }
417 else {
418 if (!strcmp(shapetype,"AliGCone")) {
419 fShape->Write();
420 }
421 else {
422 if (!strcmp(shapetype,"AliGPCone")) {
423 cout << " Saving an AliGPCone:" << endl;
424 fShape->Dump();
425 cout << endl;
426 fShape->Write();
427 }
428 else {
429 if (!strcmp(shapetype,"AliGTRD1")) {
430 fShape->Write();
431 }
432 }
433 }
434 }
435 }
436 }*/
437 fShape->Write();
438 }
439
440
441 if( !gDirectory->Get( fMaterial->GetName() ) )
442 if ( fMaterial )
443 fMaterial->Write();
444
445 if ( fConfig ) {
446 /*cout << " Con capacidad: " << fConfig->GetFormula().Capacity() << " voy a grabar esta configuracion: " << fConfig->GetFormula().Data() << endl;*/
447 fConfig->Write();
448 }
449
450 if ( fTrans )
451 fTrans->Write();
452 }
453 else
454 cout << " ERROR : Father exists but I can't find it. See AliGNode::Save, please..." << endl;
455 }
456 else { // if it's the root node
457 file->mkdir( GetName() );
458 file->cd( GetPath() );
459
460 if ( fShape )
461 fShape->Write();
462
463 if ( fMaterial )
464 fMaterial->Write();
465
466 if ( fConfig ) {
467 /*cout << " Con capacidad: " << fConfig->GetFormula().Capacity() << " voy a grabar esta configuracion: " << fConfig->GetFormula().Data() << endl;*/
468 fConfig->Write();
469 }
470
471 if ( fTrans )
472 fTrans->Write();
473 }
474
475 fflush(stdout);
476 file->Write();
477}
478
479//----------------------------------------------------------------------
480
481void AliGNode::SaveAll( TFile* file )
482{
483/* if( fParent )
484 file->cd( fParent->GetPath() );
485 else
486 file->cd();
487
488 Save( file );
489
490 for( int i=0; i<fNsons; i++ ) {
491 cout << " Saving node: " << GetPath() << " with copy number " << << endl;
492 GetNodeFromfNnode(i)->SaveAll( file );
493 }
494*/
495
496 if( !gDirectory->Get(GetName()) ) {
497 Save( file );
498
499 for( int i=0; i<fNsons; i++ )
500 GetNodeFromfNnode(i)->SaveAll( file );
501 }
502
503/* if (!file->cd(GetPath())) {
504 Save( file );
505
506 for( int i=0; i<fNsons; i++ )
507 GetNodeFromfNnode(i)->SaveAll( file );
508 }
509*/
510}
511
512//----------------------------------------------------------------------
513
514void AliGNode::AddConfig( Text_t* name, Text_t* title, Text_t* detail, Int_t beg, Int_t end )
515{
516 Int_t Nsons = GetfNsons();
517
518 TStringLong formula = "";
519
520 for( int i=0; i<Nsons; i++ ) {
521 Int_t index = fNnode->At(i); // Gets every node son's index
522 const Text_t* NodeName = ((AliGNode*)fNode->At(index))->GetName();
523 Int_t tranumber = fNtrans->At(i); // And the correspondent transform
524 const Text_t* TransfName = ((AliGTransform*)fTrans->At(tranumber))->GetName();
525
526 formula.Append(NodeName);
527 formula.Append(":");
528 formula.Append(TransfName);
529
530 if( i != fNsons-1 )
531 formula.Append("+");
532 }
533
534 //cout << " Acabo de crear la formula: " << formula << endl << endl;
535
536 const Text_t* shapetype = fShape->ClassName();
537 const Text_t* shapename = fShape->GetName();
538 const Text_t* materialname = fMaterial->GetName();
539
540 AliGConfig* tmp = new AliGConfig( name, title, formula, detail, shapetype, shapename, materialname, beg, end );
541
542 //if(fConfig) delete fConfig;
543
544 fConfig = tmp;
545}
546
547//----------------------------------------------------------------------
548
549/*void AliGNode::AddConfig( Text_t* name, Text_t* title, Text_t* detail, Int_t beg, Int_t end )
550{
551 // Creates the configuration of a node using the information passed as arguments
552 // and building the formula of the level below by building the list of its sons
553 // recursively.
554
555 Int_t Nsons = GetfNsons();
556
557 char* formula = NULL;
558
559 cout << " Nsons = " << Nsons << endl;
560
561 for( int i=0; i<Nsons; i++ ) {
562 Int_t index = fNnode->At(i); // Gets every node son's index
563 const Text_t* NodeName = ((AliGNode*)fNode->At(index))->GetName();
564 Int_t tranumber = fNtrans->At(i); // And the correspondent transform
565 const Text_t* TransfName = ((AliGTransform*)fTrans->At(tranumber))->GetName();
566
567 int lenF, lenN, lenT;
568 lenF = lenN = lenT = 0;
569
570 cout << " i = " << i << " and fNsons = " << fNsons << endl;
571
572 if ( formula ) {
573 lenF = strlen(formula);
574 cout << " formula = #" << formula << "#" << endl;
575 }
576
577 if ( NodeName ) {
578 lenN = strlen(NodeName);
579 cout << " NodeName = #" << NodeName << "#" << endl;
580 }
581
582 if ( TransfName ) {
583 lenT = strlen(TransfName);
584 cout << " TransfName = #" << TransfName << "#" << endl;
585 }
586
587 cout << " lenF: " << lenF << " - lenN: " << lenN << " - lenT: " << lenT << endl;
588
589 char* formula2;
590
591 if( i != fNsons-1 ) {
592 cout << " Arriba" << endl;
593 formula2 = new char[lenF+lenN+lenT+2];
594 }
595 else {
596 cout << " Embaixo" << endl;
597 formula2 = new char[lenF+lenN+lenT+1];
598 }
599
600 formula2[0] = '\x0';
601
602 cout << "@@@ :) @@@" << endl;
603
604 if ( formula ) {
605 strcpy( formula2, formula );
606 cout << "1 formula2 = #" << formula2 << "#" << endl;
607 }
608
609 if( NodeName ) {
610 strcat( formula2, NodeName );
611 cout << "2 formula2 = #" << formula2 << "#" << endl;
612 }
613
614 strcat( formula2, ":" );
615
616 if( TransfName ) {
617 strcat( formula2, TransfName );
618 cout << "3 formula2 = #" << formula2 << "#" << endl;
619 }
620
621 if( i != fNsons-1 ) {
622 strcat( formula2, "+" );
623 cout << "4 formula2 = #" << formula2 << "#" << endl;
624 }
625
626 //strcat( formula2, "\x0" );
627 //cout << "5 formula2 = #" << formula2 << "#" << endl;
628
629 cout << " Y formula2 tiene un tamanyo de: " << strlen(formula2) << " caracteres." << endl;
630
631 //if( formula ) delete [] formula;
632 formula = new char[strlen(formula2)];
633 strcpy( formula, formula2 );
634 if( formula2 ) delete [] formula2;
635 }
636
637 const Text_t* shapetype = fShape->ClassName();
638 const Text_t* shapename = fShape->GetName();
639 const Text_t* materialname = fMaterial->GetName();
640
641 AliGConfig* tmp = new AliGConfig( name, title, formula, detail, shapetype, shapename, materialname, beg, end );
642
643 if(fConfig) delete fConfig;
644
645 fConfig = tmp;
646}
647*/
648
649//-------------------------------------------------------------------------
650
651void AliGNode::DrawShape(Option_t *option)
652{
653 Draw(option);
654 gPad->Update();
655}
656
657//----------------------------------------------------------------------
658
659void AliGNode::Draw(Option_t* option)
660{
661
662 TString opt = option;
663 opt.ToLower();
664//*-*- Clear pad if option "same" not given
665 if (!gPad) {
666 if (!gROOT->GetMakeDefCanvas()) return;
667 (gROOT->GetMakeDefCanvas())();
668 }
669 if (!opt.Contains("same")) gPad->Clear();
670
671//*-*- Draw Referenced node
672 //gGeometry->SetGeomLevel();
673 //gGeometry->UpdateTempMatrix();
674
675 AppendPad(option);
676
677//*-*- Create a 3-D View
678 TView *view = gPad->GetView();
679 if (!view) {
680 view = new TView(1);
681 view->SetAutoRange(kTRUE);
682 Paint(option);
683 view->SetAutoRange(kFALSE);
684 }
685}
686
687//------------------------------------------------------------------
688
689void AliGNode::Paint(Option_t *option)
690{
691 // Print();
692 TPadView3D *view3D=gPad->GetView3D();
693
694 //Int_t level = gGeometry->GeomLevel();
695// restrict the levels for "range" option
696 //if (level > 3 && strcmp(option,"range") == 0) return;
697//*-*- Update translation vector and rotation matrix for new level
698 //if (level) {
699 // gGeometry->UpdateTempMatrix(fX,fY,fZ,fMatrix->GetMatrix(),fMatrix->IsReflection());
700 // if (view3D)
701 // view3D->UpdateNodeMatrix(this,option);
702 // }
703
704//*-*- Paint Referenced shape
705// Int_t vis = fShape->GetVisibility();
706// if ( vis == -1) return;
707// if (vis == -3) {
708// if (nsons == 0) vis = 1;
709// else vis = 0;
710// }
711
712 // TAttLine::Modify();
713 // TAttFill::Modify();
714 //if (fVisibility && fShape->GetVisibility()) {
715 gNode = this;
716 //fShape->SetLineColor(GetLineColor());
717 //fShape->SetLineStyle(GetLineStyle());
718 //fShape->SetLineWidth(GetLineWidth());
719 //fShape->SetFillColor(GetFillColor());
720 //fShape->SetFillStyle(GetFillStyle());
721
722 Int_t nsons = 0;
723 if (fNnode) nsons = GetfNsons();
724 if (view3D)
725 view3D->SetAttNode((TNode*)this,option);
726
727
728 if(fVis) {
729 if( fShape )
730 fShape->Paint(option);
731 else
732 cout << " Intente dibujar donde no habia shape!!! " << endl;
733 }
734 //}
735 if ( TestBit(kSonsInvisible) ) return;
736
737//*-*- Paint all sons
738 if(!nsons) return;
739
740 //gGeometry->PushLevel();
741 for( int i=0; i<nsons; i++ ) {
742
743 gAliGeometry->PushMatrix(gMatrix);
744
745 AliGNode* node = (AliGNode*) fNode->At(fNnode->At(i));
746
747 AliGTransform* trans = (AliGTransform*) fTrans->At(fNtrans->At(i));
748 gAliGeometry->UpdateMatrix(trans);
749 node->Paint(option);
750 gAliGeometry->PopMatrix();
751
752 }
753 //gGeometry->PopLevel();
754
755}
756
757
758//--------------------------------------------------------------------
759
760Int_t AliGNode::DistancetoPrimitive(Int_t px, Int_t py)
761{
762 TView *view = gPad->GetView();
763 gPad->SetSelected(view);
764 return 0;
765}
766
767//--------------------------------------------------------------------
768