Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:14

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 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
0028 
0029 #include "G4AnalysisManagerState.hh"
0030 #include "G4AnalysisUtilities.hh"
0031 
0032 using std::to_string;
0033 
0034 //_____________________________________________________________________________
0035 template <typename NT>
0036 G4TRNtupleManager<NT>::G4TRNtupleManager(const G4AnalysisManagerState& state)
0037  : G4BaseRNtupleManager(state)
0038 {}
0039 
0040 //_____________________________________________________________________________
0041 template <typename NT>
0042 G4TRNtupleManager<NT>::~G4TRNtupleManager()
0043 {
0044   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
0045     delete ntupleDescription;
0046   }
0047 }
0048 
0049 //
0050 // private methods
0051 //
0052 
0053 //_____________________________________________________________________________
0054 template <typename NT>
0055 G4TRNtupleDescription<NT>*
0056 G4TRNtupleManager<NT>::GetNtupleDescriptionInFunction(
0057   G4int id, std::string_view functionName, G4bool warn) const
0058 {
0059   G4int index = id - fFirstId;
0060   if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
0061     if ( warn) {
0062       G4Analysis::Warn("ntuple " + to_string(id) + " does not exist.",
0063         fkClass, functionName);
0064     }
0065     return nullptr;
0066   }
0067 
0068   return fNtupleDescriptionVector[index];
0069 }
0070 
0071 //_____________________________________________________________________________
0072 template <typename NT>
0073 template <typename T>
0074 G4bool
0075 G4TRNtupleManager<NT>::SetNtupleTColumn(
0076   G4int ntupleId, const G4String& columnName, T& value)
0077 {
0078   Message(G4Analysis::kVL4, "set", "ntuple T column",
0079     " ntupleId " + to_string(ntupleId) + " " + columnName);
0080 
0081   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
0082   if ( ! ntupleDescription )  return false;
0083 
0084   auto ntupleBinding = ntupleDescription->fNtupleBinding;
0085   ntupleBinding->add_column(columnName, value);
0086 
0087   Message(G4Analysis::kVL2, "set", "ntuple T column",
0088     " ntupleId " + to_string(ntupleId) + " " + columnName);
0089 
0090   return true;
0091 }
0092 
0093 //_____________________________________________________________________________
0094 template <typename NT>
0095 template <typename T>
0096 G4bool
0097 G4TRNtupleManager<NT>::SetNtupleTColumn(
0098   G4int ntupleId, const G4String& columnName, std::vector<T>& vector)
0099 {
0100   Message(G4Analysis::kVL4, "set", "ntuple T column",
0101     " ntupleId " + to_string(ntupleId) + " " + columnName);
0102 
0103   auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
0104   if ( ! ntupleDescription )  return false;
0105 
0106   auto ntupleBinding = ntupleDescription->fNtupleBinding;
0107   ntupleBinding->add_column(columnName, vector);
0108 
0109   Message(G4Analysis::kVL2, "set", "ntuple T column",
0110     " ntupleId " + to_string(ntupleId) + " " + columnName);
0111 
0112 
0113   return true;
0114 }
0115 
0116 //
0117 // protected methods
0118 //
0119 
0120 //_____________________________________________________________________________
0121 template <typename NT>
0122 G4bool G4TRNtupleManager<NT>::IsEmpty() const
0123 {
0124   return ! fNtupleDescriptionVector.size();
0125 }
0126 
0127 //_____________________________________________________________________________
0128 template <typename NT>
0129 G4bool G4TRNtupleManager<NT>::Reset()
0130 {
0131 // Reset ntuples
0132 
0133   for ( auto ntupleDescription : fNtupleDescriptionVector ) {
0134     delete ntupleDescription->fNtuple;
0135     ntupleDescription->fNtuple=nullptr;
0136   }
0137   return true;
0138 }
0139 
0140 //_____________________________________________________________________________
0141 template <typename NT>
0142 NT*
0143 G4TRNtupleManager<NT>::GetNtuple() const
0144 {
0145   return GetNtuple(fFirstId);
0146 }
0147 
0148 //_____________________________________________________________________________
0149 template <typename NT>
0150 NT*
0151 G4TRNtupleManager<NT>::GetNtuple(
0152   G4int ntupleId) const
0153 {
0154   auto rntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
0155 
0156   if ( ! rntupleDescription ) return nullptr;
0157 
0158   return rntupleDescription->fNtuple;
0159 }
0160 
0161 //_____________________________________________________________________________
0162 template <typename NT>
0163 G4int G4TRNtupleManager<NT>::SetNtuple(
0164   G4TRNtupleDescription<NT>* rntupleDescription)
0165 {
0166   G4int id = G4int(fNtupleDescriptionVector.size() + fFirstId);
0167 
0168   fNtupleDescriptionVector.push_back(rntupleDescription);
0169 
0170   return id;
0171 }
0172 
0173 //_____________________________________________________________________________
0174 template <typename NT>
0175 G4bool
0176 G4TRNtupleManager<NT>::SetNtupleIColumn(
0177   G4int ntupleId, const G4String& columnName, G4int& value)
0178 {
0179   return SetNtupleTColumn<int>(ntupleId, columnName, value);
0180 }
0181 
0182 //_____________________________________________________________________________
0183 template <typename NT>
0184 G4bool
0185 G4TRNtupleManager<NT>::SetNtupleFColumn(
0186   G4int ntupleId, const G4String& columnName, G4float& value)
0187 {
0188   return SetNtupleTColumn<float>(ntupleId, columnName, value);
0189 }
0190 
0191 //_____________________________________________________________________________
0192 template <typename NT>
0193 G4bool
0194 G4TRNtupleManager<NT>::SetNtupleDColumn(
0195   G4int ntupleId, const G4String& columnName, G4double& value)
0196 {
0197   return SetNtupleTColumn<double>(ntupleId, columnName, value);
0198 }
0199 
0200 //_____________________________________________________________________________
0201 template <typename NT>
0202 G4bool
0203 G4TRNtupleManager<NT>::SetNtupleIColumn(
0204   G4int ntupleId, const G4String& columnName, std::vector<G4int>& vector)
0205 {
0206   return SetNtupleTColumn<int>(ntupleId, columnName, vector);
0207 }
0208 
0209 //_____________________________________________________________________________
0210 template <typename NT>
0211 G4bool
0212 G4TRNtupleManager<NT>::SetNtupleFColumn(
0213   G4int ntupleId, const G4String& columnName, std::vector<G4float>& vector)
0214 {
0215   return SetNtupleTColumn<float>(ntupleId, columnName, vector);
0216 }
0217 
0218 //_____________________________________________________________________________
0219 template <typename NT>
0220 G4bool
0221 G4TRNtupleManager<NT>::SetNtupleDColumn(
0222   G4int ntupleId, const G4String& columnName, std::vector<G4double>& vector)
0223 {
0224   return SetNtupleTColumn<double>(ntupleId, columnName, vector);
0225 }
0226 
0227 //_____________________________________________________________________________
0228 template <typename NT>
0229 G4bool
0230 G4TRNtupleManager<NT>::SetNtupleSColumn(
0231   G4int ntupleId, const G4String& columnName, G4String& value)
0232 {
0233   return SetNtupleTColumn<std::string>(ntupleId, columnName, value);
0234 }
0235 
0236 //_____________________________________________________________________________
0237 template <typename NT>
0238 G4bool
0239 G4TRNtupleManager<NT>::SetNtupleSColumn(
0240   G4int ntupleId, const G4String& columnName, std::vector<std::string>& vector)
0241 {
0242   return SetNtupleTColumn<std::string>(ntupleId, columnName, vector);
0243 }
0244 
0245 //_____________________________________________________________________________
0246 template <typename NT>
0247 G4bool G4TRNtupleManager<NT>::GetNtupleRow(G4int ntupleId)
0248 {
0249   Message(G4Analysis::kVL4, "get", "ntuple row",
0250     "ntupleId " + to_string(ntupleId));
0251 
0252   auto ntupleDescription
0253     = GetNtupleDescriptionInFunction(ntupleId, "GetNtupleRow");
0254   if ( ! ntupleDescription )  return false;
0255 
0256   auto next = GetTNtupleRow(ntupleDescription);
0257 
0258   Message(G4Analysis::kVL2, "get", "ntuple row",
0259     "ntupleId " + to_string(ntupleId));
0260 
0261   return next;
0262 }
0263 
0264 
0265 //_____________________________________________________________________________
0266 template <typename NT>
0267 G4int
0268 G4TRNtupleManager<NT>::GetNofNtuples() const
0269 {
0270   return G4int(fNtupleDescriptionVector.size());
0271 }
0272 
0273