File indexing completed on 2025-01-30 09:18:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DDDB/DDDBReader.h"
0022 #include "DDDB/DDDBHelper.h"
0023 #include "DD4hep/Factories.h"
0024 #include "DD4hep/Printout.h"
0025 #include "DD4hep/Detector.h"
0026 #include "DD4hep/Path.h"
0027
0028
0029 #include <sys/types.h>
0030 #include <sys/stat.h>
0031 #include <unistd.h>
0032 #include <fcntl.h>
0033 #include <iostream>
0034 #include <cerrno>
0035 #include "TGeoManager.h"
0036 #include "TRint.h"
0037
0038 using namespace std;
0039 using namespace dd4hep;
0040 using namespace dd4hep::DDDB;
0041
0042 static void check_result(long result) {
0043 if ( 0 == result )
0044 except("DDDBExecutor","+++ Odd things going on.....");
0045
0046 if ( result != 1 )
0047 except("DDDBExecutor","+++ Odd things going on.....Processing result=%ld",result);
0048 }
0049
0050 static void usage_load_xml_dddb() {
0051 cout <<
0052 "DDDBExecutor opt [opt]\n"
0053 " Note: No '-' signs infront of identifiers! \n"
0054 " \n"
0055 " -loader <plugin> Plugin instance for XML entity resolution. \n"
0056 " -param <file-name> Preprocessing xml file \n"
0057 " -input <file-name> Directory containing DDDB \n"
0058 " -config <plugin> Execute config plugin initializing the helper. \n"
0059 " -match <string> Match string for entity resolver e.g.'conddb:' \n"
0060 " -xml <file-name> Parse additional XML files using Detector. \n"
0061 " -setup <plugin> Add setup plugin after dddb parsing. \n"
0062 " -exec <plugin> Add execution plugin after setup. \n"
0063 " -attr <file-name> Optional XML parsing for visualization attrs. \n"
0064 " -dump Call DDDB_DetectorConditionDump plugin. \n"
0065 " -visualize Call display after processing \n"
0066 ""
0067 "" << endl;
0068
0069 ::exit(EINVAL);
0070 }
0071
0072 static long run_plugin(Detector& description, const std::string& plugin, std::vector<char*>& args) {
0073 args.push_back(0);
0074 return description.apply(plugin.c_str(), args.size()-1, &args[0]);
0075 }
0076
0077 static long load_xml_dddb(Detector& description, int argc, char** argv) {
0078 if ( argc > 0 ) {
0079 string sys_id, params, match="conddb:", attr="", loader_name="DDDB_FileReader";
0080 std::vector<string> setup, xmlFiles, executors, config;
0081 std::map<std::string, std::vector<char*> > e_args, s_args, c_args;
0082 long result = 0, visualize = 0, dump = 0;
0083 long event_time = detail::makeTime(2016,4,1,12);
0084 long iov_start = -1;
0085 long iov_end = -1;
0086 char last = 0, c;
0087
0088 for(int i=0; i<argc;++i) {
0089 const char* arg = argv[i];
0090 c = 0;
0091 if ( arg[0] == '-' ) {
0092 c = ::toupper(arg[1]);
0093 switch(c) {
0094 case 'A':
0095 attr = argv[++i];
0096 last = 0;
0097 break;
0098 case 'C':
0099 config.push_back(argv[++i]);
0100 c_args[config.back()] = std::vector<char*>();
0101 last = c;
0102 break;
0103 case 'D':
0104 dump = 1;
0105 last = 0;
0106 break;
0107 case 'E':
0108 executors.push_back(argv[++i]);
0109 e_args[executors.back()] = std::vector<char*>();
0110 last = c;
0111 break;
0112 case 'I':
0113 if ( ::strncasecmp(arg+1,"IOV_START",5)==0 )
0114 iov_start = detail::makeTime(argv[++i],"%d-%m-%Y-%H:%M:%S");
0115 else if ( ::strncasecmp(arg+1,"IOV_END",5)==0 )
0116 iov_end = detail::makeTime(argv[++i],"%d-%m-%Y-%H:%M:%S");
0117 else
0118 sys_id = argv[++i];
0119 last = 0;
0120 break;
0121 case 'L':
0122 loader_name = argv[++i];
0123 last = 0;
0124 break;
0125 case 'M':
0126 match = argv[++i];
0127 last = 0;
0128 break;
0129 case 'P':
0130 params = argv[++i];
0131 last = 0;
0132 break;
0133 case 'S':
0134 setup.push_back(argv[++i]);
0135 s_args[setup.back()] = std::vector<char*>();
0136 last = c;
0137 break;
0138 case 'V':
0139 visualize = 1;
0140 last = 0;
0141 break;
0142 case 'X':
0143 xmlFiles.push_back(argv[++i]);
0144 last = 0;
0145 break;
0146 case 'H':
0147 usage_load_xml_dddb();
0148 break;
0149 case '?':
0150 usage_load_xml_dddb();
0151 break;
0152 default:
0153 usage_load_xml_dddb();
0154 }
0155 }
0156 if ( !c && last == 'C' )
0157 c_args[config.back()].push_back(argv[i]);
0158 else if ( !c && last == 'E' )
0159 e_args[executors.back()].push_back(argv[i]);
0160 else if ( !c && last == 'S' ) {
0161 s_args[setup.back()].push_back(argv[i]);
0162 }
0163 }
0164
0165 Path path = sys_id;
0166 sys_id = path.normalize().c_str();
0167
0168 xml::UriReader* resolver = 0;
0169 if ( !loader_name.empty() ) {
0170 DDDBReader* rdr = (DDDBReader*)dd4hep::PluginService::Create<void*>(loader_name,(const char*)0);
0171 rdr->setMatch(match);
0172 rdr->setDirectory(path.parent_path().c_str());
0173 if ( iov_start >= 0 && iov_end >= 0 ) {
0174 rdr->property("ValidityLower").set(iov_start);
0175 rdr->property("ValidityUpper").set(iov_end);
0176 }
0177 resolver = rdr;
0178 }
0179
0180 {
0181 const void *args[] = {resolver, 0};
0182 description.apply("DDDB_InstallHelper", 1, (char**)args);
0183 }
0184
0185
0186 for(size_t i=0; i<config.size(); ++i)
0187 run_plugin(description, config[i], c_args[config[i]]);
0188
0189
0190 if ( !params.empty() ) {
0191 const void* args[] = {0, params.c_str(), 0};
0192 printout(INFO,"DDDBExecutor","+++ Processing parameters: %s",params.c_str());
0193 result = description.apply("DDDB_Loader", 2, (char**)args);
0194 check_result(result);
0195 }
0196
0197
0198 if ( !attr.empty() ) {
0199 const void* args[] = {attr.c_str(), 0};
0200 printout(INFO,"DDDBExecutor","+++ Processing visualization attributes: %s", attr.c_str());
0201 result = description.apply("DD4hep_XMLLoader", 1, (char**)args);
0202 check_result(result);
0203 }
0204
0205
0206 if ( !sys_id.empty() ) {
0207 printout(INFO,"DDDBExecutor","+++ Processing DDDB: %s", sys_id.c_str());
0208 const void* args[] = {0, sys_id.c_str(), "/", &event_time, 0};
0209 result = description.apply("DDDB_Loader", 4, (char**)args);
0210 check_result(result);
0211 printout(INFO,"DDDBExecutor"," .... done");
0212 }
0213
0214
0215 {
0216 result = description.apply("DDDB_2dd4hep", 0, 0);
0217 check_result(result);
0218 }
0219
0220
0221 if ( !xmlFiles.empty() ) {
0222 for(size_t i=0; i<xmlFiles.size(); ++i) {
0223 const void* args[] = {xmlFiles[i].c_str(), 0};
0224 description.apply("DD4hep_XMLLoader", 1, (char**)args);
0225 }
0226 }
0227
0228
0229 for(size_t i=0; i<setup.size(); ++i)
0230 run_plugin(description, setup[i], s_args[setup[i]]);
0231
0232
0233 for(size_t i=0; i<executors.size(); ++i)
0234 run_plugin(description, executors[i], e_args[executors[i]]);
0235
0236 if ( dump ) {
0237 printout(INFO,"DDDBExecutor","------------------> Conditions dump:");
0238 description.apply("DDDB_DetectorConditionDump", 0, 0);
0239 }
0240 if ( visualize ) {
0241 pair<int, char**> a(0,0);
0242 TRint app("DDDB", &a.first, a.second);
0243 TGeoManager& mgr = description.manager();
0244 mgr.SetVisLevel(999);
0245 mgr.SetVisOption(1);
0246 description.worldVolume()->Draw("ogl");
0247 app.Run();
0248 }
0249 }
0250 return 1;
0251 }
0252 DECLARE_APPLY(DDDB_Executor,load_xml_dddb)