diff --git a/DDCAD/src/ASSIMPReader.cpp b/DDCAD/src/ASSIMPReader.cpp index 416e1925f03ffb3654cf38d6e73c899d11795e9a..8f9dfc673134c6d77e3d694a4c2262697bb5e1e4 100644 --- a/DDCAD/src/ASSIMPReader.cpp +++ b/DDCAD/src/ASSIMPReader.cpp @@ -12,44 +12,26 @@ //========================================================================== /// Framework include files -#include <DD4hep/Shapes.h> #include <DD4hep/Printout.h> #include <DD4hep/Detector.h> #include <DDCAD/ASSIMPReader.h> /// Open Asset Importer Library - -#include "assimp/Importer.hpp" #include "assimp/scene.h" #include "assimp/postprocess.h" +#include "assimp/Importer.hpp" /// C/C++ include files #include <sstream> using namespace dd4hep; using namespace dd4hep::cad; -#if 0 - if ( shape->GetNfacets() > 2 ) { - shape->CloseShape(true,true,true); - if ( dump_facets ) { - for( size_t i=0, n=shape->GetNfacets(); i < n; ++i ) { - const auto& facet = shape->GetFacet(i); - std::stringstream str; - str << facet; - printout(ALWAYS,"ASSIMPReader","++ Facet %4ld : %s", - i, str.str().c_str()); - } - } - result.emplace_back(std::unique_ptr<TGeoTessellated>(shape.ptr())); - continue; - } - delete shape.ptr(); -#endif + /// Read input file std::vector<std::unique_ptr<TGeoTessellated> > ASSIMPReader::readShapes(const std::string& source, double unit_length) const { - typedef TessellatedSolid::Vertex Vertex; + using Vertex = TessellatedSolid::Vertex; std::vector<std::unique_ptr<TGeoTessellated> > result; std::unique_ptr<Assimp::Importer> importer = std::make_unique<Assimp::Importer>(); int aiflags = aiProcess_Triangulate|aiProcess_JoinIdenticalVertices|aiProcess_CalcTangentSpace; @@ -64,17 +46,6 @@ ASSIMPReader::readShapes(const std::string& source, double unit_length) const if ( mesh->mNumFaces > 0 ) { auto name = mesh->mName.C_Str(); const aiVector3D* v = mesh->mVertices; -#if 0 - TessellatedSolid shape(name, mesh->mNumFaces); - for(unsigned int i=0; i < mesh->mNumFaces; i++) { - const aiFace& face = mesh->mFaces[i]; - const unsigned int* idx = face.mIndices; - Vertex a(v[idx[0]].x*unit, v[idx[0]].y*unit, v[idx[0]].z*unit); - Vertex b(v[idx[1]].x*unit, v[idx[1]].y*unit, v[idx[1]].z*unit); - Vertex c(v[idx[2]].x*unit, v[idx[2]].y*unit, v[idx[2]].z*unit); - shape->AddFacet(a,b,c); - } -#endif std::vector<Vertex> vertices; vertices.reserve(mesh->mNumVertices); for(unsigned int i=0; i < mesh->mNumVertices; i++) { @@ -111,7 +82,7 @@ ASSIMPReader::readShapes(const std::string& source, double unit_length) const std::vector<std::unique_ptr<TGeoVolume> > ASSIMPReader::readVolumes(const std::string& source, double unit_length) const { - typedef TessellatedSolid::Vertex Vertex; + using Vertex = TessellatedSolid::Vertex; std::vector<std::unique_ptr<TGeoVolume> > result; std::unique_ptr<Assimp::Importer> importer = std::make_unique<Assimp::Importer>(); bool dump_facets = ((flags>>8)&0x1) == 1; @@ -139,17 +110,6 @@ ASSIMPReader::readVolumes(const std::string& source, double unit_length) const const unsigned int* idx = mesh->mFaces[i].mIndices; shape->AddFacet(idx[0], idx[1], idx[2]); } -#if 0 - TessellatedSolid shape(name, mesh->mNumFaces); - for(unsigned int i=0; i < mesh->mNumFaces; i++) { - const aiFace& face = mesh->mFaces[i]; - const unsigned int* idx = face.mIndices; - Vertex a(v[idx[0]].x*unit, v[idx[0]].y*unit, v[idx[0]].z*unit); - Vertex b(v[idx[1]].x*unit, v[idx[1]].y*unit, v[idx[1]].z*unit); - Vertex c(v[idx[2]].x*unit, v[idx[2]].y*unit, v[idx[2]].z*unit); - shape->AddFacet(a,b,c); - } -#endif if ( shape->GetNfacets() > 2 ) { std::string mat_name; Material mat; diff --git a/DDCAD/src/ASSIMPWriter.cpp b/DDCAD/src/ASSIMPWriter.cpp index 666227a156fbcdd5bf04db4a46300cb5508627ff..1ab11d62739a1da31778118a21a86420b178b646 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -12,8 +12,6 @@ //========================================================================== /// Framework include files -#include <DD4hep/Shapes.h> -#include <DD4hep/Objects.h> #include <DD4hep/Detector.h> #include <DD4hep/Printout.h> #include <DDCAD/ASSIMPWriter.h> @@ -23,10 +21,11 @@ #include "assimp/Exporter.hpp" #include "assimp/scene.h" -#include <TBuffer3D.h> +/// ROOT include files #include <TBuffer3DTypes.h> #include <TGeoBoolNode.h> #include <TGeoMatrix.h> +#include <TBuffer3D.h> #include <TClass.h> #include <CsgOps.h> @@ -37,7 +36,7 @@ using namespace std; using namespace dd4hep; using namespace dd4hep::cad; -using _Vertex = Tessellated::Vertex_t; +using Vertex = Tessellated::Vertex_t; namespace { @@ -54,12 +53,12 @@ namespace { if ( sol->IsA() != TGeoShapeAssembly::Class() ) cont.push_back(make_pair(p, mother.get())); if ( recursive ) - _collect(cont, recursive, *mother, p); + _collect(cont, recursive, *mother, p); if ( sol->IsA() != TGeoShapeAssembly::Class() ) mother.release(); } } - bool equals(_Vertex const &lhs, _Vertex const &rhs) { + bool equals(Vertex const &lhs, Vertex const &rhs) { constexpr double kTolerance = 1.e-32; return TMath::Abs(lhs[0] - rhs[0]) < kTolerance && TMath::Abs(lhs[1] - rhs[1]) < kTolerance && @@ -100,13 +99,13 @@ namespace { unique_ptr<TGeoTessellated> TessellateShape::build_mesh(int id, const std::string& name, TGeoShape* shape) { auto mesh = unique_ptr<RootCsg::TBaseMesh>(this->make_mesh(shape)); size_t nskip = 0; - vector<_Vertex> vertices; + vector<Vertex> vertices; vertices.reserve(mesh->NumberOfVertices()); map<size_t,size_t> vtx_index_replacements; for( size_t ipoint = 0, npoints = mesh->NumberOfVertices(); ipoint < npoints; ++ipoint ) { long found = -1; const double* v = mesh->GetVertex(ipoint); - _Vertex vtx(v[0], v[1], v[2]); + Vertex vtx(v[0], v[1], v[2]); for(size_t i=0; i < vertices.size(); ++i) { if ( equals(vertices[i],vtx) ) { vtx_index_replacements[ipoint] = found = i; @@ -152,7 +151,7 @@ namespace { ++nskip; continue; } - _Vertex w[3] = {vertices[vv0],vertices[vv1],vertices[vv2]}; + Vertex w[3] = {vertices[vv0],vertices[vv1],vertices[vv2]}; if ( TGeoFacet::CompactFacet(w, 3) < 3 ) { ++nskip; continue; @@ -225,7 +224,7 @@ namespace { } unique_ptr<TGeoTessellated> TessellateShape::tessellate_primitive(const std::string& name, Solid solid) { - using vtx_t = _Vertex; + using vtx_t = Vertex; const TBuffer3D& buf3D = solid->GetBuffer3D(TBuffer3D::kAll, false); struct pol_t { int c, n; int segs[1]; } *pol = nullptr; struct seg_t { int c, _1, _2; }; @@ -307,7 +306,7 @@ int ASSIMPWriter::write(const std::string& file_name, root->mNumMeshes = 0; root->mNumChildren = 0; root->mChildren = new aiNode* [num_mesh]; - root->mMeshes = 0;//new unsigned int[root->mNumMeshes]; + root->mMeshes = 0; auto* geo_transform = TGeoShape::GetTransform(); TGeoHMatrix identity; @@ -384,7 +383,7 @@ int ASSIMPWriter::write(const std::string& file_name, face.mNumIndices = 0; face.mIndices = nullptr; } - _Vertex vtx, tmp, norm; + Vertex vtx, tmp, norm; for( long j=0, nvx=0, n=tes->GetNfacets(); j < n; ++j ) { bool degenerated = false; const auto& facet = tes->GetFacet(j); @@ -411,9 +410,9 @@ int ASSIMPWriter::write(const std::string& file_name, stringstream str; const auto* id = face.mIndices; const auto* vv = mesh->mVertices; - TGeoFacet fac(_Vertex(vv[id[0]].x,vv[id[0]].y,vv[id[0]].z), - _Vertex(vv[id[1]].x,vv[id[1]].y,vv[id[1]].z), - _Vertex(vv[id[2]].x,vv[id[2]].y,vv[id[2]].z)); + TGeoFacet fac(Vertex(vv[id[0]].x,vv[id[0]].y,vv[id[0]].z), + Vertex(vv[id[1]].x,vv[id[1]].y,vv[id[1]].z), + Vertex(vv[id[2]].x,vv[id[2]].y,vv[id[2]].z)); str << fac; printout(ALWAYS,"ASSIMPWriter","++ Facet %4ld : %s", j, str.str().c_str()); } @@ -426,10 +425,13 @@ int ASSIMPWriter::write(const std::string& file_name, /// Check if we have here a valid mesh if ( 0 == mesh->mNumFaces || 0 == mesh->mNumVertices ) { - delete [] mesh->mVertices; + if ( mesh->mVertices ) delete [] mesh->mVertices; + mesh->mVertices = nullptr; mesh->mNumVertices = 0; - delete [] mesh->mNormals; - delete [] mesh->mFaces; + if ( mesh->mNormals ) delete [] mesh->mNormals; + mesh->mNormals = nullptr; + if ( mesh->mFaces ) delete [] mesh->mFaces; + mesh->mFaces = nullptr; mesh->mNumFaces = 0; continue; } diff --git a/DDCAD/src/plugins/CADPlugins.cpp b/DDCAD/src/plugins/CADPlugins.cpp index 3d4820d7c3f0b31d2a91983073f8913aa6625ab6..231dc6fb5e273c8473d77bfb0c41c032dede4e11 100644 --- a/DDCAD/src/plugins/CADPlugins.cpp +++ b/DDCAD/src/plugins/CADPlugins.cpp @@ -221,11 +221,11 @@ static Handle<TObject> create_CAD_Volume(Detector& dsc, xml_h e) { xml_dim_t x_rot = x_vol.child(_U(rotation),false); if ( x_vol.hasAttr(_U(material)) ) { - string mat_name = x_vol.attr<string>(_U(material)); + string mat_name = x_vol.attr<string>(_U(material)); mat = dsc.material(mat_name); - if ( !mat.isValid() ) - except("CAD_MultiVolume","+++ Failed to access material "+mat_name); - vol.setMaterial(mat); + if ( !mat.isValid() ) + except("CAD_MultiVolume","+++ Failed to access material "+mat_name); + vol.setMaterial(mat); } Position pos; RotationZYX rot; @@ -251,8 +251,8 @@ static Handle<TObject> create_CAD_Volume(Detector& dsc, xml_h e) { for(size_t i=0; i < volumes.size(); ++i) { Volume vol = volumes[i].release(); if ( vol.isValid() ) { - if ( (vol.material() == dsc.air()) && default_material.isValid() ) - vol.setMaterial(default_material); + if ( (vol.material() == dsc.air()) && default_material.isValid() ) + vol.setMaterial(default_material); envelope.placeVolume(vol); } } @@ -335,7 +335,7 @@ static long CAD_export(Detector& description, int argc, char** argv) { auto num_mesh = wr.write(fname, ftype, places, recursive, scale); if ( num_mesh < 0 ) { printout(ERROR, "DD4hep_CAD_export","+++ Failed to export shapes to CAD file: %s [%s]", - fname.c_str(), ftype.c_str()); + fname.c_str(), ftype.c_str()); } return 1; } diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp index 96c44839015be69d8ae2058a2797453c283b0cad..d7e7ce92865d1b3e364d47e08c157add02a2a47b 100644 --- a/DDCore/src/MatrixHelpers.cpp +++ b/DDCore/src/MatrixHelpers.cpp @@ -275,7 +275,7 @@ double dd4hep::detail::matrix::determinant(const Rotation3D& rot) { /// Check matrices for equality int dd4hep::detail::matrix::_matrixEqual(const TGeoMatrix& left, const TGeoMatrix& right) { - double epsilon = 1e-12; + static constexpr double epsilon = 1e-12; int result = MATRICES_EQUAL; const Double_t* t1 = left.GetTranslation(); const Double_t* t2 = right.GetTranslation(); diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index 37ae9366861a6a596ed7fba3130aace7a2244e17..d4b4999c4e6e64cd8ac6c64d076c51c19b3045af 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -53,18 +53,20 @@ using namespace dd4hep::detail; typedef TGeoNode geo_node_t; typedef TGeoVolume geo_volume_t; typedef TGeoVolumeAssembly geo_assembly_t; -template <typename T> static typename T::Object* _userExtension(const T& v) { - typedef typename T::Object O; - O* o = (O*)(v.ptr()->GetUserExtension()); - return o; -} ClassImp(PlacedVolumeExtension) namespace { + static constexpr double s_rotation_test_limit = 1e-14; static bool s_verifyCopyNumbers = true; + template <typename T> typename T::Object* _userExtension(const T& v) { + typedef typename T::Object O; + O* o = (O*)(v.ptr()->GetUserExtension()); + return o; + } + TGeoVolume* _createTGeoVolume(const string& name, TGeoShape* s, TGeoMedium* m) { geo_volume_t* e = new geo_volume_t(name.c_str(),s,m); e->SetUserExtension(new Volume::Object()); @@ -100,9 +102,9 @@ namespace { public: void setShapeTitle(TGeoVolume* vol) { if ( vol ) { - TGeoShape* sh = vol->GetShape(); - string tag = get_shape_tag(sh); - sh->SetTitle(tag.c_str()); + TGeoShape* sh = vol->GetShape(); + string tag = get_shape_tag(sh); + sh->SetTitle(tag.c_str()); } } @@ -123,10 +125,10 @@ namespace { if ( c == TGeoVolumeMulti::Class() ) { TGeoVolumeMulti* mv = (TGeoVolumeMulti*)v; for( int i=0, n=mv->GetNvolumes(); i<n; ++i ) { - TGeoVolume* vol = mv->GetVolume(i); - this->setShapeTitle(vol); + TGeoVolume* vol = mv->GetVolume(i); + this->setShapeTitle(vol); (*this)(vol); - } + } } for( Int_t i=0; i<v->GetNdaughters(); ++i ) { geo_node_t* pv = v->GetNode(i); @@ -170,10 +172,10 @@ namespace { old_e->reflected = new_v; new_e->reflected = old_v; for(int i=0, n=new_mv->GetNvolumes(); i<n; ++i) { - TGeoVolume* vol = new_mv->GetVolume(i); - this->setShapeTitle(vol); + TGeoVolume* vol = new_mv->GetVolume(i); + this->setShapeTitle(vol); (*this)(vol, old_mv->GetVolume(i), sd, set_bit); - } + } } else except("dd4hep","VolumeImport: Unknown TGeoVolume sub-class: %s",new_v->IsA()->GetName()); @@ -303,8 +305,8 @@ void ReflectionBuilder::execute() const { TGeoMatrix* matrix = node->GetMatrix(); if (matrix->IsReflection()) { if ( print_active ) { - printout(INFO,"ReflectionBuilder","Reflection matrix:"); - matrix->Print(); + printout(INFO,"ReflectionBuilder","Reflection matrix:"); + matrix->Print(); } Volume vol(node->GetVolume()); TGeoMatrix* mclone = new TGeoCombiTrans(*matrix); @@ -312,13 +314,13 @@ void ReflectionBuilder::execute() const { // Reflect just the rotation component //mclone->ReflectZ(kFALSE, kTRUE); if ( print_active ) { - printout(INFO,"ReflectionBuilder","CLONE matrix:"); - mclone->Print(); + printout(INFO,"ReflectionBuilder","CLONE matrix:"); + mclone->Print(); } TGeoNodeMatrix* nodematrix = (TGeoNodeMatrix*)node; nodematrix->SetMatrix(mclone); if ( print_active ) { - printout(INFO,"ReflectionBuilder","Reflected volume: %s ", vol.name()); + printout(INFO,"ReflectionBuilder","Reflected volume: %s ", vol.name()); } Volume refl = vol.reflect(vol.sensitiveDetector()); node->SetVolume(refl.ptr()); @@ -624,7 +626,7 @@ Volume Volume::divide(const std::string& divname, int iaxis, int ndiv, return VolumeMulti(mvp); } except("dd4hep","Volume: Failed to divide volume %s -> %s [Invalid result]", - p->GetName(), divname.c_str()); + p->GetName(), divname.c_str()); } except("dd4hep","Volume: Attempt to divide an invalid logical volume."); return nullptr; @@ -655,7 +657,7 @@ PlacedVolume _addNode(TGeoVolume* par, TGeoVolume* daughter, int id, TGeoMatrix* const Double_t* r = transform->GetRotationMatrix(); if ( r ) { Double_t test_rot = r[0] + r[4] + r[8] - 3.0; - if ( TMath::Abs(test_rot) < 1E-12) + if ( TMath::Abs(test_rot) < s_rotation_test_limit ) transform->ResetBit(TGeoMatrix::kGeoRotation); else transform->SetBit(TGeoMatrix::kGeoRotation); @@ -846,43 +848,43 @@ const Volume& Volume::setVisAttributes(const VisAttr& attr) const { m_element->SetVisContainers(kTRUE); m_element->SetVisDaughters(vis->showDaughters ? kTRUE : kFALSE); printout(DEBUG,"setVisAttributes", - "Set color %3d transparent(alpha:%.3f): %3d [%02X,%02X,%02X] DrawingStyle:%9s LineStyle:%6s for volume %s", - col_num, vis->alpha, col_tr_num, - int(255*col->GetRed()), - int(255*col->GetGreen()), - int(255*col->GetBlue()), - draw_style == VisAttr::SOLID ? "Solid" : "Wireframe", - line_style == VisAttr::SOLID ? "Solid" : "Dashed", - name() - ); + "Set color %3d transparent(alpha:%.3f): %3d [%02X,%02X,%02X] DrawingStyle:%9s LineStyle:%6s for volume %s", + col_num, vis->alpha, col_tr_num, + int(255*col->GetRed()), + int(255*col->GetGreen()), + int(255*col->GetBlue()), + draw_style == VisAttr::SOLID ? "Solid" : "Wireframe", + line_style == VisAttr::SOLID ? "Solid" : "Dashed", + name() + ); m_element->SetLineWidth(10); m_element->SetLineColor(col_num); m_element->SetFillColor(col_tr_num); if (draw_style == VisAttr::SOLID) { - m_element->SetFillStyle(1001); // Root: solid + m_element->SetFillStyle(1001); // Root: solid #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) - // As suggested by Valentin Volkl https://sft.its.cern.ch/jira/browse/DDFORHEP-20 - // - // According to https://root.cern.ch/phpBB3/viewtopic.php?t=2309#p66013 - // a transparency>50 will make a volume invisible in the normal pad. - // Hence: possibly restrict transparency to a maximum of 50. - // but let's see first how this behaves. - m_element->SetTransparency((1.0-vis->alpha)*100); + // As suggested by Valentin Volkl https://sft.its.cern.ch/jira/browse/DDFORHEP-20 + // + // According to https://root.cern.ch/phpBB3/viewtopic.php?t=2309#p66013 + // a transparency>50 will make a volume invisible in the normal pad. + // Hence: possibly restrict transparency to a maximum of 50. + // but let's see first how this behaves. + m_element->SetTransparency((1.0-vis->alpha)*100); #endif } else { - printout(DEBUG,"setVisAttributes","Set to wireframe vis:%s",name()); - m_element->SetLineColor(kBlack); - m_element->SetFillColor(0); - m_element->SetFillStyle(0); // Root: hollow + printout(DEBUG,"setVisAttributes","Set to wireframe vis:%s",name()); + m_element->SetLineColor(kBlack); + m_element->SetFillColor(0); + m_element->SetFillStyle(0); // Root: hollow } if (line_style == VisAttr::SOLID) // Root line style: 1=solid, 2=dash, 3=dot, 4=dash-dot. - m_element->SetLineStyle(1); + m_element->SetLineStyle(1); else if (line_style == VisAttr::DASHED) - m_element->SetLineStyle(2); + m_element->SetLineStyle(2); else - m_element->SetLineStyle(line_style); + m_element->SetLineStyle(line_style); } else { except("Volume","setVisAttributes: encountered valid, but badly initialized visattr: %s",attr.name()); diff --git a/DDDigi/include/DDDigi/DigiDDG4Input.h b/DDDigi/include/DDDigi/DigiDDG4Input.h new file mode 100644 index 0000000000000000000000000000000000000000..70b290ee977e74a2968ad30680cb660740025510 --- /dev/null +++ b/DDDigi/include/DDDigi/DigiDDG4Input.h @@ -0,0 +1,62 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DDDIGI_DIGIDDG4INPUT_H +#define DDDIGI_DIGIDDG4INPUT_H + +/// Framework include files +#include "DDDigi/DigiInputAction.h" + +// Forward declarations +class TFile; +class TTree; +class TBranch; + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for the Digitization part of the AIDA detector description toolkit + namespace digi { + + // Forward declarations + class DigiDDG4Input; + + /// Base class for input actions to the digitization + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + class DigiDDG4Input : public DigiInputAction { + protected: + /// Reference to the current ROOT file to be read + TFile* m_current; + /// List of input sources to be worked down + std::vector<std::string> m_todo; + + protected: + /// Define standard assignments and constructors + DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiDDG4Input); + + public: + /// Standard constructor + DigiDDG4Input(const DigiKernel& kernel, const std::string& nam); + /// Default destructor + virtual ~DigiDDG4Input(); + /// Callback to read event input + virtual void execute(DigiContext& context) const override; + }; + + } // End namespace digi +} // End namespace dd4hep +#endif // DDDIGI_DIGIDDG4INPUT_H diff --git a/DDDigi/include/DDDigi/DigiStore.h b/DDDigi/include/DDDigi/DigiStore.h new file mode 100644 index 0000000000000000000000000000000000000000..c79a8aac92d696b4ae4ed7e97d663e18e811017d --- /dev/null +++ b/DDDigi/include/DDDigi/DigiStore.h @@ -0,0 +1,138 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DDDIGI_DIGISTORE_H +#define DDDIGI_DIGISTORE_H + +// Framework incloude files +#include "DDDigi/DigiData.h" + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + // Forward declarations + + /// Namespace for the Digitization part of the AIDA detector description toolkit + namespace digi { + + /// + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + class DigiInputs { + public: + friend class DigiStore; + + /// Forward definition of the key type + typedef Key::key_type key_type; + + protected: +#if defined(DD4HEP_INTERPRETER_MODE) + std::map<key_type, long> data; +#else + std::map<key_type, dd4hep::any> data; +#endif + public: + /// Define standard assignments and constructors + DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiInputs); + +#if !defined(DD4HEP_INTERPRETER_MODE) + /// Retrieve item by key from the data container + template <typename T> const T& get(const Key& key) const { + auto iter = data.find(key.toLong()); + if ( iter != data.end() ) { + T* ptr = dd4hep::any_cast<T>(&(*iter).second); + if ( ptr ) return *ptr; + except("DigiEvent","Invalid data requested from store [cast failed]. Key:%ld",key.toLong()); + } + except("DigiEvent","Invalid data requested from store. Key:%ld",key.toLong()); + throw std::runtime_error("DigiEvent"); // Will never get here! + } +#endif + }; + + /// + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + class DigiOutputs { + public: + friend class DigiStore; + + /// Forward definition of the key type + typedef Key::key_type key_type; + + protected: +#if defined(DD4HEP_INTERPRETER_MODE) + std::map<key_type, long> data; +#else + std::map<key_type, dd4hep::any> data; +#endif + std::mutex lock; + public: + /// Define standard assignments and constructors + DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiOutputs); + +#if !defined(DD4HEP_INTERPRETER_MODE) + /// Add item by key to the data + template<typename T> bool put(const Key& key, T&& object) { + std::lock_guard<std::mutex> guard(lock); + bool ret = data.emplace(key.toLong(),make_any<T>(object)).second; + if ( ret ) return ret; + except("DigiEvent","Invalid request to store data in store. Key:%ld",key.toLong()); + return false; + } +#endif + }; + + /// + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + class DigiStore { + public: + /// Forward definition of the key type + typedef Key::key_type key_type; + + /// Container of input data + DigiInputs inputs; + /// Container of output data + DigiOutputs outputs; + + protected: + /// Define standard assignments and constructors + DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiStore); + + public: + /// Standard constructor + DigiStore(const DigiKernel& kernel, const std::string& nam); + /// Default destructor + virtual ~DigiStore(); + /// Add a set of input data to the store + void add_inputs(const std::map<key_type,dd4hep::any>& items); + /// Move produced results out of the store + std::map<key_type,dd4hep::any> move_outputs(); + }; + + } // End namespace digi +} // End namespace dd4hep + +#endif // DDDIGI_DIGISTORE_H diff --git a/DDDigi/plugins/Components.cpp b/DDDigi/plugins/Components.cpp index 7ed029637c7eb3e552f9024fd63c9c48e57ab1ec..e7080658446eaa3408a9b452b5503079dc8dda48 100644 --- a/DDDigi/plugins/Components.cpp +++ b/DDDigi/plugins/Components.cpp @@ -24,6 +24,9 @@ #include "DDDigi/DigiInputAction.h" DECLARE_DIGIEVENTACTION_NS(dd4hep::digi,DigiInputAction) +#include "DDDigi/DigiDDG4Input.h" +DECLARE_DIGIEVENTACTION_NS(dd4hep::digi,DigiDDG4Input) + #include "DDDigi/DigiSynchronize.h" DECLARE_DIGIEVENTACTION_NS(dd4hep::digi,DigiSynchronize) diff --git a/DDDigi/src/DigiDDG4Input.cpp b/DDDigi/src/DigiDDG4Input.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c39ed2ba1c4c753945bf6dc109f181d6550d154d --- /dev/null +++ b/DDDigi/src/DigiDDG4Input.cpp @@ -0,0 +1,43 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/InstanceCount.h" +#include "DDDigi/DigiDDG4Input.h" + +// C/C++ include files +#include <stdexcept> +#include <unistd.h> + +using namespace std; +using namespace dd4hep::digi; + +/// Standard constructor +DigiDDG4Input::DigiDDG4Input(const DigiKernel& kernel, const string& nam) + : DigiInputAction(kernel, nam) +{ + InstanceCount::increment(this); +} + +/// Default destructor +DigiDDG4Input::~DigiDDG4Input() { + InstanceCount::decrement(this); +} + +/// Pre-track action callback +void DigiDDG4Input::execute(DigiContext& /* context */) const { + ::sleep(1); + info("+++ Virtual method execute()"); + return; + //except("DigiDDG4Input","+++ Virtual method execute() MUST be overloaded!"); +} diff --git a/DDDigi/src/DigiStore.cpp b/DDDigi/src/DigiStore.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b588973f311d0e8b302c962aadabbb3c440ee3fb --- /dev/null +++ b/DDDigi/src/DigiStore.cpp @@ -0,0 +1,25 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/InstanceCount.h" +#include "DDDigi/DigiKernel.h" +#include "DDDigi/DigiContext.h" +#include "DDDigi/DigiStore.h" + +// C/C++ include files +#include <stdexcept> + +using namespace std; +using namespace dd4hep::digi; + diff --git a/examples/DDCAD/CMakeLists.txt b/examples/DDCAD/CMakeLists.txt index bedd641c69cdb1113d44aa82f54966a70233b22f..4d85a35749ffec968b4fd9968279f34aa02b6281 100644 --- a/examples/DDCAD/CMakeLists.txt +++ b/examples/DDCAD/CMakeLists.txt @@ -53,7 +53,7 @@ list(APPEND DDCAD_Tests BHV_Boxing_Toes Collada_duck PLY_Wuson) foreach (test ${DDCAD_Tests}) dd4hep_add_test_reg( DDCAD_Check_Shape_${test} COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" - EXEC_ARGS geoDisplay file:${DDCAD_INSTALL}/compact/Check_Shape_${test}.xml -load -destroy + EXEC_ARGS geoDisplay file:${DDCADEx_INSTALL}/compact/Check_Shape_${test}.xml -load -destroy REGEX_PASS "Shape verification SUCCESSFUL." REGEX_FAIL "ERROR;FAILED" ) endforeach()