Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:56

0001 /*
0002  * CppExporter.h
0003  *
0004  *  Created on: 23.03.2015
0005  *      Author: swenzel
0006  */
0007 
0008 #ifndef VECGEOM_CPPEXPORTER_H_
0009 #define VECGEOM_CPPEXPORTER_H_
0010 
0011 #include "VecGeom/base/Global.h"
0012 #include <map>
0013 #include <ostream>
0014 #include <set>
0015 #include <list>
0016 #include <vector>
0017 
0018 // Compile for vecgeom namespace to work as interface
0019 namespace vecgeom {
0020 
0021 #ifndef VECCORE_CUDA
0022 inline
0023 #endif
0024     namespace cxx {
0025 
0026 class Transformation3D;
0027 class LogicalVolume;
0028 class VPlacedVolume;
0029 
0030 // a class to provide serialization functionality of an existing
0031 // geometry hierarchy to C++ code; This code can then be compiled into a library
0032 // from which the geometry can be reloaded quickly
0033 // This export is useful in situations where other export/import functionality can be used or is not convenient
0034 
0035 // NOTE: The class is implemented in isolation of any shape functionality (but as a friend of geometry classes)
0036 // in order not to bloat the functionality and interfaces of geometry classes with serialization specific code
0037 // the obvious drawback is that the Exporter has to be updated whenever new classes are added or changed
0038 
0039 // idea: could also export in specialized mode
0040 
0041 // TODO:
0042 // a) use more efficient containers for this treatment -- revise export algorithms; improve structure of code
0043 // b) look for possibilities to reduce memory ( if we see that a transformation will be instantiated twice )
0044 // c) optimized memory allocation in the construction of the detector; we could allocate only once and
0045 //      then use placement new to place the transformations, logical volumes etc.
0046 // d) ultimately we could try to bring together things in memory which are used together:
0047 //       certain transformation - volume combinations
0048 // e) split the output into various smaller functions which could be compiled in parallel
0049 //    ( currently compiling the cms detector from the produced source takes quite a while ... )
0050 // f) dump numeric values according to their precision needed ( the default precision will likely lead to errors )
0051 // first version: Sandro Wenzel 26.3.2015
0052 
0053 class GeomCppExporter {
0054   // declare the friend classes
0055   friend Transformation3D;
0056 
0057 private:
0058   // mapping pointer to variable names for Transformations
0059   std::map<Transformation3D const *, std::string> fTrafoToStringMap;
0060   // mapping pointer to variable names for logical volumes
0061   std::map<LogicalVolume const *, std::string> fLVolumeToStringMap;
0062   std::set<std::string> fNeededHeaderFiles;
0063 
0064   std::list<LogicalVolume const *> fListofTreatedLogicalVolumes;
0065   // container to keep track of logical volumes which need to be coded in C++
0066   // at a later stage because a dependency is not satisfied
0067   std::list<LogicalVolume const *> fListofDeferredLogicalVolumes;
0068 
0069   void DumpTransformations(std::vector<std::string> &, std::stringstream &, std::vector<std::string> &,
0070                            std::list<Transformation3D const *> const &);
0071   void DumpLogicalVolumes(std::ostream &, std::ostream & /* extern decl */, std::ostream & /* lvol definitions */,
0072                           std::list<LogicalVolume const *> const &);
0073   void DumpGeomHierarchy(std::vector<std::string> &, std::list<LogicalVolume const *> const &);
0074   void DumpHeader(std::ostream &);
0075 
0076   void DumpEntryFunction();
0077 
0078   void ScanGeometry(VPlacedVolume const *const volume, std::list<LogicalVolume const *> &,
0079                     std::list<LogicalVolume const *> &boollvlist, std::list<Transformation3D const *> &);
0080 
0081   // private Constructor
0082   GeomCppExporter()
0083       : fTrafoToStringMap(), fLVolumeToStringMap(), fNeededHeaderFiles(), fListofTreatedLogicalVolumes(),
0084         fListofDeferredLogicalVolumes()
0085   {
0086   }
0087 
0088 public:
0089   static GeomCppExporter &Instance()
0090   {
0091     static GeomCppExporter instance;
0092     return instance;
0093   }
0094   const char *ClassName() const { return "GeomCppExporter"; }
0095 
0096   void DumpGeometry(std::ostream &);
0097 };
0098 }
0099 } // end namespace
0100 
0101 #endif /* CPPEXPORTER_H_ */