Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FluxMgr Class Reference

The point of entry for interfacing with the flux package. holds methods for creating sources and sending new particles, and methods for interfacing with the satellite position, and setting the position variables. It is instantiated with the names of the xml files to be used as input to the xml parser. More...

#include <FluxMgr.h>

List of all members.

Public Methods

 FluxMgr (const std::vector< std::string > &fileList, std::string dtd="")
 ctor for multiple XML documents. More...

 ~FluxMgr ()
EventSourcesource (std::string name)
 create and return a source by name. More...

std::list< std::string > sourceList () const
 access to the source list. More...

void setArea (double area)
 set the target area. More...

void test (std::ostream &out, std::string source_name, int count)
 generate some test output. More...

void setOrientation (std::pair< double, double > ang)
 set the angular (off-zenith) values of the GLAST satellite. More...

std::pair< double, double > getOrientation ()
 get the angular values of the satellite. More...

std::vector< std::pair< std::string,
std::list< std::string > > > 
sourceOriginList () const
 this should return the source file names, along with the contained sources. More...

void setGlastPosition (std::pair< double, double > pos)
 set the orbital (position) values of the GLAST satellite. More...

void addFactory (std::string name, const ISpectrumFactory *factory)
void setExpansion (double p)
 set the expansion factor for the orbit (-1) = random. More...

void pass (double t)
 pass a specific amount of time. More...

GPStime time () const
 Get the time as held by GPS. More...

void synch ()
 synch satellite location with current time. More...

void sampleintvl (double t)
 set the sample interval. More...

std::pair< double, double > location ()
 get the current satellite location. More...

Rotation CELTransform (double time)
 get the transformation matrix due to orientation of the Galaxy. More...

Rotation orientTransform (double time)
 get the transformation matrix due to orientation of the spacecraft. More...

Rotation FluxMgr::transformGlastToGalactic (double time)
 this transforms glast-local (cartesian) vectors into galactic (cartesian) vectors. More...

void setRockType (GPS::RockType rockType)
 this sets the rocking mode in GPS. More...

void setRockType (int rockType)
 this sets the rocking mode in GPS. More...


Private Methods

DOM_Element getLibrarySource (const DOMString &id)
 source library lookup. Each source is uniquely identified by its "name" attribute because "name" is of type ID. More...

void defaultFile ()
void init (const std::vector< std::string > &fileList)
EventSourcegetSourceFromXML (const DOM_Element &src)
std::string writeXmlFile (const std::vector< std::string > &fileList)
 internal routine that creates the document. More...


Private Attributes

DOM_Document m_library_doc
DOM_Element s_library
std::vector< DOM_Document > m_library_doclist
std::vector< DOM_Element > s_librarylist
std::map< std::string, std::pair<
DOM_Element, std::string > > 
m_sources
 list of sources for easy lookup. More...

std::string m_dtd
 filename for dtd. More...


Detailed Description

The point of entry for interfacing with the flux package. holds methods for creating sources and sending new particles, and methods for interfacing with the satellite position, and setting the position variables. It is instantiated with the names of the xml files to be used as input to the xml parser.

$Header $

Definition at line 31 of file FluxMgr.h.


Constructor & Destructor Documentation

FluxMgr::FluxMgr const std::vector< std::string > &    fileList,
std::string    dtdname = ""
 

ctor for multiple XML documents.

Definition at line 23 of file FluxMgr.cxx.

References defaultFile(), and init().

00024 : m_dtd(dtdname.empty()? "$(FLUXSVCROOT)/xml/source.dtd" : dtdname )
00025 {
00026     if( fileList.empty() ){
00027         defaultFile();
00028     }else{              
00029         init(fileList);         
00030     }   
00031 }

FluxMgr::~FluxMgr  
 

Definition at line 107 of file FluxMgr.cxx.

00107                  {
00108 }


Member Function Documentation

void FluxMgr::addFactory std::string    name,
const ISpectrumFactory   factory
 

Definition at line 309 of file FluxMgr.cxx.

References SpectrumFactoryTable::addFactory(), and SpectrumFactoryTable::instance().

Referenced by FluxSvc::addFactory().

00309                                                                          {
00310     SpectrumFactoryTable::instance()->addFactory(name,factory);
00311 }

Rotation FluxMgr::CELTransform double    time
 

get the transformation matrix due to orientation of the Galaxy.

Definition at line 355 of file FluxMgr.cxx.

References GPS::instance(), and time().

00355                                          {
00356     return GPS::instance()->CELTransform(time);
00357 }

void FluxMgr::defaultFile   [private]
 

Definition at line 33 of file FluxMgr.cxx.

References init().

Referenced by FluxMgr().

00033                          {
00034     //Purpose: to set the default xml file and initialize the package to use it.
00035     std::vector<std::string> input;
00036     // must find the source_library.xml file.
00037     // set up the xml document to use for initialization parameters
00038     static const char* initialization_document="source_library.xml";
00039     const char* flux_root = ::getenv("FLUXSVCROOT");
00040     std::string doc_path= (flux_root? std::string(flux_root)+"/xml/" : "");
00041     input.push_back(/*doc_path+initialization_document*/"$(FLUXSVCROOT)/xml/source_library.xml");       
00042     init(input);
00043 }

Rotation FluxMgr::FluxMgr::transformGlastToGalactic double    time
 

this transforms glast-local (cartesian) vectors into galactic (cartesian) vectors.

DOM_Element FluxMgr::getLibrarySource const DOMString &    id [private]
 

source library lookup. Each source is uniquely identified by its "name" attribute because "name" is of type ID.

Definition at line 187 of file FluxMgr.cxx.

References m_library_doc, and s_library.

Referenced by getSourceFromXML().

00188 {
00189     //Purpose: source library lookup.  Each source is uniquely identified
00190     // by its "name" attribute because "name" is of type ID
00191     
00192     // quit if the library was unitialized
00193     if (s_library == DOM_Element() ) return DOM_Element(); 
00194     
00195     return m_library_doc.getElementById(id);
00196 }

std::pair< double, double > FluxMgr::getOrientation  
 

get the angular values of the satellite.

Definition at line 317 of file FluxMgr.cxx.

References GPS::instance(), and GPS::rotateAngles().

Referenced by FluxSvc::getOrientation().

00317                                               {
00318     return GPS::instance()->rotateAngles();
00319 }

EventSource * FluxMgr::getSourceFromXML const DOM_Element &    src [private]
 

Definition at line 125 of file FluxMgr.cxx.

References CompositeSource::addSource(), FATAL_MACRO, and getLibrarySource().

Referenced by source().

00126 {
00127     //Purpose: sourceFromXML - create a new EventSource from a DOM element
00128     //instantiated, e.g., from a description in source_library.xml
00129     //Input:  the element holding particle information.
00130     DOM_Node    childNode = src.getFirstChild();
00131     if (childNode == DOM_Node()) {
00132     /*
00133     FATAL_MACRO("Improperly formed XML event source");
00134     return 0;
00135         */
00136         // no child node: expect to find the name defined.
00137         return  new FluxSource(src);
00138     }
00139     
00140     DOM_Element sname = xml::Dom::getFirstChildElement(src);
00141     if (sname == DOM_Element() ) {
00142         FATAL_MACRO("Improperly formed XML event source");
00143         return 0;
00144     }
00145     // If we got here, should have legit child element
00146     if ((sname.getTagName()).equals("spectrum")) {
00147         return  new FluxSource(src);
00148     }
00149     else if ((sname.getTagName()).equals("nestedSource")) {
00150         
00151         double flux = atof (xml::Dom::getAttribute(src, "flux").c_str());
00152         // Search for and process immediate child elements.  All must
00153         // be of type "nestedSource".  There may be more than one.
00154         // Content model for nestedSource is EMPTY, so can omit check
00155         // for that in the code
00156         
00157         CompositeSource* cs;
00158         if(flux == 1.0){
00159             cs = new CompositeSource();
00160         }else{ cs = new CompositeDiffuse(flux);
00161         }
00162         do { 
00163             //        DOM_Element sourceChild = (DOM_Element &) childNode;
00164             DOM_Element selem = 
00165                 getLibrarySource(sname.getAttribute("sourceRef"));
00166             if (selem == DOM_Element()) {
00167                 FATAL_MACRO("source name" << 
00168                     xml::Dom::transToChar(sname.getAttribute("sourceRef")) << 
00169                     "' not in source library");
00170             }
00171             cs->addSource(getSourceFromXML(selem)); 
00172             sname = xml::Dom::getSiblingElement(sname);
00173         } 
00174         while (sname != DOM_Element() );
00175         return cs;
00176     }
00177     else {
00178         FATAL_MACRO("Unexpected element: "<< 
00179             xml::Dom::transToChar(sname.getTagName()) );
00180     }
00181     return 0;
00182 }

void FluxMgr::init const std::vector< std::string > &    fileList [private]
 

Definition at line 45 of file FluxMgr.cxx.

References DLL_DECL_SPECTRUM, FATAL_MACRO, m_library_doc, m_sources, s_library, and writeXmlFile().

Referenced by defaultFile(), and FluxMgr().

00045                                                       { 
00046     
00047     //Purpose:  to initialize the infrastructure of the package with
00048     //the named xml files.
00049     std::string fileName;
00050     
00051     xml::XmlParser parser;
00052     
00053     std::string xmlFileIn = writeXmlFile(fileList);
00054     
00055     // a quick way of displaying what goes to the parser
00056     //std::cout << xmlFileIn <<std::endl;
00057     
00058     m_library_doc = parser.parse(xmlFileIn);
00059     
00060     if (m_library_doc == DOM_Document()) {
00061         FATAL_MACRO("Parse error: processing the document" << std::endl
00062             << xmlFileIn << std::endl);
00063         return;
00064     }
00065     
00066     // Root element is of type source_library.  Content is
00067     // one or more source elements.
00068     
00069     s_library = m_library_doc.getDocumentElement();
00070     
00071     // loop through the source elements to create a map of names, DOM_Elements
00072     if (s_library != DOM_Element()) {
00073         
00074         DOM_Element child = xml::Dom::getFirstChildElement(s_library);
00075         DOM_Element toplevel = xml::Dom::getFirstChildElement(s_library);
00076         
00077         while (child != DOM_Element()) {
00078             while (child.getAttribute("name") == DOMString()) {
00079                 s_library = child;
00080                 child = xml::Dom::getFirstChildElement(s_library);
00081             }
00082             
00083             while (child != DOM_Element()) {
00084                 std::string name = xml::Dom::transToChar(child.getAttribute("name"));
00085                 //std::cout << name << std::endl;
00086                 std::string parentfilename = xml::Dom::transToChar(toplevel.getAttribute("title"));
00087                 m_sources[name]=std::make_pair<DOM_Element,std::string>(child,parentfilename);
00088                 child = xml::Dom::getSiblingElement(child);
00089             }
00090             
00091             child = xml::Dom::getSiblingElement(toplevel);
00092             toplevel=child;
00093         }
00094         
00095     }
00096     // these are the spectra that we want to make available
00097     DLL_DECL_SPECTRUM( CHIMESpectrum);
00098     DLL_DECL_SPECTRUM( AlbedoPSpectrum);
00099     DLL_DECL_SPECTRUM( HeSpectrum);
00100     DLL_DECL_SPECTRUM( GalElSpectrum);
00101     DLL_DECL_SPECTRUM( FILESpectrum);
00102     DLL_DECL_SPECTRUM( TimeCandle);
00103     
00104 }

std::pair< double, double > FluxMgr::location  
 

get the current satellite location.

Definition at line 350 of file FluxMgr.cxx.

References GPS::instance(), GPS::lat(), and GPS::lon().

Referenced by FluxSvc::location(), and rootplot::rootplot().

00350                                         {
00351     return std::make_pair<double,double>(GPS::instance()->lat(),GPS::instance()->lon());
00352 }

Rotation FluxMgr::orientTransform double    time
 

get the transformation matrix due to orientation of the spacecraft.

Definition at line 360 of file FluxMgr.cxx.

References GPS::instance(), GPS::rockingAngleTransform(), and time().

00360                                             {
00361     return GPS::instance()->rockingAngleTransform(time);
00362 }

void FluxMgr::pass double    t
 

pass a specific amount of time.

Definition at line 332 of file FluxMgr.cxx.

References GPS::instance(), GPS::pass(), and synch().

Referenced by FluxSvc::pass(), Flux::pass(), rootplot::rootplot(), and test().

00332                           {
00333     GPS::instance()->pass(t);
00334     synch();
00335 }

void FluxMgr::sampleintvl double    t
 

set the sample interval.

void FluxMgr::setArea double    area
 

set the target area.

void FluxMgr::setExpansion double    p
 

set the expansion factor for the orbit (-1) = random.

Definition at line 326 of file FluxMgr.cxx.

References GPS::expansion(), and GPS::instance().

Referenced by rootplot::rootplot(), and test().

00326                                    {
00327     // set the expansion factor for the orbit (-1) = random
00328     GPS::instance()->expansion(p);
00329 }

void FluxMgr::setGlastPosition std::pair< double, double >    pos
 

set the orbital (position) values of the GLAST satellite.

Definition at line 321 of file FluxMgr.cxx.

References GPS::ascendingLon(), and GPS::instance().

00321                                                         {
00322     GPS::instance()->ascendingLon(pos.first);
00323     GPS::instance()->ascendingLon(pos.second);
00324 }

void FluxMgr::setOrientation std::pair< double, double >    ang
 

set the angular (off-zenith) values of the GLAST satellite.

Definition at line 313 of file FluxMgr.cxx.

References GPS::instance(), and GPS::rotateAngles().

Referenced by FluxSvc::setOrientation().

00313                                                       {
00314     GPS::instance()->rotateAngles(ang);
00315 }

void FluxMgr::setRockType int    rockType
 

this sets the rocking mode in GPS.

Definition at line 375 of file FluxMgr.cxx.

References GPS::instance(), and GPS::setRockType().

00375                                      {
00376    GPS::instance()->setRockType(rockType);
00377 }

void FluxMgr::setRockType GPS::RockType    rockType
 

this sets the rocking mode in GPS.

Definition at line 370 of file FluxMgr.cxx.

References GPS::instance(), GPS::RockType, and GPS::setRockType().

Referenced by FluxSvc::setRockType().

00370                                              {
00371    GPS::instance()->setRockType(rockType);
00372 }

EventSource * FluxMgr::source std::string    name
 

create and return a source by name.

Definition at line 110 of file FluxMgr.cxx.

References getSourceFromXML(), SpectrumFactoryTable::instance(), SpectrumFactoryTable::instantiate(), and m_sources.

Referenced by Flux::Flux(), rootplot::rootplot(), and test().

00111 {
00112     //Purpose: to return a pointer to a source, referenced by name.
00113     //Input: the name of the desired source.
00114     // first check that it is in the library
00115     if( m_sources.find(name)==m_sources.end() ) {
00116         // nope. Maybe a Spectrum object
00117         ISpectrum* s = SpectrumFactoryTable::instance()->instantiate(name);
00118         
00119         return s? new FluxSource(s) : (EventSource*)0;
00120     }
00121     return getSourceFromXML(m_sources[name].first);
00122 }

std::list< std::string > FluxMgr::sourceList   const
 

access to the source list.

Definition at line 198 of file FluxMgr.cxx.

References m_sources.

Referenced by FluxSvc::initialize(), main(), and rootplot::rootplot().

00199 {
00200     std::list<std::string> s;
00201     for( std::map<std::string, std::pair<DOM_Element,std::string> >::const_iterator it = m_sources.begin();
00202     it != m_sources.end();
00203     ++it){
00204         s.push_back((*it).first);
00205     }
00206     return s;
00207 }

std::vector< std::pair< std::string,std::list< std::string > > > FluxMgr::sourceOriginList   const
 

this should return the source file names, along with the contained sources.

Definition at line 209 of file FluxMgr.cxx.

References m_sources.

Referenced by FluxSvc::sourceOriginList().

00210 {
00211     std::vector<std::pair< std::string ,std::list<std::string> > > originList;
00212     for( std::map<std::string, std::pair<DOM_Element,std::string> >::const_iterator it = m_sources.begin();
00213     it != m_sources.end();
00214     ++it){
00215         //now see if we can find the filename already used in the vector:
00216         std::vector<std::pair< std::string ,std::list<std::string> > >::iterator topiter;
00217         for(topiter = originList.begin() ; topiter != originList.end() ; topiter++){
00218             if( (*topiter).first==(*it).second.second) break;
00219         }
00220 
00221         if( topiter != originList.end() ){ (*topiter).second.push_back((*it).first);
00222         }else{
00223             std::list<std::string> abc;
00224             abc.push_back((*it).first);
00225             originList.push_back(std::make_pair< std::string ,std::list<std::string> >((*it).second.second,abc) );
00226         }
00227 
00228     }
00229 
00230     return originList;
00231 }

void FluxMgr::synch  
 

synch satellite location with current time.

Definition at line 341 of file FluxMgr.cxx.

References GPS::instance(), and GPS::synch().

Referenced by pass().

00341                    {
00342     GPS::instance()->synch();
00343 }

void FluxMgr::test std::ostream &    cout,
std::string    source_name,
int    count
 

generate some test output.

Definition at line 234 of file FluxMgr.cxx.

References FluxSource::energy(), EventSource::event(), FluxSource::flux(), EventSource::fullTitle(), EventSource::howManySources(), GPS::instance(), EventSource::interval(), FluxSource::launchDir(), FluxSource::launchPoint(), EventSource::numSource(), pass(), EventSource::rate(), FluxSource::refLaunch(), FluxSource::refPoint(), GPS::rotateAngles(), setExpansion(), source(), FluxSource::spectrum(), time(), and EventSource::totalArea().

Referenced by main().

00235 {   
00236     EventSource* e = source(source_name);
00237     setExpansion(1.);
00238     double time=0.;
00239     
00240     const int howMany = e->howManySources();
00241     //int counts[howMany] = 0;
00242     std::vector<int> counts;
00243     
00244     //std::vector<int>::const_iterator countIter = counts.begin();
00245     
00246     int q;
00247     for(q=0 ; q<=howMany+2 ; q++){
00248         counts.push_back(0);
00249         //  countIter++;
00250     }
00251     
00252     cout << "running source: " << e->fullTitle() << std::endl;
00253     cout << " Total rate is: " << e->rate(time) << " Hz into " << e->totalArea() << " m^2" << std::endl;
00254     //cout << "LaunchType" << f->retLaunch() << "Pointtype" << f->retPoint() <<std::endl;
00255     cout << " there are " << howMany << " Sources total..." << std::endl;
00256     cout << "    Generating " << count << " trials " << std::endl;
00257     cout << " --------------------------------" << std::endl;
00258     
00259     //testing rotateangles function
00260     GPS::instance()->rotateAngles(std::make_pair<double,double>(0.0,0.3));
00261     
00262     FluxSource* f;
00263     double totalinterval;
00264     for( int i = 0; i< count; ++i) {
00265         
00266         f = e->event(time);
00267         //TESTING THE lat, lon FUNCTIONS
00268         //cout << std::endl << "lat=" << GPS::instance()->lat() << ' ' <<"lon=" << GPS::instance()->lon() << std::endl;
00269         //double curTime=GPS::instance()->time();
00270         //cout << std::endl << "testlat=" << GPS::instance()->orbit()->testLatitude(curTime) << ' ' << "testlon=" << GPS::instance()->orbit()->testLongitude(curTime) << std::endl;
00271         
00272         double interval=e->interval(time);
00273         
00274         //here we increment the "elapsed" time and the "orbital" time,
00275         //just as is done in flux.  NOTE: this is important for the operation 
00276         //of fluxsource, and is expected.
00277         time+=interval;
00278         pass(interval);
00279         int sourceNumber = e->numSource();
00280         if(sourceNumber==-1){counts[0]++;
00281         }else{counts[sourceNumber]++;}
00282         
00283         totalinterval+=interval;
00284         cout << "LaunchType = " << f->refLaunch() << " , Pointtype = " << f->refPoint() <<std::endl;
00285         cout << f->spectrum()->particleName();
00286         cout << "(" << f->energy();
00287         cout << " GeV), Launch: " << f->launchPoint() 
00288             << " Dir " << f->launchDir() << " ,Flux="
00289             << f->flux(time) << " ,Interval="
00290             << interval << "   Event ID number: "<< sourceNumber <<std::endl
00291             << "elapsed time = " << totalinterval << std::endl;
00292     }
00293     cout << "------------------------------------------------------" << std::endl;
00294     
00295     cout << std::endl << "Average Interval=" << totalinterval/count <<" , "
00296         << "Average rate = " << count/totalinterval <<std::endl;
00297     
00298     cout << "Source Statistics: " << std::endl;
00299     for(q=0 ; q<howMany ; q++){
00300         cout << "source #" << q+1 << ": " << counts[q] << " events counted." << std::endl;
00301         //  countIter++;
00302     }
00303     
00304     delete e;
00305     
00306 }

GPStime FluxMgr::time   const
 

Get the time as held by GPS.

Definition at line 337 of file FluxMgr.cxx.

References GPS::instance(), and GPS::time().

Referenced by CELTransform(), Flux::gpsTime(), orientTransform(), and test().

00337                             {
00338     return GPS::instance()->time();
00339 }

std::string FluxMgr::writeXmlFile const std::vector< std::string > &    fileList [private]
 

internal routine that creates the document.

Definition at line 379 of file FluxMgr.cxx.

References m_dtd.

Referenced by init().

00379                                                                     {
00393     std::strstream fileString;
00394     // Unique tag to add to ENTITY elements in the DTD.
00395     char libchar = 'a';
00396     std::string inFileName;
00397     
00398     std::vector<std::string>::const_iterator iter = fileList.begin();
00399     
00400     //the default DTD file
00401     inFileName=m_dtd;
00402     //replace $(FLUXROOT) by its system variable
00403     xml::IFile::extractEnvVar(&inFileName);
00404     
00405     //this stuff goes in the beginnning of the XML file to be read into the parser
00406     fileString << "<?xml version='1.0' ?>" << std::endl << "<!DOCTYPE source_library" 
00407         << " SYSTEM " << '"' << inFileName << '"' << " [" << std::endl;
00408     
00409     //as long as there are files in the file list...
00410     for (;iter != fileList.end(); iter++) {
00411         
00412         // get the file name, and evaluate any system variables in it
00413         inFileName=(*iter).c_str();
00414         xml::IFile::extractEnvVar(&inFileName);
00415         
00416         //then make an ENTITY entry specifying where the file is
00417         fileString << "<!ENTITY " << "library" << libchar << " SYSTEM " << '"' 
00418             << inFileName << "\" >" << std::endl;      
00419         libchar++;
00420     }
00421     
00422     fileString << "]>" << std::endl << "<source_library>" << std::endl;
00423     iter = fileList.begin();
00424     libchar = 'a';
00425     
00426     //as long as there are files in the file list...
00427     for (;iter != fileList.end(); iter++) {
00428         // add a reference to the file name
00429         fileString << "&library" << libchar << ";" << std::endl;       
00430         libchar++;
00431     }
00432     
00433     fileString << "</source_library>" << '\0';
00434     return fileString.str();
00435     
00436 }


Member Data Documentation

std::string FluxMgr::m_dtd [private]
 

filename for dtd.

Definition at line 127 of file FluxMgr.h.

Referenced by writeXmlFile().

DOM_Document FluxMgr::m_library_doc [private]
 

Definition at line 111 of file FluxMgr.h.

Referenced by getLibrarySource(), and init().

std::vector<DOM_Document> FluxMgr::m_library_doclist [private]
 

Definition at line 115 of file FluxMgr.h.

std::map<std::string, std::pair<DOM_Element,std::string> > FluxMgr::m_sources [private]
 

list of sources for easy lookup.

Definition at line 121 of file FluxMgr.h.

Referenced by init(), source(), sourceList(), and sourceOriginList().

DOM_Element FluxMgr::s_library [private]
 

Definition at line 113 of file FluxMgr.h.

Referenced by getLibrarySource(), and init().

std::vector<DOM_Element> FluxMgr::s_librarylist [private]
 

Definition at line 117 of file FluxMgr.h.


The documentation for this class was generated from the following files:
Generated on Wed Oct 16 14:01:33 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001