Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:00

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 /// file: ChromosomeMapper.cc
0028 /// brief: Implementation of class to track chromosomes
0029 #include "ChromosomeMapper.hh"
0030 
0031 #include "ChromosomeMessenger.hh"
0032 #include "DNAHashing.hh"
0033 #include "VirtualChromosome.hh"
0034 
0035 #include <fstream>
0036 #include <sstream>
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 ChromosomeMapper::ChromosomeMapper() : fChromosomes({})
0041 {
0042   fpChromosomeMessenger = new ChromosomeMessenger(this);
0043   fpChromosomeFactory = new ChromosomeFactory();
0044 }
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 ChromosomeMapper::~ChromosomeMapper()
0049 {
0050   delete fpChromosomeMessenger;
0051   delete fpChromosomeFactory;
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 [[maybe_unused]] G4String ChromosomeMapper::GetCurrentChromosomeKey(const G4ThreeVector& pos) const
0057 {
0058   G4String key = "";
0059   for (const auto& Chromosome : fChromosomes) {
0060     if (Chromosome.second->PointInChromosome(pos)) {
0061       // key = Chromosome.first;
0062       key = Chromosome.second->GetName();
0063       break;
0064     }
0065   }
0066   return key;
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 [[maybe_unused]] VirtualChromosome* ChromosomeMapper::GetChromosome(const G4ThreeVector& pos) const
0072 {
0073   for (const auto& fChromosome : fChromosomes) {
0074     if (fChromosome.second->PointInChromosome(pos)) {
0075       return fChromosome.second;
0076     }
0077   }
0078   return nullptr;
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 [[maybe_unused]] VirtualChromosome* ChromosomeMapper::GetChromosome(const G4String& key) const
0084 {
0085   uint32_t key_i = G4::hashing::crc32::Hash(key);
0086 
0087   try {
0088     return fChromosomes.at(key_i);
0089   }
0090   catch (const std::out_of_range& oor) {
0091     G4cout << "Chromosome does not exist with key: " << key << G4endl;
0092     return nullptr;
0093   }
0094 }
0095 
0096 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0097 
0098 void ChromosomeMapper::AddChromosome(const G4String& key, const std::vector<G4String>& commands)
0099 {
0100   uint32_t key_i = G4::hashing::crc32::Hash(key);
0101 
0102   auto it = fChromosomes.find(key_i);
0103 
0104   if (it == fChromosomes.end()) {
0105     auto* newChromosome = ChromosomeFactory::MakeChromosome(key, commands);
0106     fChromosomes.emplace(key_i, newChromosome);
0107   }
0108   else {
0109     G4ExceptionDescription errmsg;
0110     errmsg << "ChromosomeMapper:: "
0111            << "Chromosome already exists with key: " << key << G4endl;
0112     G4Exception("ChromosomeMapper::AddChromosome", "", FatalException, errmsg);
0113   }
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 void ChromosomeMapper::SavePlotData(const G4String& filename)
0119 {
0120   std::fstream fs(filename, std::fstream::in | std::fstream::out | std::fstream::trunc);
0121   for (auto& fChromosome : fChromosomes) {
0122     fs << fChromosome.second->Plot();
0123   }
0124   fs.close();
0125 }
0126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0127 
0128 [[maybe_unused]] std::vector<G4String> ChromosomeMapper::GetChromosomeKeys() const
0129 {
0130   std::vector<G4String> keys;
0131   for (const auto& fChromosome : fChromosomes) {
0132     keys.push_back(fChromosome.second->GetName());
0133   }
0134   return keys;
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0138 
0139 void ChromosomeMapper::Test()
0140 {
0141   fpChromosomeFactory->Test();
0142 }