2 added + 10 modified, total 12 files
lcdd/include
diff -N LCDDFieldManager.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCDDFieldManager.hh 4 May 2006 20:48:44 -0000 1.1
@@ -0,0 +1,42 @@
+#ifndef LCDDFieldManager_hh
+#define LCDDFieldManager_hh 1
+
+#include "MagneticFieldOverlay.hh"
+#include "LCDDProcessor.hh"
+#include "G4FieldManager.hh"
+#include "G4TransportationManager.hh"
+
+class LCDDFieldManager
+{
+
+public:
+
+ virtual ~LCDDFieldManager();
+
+ static LCDDFieldManager* instance();
+
+ MagneticFieldOverlay* makeOverlay(std::vector<G4MagneticField*> fields);
+
+ void setup();
+
+ G4MagneticField* setup(std::vector<G4MagneticField*> fields);
+
+ void initialize(G4MagneticField* field);
+
+ void addGlobalField(G4MagneticField* f);
+
+ void addField(G4MagneticField* f);
+
+private:
+
+ LCDDFieldManager();
+
+private:
+
+ std::vector<G4MagneticField*> m_globalfields;
+ std::vector<G4MagneticField*> m_allfields;
+
+ static LCDDFieldManager* m_instance;
+};
+
+#endif
lcdd/include
diff -N global_field.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ global_field.hh 4 May 2006 20:48:44 -0000 1.3
@@ -0,0 +1,29 @@
+// $Header: /cvs/lcd/lcdd/include/global_field.hh,v 1.3 2006/05/04 20:48:44 jeremy Exp $
+
+#ifndef global_field_hh
+#define global_field_hh 1
+
+#include "Saxana/SAXObject.h"
+
+#include "GlobalFieldType.hh"
+
+/**
+ @class global_field
+ @brief global_field element from schema.
+ */
+class global_field : public SAXObject, public GlobalFieldType
+{
+public:
+ global_field()
+ {}
+
+ virtual ~global_field()
+ {}
+
+ virtual SAXObject::Type type()
+ {
+ return SAXObject::element;
+ }
+};
+
+#endif
lcdd/include
diff -u -r1.19 -r1.20
--- LCDDProcessor.hh 21 Apr 2006 23:51:26 -0000 1.19
+++ LCDDProcessor.hh 4 May 2006 20:48:44 -0000 1.20
@@ -58,25 +58,12 @@
// Mag Field
void addMagneticField(std::string& name, G4MagneticField* mag);
-
G4MagneticField* getMagneticField(const std::string& name);
G4MagneticField* getMagneticField(const char* name);
LCDDProcessor::MagneticFields::const_iterator getMagneticFieldsBegin();
LCDDProcessor::MagneticFields::const_iterator getMagneticFieldsEnd();
- // DEPRECATED
- void setGlobalMagneticField(G4MagneticField *mag);
-
- // DEPRECATED
- void setGlobalMagneticField( const std::string& name);
-
- // DEPRECATED
- void setGlobalMagneticField( const char* name);
-
- // Setup the global overlay field.
- void setupGlobalMagneticField();
-
// Regions
void addRegion(std::string& name, G4Region* reg);
@@ -120,9 +107,6 @@
LCDDProcessor::VisAttributes m_visAttributes;
LCDDProcessor::LimitSets m_limitSets;
- // was global field setup?
- bool m_globalMagneticFieldIsInitialized;
-
// static singleton instance var
static LCDDProcessor* sInstance;
};
lcdd/schemas/lcdd/1.0
diff -u -r1.8 -r1.9
--- lcdd_fields.xsd 22 Apr 2006 00:04:09 -0000 1.8
+++ lcdd_fields.xsd 4 May 2006 20:48:44 -0000 1.9
@@ -14,12 +14,23 @@
</xs:annotation>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" ref="field" />
+ <xs:element name="global_field" minOccurs="0" maxOccurs="1" type="GlobalFieldType" />
</xs:sequence>
</xs:complexType>
<xs:element name="fields" type="FieldsType">
</xs:element>
+ <xs:complexType name="GlobalFieldType">
+ <xs:annotation>
+ <xs:documentation>
+ </xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="fieldref" minOccurs="1" maxOccurs="1" type="ReferenceType" />
+ </xs:sequence>
+ </xs:complexType>
+
<xs:complexType name="FieldType">
<xs:attribute name="name" type="xs:ID"/>
<xs:attribute default="tesla" name="funit" type="xs:string"/>
lcdd/src
diff -N LCDDFieldManager.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCDDFieldManager.cc 4 May 2006 20:48:45 -0000 1.1
@@ -0,0 +1,75 @@
+#include "LCDDFieldManager.hh"
+
+LCDDFieldManager* LCDDFieldManager::m_instance = 0;
+
+LCDDFieldManager::~LCDDFieldManager()
+{}
+
+LCDDFieldManager* LCDDFieldManager::instance()
+{
+ if (m_instance == 0) {
+ m_instance = new LCDDFieldManager();
+ }
+ return m_instance;
+}
+
+MagneticFieldOverlay* LCDDFieldManager::makeOverlay(std::vector<G4MagneticField*> fields)
+{
+ MagneticFieldOverlay* overlay = new MagneticFieldOverlay();
+ for (std::vector<G4MagneticField*>::const_iterator iter = fields.begin();
+ iter != fields.end();
+ iter++) {
+ overlay->addMagneticField(*iter);
+ }
+ return overlay;
+}
+
+void LCDDFieldManager::setup()
+{
+ G4MagneticField* field = 0;
+ if (m_globalfields.size() != 0) {
+ field = setup(m_globalfields);
+ }
+ else if (m_allfields.size() != 0) {
+ field = setup(m_allfields);
+ }
+ initialize(field);
+}
+
+G4MagneticField* LCDDFieldManager::setup(std::vector<G4MagneticField*> fields)
+{
+ G4MagneticField* field = 0;
+ if (fields.size() == 0) {
+ G4cerr << "ERROR - No fields to setup." << G4endl;
+ }
+ else if (fields.size() == 1) {
+ field = fields[0];
+ }
+ else {
+ field = makeOverlay(fields);
+ }
+ return field;
+}
+
+void LCDDFieldManager::initialize(G4MagneticField* field)
+{
+ if (field != 0) {
+ G4FieldManager* fieldMgr =
+ G4TransportationManager::GetTransportationManager()->GetFieldManager();
+ fieldMgr->SetDetectorField(field);
+ fieldMgr->CreateChordFinder(field);
+ }
+}
+
+void LCDDFieldManager::addGlobalField(G4MagneticField* f)
+{
+ m_globalfields.push_back(f);
+}
+
+void LCDDFieldManager::addField(G4MagneticField* f)
+{
+ m_allfields.push_back(f);
+}
+
+LCDDFieldManager::LCDDFieldManager()
+{}
lcdd/src
diff -N global_fieldProcess.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ global_fieldProcess.cc 4 May 2006 20:48:45 -0000 1.3
@@ -0,0 +1,72 @@
+// $Header: /cvs/lcd/lcdd/src/global_fieldProcess.cc,v 1.3 2006/05/04 20:48:45 jeremy Exp $
+
+#include "Saxana/ProcessingConfigurator.h"
+#include "Saxana/ProcessingContext.h"
+#include "Saxana/SAXProcessor.h"
+#include "Saxana/StateStack.h"
+#include "Saxana/SAXProcessingState.h"
+#include "Saxana/SAXStateProcess.h"
+#include "Saxana/SAXComponentFactory.h"
+
+#include "global_field.hh"
+#include "SensitiveDetectorTypeProcess.hh"
+
+#include <iostream>
+
+/**
+ @class global_fieldProcess
+ @brief SAX process for global_field element.
+*/
+class global_fieldProcess : public SAXStateProcess
+{
+public:
+ global_fieldProcess(const ProcessingContext* context = 0)
+ : SAXStateProcess(context),
+ m_obj(0)
+ {}
+
+ virtual ~global_fieldProcess()
+ {}
+
+ virtual void StartElement(const std::string&, const ASCIIAttributeList&)
+ {
+ //std::cout << "global_fieldProcess::StartElement: " << name << std::endl;
+
+ SAXObject** obj = Context()->GetTopObject();
+
+ global_field* cal = new global_field;
+
+ m_obj = cal;
+ *obj = cal;
+ }
+
+ virtual void EndElement(const std::string&)
+ {
+ //std::cout << "global_fieldProcess::EndElement: " << name << " " << std::endl;
+ }
+
+ virtual void Characters(const std::string&)
+ {}
+
+ virtual void StackPopNotify(const std::string& name)
+ {
+ //std::cout << "global_fieldProcess::StackPopNotify: " << name << std::endl;
+
+ SAXObject** so = Context()->GetTopObject();
+ global_field* fobj = dynamic_cast<global_field*>( m_obj );
+
+ fobj->add_content( name, *so);
+ }
+
+ virtual const std::string& State() const
+ {
+ static std::string tag = "global_field";
+ return tag;
+ }
+
+protected:
+ SAXObject* m_obj;
+
+};
+
+DECLARE_PROCESS_FACTORY(global_fieldProcess)
lcdd/src
diff -N global_fieldSubscriber.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ global_fieldSubscriber.cc 4 May 2006 20:48:45 -0000 1.9
@@ -0,0 +1,91 @@
+// $Id: global_fieldSubscriber.cc,v 1.9 2006/05/04 20:48:45 jeremy Exp $
+
+// lcdd
+#include "LCDDProcessor.hh"
+#include "LCDDFieldManager.hh"
+#include "global_field.hh"
+#include "FieldType.hh"
+
+// gdml
+#include "Saxana/SAXSubscriber.h"
+#include "Saxana/SAXComponentFactory.h"
+#include "G4Processor/GDMLProcessor.h"
+
+// std
+#include <iostream>
+
+// Geant4
+#include "G4MagneticField.hh"
+
+/**
+ @class global_fieldSubscriber
+ @brief SAX subscriber for global_field element.
+ @note Resolves fieldref and sets global field in LCDDProcessor.
+*/
+class global_fieldSubscriber : virtual public SAXSubscriber
+{
+public:
+ virtual const SAXComponentObject* Build() const
+ {
+ return this;
+ }
+
+public:
+ global_fieldSubscriber()
+ {
+ Subscribe( "global_field" );
+ }
+
+ virtual ~global_fieldSubscriber()
+ {}
+
+ virtual void Activate( const SAXObject* object)
+ {
+ //std::cout << "global_field Subscriber" << std::endl;
+
+ const global_field* fobj = 0;
+ G4MagneticField* mag = 0;
+ LCDDProcessor* proc = LCDDProcessor::instance();
+
+ if ( object != 0 ) {
+ fobj = dynamic_cast<const global_field*>( object );
+
+ if ( fobj ) {
+ const ContentSequence* seq = fobj->get_content();
+
+ size_t count = seq->size();
+
+ for ( size_t i = 0; i < count; i++ ) {
+ if ( seq->content(i).tag == "fieldref" ) {
+ FieldType::fieldref* fref =
+ dynamic_cast<FieldType::fieldref*>( seq->content(i).object );
+
+ //std::cout << "fieldref: " << fref->get_ref() << std::endl;
+
+ mag = proc->getMagneticField( fref->get_ref() );
+
+ if (mag != 0) {
+ LCDDFieldManager::instance()->addGlobalField(mag);
+ }
+
+ //if ( mag ) {
+ // proc->setGlobalMagneticField( mag );
+ //}
+ /* FATAL ERROR: field was not found */
+ //else {
+ // std::cerr << "Unknown field reference: " << fref->get_ref() << std::endl;
+ // G4Exception("Failed to setup specified global field.");
+ //}
+ }
+ }
+
+ }
+ else {
+ std::cerr << "Failed cast to global_field!" << std::endl;
+ }
+ }
+ }
+};
+
+DECLARE_SUBSCRIBER_FACTORY(global_fieldSubscriber)
+
lcdd/src
diff -u -r1.10 -r1.11
--- LCDDDetectorConstruction.cc 21 Apr 2006 23:51:27 -0000 1.10
+++ LCDDDetectorConstruction.cc 4 May 2006 20:48:45 -0000 1.11
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/LCDDDetectorConstruction.cc,v 1.10 2006/04/21 23:51:27 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/LCDDDetectorConstruction.cc,v 1.11 2006/05/04 20:48:45 jeremy Exp $
// LCDD
#include "LCDDDetectorConstruction.hh"
@@ -55,7 +55,7 @@
// Setup the global magnetic field.
// TODO: Probably this call belongs someplace else. It is the only
// direct coupling to LCDDProcessor.
- LCDDProcessor::instance()->setupGlobalMagneticField();
+ //LCDDProcessor::instance()->setupGlobalMagneticField();
// stop build timer and print
geoTimer.Stop();
lcdd/src
diff -u -r1.22 -r1.23
--- LCDDLibLoad.cc 22 Apr 2006 00:04:09 -0000 1.22
+++ LCDDLibLoad.cc 4 May 2006 20:48:45 -0000 1.23
@@ -36,6 +36,7 @@
// field
LOAD_COMPONENT(fieldrefProcess);
+ LOAD_COMPONENT(global_fieldProcess);
LOAD_COMPONENT(solenoidProcess);
LOAD_COMPONENT(rz_field_mapProcess);
LOAD_COMPONENT(rzbProcess);
@@ -77,6 +78,7 @@
LOAD_COMPONENT(solenoidSubscriber);
LOAD_COMPONENT(rz_field_mapSubscriber);
LOAD_COMPONENT(dipoleSubscriber);
+ LOAD_COMPONENT(global_fieldSubscriber);
// region
LOAD_COMPONENT(regionSubscriber);
lcdd/src
diff -u -r1.5 -r1.6
--- LCDDParser.cc 6 Sep 2005 17:25:08 -0000 1.5
+++ LCDDParser.cc 4 May 2006 20:48:45 -0000 1.6
@@ -1,10 +1,14 @@
-// $Header: /cvs/lcd/lcdd/src/LCDDParser.cc,v 1.5 2005/09/06 17:25:08 jeremy Exp $
-
+// $Header: /cvs/lcd/lcdd/src/LCDDParser.cc,v 1.6 2006/05/04 20:48:45 jeremy Exp $
#include "LCDDParser.hh"
+// lcdd
+#include "LCDDFieldManager.hh"
+
+// gdml
#include "G4Processor/GDMLProcessor.h"
#include "Saxana/SAXComponentFactoryTable.h"
+// geant4
#include "G4VPhysicalVolume.hh"
extern "C" void LCDDLibLoad();
@@ -104,6 +108,11 @@
G4Exception("GDML failed to construct the world volume.");
}
+ // Setup magnetic field.
+ LCDDFieldManager::instance()->setup();
+
+ //LCDDProcessor::instance()->setupGlobalMagneticField();
+
// should only happen once
m_constructed = true;
}
lcdd/src
diff -u -r1.13 -r1.14
--- LCDDProcessor.cc 21 Apr 2006 23:51:27 -0000 1.13
+++ LCDDProcessor.cc 4 May 2006 20:48:45 -0000 1.14
@@ -1,5 +1,7 @@
#include "LCDDProcessor.hh"
+#include "LCDDFieldManager.hh"
+
#include "G4TransportationManager.hh"
#include "G4FieldManager.hh"
#include "G4EventManager.hh"
@@ -12,8 +14,7 @@
LCDDProcessor* LCDDProcessor::sInstance = 0;
LCDDProcessor::LCDDProcessor()
- : m_header(0),
- m_globalMagneticFieldIsInitialized(0)
+ : m_header(0)
{}
LCDDProcessor::~LCDDProcessor()
@@ -86,59 +87,6 @@
return m_magneticFields.end();
}
-void LCDDProcessor::setupGlobalMagneticField()
-{
- // Add all the magnetic fields declared in the LCDD file to an overlay field.
- MagneticFieldOverlay* overlay = new MagneticFieldOverlay();
- for (MagneticFields::const_iterator iter = m_magneticFields.begin();
- iter != m_magneticFields.end();
- iter++) {
- overlay->addMagneticField(iter->second);
- }
-
- // Setup Geant4 to use the overlay field.
- G4FieldManager* fieldMgr =
- G4TransportationManager::GetTransportationManager()->GetFieldManager();
- fieldMgr->SetDetectorField(overlay);
- fieldMgr->CreateChordFinder(overlay);
-
- m_globalMagneticFieldIsInitialized = true;
-}
-
-// DEPRECATED
-void LCDDProcessor::setGlobalMagneticField(G4MagneticField *mag)
-{
- if( m_globalMagneticFieldIsInitialized == false ) {
- G4FieldManager* fieldMgr =
- G4TransportationManager::GetTransportationManager()->GetFieldManager();
- fieldMgr->SetDetectorField(mag);
- fieldMgr->CreateChordFinder(mag);
- m_globalMagneticFieldIsInitialized = true;
- }
- else {
- std::cerr << "Global MagneticField is already initialized!" << std::endl;
- }
-}
-
-// DEPRECATED
-void LCDDProcessor::setGlobalMagneticField( const std::string& name)
-{
- G4MagneticField* m = getMagneticField( name );
-
- if ( m ) {
- setGlobalMagneticField( m );
- }
- else {
- std::cerr << "Could not find <" << name << "> to set global MagneticField." << std::endl;
- }
-}
-
-void LCDDProcessor::setGlobalMagneticField( const char* name)
-{
- std::string key = name;
- setGlobalMagneticField( key );
-}
-
void LCDDProcessor::addRegion(std::string& name, G4Region* reg)
{
m_regions[name] = reg;
lcdd/src
diff -u -r1.1 -r1.2
--- MagneticFieldOverlay.cc 21 Apr 2006 23:51:27 -0000 1.1
+++ MagneticFieldOverlay.cc 4 May 2006 20:48:45 -0000 1.2
@@ -1,7 +1,7 @@
-// $Header: /cvs/lcd/lcdd/src/MagneticFieldOverlay.cc,v 1.1 2006/04/21 23:51:27 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/MagneticFieldOverlay.cc,v 1.2 2006/05/04 20:48:45 jeremy Exp $
#include "MagneticFieldOverlay.hh"
-//#include <iostream>
+#include <iostream>
MagneticFieldOverlay::MagneticFieldOverlay()
{}
CVSspam 0.2.8