ATLAS Offline Software
han_config_gen.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 #include <string>
7 #include <cstdlib>
8 
11 
14 #include "TInterpreter.h"
15 
16 namespace {
17 
18 int usage( const std::string& command_name, int exit_code );
19 
20 struct CmdLineArgs {
21  int parse( int argc, char *argv[] );
22 
23  std::string m_connectionString = "sqlite://;schema=/afs/cern.ch/user/a/atlasdqm/dqmdisk1/cherrypy-devel/RefDB.db;dbname=REFDB";
24  long m_runNumber = 2147483646;
25  bool m_bulk = false;
26 
27  std::string command;
28  std::string mconfig;
29  std::string conds;
30 };
31 
32 } // unnamed namespace
33 
34 
35 int main ATLAS_NOT_THREAD_SAFE ( int argc, char *argv[] )
36 {
37  CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); });
38 
39  CmdLineArgs arg;
40  int rc = arg.parse( argc, argv );
41  if (rc!=0) return rc;
42 
43  std::string infileName( arg.mconfig );
45  //std::cout<<__PRETTY_FUNCTION__<<"Input Conditions="<<dqi::ConditionsSingleton::getInstance().getCondition()
46  //<<std::endl;
47  std::string outfileName;
48 
49  std::string::size_type s = infileName.size();
50  std::string::size_type p = infileName.rfind( '.', s );
51  outfileName = infileName.substr( 0, p );
52  outfileName += ".hcfg";
53 
55  config.AssembleAndSave( infileName, outfileName, arg.m_connectionString, arg.m_runNumber, arg.m_bulk);
56  return 0;
57 }
58 
59 
60 // ************************************************************
61 // Private Functions
62 // ************************************************************
63 
64 namespace {
65 
66 int CmdLineArgs::parse( int argc, char *argv[] )
67 {
68  command = argv[0];
69  if( argc > 10 ) return usage( command, 1 );
70  if( argc < 2 ) return usage( command, 0 );
71 
72  mconfig = argv[1];
73 
74  if(argc >= 3) {
75  int ic = 2;
76  while(ic < argc) {
77  int ir = argc - ic;
78  std::string par0 = argv[ic];
79  if(par0 == "-c") {
80  if(ir > 1) {
81  m_connectionString = argv[ic + 1];
82  std::cout << "Setting DB connection string to " << m_connectionString << std::endl;
83  ++ic;
84  }
85  } else if(par0 == "-r") {
86  if(ir > 1) {
87  try {
88  m_runNumber = std::stol(argv[ic + 1]);
89  std::cout << "Setting run number to " << m_runNumber << std::endl;
90  ++ic;
91  } catch(std::exception& e) {
92  std::cout << "Error with input arguments, specified run " << argv[ic+1] << " not a long" << '\n';
93  }
94  }
95  } else if(par0 == "-b") {
96  if(ir > 1) {
97  m_bulk = (strcmp(argv[ic+1], "true") == 0);
98  std::cout << "Setting bulk processing mode to " << (m_bulk ? "true" : "false") << std::endl;
99  ++ic;
100  }
101  } else {
102  conds = argv[ic];
103  }
104  ++ic;
105  }
106  }
107  return 0;
108 }
109 
110 
111 int usage( const std::string& command_name, int exit_code )
112 {
113  std::string message;
114  message += "\n";
115  message += "This program takes as an argument the name of a file containing\n";
116  message += "a MiniConfig configuration and produces a similarly named Root file\n";
117  message += "containing a configuration for the \'han\' application\n";
118 
119  std::string::size_type s = command_name.size();
120  std::string::size_type p = command_name.rfind( '/', s );
121  std::string short_name = command_name.substr( p+1, s );
122 
123  std::cout << "\n";
124  std::cout << "Usage: " << short_name << " <filename>\n";
125  std::cout << message << "\n";
126  return exit_code;
127 }
128 
129 
130 } // unnamed namespace
AtlCoolConsole.usage
tuple usage
Definition: AtlCoolConsole.py:443
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
dqi::ConditionsSingleton::getInstance
static ConditionsSingleton & getInstance()
Definition: ConditionsSingleton.cxx:20
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ubsan_suppress.h
Helper for suppressing ubsan warnings.
ATLAS_NOT_THREAD_SAFE
int main ATLAS_NOT_THREAD_SAFE(int argc, char *argv[])
Definition: han_config_gen.cxx:35
python.base_data.config
config
Definition: base_data.py:21
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ConditionsSingleton.h
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
calibdata.exception
exception
Definition: calibdata.py:496
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
grepfile.ic
int ic
Definition: grepfile.py:33
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
dqi::HanConfig
Definition: HanConfig.h:48
dqi::ConditionsSingleton::setCondition
void setCondition(const std::string &c)
Definition: ConditionsSingleton.cxx:25
CxxUtils::ubsan_suppress
void ubsan_suppress(void(*func)())
Helper for suppressing ubsan warnings.
Definition: ubsan_suppress.cxx:69
checker_macros.h
Define macros for attributes used to control the static checker.
get_generator_info.command
string command
Definition: get_generator_info.py:38
HanConfig.h