/home/cern/BDSIM_new/include/BDSGeometryGDML.hh

00001 /* * BDSIM code.    Version 1.0
00002    * Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    * Last modified 24.7.2002
00004    * Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 
00006 
00007    Author of this code: John C. Carter, Royal Holloway, Univ. of London.
00008    Last modified 13.04.2005
00009 */
00010 
00011 #ifdef USE_XML
00012 
00013 #ifndef BDSGeometryGDML_h
00014 #define BDSGeometryGDML_h 1
00015 
00016 #include "globals.hh"
00017 #include "BDSMaterials.hh"
00018 #include "G4LogicalVolume.hh"
00019 #include "G4VSolid.hh"
00020 #include "G4Cons.hh"
00021 #include "G4Tubs.hh"
00022 #include "G4Polycone.hh"
00023 #include "G4SubtractionSolid.hh"
00024 #include "G4Box.hh"
00025 #include "G4UserLimits.hh"
00026 #include "G4VisAttributes.hh"
00027 #include "BDSMySQLTable.hh"
00028 #include "G4VPhysicalVolume.hh"
00029 #include "G4PVPlacement.hh"
00030 #include "G4MagIntegratorStepper.hh"
00031 #include "G4Mag_UsualEqRhs.hh"
00032 #include "G4ChordFinder.hh"
00033 #include "G4FieldManager.hh"
00034 #include "BDSSamplerSD.hh"
00035 #include <fstream>
00036 #include <vector>
00037 #include <map>
00038 #include "BDSMagFieldSQL.hh"
00039 
00040 // Headers required for XML parsing
00041 #include <libxml/xmlmemory.h>
00042 #include <libxml/parser.h>
00043 #include <libxml/xpath.h>
00044 
00045 
00046 extern BDSMaterials* theMaterials;
00047 
00048 //using namespace std;
00049 
00050 class BDSClassicalRK4;
00051 
00052 struct POS_REF{
00053   G4String name;
00054   G4ThreeVector value;
00055 };
00056 
00057 struct ROT_REF{
00058   G4String name;
00059   G4ThreeVector value;
00060 };
00061 
00062 struct CONST_REF{
00063   G4String name;
00064   G4double value;
00065 };
00066 
00067 struct VIS_REF{
00068   G4String name;
00069   G4VisAttributes* value;
00070 };
00071 
00072 class BDSGeometryGDML
00073 {
00074 public:
00075   BDSGeometryGDML(G4String GDMLfile);
00076   ~BDSGeometryGDML();
00077 
00078   void parseDoc();
00079   void parseGDML(xmlNodePtr cur);
00080   void parseDISPLAY(xmlNodePtr cur);
00081   void parseVIS(xmlNodePtr cur);
00082   void parseDEFINE(xmlNodePtr cur);
00083   void parseMATERIALS(xmlNodePtr cur);
00084   void parseSOLID(xmlNodePtr cur);
00085   void parseSTRUCTURE(xmlNodePtr cur);
00086   void parseVOLUME(xmlNodePtr cur);
00087   void parsePHYSVOL(xmlNodePtr cur, G4String volume_name);
00088 
00089   G4RotationMatrix* RotateComponent(G4ThreeVector rotvalues);
00090 
00091   void Construct(G4LogicalVolume *marker);
00092   std::vector<G4LogicalVolume*> VOL_LIST;
00093   G4String parseStrChar(xmlChar* value);
00094   G4double parseDblChar(xmlChar* value);
00095   G4bool parseBoolChar(xmlChar* value);
00096 
00097   G4bool stripwhitespace(G4String& str);
00098 
00099   // used for parsing strings for math calculations
00100   G4bool EvaluateExpression(const char*, G4double& result);
00101   G4bool EvaluateTerm(const char* term, G4int termLength, G4double& result);
00102   G4bool VerifyExpression(const char*);
00103   G4bool VerifyNumber(const char*);
00104   G4bool StrToFloat(const char* str, G4int start, G4int end, G4double& f);
00105 
00106 private:
00107 
00108   // Fetching of imported objects
00109   G4VisAttributes* GetVisByName(G4String name);
00110   G4VSolid* GetSolidByName(G4String name);
00111   G4LogicalVolume* GetLogVolByName(G4String name);
00112   G4ThreeVector GetPosition(G4String name);
00113   G4ThreeVector GetPosition(xmlNodePtr cur, G4double lunit=0.0);
00114   G4RotationMatrix* GetRotation(G4String name);
00115   G4RotationMatrix* GetRotation(xmlNodePtr cur, G4double aunit=0.0);
00116 
00117 
00118   //Solid Builders
00119 
00120   void BuildBox(xmlNodePtr cur);
00121   void BuildTube(xmlNodePtr cur);
00122   void BuildPolycone(xmlNodePtr cur);
00123   void BuildSubtraction(xmlNodePtr cur);
00124 
00125   G4String itsGDMLfile;
00126   G4LogicalVolume* itsMarkerVol;
00127   std::vector <struct CONST_REF> CONST_LIST;
00128   std::vector <struct POS_REF> POS_LIST;
00129   std::vector <struct ROT_REF> ROT_LIST;
00130   std::vector <struct VIS_REF> VIS_LIST;
00131   std::vector <G4VSolid*> SOLID_LIST;
00132   std::vector <G4LogicalVolume*> LOGVOL_LIST;
00133 
00134   G4double visRed, visGreen, visBlue;
00135 
00136 
00137 protected:
00138 };
00139 
00140 inline G4ThreeVector BDSGeometryGDML::GetPosition(xmlNodePtr cur, G4double lunit)
00141 {
00142   G4String name, type;
00143   G4double unit;
00144   G4ThreeVector pos;
00145 
00146   name = parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"));     
00147   unit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"unit"));     
00148   type = parseStrChar(xmlGetProp(cur,(const xmlChar*)"type"));     
00149   pos  = G4ThreeVector(parseDblChar(xmlGetProp(cur,(const xmlChar*)"x")),
00150                        parseDblChar(xmlGetProp(cur,(const xmlChar*)"y")),
00151                        parseDblChar(xmlGetProp(cur,(const xmlChar*)"z")));
00152   if(unit!=0.0 && lunit==0) pos*=unit;
00153   else if(lunit!=0.0) pos*=lunit;
00154   POS_REF apos;
00155   apos.name = name;
00156   apos.value = pos;
00157   POS_LIST.push_back(apos);
00158   //G4cout << "pos: " <<name << " " << pos << G4endl;
00159   return pos;
00160 }
00161 inline G4ThreeVector BDSGeometryGDML::GetPosition(G4String name)
00162 {
00163   G4int ID = -1;
00164   G4int i;
00165   for(i=0; i<(G4int)POS_LIST.size();i++)
00166     {
00167       if(POS_LIST[i].name==name)
00168         {
00169           ID=i;
00170           break;
00171         }
00172     }
00173   if(ID==-1) // couldn't find it.
00174     {
00175       G4cout << "Couldn't find position: " << name<<G4endl;
00176       G4Exception("Quitting in BDSGeometryGDML");
00177     } 
00178   //G4cout << "pos: " <<name << " " << POS_LIST[ID].value << G4endl;
00179   return POS_LIST[ID].value;
00180 }
00181 inline G4RotationMatrix* BDSGeometryGDML::GetRotation(xmlNodePtr cur, G4double aunit)
00182 {
00183   G4String name, type;
00184   G4double unit;
00185   G4ThreeVector rotvect;
00186   
00187   name = parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"));     
00188   unit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"unit"));     
00189   type = parseStrChar(xmlGetProp(cur,(const xmlChar*)"type"));     
00190   rotvect = G4ThreeVector(parseDblChar(xmlGetProp(cur,(const xmlChar*)"x")),
00191                           parseDblChar(xmlGetProp(cur,(const xmlChar*)"y")),
00192                           parseDblChar(xmlGetProp(cur,(const xmlChar*)"z")));
00193   if(unit!=0.0 && aunit==0) rotvect*=unit;
00194   else if(aunit!=0.0) rotvect*=aunit;
00195   ROT_REF arot;
00196   arot.name = name;
00197   arot.value = rotvect;
00198   ROT_LIST.push_back(arot);
00199   //G4cout << "rot: " << name << " "<<rotvect << G4endl;
00200   return RotateComponent(rotvect);
00201 }
00202 inline G4RotationMatrix* BDSGeometryGDML::GetRotation(G4String name)
00203 {
00204   G4int ID = -1;
00205   G4int i;
00206   for(i=0; i<(G4int)ROT_LIST.size();i++)
00207     {
00208       if(ROT_LIST[i].name==name)
00209         {
00210           ID=i;
00211           break;
00212         }
00213     }
00214   if(ID==-1) // couldn't find it.
00215     {
00216       G4cout << "Couldn't find rotation: " << name<<G4endl;
00217       G4Exception("Quitting in BDSGeometryGDML");
00218     } 
00219   //G4cout << "rot: " << name << " "<<ROT_LIST[ID].value << G4endl;
00220   return RotateComponent(ROT_LIST[ID].value);
00221 }
00222 inline G4VisAttributes* BDSGeometryGDML::GetVisByName(G4String name)
00223 {
00224   G4int ID = -1;
00225   G4int i;
00226   for(i=0; i<(G4int)VIS_LIST.size(); i++)
00227     {
00228       if(VIS_LIST[i].name==name)
00229         {
00230           ID=i;
00231           break;
00232         }
00233     }
00234   if(ID==-1) // couldn't find it.
00235     {
00236       G4cout << "Couldn't find visref: " << name<<G4endl;
00237       G4cout << "Using default Vis settings" << G4endl;
00238       return new G4VisAttributes(G4Colour(1.0,1.0,1.0));
00239     } 
00240   
00241   return VIS_LIST[ID].value;
00242 }
00243 inline G4VSolid* BDSGeometryGDML::GetSolidByName(G4String name)
00244 {
00245   G4int ID = -1;
00246   G4int i;
00247   for(i=0; i<(G4int)SOLID_LIST.size(); i++)
00248     {
00249       if(SOLID_LIST[i]->GetName()==name)
00250         {
00251           ID=i;
00252           break;
00253         }
00254     }
00255   if(ID==-1) // couldn't find it.
00256     {
00257       G4cout << "Couldn't find solid: " << name<<G4endl;
00258       G4Exception("Quitting in BDSGeometryGDML");
00259     } 
00260   return SOLID_LIST[ID];
00261 }
00262 
00263 inline G4LogicalVolume* BDSGeometryGDML::GetLogVolByName(G4String name)
00264 {
00265   G4String::caseCompare cmpmode = G4String::ignoreCase;
00266   G4int ID = -1;
00267   G4int i;
00268   for(i=0; i<(G4int)LOGVOL_LIST.size(); i++)
00269     {
00270       if(LOGVOL_LIST[i]->GetName()==name)
00271         {
00272           ID=i;
00273           break;
00274         }
00275     }
00276   if(ID==-1) // couldn't find it.
00277     {
00278       G4cout << "Couldn't find logical volume: " << name<<G4endl;
00279       G4Exception("Quitting in BDSGeometryGDML");
00280     }
00281   return LOGVOL_LIST[ID];
00282 }
00283 
00284 inline G4String BDSGeometryGDML::parseStrChar(xmlChar* value)
00285 {
00286   if(value==NULL) return "";
00287   G4String val = G4String((char*)value);
00288   //G4cout << "strVAL: "<< val << G4endl;
00289   return val;
00290 }
00291 
00292 inline G4bool BDSGeometryGDML::parseBoolChar(xmlChar* value)
00293 {
00294   if(value==NULL) return false;
00295   G4String val = G4String((char*)value);
00296   
00297   if(val=="true") return true;
00298   if(val=="false") return false;
00299 
00300   return false;
00301 }
00302 
00303 inline G4double BDSGeometryGDML::parseDblChar(xmlChar* value)
00304 {
00305   if(value==NULL) return 0.0;
00306   G4String val = G4String((char*)value);
00307   stripwhitespace(val);
00308   //G4cout << "dblVAL: "<< val << G4endl;
00309   // now check for defined constants
00310   for(G4int i=0; i<CONST_LIST.size(); i++)
00311     {
00312       if(val.contains(CONST_LIST[i].name))
00313         {
00314           //check that this is the entire constant, and not part of a larger name
00315           // e.g "zpos" and "zpos_world"
00316           G4int endpos = val.index(CONST_LIST[i].name)+(CONST_LIST[i].name).length();
00317           G4int startpos = val.index(CONST_LIST[i].name);
00318           G4bool replaceStr = false;
00319           if(val==CONST_LIST[i].name) replaceStr = true;
00320           
00321           //check after string for math operators or end of string
00322           else if((val.data()[endpos] == '+' ||
00323                    val.data()[endpos] == '-' ||
00324                    val.data()[endpos] == '*' ||
00325                    val.data()[endpos] == '/' ||
00326                    endpos>=val.length())     &&
00327                   (val.data()[startpos-1] == '+' ||
00328                    val.data()[startpos-1] == '-' ||
00329                    val.data()[startpos-1] == '*' ||
00330                    val.data()[startpos-1] == '/' ||
00331                    startpos-1<=0))
00332             replaceStr = true;
00333  
00334           // replace all instances of constant with value
00335 
00336           if(replaceStr)
00337             {
00338               char constval[40];
00339               sprintf(constval,"%f",CONST_LIST[i].value);
00340               val.replace(val.index((CONST_LIST[i].name)), (CONST_LIST[i].name).length(), constval);
00341               i=0;
00342             }
00343         }
00344     }
00345   G4double dbl_val = 0.0;
00346 
00347   if(VerifyExpression(val)) EvaluateExpression(val.data(),dbl_val);
00348   else
00349     {
00350       G4cout << "Unable to evaluate expression: " << value << G4endl;
00351       G4Exception("Check spellings and that constants are declared properly");
00352     }
00353     
00354   return dbl_val;
00355 }
00356 
00357 inline G4bool BDSGeometryGDML::EvaluateExpression(const char* expr, G4double& result)
00358 {
00359 
00360   G4int length = strlen(expr);
00361   G4int end = length-1;
00362   double term;
00363   result = 0.0;
00364   G4int i;
00365   for(i = length-1; i>=0; i--)
00366     {
00367       if(expr[i]=='+')
00368         {
00369           if(!EvaluateTerm(expr + i + 1, end-i, term))
00370             return false;
00371           result += term;
00372           end = i-1;
00373         }
00374       else if (expr[i] == '-')
00375         {
00376           if(!EvaluateTerm(expr + i + 1, end-i, term))
00377             return false;
00378           result -= term;
00379           end = i-1;      
00380         }
00381     }
00382   
00383   if (expr[0] !='+' && expr[0]!='-')
00384     {
00385       if(!EvaluateTerm(expr, end+1, term))
00386         return false;
00387       result += term;
00388       end = i-1;          
00389     }
00390 
00391   return true;
00392 
00393 }
00394 
00395 inline G4bool BDSGeometryGDML::EvaluateTerm(const char* term, G4int termLength, G4double& result)
00396 {
00397   G4int end = termLength-1;
00398   result = 1.0;
00399   G4double number;
00400   G4int i;
00401   for (i = end ; i>=0; i--)
00402     {
00403       if(term[i] == '*')
00404         {
00405           if(!StrToFloat(term+i+1, 0, end-i, number))
00406             return false;
00407           result *= number;
00408           end = i-1;
00409         }
00410       else if(term[i] == '/')
00411         {
00412           if(!StrToFloat(term+i+1, 0, end-i, number))
00413             return false;
00414           result /= number;
00415           end = i-1;
00416         }
00417     }
00418   if (term[0] != '*' && term[0] != '/')
00419     {    
00420       if(!StrToFloat(term, 0, end+1, number))
00421         return false;
00422       result *= number;
00423     }
00424   return true;
00425 }
00426 
00427 inline G4bool BDSGeometryGDML::VerifyExpression(const char* expr)
00428 {
00429   G4int length = strlen(expr);
00430   if(length==0) return false;
00431   G4int i;
00432   for (i=0; i<length; i++)
00433     {
00434       if(expr[i] >='0' && expr[i] <= '9')
00435         continue;
00436       else
00437         if (expr[i] == '+' || expr[i] =='-' || expr[i] =='*' ||
00438             expr[i] == '/' || expr[i] =='.' || expr[i] =='e' ||
00439             expr[i] == 'E' || expr[i] =='^')
00440           continue;
00441         else return false;
00442     }
00443   return true;
00444 }
00445 
00446 inline G4bool BDSGeometryGDML::VerifyNumber(const char* expr)
00447 {
00448   G4int length = strlen(expr);
00449   if(length==0) return false;
00450   G4int i;
00451   for (i=0; i<length; i++)
00452     {
00453       if(expr[i] >='0' && expr[i] <= '9')
00454         continue;
00455       else
00456         if (expr[i] =='.') continue;
00457         else return false;
00458     }
00459   return true;
00460 }
00461 
00462 inline G4bool BDSGeometryGDML::StrToFloat(const char* str, G4int start, G4int end, G4double& f)
00463 {
00464   if(!str) return false;
00465   
00466   G4double factor=0.1;
00467   G4int i,j;
00468   for(i=start; i<end; i++)
00469     {
00470 
00471       if(str[i]=='.' && (str[i+1]=='e' || str[i]=='E' || str[i] =='^'))
00472         {
00473           for(j= i+2; j< end; j++)
00474             if(str[j] <'0' || str[j] >'9') return false;
00475           break;
00476         }
00477       else if(str[i]=='.')
00478         {
00479           for(j= i+1; j< end; j++)
00480             if(str[j] <'0' || str[j] >'9') return false;
00481           break;
00482         }
00483       else if(str[i] =='^')
00484         {
00485           for(j= i+1; j< end; j++)
00486             {
00487               if(str[j] == '.') continue;
00488               if(str[j] <'0' || str[j] >'9') return false;
00489             }
00490           break;
00491         }
00492       else if(str[i]=='e'  || str[i]=='E')
00493         {
00494           for(j= i+1; j< end; j++)
00495             if(str[j] <'0' || str[j] >'9') return false;
00496           break;
00497         }
00498       else if(str[i] <'0' || str[i]>'9') return false;
00499       factor *=10;
00500     }
00501   
00502   f=0.0;
00503   for(i=start; i<end; i++)
00504     {
00505       if(str[i]=='.') continue;
00506 
00507       else if(str[i]=='e'  || str[i]=='E')
00508         {               
00509           G4double f1 = 0.0;
00510           G4double f2 = 0.0;
00511           StrToFloat(str,0,i,f1);
00512           StrToFloat(str,i+1,end,f2);
00513           f = f1*pow(10,f2);
00514         }
00515       else if(str[i]=='^')
00516         {
00517           G4double f1 = 0.0;
00518           G4double f2 = 0.0;
00519           StrToFloat(str,0,i,f1);
00520           StrToFloat(str,i+1,end,f2);
00521           f = pow(f1,f2);
00522         }
00523 
00524       else
00525         {
00526           f+= (G4double)(str[i] - '0')*factor;
00527           factor *= 0.1;
00528         }
00529     }
00530   return true;
00531 
00532 }
00533 
00534 inline G4bool BDSGeometryGDML::stripwhitespace(G4String& str)
00535 {
00536   //return false if nothing done
00537   if(str.length()==0) return false;
00538 
00539   G4String newstr;
00540 
00541   str_size i;
00542   for(i=0;i<str.length();i++)
00543     {
00544       if(str[i] != ' ')
00545         newstr+=str[i];
00546     }
00547 
00548   str = newstr;
00549   return true;
00550 }
00551 
00552 inline void BDSGeometryGDML::BuildBox(xmlNodePtr cur)
00553 {
00554   G4String name = parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"));
00555   G4double x = parseDblChar(xmlGetProp(cur,(const xmlChar*)"x")); 
00556   G4double y = parseDblChar(xmlGetProp(cur,(const xmlChar*)"y")); 
00557   G4double z = parseDblChar(xmlGetProp(cur,(const xmlChar*)"z")); 
00558   
00559   G4double lunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"lunit"));
00560   G4double aunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"launit"));
00561   
00562   if(aunit!=0) {}
00563   if(lunit!=0) 
00564     {
00565       x*=lunit;
00566       y*=lunit;
00567       z*=lunit;
00568     }
00569   
00570   SOLID_LIST.push_back(new G4Box(name,
00571                                  x/2.0,
00572                                  y/2.0,
00573                                  z/2.0)
00574                        );
00575 }
00576 inline void BDSGeometryGDML::BuildTube(xmlNodePtr cur)
00577 {
00578   G4String name = parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"));
00579   G4double rmin = parseDblChar(xmlGetProp(cur,(const xmlChar*)"rmin"));
00580   G4double rmax = parseDblChar(xmlGetProp(cur,(const xmlChar*)"rmax"));
00581   G4double length = parseDblChar(xmlGetProp(cur,(const xmlChar*)"z"));
00582   G4double dphi = parseDblChar(xmlGetProp(cur,(const xmlChar*)"deltaphi"));
00583   
00584   G4double lunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"lunit"));
00585   G4double aunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"launit"));
00586   
00587   if(aunit!=0) dphi*=aunit;
00588   if(lunit!=0) 
00589     {
00590       rmin*=lunit;
00591       rmax*=lunit;
00592       length*=lunit;
00593     }
00594   
00595   SOLID_LIST.push_back(new G4Tubs(name,
00596                                   rmin,
00597                                   rmax,
00598                                   length/2.0,
00599                                   0.0,
00600                                   dphi)
00601                        );
00602 }
00603 inline void BDSGeometryGDML::BuildPolycone(xmlNodePtr cur)
00604 {
00605   xmlNodePtr tempcur = cur->xmlChildrenNode;
00606   
00607   G4int numZPlanes = 0;
00608   while(tempcur!=NULL)
00609     {
00610       if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"zplane")))
00611         numZPlanes++;
00612       tempcur = tempcur->next;
00613     }
00614   
00615   G4double* zPlanes = NULL;
00616   G4double* rInner = NULL;
00617   G4double* rOuter = NULL;
00618   zPlanes = new G4double[numZPlanes];
00619   rInner = new G4double[numZPlanes];
00620   rOuter = new G4double[numZPlanes];
00621   
00622   tempcur = cur->xmlChildrenNode;
00623   G4int i=0;
00624   while(tempcur!=NULL)
00625     {
00626       if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"zplane")))
00627         {
00628           zPlanes[i] = parseDblChar(xmlGetProp(tempcur,(const xmlChar*)"z"));
00629           rInner[i] = parseDblChar(xmlGetProp(tempcur,(const xmlChar*)"rmin"));
00630           rOuter[i] = parseDblChar(xmlGetProp(tempcur,(const xmlChar*)"rmax"));
00631           i++;
00632         }
00633       tempcur = tempcur->next;
00634     }
00635   
00636   SOLID_LIST.push_back(new G4Polycone((parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"))),
00637                                       parseDblChar(xmlGetProp(cur,(const xmlChar*)"startphi")),
00638                                       parseDblChar(xmlGetProp(cur,(const xmlChar*)"deltaphi")),
00639                                       numZPlanes,
00640                                       zPlanes,
00641                                       rInner,
00642                                       rOuter)
00643                        );
00644   
00645   delete [] rInner;
00646   rInner = NULL;
00647   delete [] rOuter;
00648   rOuter = NULL;
00649   delete [] zPlanes;
00650   zPlanes = NULL;
00651 }
00652 inline void BDSGeometryGDML::BuildSubtraction(xmlNodePtr cur)
00653 {
00654   
00655   G4String name = parseStrChar(xmlGetProp(cur,(const xmlChar*)"name"));
00656   G4double lunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"lunit"));
00657   G4double aunit = parseDblChar(xmlGetProp(cur,(const xmlChar*)"launit"));
00658   G4String firstname, secondname;
00659   
00660   G4ThreeVector PlacementPoint = G4ThreeVector(0.,0.,0.);
00661 
00662   G4RotationMatrix* componentRotation = NULL;
00663 
00664   G4ThreeVector FirstPlacementPoint = G4ThreeVector(0.,0.,0.);
00665 
00666   G4RotationMatrix* componentFirstRot = NULL;
00667   
00668   xmlNodePtr tempcur = cur->xmlChildrenNode;
00669   
00670   while(tempcur!=NULL)
00671     {
00672       if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"first")))
00673         firstname = parseStrChar(xmlGetProp(tempcur,(const xmlChar*)"ref"));
00674       
00675       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"second")))
00676         secondname = parseStrChar(xmlGetProp(tempcur,(const xmlChar*)"ref"));
00677       
00678       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"position")))
00679         PlacementPoint = GetPosition(tempcur,lunit);
00680       
00681       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"positionref")))
00682         PlacementPoint = GetPosition(parseStrChar(xmlGetProp(tempcur,(const xmlChar*)"ref")));
00683       
00684       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"rotation")))
00685         componentRotation = GetRotation(tempcur,aunit);
00686 
00687       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"rotationref")))
00688         componentRotation = GetRotation(parseStrChar(xmlGetProp(tempcur,(const xmlChar*)"ref")));
00689       
00690       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"firstposition")))
00691         G4cout << "BDSGeometryGDML::BuildSubtraction: " << name<< " firstposition not supported" << G4endl;
00692 
00693       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"firstpositionref")))
00694         G4cout << "BDSGeometryGDML::BuildSubtraction: " << name<< " firstpositionref not supported" << G4endl;
00695         
00696       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"firstrotation")))
00697         G4cout << "BDSGeometryGDML::BuildSubtraction: " << name<< " firstrotation not supported" << G4endl;
00698         
00699       else if ((!xmlStrcmp(tempcur->name, (const xmlChar *)"firstrotationref")))
00700         G4cout << "BDSGeometryGDML::BuildSubtraction: " << name<< " firstrotationref not supported" << G4endl;
00701               
00702       tempcur = tempcur->next;
00703     }
00704   
00705   
00706   if(componentRotation==0 && PlacementPoint==0)
00707     {
00708       SOLID_LIST.push_back(new G4SubtractionSolid(name,
00709                                                   GetSolidByName(firstname),
00710                                                   GetSolidByName(secondname))
00711                            );
00712     }
00713   else
00714     {
00715       G4Transform3D transform(*componentRotation,PlacementPoint);
00716       SOLID_LIST.push_back(new G4SubtractionSolid(name,
00717                                                   GetSolidByName(firstname),
00718                                                   GetSolidByName(secondname),
00719                                                   transform)
00720                            );
00721       
00722     }
00723     
00724 }
00725 
00726 
00727 #endif
00728 
00729 #endif //from use_xml

Generated on Wed Mar 5 17:25:21 2008 for BDSIM by  doxygen 1.5.3