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[ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/particle_hp/include/G4ArrayOps.hh (Version 11.3.0) and /processes/hadronic/models/particle_hp/include/G4ArrayOps.hh (Version 10.3.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /*                                                 26 /*
 27  * File:   G4ArrayOps.hh                           27  * File:   G4ArrayOps.hh
 28  * Author: B. Wendt (wendbryc@isu.edu)             28  * Author: B. Wendt (wendbryc@isu.edu)
 29  *                                                 29  *
 30  * Created on July 28, 2012, 16:08                 30  * Created on July 28, 2012, 16:08
 31  */                                                31  */
 32                                                    32 
 33 // All the arrays that use the functions in th     33 // All the arrays that use the functions in this namespace MUST have a
 34 // [] (bracket) operator for element-wise acce     34 // [] (bracket) operator for element-wise access
 35                                                    35 
 36 #ifndef G4ARRAYOPS_HH                              36 #ifndef G4ARRAYOPS_HH
 37 #define G4ARRAYOPS_HH                          <<  37 #define G4ARRAYOPS_HH
 38                                                << 
 39 #include "globals.hh"                          << 
 40                                                    38 
 41 #include <vector>                                  39 #include <vector>
 42                                                    40 
                                                   >>  41 #include "globals.hh"
                                                   >>  42 
 43 /** G4ArrayOps is a namespace that provides te     43 /** G4ArrayOps is a namespace that provides template functions for
 44  *  performing basic arithmatic operations on      44  *  performing basic arithmatic operations on any data type that
 45  *  is accessed with the [] operator.              45  *  is accessed with the [] operator.
 46  */                                                46  */
 47 namespace G4ArrayOps                               47 namespace G4ArrayOps
 48 {                                                  48 {
 49 /** Set's all the values in an array to a cons <<  49     /** Set's all the values in an array to a constant */
 50 template<class T>                              <<  50     template< class T >
 51 void Set(G4int Elements, T* To, T Value)       <<  51     void Set( G4int Elements,
 52 {                                              <<  52                T* To,
 53   for (G4int position = 0; position < Elements <<  53                T Value )
 54     To[position] = Value;                      <<  54     {
 55   }                                            <<  55         for(G4int position = 0; position < Elements; position++)
 56 }                                              <<  56         {
 57                                                <<  57             To[position] = Value;
 58 /** Copy values from one array to another */   <<  58         }
 59 template<class T>                              <<  59     }
 60 void Copy(G4int Elements, T* To, T* From)      <<  60 
 61 {                                              <<  61     /** Copy values from one array to another */
 62   for (G4int position = 0; position < Elements <<  62     template< class T >
 63     To[position] = From[position];             <<  63     void Copy( G4int Elements,
 64   }                                            <<  64                T* To,
 65 }                                              <<  65                T* From )
 66                                                <<  66     {
 67 /** Add two arrays together. If the second arr <<  67         for(G4int position = 0; position < Elements; position++)
 68  *  'To' array is used as if the function were <<  68         {
 69  */                                            <<  69             To[position] = From[position];
 70 template<class T>                              <<  70         }
 71 void Add(G4int Elements, T* To, T* A1, T* A2 = <<  71     }
 72 {                                              <<  72 
 73   if (A2 == nullptr) {                         <<  73     /** Add two arrays together. If the second array is NULL then the
 74     A2 = To;                                   <<  74      *  'To' array is used as if the function were the += operator.
 75   }                                            <<  75      */
 76                                                <<  76     template< class T >
 77   for (G4int position = 0; position < Elements <<  77     void Add( G4int Elements,
 78     To[position] = A2[position] + A1[position] <<  78               T* To,
 79   }                                            <<  79               T* A1,
 80 }                                              <<  80               T* A2 = NULL )
 81                                                <<  81     {
 82 /** Add a constant to an array. If the second  <<  82         if(A2 == NULL)
 83  *  'To' array is used as if the function were <<  83         {
 84  */                                            <<  84             A2 = To;
 85 template<class T>                              <<  85         }
 86 void Add(G4int Elements, T* To, T A1, T* A2 =  <<  86 
 87 {                                              <<  87         for(G4int position = 0; position < Elements; position++)
 88   if (A2 == NULL) {                            <<  88         {
 89     A2 = To;                                   <<  89             To[position] = A2[position] + A1[position];
 90   }                                            <<  90         }
 91                                                <<  91     }
 92   for (G4int position = 0; position < Elements <<  92 
 93     To[position] = A1 + A2[position];          <<  93     /** Add a constant to an array. If the second array is NULL then the
 94   }                                            <<  94      *  'To' array is used as if the function were the += operator.
 95 }                                              <<  95      */
 96                                                <<  96     template< class T >
 97 /** Subtract an array from another. If the sec <<  97     void Add( G4int Elements,
 98  *  'To' array is used as if the function were <<  98               T* To,
 99  */                                            <<  99               T A1,
100 template<class T>                              << 100               T* A2 = NULL )
101 void Subtract(G4int Elements, T* To, T* Minuen << 101     {
102 {                                              << 102         if(A2 == NULL)
103   if (Subtrahend == NULL) {                    << 103         {
104     Subtrahend = Minuend;                      << 104             A2 = To;
105     Minuend = To;                              << 105         }
106   }                                            << 106 
107                                                << 107         for(G4int position = 0; position < Elements; position++)
108   for (G4int position = 0; position < Elements << 108         {
109     To[position] = Minuend[position] - Subtrah << 109             To[position] = A1 + A2[position];
110   }                                            << 110         }
111 }                                              << 111     }
112                                                << 112 
113 /** Multiply two arrays together. If the secon << 113     /** Subtract an array from another. If the second array is NULL then the
114  *  'To' array is used as if the function were << 114      *  'To' array is used as if the function were the -= operator.
115  */                                            << 115      */
116 template<class T>                              << 116     template< class T >
117 void Multiply(G4int Elements, T* To, T* M1, T* << 117     void Subtract( G4int Elements,
118 {                                              << 118                    T* To,
119   if (M2 == nullptr) {                         << 119                    T* Minuend,
120     M2 = To;                                   << 120                    T* Subtrahend = NULL )
121   }                                            << 121     {
122                                                << 122         if(Subtrahend == NULL)
123   for (G4int position = 0; position < Elements << 123         {
124     To[position] = M2[position] * M1[position] << 124             Subtrahend = Minuend;
125   }                                            << 125             Minuend = To;
126 }                                              << 126         }
                                                   >> 127 
                                                   >> 128         for(G4int position = 0; position < Elements; position++)
                                                   >> 129         {
                                                   >> 130             To[position] = Minuend[position] - Subtrahend[position];
                                                   >> 131         }
                                                   >> 132     }
                                                   >> 133 
                                                   >> 134     /** Multiply two arrays together. If the second array is NULL then the
                                                   >> 135      *  'To' array is used as if the function were the *= operator.
                                                   >> 136      */
                                                   >> 137     template< class T >
                                                   >> 138     void Multiply( G4int Elements,
                                                   >> 139                    T* To,
                                                   >> 140                    T* M1,
                                                   >> 141                    T* M2 = NULL )
                                                   >> 142     {
                                                   >> 143         if(M2 == NULL)
                                                   >> 144         {
                                                   >> 145             M2 = To;
                                                   >> 146         }
                                                   >> 147 
                                                   >> 148         for(G4int position = 0; position < Elements; position++)
                                                   >> 149         {
                                                   >> 150             To[position] = M2[position] * M1[position];
                                                   >> 151         }
                                                   >> 152     }
                                                   >> 153 
                                                   >> 154     /** Multiply an array by a constant. If the second array is NULL then the
                                                   >> 155      *  'To' array is used as if the function were the *= operator.
                                                   >> 156      */
                                                   >> 157     template< class T >
                                                   >> 158     void Multiply( G4int Elements,
                                                   >> 159                    T* To,
                                                   >> 160                    T M1,
                                                   >> 161                    T* M2 = NULL )
                                                   >> 162     {
                                                   >> 163         if(M2 == NULL)
                                                   >> 164         {
                                                   >> 165             M2 = To;
                                                   >> 166         }
                                                   >> 167 
                                                   >> 168         for(G4int position = 0; position < Elements; position++)
                                                   >> 169         {
                                                   >> 170             To[position] = M2[position] * M1;
                                                   >> 171         }
                                                   >> 172     }
                                                   >> 173 
                                                   >> 174     /** Divide an array by another. If the second array is NULL then the
                                                   >> 175      *  'To' array is used as if the function were the /= operator.
                                                   >> 176      */
                                                   >> 177     template< class T >
                                                   >> 178     void Divide( G4int Elements,
                                                   >> 179                  T* To,
                                                   >> 180                  T* Numerator,
                                                   >> 181                  T* Denominator = NULL )
                                                   >> 182     {
                                                   >> 183         if(Denominator == NULL)
                                                   >> 184         {
                                                   >> 185             Denominator = Numerator;
                                                   >> 186             Numerator = To;
                                                   >> 187         }
                                                   >> 188 
                                                   >> 189         for(G4int position = 0; position < Elements; position++)
                                                   >> 190         {
                                                   >> 191             To[position] = Numerator[position] / Denominator[position];
                                                   >> 192         }
                                                   >> 193     }
                                                   >> 194 
                                                   >> 195     /** Divide a constant by an array. If the second array is NULL then the
                                                   >> 196      *  'To' array is used as if the function were the /= operator.
                                                   >> 197      */
                                                   >> 198     template< class T >
                                                   >> 199     void Divide( G4int Elements,
                                                   >> 200                  T* To,
                                                   >> 201                  T Numerator,
                                                   >> 202                  T* Denominator = NULL )
                                                   >> 203     {
                                                   >> 204         if(Denominator == NULL)
                                                   >> 205         {
                                                   >> 206             Denominator = To;
                                                   >> 207         }
                                                   >> 208 
                                                   >> 209         for(G4int position = 0; position < Elements; position++)
                                                   >> 210         {
                                                   >> 211             To[position] = Numerator / Denominator[position];
                                                   >> 212         }
                                                   >> 213     }
                                                   >> 214 
                                                   >> 215     template< class T >
                                                   >> 216     void DeleteVectorOfPointers( std::vector< T >& Vector )
                                                   >> 217     {
                                                   >> 218       for(unsigned int i = 0; i < Vector.size(); i++)
                                                   >> 219       {
                                                   >> 220       delete Vector[i];
                                                   >> 221     }
127                                                   222 
128 /** Multiply an array by a constant. If the se << 223       delete &Vector;
129  *  'To' array is used as if the function were << 224     }
130  */                                            << 
131 template<class T>                              << 
132 void Multiply(G4int Elements, T* To, T M1, T*  << 
133 {                                              << 
134   if (M2 == NULL) {                            << 
135     M2 = To;                                   << 
136   }                                            << 
137                                                << 
138   for (G4int position = 0; position < Elements << 
139     To[position] = M2[position] * M1;          << 
140   }                                            << 
141 }                                                 225 }
142                                                   226 
143 /** Divide an array by another. If the second  << 227 #endif  /** G4ARRAYOPS_HH */
144  *  'To' array is used as if the function were << 
145  */                                            << 
146 template<class T>                              << 
147 void Divide(G4int Elements, T* To, T* Numerato << 
148 {                                              << 
149   if (Denominator == NULL) {                   << 
150     Denominator = Numerator;                   << 
151     Numerator = To;                            << 
152   }                                            << 
153                                                << 
154   for (G4int position = 0; position < Elements << 
155     To[position] = Numerator[position] / Denom << 
156   }                                            << 
157 }                                              << 
158                                                << 
159 /** Divide a constant by an array. If the seco << 
160  *  'To' array is used as if the function were << 
161  */                                            << 
162 template<class T>                              << 
163 void Divide(G4int Elements, T* To, T Numerator << 
164 {                                              << 
165   if (Denominator == nullptr) {                << 
166     Denominator = To;                          << 
167   }                                            << 
168                                                << 
169   for (G4int position = 0; position < Elements << 
170     To[position] = Numerator / Denominator[pos << 
171   }                                            << 
172 }                                              << 
173                                                << 
174 template<class T>                              << 
175 void DeleteVectorOfPointers(std::vector<T>& Ve << 
176 {                                              << 
177   for (unsigned int i = 0; i < Vector.size();  << 
178     delete Vector[i];                          << 
179   }                                            << 
180                                                << 
181   delete &Vector;                              << 
182 }                                              << 
183 }  // namespace G4ArrayOps                     << 
184                                                   228 
185 #endif /** G4ARRAYOPS_HH */                    << 
186                                                   229