G4PersistencyCenterMessenger.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // File: G4PersistencyCenterMessenger.cc
00027 //
00028 // History:
00029 //   01.07.18  Youhei Morita  Initial creation (with "fadsclass")
00030 
00031 #include "G4PersistencyCenterMessenger.hh"
00032 
00033 // Implementation of Constructor #1
00034 G4PersistencyCenterMessenger::G4PersistencyCenterMessenger(G4PersistencyCenter* p)
00035  : pc(p)
00036 {
00037   std::string name = "/persistency/";
00038   directory=new G4UIdirectory(name.c_str());
00039   directory->SetGuidance("Control commands for Persistency package");
00040 
00041   std::string cmd = name + "verbose";
00042 
00043   verboseCmd = new G4UIcmdWithAnInteger(cmd.c_str(),this);
00044   verboseCmd->SetGuidance("Set the verbose level of G4PersistencyManager.");
00045   verboseCmd->SetGuidance(" 0 : Silent (default)");
00046   verboseCmd->SetGuidance(" 1 : Display main topics");
00047   verboseCmd->SetGuidance(" 2 : Display event-level topics");
00048   verboseCmd->SetGuidance(" 3 : Display debug information");
00049   verboseCmd->SetParameterName("level",true);
00050   verboseCmd->SetDefaultValue(0);
00051   verboseCmd->SetRange("level >=0 && level <=3");
00052 
00053   std::string vname = name + "select";
00054 
00055   cmd = vname;
00056   select = new G4UIcmdWithAString(cmd.c_str(),this);
00057   select->SetGuidance("Selection of a persistency package");
00058   select->SetParameterName("Persistency package name", true, true);
00059   select->SetCandidates("ODBMS ROOT None");
00060 
00061   vname = name + "store/";
00062 
00063   subdir1 = new G4UIdirectory(vname.c_str());
00064   subdir1->SetGuidance("Specifiy object types for store");
00065 
00066   wrObj.push_back("HepMC");
00067   wrObj.push_back("MCTruth");
00068   wrObj.push_back("Hits");
00069 
00070   std::string guidance;
00071   int i;
00072 
00073   for ( i = 0; i < 3; i++ )
00074   {
00075     cmd = vname + wrObj[i];
00076     guidance = "Store " + wrObj[i] + " objects for output";
00077     storeObj.push_back(new G4UIcmdWithAString(cmd.c_str(),this));
00078     storeObj[i]->SetGuidance(guidance.c_str());
00079     if ( wrObj[i] == "HepMC" ) {
00080       storeObj[i]->SetCandidates("on off recycle");
00081     } else {
00082       storeObj[i]->SetCandidates("on off");
00083     }
00084   }
00085 
00086   vname += "using/";
00087   subdir2 = new G4UIdirectory(vname.c_str());
00088   subdir2->SetGuidance("Select I/O manager for store");
00089 
00090   cmd = vname + "hitIO";
00091   regHitIO = new G4UIcmdWithAString(cmd.c_str(),this);
00092   regHitIO->SetGuidance("Resiter Hits I/O Manager");
00093   regHitIO->SetParameterName("Name of Hits I/O Manager", true, true);
00094 
00095   vname = name + "set/";
00096   subdir3 = new G4UIdirectory(vname.c_str());
00097   subdir3->SetGuidance("Set various parameters"); 
00098 
00099   vname += "writeFile/";
00100   subdir4 = new G4UIdirectory(vname.c_str());
00101   subdir4->SetGuidance("Set output file names for object types");
00102 
00103   for ( i = 0; i < 3; i++ )
00104   {
00105     cmd = vname + wrObj[i];
00106     guidance = "Set an output file name for " + wrObj[i] + ".";
00107     setWrFile.push_back(new G4UIcmdWithAString(cmd.c_str(),this));
00108     setWrFile[i]->SetGuidance(guidance.c_str());
00109     setWrFile[i]->SetParameterName("file name", true, true);
00110   }
00111 
00112   vname = name + "set/ReadFile/";
00113   subdir5 = new G4UIdirectory(vname.c_str());
00114   subdir5->SetGuidance("Set input file names for object types");
00115 
00116   rdObj.push_back("Hits");
00117 
00118   cmd = vname + rdObj[0];
00119   guidance = "Set an input file name for " + rdObj[0] + ".";
00120   setRdFile.push_back(new G4UIcmdWithAString(cmd.c_str(),this));
00121   setRdFile[0]->SetGuidance(guidance.c_str());
00122   setRdFile[0]->SetParameterName("file name", true, true);
00123 
00124   cmd = name + "printall";
00125   printAll = new G4UIcmdWithoutParameter(cmd.c_str(),this);
00126   printAll->SetGuidance("Print all parameters.");
00127 
00128 }
00129 
00130 // Implementation of Destructor #1
00131 G4PersistencyCenterMessenger::~G4PersistencyCenterMessenger()
00132 {
00133   delete directory;
00134   delete subdir1;
00135   delete subdir2;
00136   delete subdir3;
00137   delete subdir4;
00138   delete subdir5;
00139   delete verboseCmd;
00140   delete select;
00141   delete regHitIO;
00142   for ( int i = 0; i < 3; i++ )
00143   {
00144     delete storeObj[i];
00145     delete setWrFile[i];
00146   }
00147   delete setRdFile[0];
00148   delete printAll;
00149 }
00150 
00151 // Implementation of SetNewValue
00152 void G4PersistencyCenterMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
00153 {
00154   if (command==verboseCmd)
00155   {
00156     pc->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
00157   }
00158   else if (command==select)
00159   {
00160     pc->SelectSystem(newValues);
00161   }
00162   else if (command==regHitIO)
00163   {
00164     pc->AddHCIOmanager(PopWord(newValues,1," "),PopWord(newValues,2," "));
00165   }
00166   else if (command==setRdFile[0])
00167   {
00168     pc -> SetReadFile ( rdObj[0],newValues);
00169   }
00170   else if (command==printAll)
00171   {
00172     pc->PrintAll();
00173   }
00174   else
00175   {
00176     for( int i=0; i<3; i++ ) {
00177       if( command==storeObj[i] )
00178       {
00179         StoreMode mode = kOff;
00180         if( newValues == "on" ) {
00181           mode = kOn;
00182         } else if ( newValues == "off" ) {
00183           mode = kOff;
00184         } else if ( newValues == "recycle" ) {
00185           mode = kRecycle;
00186         } else {
00187           G4cerr << "Unrecognized keyword - \"" << newValues << "\"."
00188                  << G4endl;
00189         }
00190         pc->SetStoreMode(wrObj[i],mode);
00191         break;
00192       }
00193       else if( command==setWrFile[i] )
00194       {
00195         pc->SetWriteFile(wrObj[i],newValues);
00196         break;
00197       }
00198     }
00199   }
00200 }
00201 
00202 // Implementation of GetCurrentValue
00203 G4String G4PersistencyCenterMessenger::GetCurrentValue(G4UIcommand* command)
00204 {
00205   G4String ustr="Undefined";
00206 
00207   if (command==select)
00208   {
00209     return pc->VerboseLevel();
00210   }
00211   else if (command==select)
00212   {
00213     return pc->CurrentSystem();
00214   }
00215   else if (command==regHitIO)
00216   {
00217     return pc->CurrentHCIOmanager();
00218   }
00219   else if (command==setRdFile[0])
00220   {
00221     return pc->CurrentReadFile(rdObj[0]);
00222   }
00223   else
00224   {
00225     for( int i=0; i<3; i++ ) {
00226       if( command==storeObj[i] )
00227       {
00228         switch (pc->CurrentStoreMode(wrObj[i])) {
00229           case kOn:
00230             return "on";
00231             break;
00232           case kOff:
00233             return "off";
00234             break;
00235           case kRecycle:
00236             return "recycle";
00237             break;
00238           default:
00239             return "?????";
00240             break;
00241         };
00242       }
00243       else if( command==setWrFile[i] )
00244       {
00245         return pc->CurrentWriteFile(wrObj[i]);
00246       }
00247     }
00248   }
00249 
00250   return ustr;
00251 }
00252 
00253 // Implementation of PopWord
00254 std::string G4PersistencyCenterMessenger::PopWord(std::string text, int n, std::string delim)
00255 {
00256   if ( text.length() <= 0 ) return "";
00257   int p = 0, p0 = 0;
00258   int p1 = 0;
00259   for ( int i = 0; i < n; i++ ) {
00260     p1 = text.find_first_of(delim,p0+1);
00261     while( p1 == p0+1 ) {
00262       p0 = p1;
00263       p1 = text.find_first_of(delim,p0+1);
00264     }
00265     p  = p0;
00266     if ( p1 < 0 ) {
00267       if ( i+1 < n ) return "";
00268       p1 = text.length();
00269       break;
00270     }
00271     p0 = p1;
00272   }
00273   if (p > 0) p++;
00274   return text.substr(p,p1-p);
00275 }
00276 
00277 // End of G4PersistencyCenterMessenger.cc
00278 

Generated on Mon May 27 17:49:18 2013 for Geant4 by  doxygen 1.4.7