ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4NtupleMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4NtupleMessenger.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
27 // Author: Ivana Hrivnacova, 05/05/2015 (ivana@ipno.in2p3.fr)
28 
29 #include "G4NtupleMessenger.hh"
30 #include "G4VAnalysisManager.hh"
31 #include "G4AnalysisUtilities.hh"
32 
33 #include "G4UIcommand.hh"
34 #include "G4UIparameter.hh"
35 #include "G4UIcmdWithABool.hh"
36 
37 #include <iostream>
38 
39 using namespace G4Analysis;
40 
41 //_____________________________________________________________________________
43  : G4UImessenger(),
44  fManager(manager),
45  fSetActivationCmd(nullptr),
46  fSetActivationAllCmd(nullptr)
47 {
48  fNtupleDir = G4Analysis::make_unique<G4UIdirectory>("/analysis/ntuple/");
49  fNtupleDir->SetGuidance("ntuple control");
50 
53 }
54 
55 //_____________________________________________________________________________
57 {
58 }
59 
60 //
61 // public functions
62 //
63 
64 //_____________________________________________________________________________
66 {
67  auto ntupleId = new G4UIparameter("NtupleId", 'i', false);
68  ntupleId->SetGuidance("Ntuple id");
69  ntupleId->SetParameterRange("NtupleId>=0");
70 
71  auto ntupleActivation = new G4UIparameter("NtupleActivation", 's', true);
72  ntupleActivation->SetGuidance("Ntuple activation");
73  ntupleActivation->SetDefaultValue("none");
74 
75  fSetActivationCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/ntuple/setActivation", this);
76  G4String guidance("Set activation for the ntuple of given id");
77 
78  fSetActivationCmd->SetGuidance(guidance);
79  fSetActivationCmd->SetParameter(ntupleId);
80  fSetActivationCmd->SetParameter(ntupleActivation);
81  fSetActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
82 }
83 
84 //_____________________________________________________________________________
86 {
88  = G4Analysis::make_unique<G4UIcmdWithABool>("/analysis/ntuple/setActivationToAll", this);
89  G4String guidance("Set activation to all ntuples");
90  fSetActivationAllCmd->SetGuidance(guidance);
91  fSetActivationAllCmd->SetParameterName("AllNtupleActivation",false);
92 }
93 
94 //
95 // public methods
96 //
97 
98 //_____________________________________________________________________________
100 {
101  if ( command == fSetActivationCmd.get() ) {
102  // tokenize parameters in a vector
103  std::vector<G4String> parameters;
104  G4Analysis::Tokenize(newValues, parameters);
105  // check consistency
106  if ( parameters.size() == command->GetParameterEntries() ) {
107  auto counter = 0;
108  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
109  auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
110  fManager->SetNtupleActivation(id, activation);
111  }
112  else {
113  // Should never happen but let's check anyway for consistency
114  G4ExceptionDescription description;
115  description
116  << "Got wrong number of \"" << command->GetCommandName()
117  << "\" parameters: " << parameters.size()
118  << " instead of " << command->GetParameterEntries()
119  << " expected" << G4endl;
120  G4Exception("G4NtupleMessenger::SetNewValue",
121  "Analysis_W013", JustWarning, description);
122  }
123  }
124  else if ( command == fSetActivationAllCmd.get() ) {
125  auto activation = fSetActivationAllCmd->GetNewBoolValue(newValues);
126  fManager->SetNtupleActivation(activation);
127  }
128 }