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] [ 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 /analysis/management/src/G4NtupleMessenger.cc (Version 11.3.0) and /analysis/management/src/G4NtupleMessenger.cc (Version 10.4.p2)


  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 // $Id$
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 05/05/2015  (ivan     28 // Author: Ivana Hrivnacova, 05/05/2015  (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4NtupleMessenger.hh"                    30 #include "G4NtupleMessenger.hh"
 30 #include "G4VAnalysisManager.hh"                   31 #include "G4VAnalysisManager.hh"
 31 #include "G4AnalysisUtilities.hh"                  32 #include "G4AnalysisUtilities.hh"
 32                                                    33 
 33 #include "G4UIcommand.hh"                          34 #include "G4UIcommand.hh"
 34 #include "G4UIparameter.hh"                        35 #include "G4UIparameter.hh"
 35 #include "G4UIcmdWithABool.hh"                     36 #include "G4UIcmdWithABool.hh"
 36 #include "G4UIcmdWithAString.hh"               <<  37 
 37 #include "G4UIcmdWithoutParameter.hh"          <<  38 #include <iostream>
 38                                                    39 
 39 using namespace G4Analysis;                        40 using namespace G4Analysis;
 40 using std::to_string;                          << 
 41                                                    41 
 42 //____________________________________________     42 //_____________________________________________________________________________
 43 G4NtupleMessenger::G4NtupleMessenger(G4VAnalys     43 G4NtupleMessenger::G4NtupleMessenger(G4VAnalysisManager* manager)
 44   : fManager(manager)                          <<  44   : G4UImessenger(),
                                                   >>  45     fManager(manager),
                                                   >>  46     fSetActivationCmd(nullptr),
                                                   >>  47     fSetActivationAllCmd(nullptr)
 45 {                                                  48 {
 46   fNtupleDir = std::make_unique<G4UIdirectory> <<  49   fNtupleDir = G4Analysis::make_unique<G4UIdirectory>("/analysis/ntuple/");
 47   fNtupleDir->SetGuidance("ntuple control");       50   fNtupleDir->SetGuidance("ntuple control");
 48                                                <<  51   
 49   CreateCmd();                                 << 
 50   CreateColumnCmds();                          << 
 51   FinishCmd();                                 << 
 52   DeleteCmd();                                 << 
 53   SetActivationCmd();                              52   SetActivationCmd();
 54   SetActivationToAllCmd();                         53   SetActivationToAllCmd();
 55   SetFileNameCmd();                            << 
 56   SetFileNameToAllCmd();                       << 
 57   ListCmd();                                   << 
 58 }                                                  54 }
 59                                                    55 
 60 //____________________________________________     56 //_____________________________________________________________________________
 61 G4NtupleMessenger::~G4NtupleMessenger() = defa <<  57 G4NtupleMessenger::~G4NtupleMessenger()
                                                   >>  58 {
                                                   >>  59 }
 62                                                    60 
 63 //                                                 61 //
 64 // private functions                           <<  62 // public functions
 65 //                                                 63 //
 66                                                    64 
 67 //____________________________________________     65 //_____________________________________________________________________________
 68 void G4NtupleMessenger::AddIdParameter(G4UIcom <<  66 void G4NtupleMessenger::SetActivationCmd()
 69 {                                                  67 {
 70   auto ntupleId = new G4UIparameter("NtupleId"     68   auto ntupleId = new G4UIparameter("NtupleId", 'i', false);
 71   ntupleId->SetGuidance("Ntuple id");              69   ntupleId->SetGuidance("Ntuple id");
 72   ntupleId->SetParameterRange("NtupleId>=0");      70   ntupleId->SetParameterRange("NtupleId>=0");
 73                                                    71 
 74   command.SetParameter(ntupleId);              <<  72   auto ntupleActivation = new G4UIparameter("NtupleActivation", 's', true);
 75 }                                              <<  73   ntupleActivation->SetGuidance("Ntuple activation");
 76                                                <<  74   ntupleActivation->SetDefaultValue("none");
 77 //____________________________________________ << 
 78 void G4NtupleMessenger::CreateCmd()            << 
 79 {                                              << 
 80   fCreateCmd = CreateCommand<G4UIcommand>("cre << 
 81                                                << 
 82   auto ntName = new G4UIparameter("name", 's', << 
 83   ntName->SetGuidance("Ntuple name");          << 
 84   fCreateCmd->SetParameter(ntName);            << 
 85                                                << 
 86   auto ntTitle = new G4UIparameter("title", 's << 
 87   ntTitle->SetGuidance("Ntuple title");        << 
 88   fCreateCmd->SetParameter(ntTitle);           << 
 89 }                                              << 
 90                                                << 
 91 //____________________________________________ << 
 92 void G4NtupleMessenger::CreateColumnCmds()     << 
 93 {                                              << 
 94   std::vector<char> colTypes = {'I', 'F', 'D', << 
 95                                                << 
 96   for (auto colType : colTypes ) {             << 
 97     G4String name = "createColumn";            << 
 98     G4String guidance = "Create  ntuple column << 
 99     name.insert(6, 1, colType);                << 
100     guidance.insert(7, 1, colType);            << 
101     auto cmd = CreateCommand<G4UIcmdWithAStrin << 
102     fCreateColumnCmds[colType] = std::move(cmd << 
103   }                                            << 
104 }                                              << 
105                                                << 
106 //____________________________________________ << 
107 void G4NtupleMessenger::FinishCmd()            << 
108 {                                              << 
109   fFinishCmd = CreateCommand<G4UIcmdWithoutPar << 
110     "finish", "Finish creating ntuple");       << 
111 }                                              << 
112                                                << 
113 //____________________________________________ << 
114 void G4NtupleMessenger::DeleteCmd()            << 
115 {                                              << 
116   fDeleteCmd = CreateCommand<G4UIcommand>(     << 
117     "delete", "Delete ntuple with given id");  << 
118                                                << 
119   // Add Id parameter                          << 
120   AddIdParameter(*fDeleteCmd);                 << 
121                                                << 
122   auto parKeepSetting = new G4UIparameter("kee << 
123   G4String guidance =                          << 
124     "If set true, activation, file name, etc.  << 
125     "and applied when a new object with the sa << 
126   parKeepSetting->SetGuidance(guidance.c_str() << 
127   parKeepSetting->SetDefaultValue("false");    << 
128   fDeleteCmd->SetParameter(parKeepSetting);    << 
129 }                                              << 
130                                                << 
131 //____________________________________________ << 
132 void G4NtupleMessenger::SetActivationCmd()     << 
133 {                                              << 
134   fSetActivationCmd = CreateCommand<G4UIcomman << 
135     "setActivation", "Set activation for the n << 
136                                                    75 
137   AddIdParameter(*fSetActivationCmd);          <<  76   fSetActivationCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/ntuple/setActivation", this);
                                                   >>  77   G4String guidance("Set activation for the ntuple of given id");
138                                                    78 
139   auto ntupleActivation = new G4UIparameter("N <<  79   fSetActivationCmd->SetGuidance(guidance);
140   ntupleActivation->SetGuidance("Ntuple activa <<  80   fSetActivationCmd->SetParameter(ntupleId);
141   ntupleActivation->SetDefaultValue(true);     << 
142   fSetActivationCmd->SetParameter(ntupleActiva     81   fSetActivationCmd->SetParameter(ntupleActivation);
143 }                                              <<  82   fSetActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
                                                   >>  83 }  
144                                                    84 
145 //____________________________________________     85 //_____________________________________________________________________________
146 void G4NtupleMessenger::SetActivationToAllCmd(     86 void G4NtupleMessenger::SetActivationToAllCmd()
147 {                                                  87 {
148   fSetActivationAllCmd = CreateCommand<G4UIcmd <<  88   fSetActivationAllCmd 
149     "setActivationToAll", "Set activation to a <<  89     = G4Analysis::make_unique<G4UIcmdWithABool>("/analysis/ntuple/setActivationToAll", this);
                                                   >>  90   G4String guidance("Set activation to all ntuples");
                                                   >>  91   fSetActivationAllCmd->SetGuidance(guidance);
150   fSetActivationAllCmd->SetParameterName("AllN     92   fSetActivationAllCmd->SetParameterName("AllNtupleActivation",false);
151 }                                              <<  93 }  
152                                                <<  94   
153 //____________________________________________ << 
154 void G4NtupleMessenger::SetFileNameCmd()       << 
155 {                                              << 
156   fSetFileNameCmd = CreateCommand<G4UIcommand> << 
157     "setFileName", "Set file name for the ntup << 
158                                                << 
159   AddIdParameter(*fSetFileNameCmd);            << 
160                                                << 
161   auto ntupleFileName = new G4UIparameter("Ntu << 
162   ntupleFileName->SetGuidance("Ntuple file nam << 
163   fSetFileNameCmd->SetParameter(ntupleFileName << 
164 }                                              << 
165                                                << 
166 //____________________________________________ << 
167 void G4NtupleMessenger::SetFileNameToAllCmd()  << 
168 {                                              << 
169   fSetFileNameAllCmd = CreateCommand<G4UIcmdWi << 
170     "setFileNameToAll", "Set file name to all  << 
171   fSetFileNameAllCmd->SetParameterName("AllNtu << 
172 }                                              << 
173                                                << 
174 //____________________________________________ << 
175 void G4NtupleMessenger::ListCmd()              << 
176 {                                              << 
177   fListCmd = CreateCommand<G4UIcommand>("list" << 
178   fListCmd->AvailableForStates(G4State_Idle, G << 
179                                                << 
180   auto parOnlyIfActive = new G4UIparameter("on << 
181   parOnlyIfActive->SetGuidance("Option whether << 
182   parOnlyIfActive->SetDefaultValue("true");    << 
183   fListCmd->SetParameter(parOnlyIfActive);     << 
184 }                                              << 
185                                                << 
186 //                                                 95 //
187 // public methods                                  96 // public methods
188 //                                                 97 //
189                                                    98 
190 //____________________________________________     99 //_____________________________________________________________________________
191 void G4NtupleMessenger::SetNewValue(G4UIcomman    100 void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
192 {                                                 101 {
193   // process "All" commands first              << 
194                                                << 
195   if ( command == fSetActivationAllCmd.get() ) << 
196     fManager->SetActivation(fSetActivationAllC << 
197     return;                                    << 
198   }                                            << 
199                                                << 
200   if ( command == fSetFileNameAllCmd.get() ) { << 
201     fManager->SetFileName(newValues);          << 
202     return;                                    << 
203   }                                            << 
204                                                << 
205   // Tokenize parameters in a vector           << 
206   std::vector<G4String> parameters;            << 
207   G4Analysis::Tokenize(newValues, parameters); << 
208   // check consistency                         << 
209   if ( parameters.size() != command->GetParame << 
210     // Should never happen but let's check any << 
211     G4Analysis::Warn(                          << 
212       "Got wrong number of \"" + command->GetC << 
213       "\" parameters: " + std::to_string(param << 
214       " instead of " + std::to_string(command- << 
215       fkClass, "WarnAboutParameters");         << 
216     return;                                    << 
217   }                                            << 
218                                                << 
219   auto counter = 0;                            << 
220                                                << 
221   // commands without Id parameter             << 
222                                                << 
223   if ( command == fCreateCmd.get() ) {         << 
224     const auto& name = parameters[counter++];  << 
225     const auto& title = parameters[counter++]; << 
226     fTmpNtupleId = fManager->CreateNtuple(name << 
227     return;                                    << 
228   }                                            << 
229                                                << 
230   for (const auto& [colType, checkCommand] : f << 
231     if ( command == checkCommand.get() ) {     << 
232       const auto& name = parameters[counter++] << 
233       switch (colType) {                       << 
234         case 'I':                              << 
235           fManager->CreateNtupleIColumn(fTmpNt << 
236           return;                              << 
237         case 'F':                              << 
238           fManager->CreateNtupleFColumn(fTmpNt << 
239           return;                              << 
240         case 'D':                              << 
241           fManager->CreateNtupleDColumn(fTmpNt << 
242           return;                              << 
243         case 'S':                              << 
244           fManager->CreateNtupleSColumn(fTmpNt << 
245           return;                              << 
246         default:                               << 
247           return;                              << 
248       }                                        << 
249     }                                          << 
250   }                                            << 
251                                                << 
252   if ( command == fFinishCmd.get() ) {         << 
253     fManager->FinishNtuple(fTmpNtupleId);      << 
254     fTmpNtupleId = G4Analysis::kInvalidId;     << 
255     return;                                    << 
256   }                                            << 
257                                                << 
258   // commands with Id parameter                << 
259                                                << 
260   auto id = G4UIcommand::ConvertToInt(paramete << 
261                                                << 
262   if ( command == fDeleteCmd.get() ) {         << 
263     const auto& keepSetting = G4UIcommand::Con << 
264     fManager->DeleteNtuple(id, keepSetting);   << 
265     return;                                    << 
266   }                                            << 
267                                                << 
268   if ( command == fSetActivationCmd.get() ) {     102   if ( command == fSetActivationCmd.get() ) {
269     fManager->SetNtupleActivation(id, G4UIcomm << 103     // tokenize parameters in a vector
270     return;                                    << 104     std::vector<G4String> parameters;
271   }                                            << 105     G4Analysis::Tokenize(newValues, parameters);
272                                                << 106     // check consistency
273   if ( command == fSetFileNameCmd.get() ) {    << 107     if ( G4int(parameters.size()) == command->GetParameterEntries() ) {
274     fManager->SetNtupleFileName(id, parameters << 108       auto counter = 0;
275     return;                                    << 109       auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
276   }                                            << 110       auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
277                                                << 111       fManager->SetNtupleActivation(id, activation);     
278   if ( command == fListCmd.get() ) {           << 112     }
279     const auto& onlyIfActive = G4UIcommand::Co << 113     else {
280     fManager->ListNtuple(onlyIfActive);        << 114       // Should never happen but let's check anyway for consistency
281     return;                                    << 115       G4ExceptionDescription description;
282   }                                            << 116       description 
283 }                                              << 117         << "Got wrong number of \"" << command->GetCommandName() 
                                                   >> 118         << "\" parameters: " << parameters.size()
                                                   >> 119         << " instead of " << command->GetParameterEntries() 
                                                   >> 120         << " expected" << G4endl;
                                                   >> 121       G4Exception("G4NtupleMessenger::SetNewValue",
                                                   >> 122                   "Analysis_W013", JustWarning, description);
                                                   >> 123     }  
                                                   >> 124   }
                                                   >> 125   else if ( command == fSetActivationAllCmd.get() ) {
                                                   >> 126     auto activation = fSetActivationAllCmd->GetNewBoolValue(newValues);
                                                   >> 127     fManager->SetNtupleActivation(activation);
                                                   >> 128   }  
                                                   >> 129 }  
284                                                   130