Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:58

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:  MolecularMoleculeList.hh
0028 /// brief: Enumerators for DNA molecules
0029 
0030 #ifndef MOLECULAR_MOLECULE_LIST_HH
0031 #define MOLECULAR_MOLECULE_LIST_HH
0032 
0033 #include "DNAHashing.hh"
0034 
0035 #include "globals.hh"
0036 
0037 typedef enum molecule
0038 {
0039   UNSPECIFIED,
0040   SUGAR,
0041   PHOSPHATE,
0042   GUANINE,
0043   ADENINE,
0044   CYTOSINE,
0045   THYMINE,
0046   Count
0047 } molecule;
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 namespace utility
0052 {
0053 using namespace G4::hashing;
0054 // Larson: works for the given set of words and is the fastest
0055 #define CT_HASHER(x) larson::Cthash(x)
0056 #define DEFINE_HASHER
0057 #define RT_HASHER(x) larson::Hash(x)
0058 
0059 // Default
0060 // #define CT_HASHER(x) "x"_hash
0061 // #define DEFINE_HASHER G4ThreadLocalStatic G4::hashing::hasher<std::string>
0062 //_hasher; #define RT_HASHER(x) _hasher(x)
0063 
0064 // CRC32
0065 // #define CT_HASHER(x) crc32::hash(x)
0066 // #define DEFINE_HASHER
0067 // #define RT_HASHER(x) crc32::hash(x)
0068 
0069 // STL
0070 //  static constexpr size_t sugar_h = 18188831749337764501llu;
0071 //  static constexpr size_t p_h = 18387783588576939323llu;
0072 //  static constexpr size_t a_h = 13783237927007415;
0073 //  static constexpr size_t g_h = 8059069078009542073;
0074 //  static constexpr size_t t_h = 11553912749450711402llu;
0075 //  static constexpr size_t c_h = 17880634351340259280llu;
0076 // #define CT_HASHER(x) crc32::hash(x)
0077 // #define DEFINE_HASHER G4ThreadLocalStatic std::hash<std::string> stdhasher;
0078 // #define RT_HASHER(x) stdhasher(x)
0079 
0080 static constexpr size_t fSugar_h = CT_HASHER("SUGAR");
0081 static constexpr size_t fP_h = CT_HASHER("PHOSPHATE");
0082 static constexpr size_t fA_h = CT_HASHER("ADENINE");
0083 static constexpr size_t fG_h = CT_HASHER("GUANINE");
0084 static constexpr size_t fT_h = CT_HASHER("THYMINE");
0085 static constexpr size_t fC_h = CT_HASHER("CYTOSINE");
0086 
0087 inline ::molecule GetMoleculeEnum(const G4String& mol)
0088 {
0089   G4String _mol(mol);
0090   std::transform(_mol.begin(), _mol.end(), _mol.begin(), ::toupper);
0091 
0092   DEFINE_HASHER
0093   size_t mol_h = RT_HASHER(std::string(_mol));
0094 
0095   switch (mol_h) {
0096     case fSugar_h:
0097       //          G4cout << "RETURN SUGAR FOR : " << mol << G4endl;
0098       return SUGAR;
0099     case fP_h:
0100       //          G4cout << "RETURN P FOR : " << mol << G4endl;
0101       return PHOSPHATE;
0102     case fA_h:
0103       //          G4cout << "RETURN A FOR : " << mol << G4endl;
0104       return ADENINE;
0105     case fG_h:
0106       //          G4cout << "RETURN G FOR : " << mol << G4endl;
0107       return GUANINE;
0108     case fC_h:
0109       //          G4cout << "RETURN C FOR : " << mol << G4endl;
0110       return CYTOSINE;
0111     case fT_h:
0112       //          G4cout << "RETURN T FOR : " << mol << G4endl;
0113       return THYMINE;
0114     default:
0115       //          G4cout << "RETURN UNSPECIFIED FOR : " << mol << G4endl;
0116       //          G4cout << "p_h " << p_h << G4endl;
0117       G4Exception("MolecularMoleculeList::GetMoleculeEnum", "ERR_UNKNOWN_MOLECULE", JustWarning,
0118                   "Unknown molecule");
0119       return UNSPECIFIED;
0120   }
0121 }
0122 
0123 inline G4String GetMoleculeEnumString(::molecule mol)
0124 {
0125   switch (mol) {
0126     case PHOSPHATE:
0127       return "Phosphate";
0128     case SUGAR:
0129       return "Sugar";
0130     case GUANINE:
0131       return "Guanine";
0132     case ADENINE:
0133       return "Adenine";
0134     case CYTOSINE:
0135       return "Cytosine";
0136     case THYMINE:
0137       return "Thymine";
0138     default:
0139       return "Unspecified";
0140   }
0141 }
0142 
0143 // TODO : move to test part
0144 inline int TestMoleculeEnum()
0145 {
0146   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("PHOSPHATE"))) << G4endl;
0147 
0148   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("SUGAR"))) << G4endl;
0149 
0150   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("GUANINE"))) << G4endl;
0151 
0152   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("ADENINE"))) << G4endl;
0153 
0154   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("THYMINE"))) << G4endl;
0155 
0156   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("CYTOSINE"))) << G4endl;
0157 
0158   G4cout << GetMoleculeEnumString(utility::GetMoleculeEnum(G4String("CyToSiNe"))) << G4endl;
0159 
0160   return 0;
0161 }
0162 }  // namespace utility
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0165 
0166 #endif  // MOLECULAR_MOLECULE_LIST_HH