File indexing completed on 2025-01-18 09:14:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "PersistencySetup.h"
0029 #include "DD4hep/Factories.h"
0030
0031 using namespace std;
0032 using namespace dd4hep;
0033 using namespace PersistencyExamples;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 static int persistency_example (Detector& , int argc, char** argv) {
0044 string output;
0045 bool arg_error = false;
0046 for(int i=0; i<argc && argv[i]; ++i) {
0047 if ( 0 == ::strncmp("-output",argv[i],4) )
0048 output = argv[++i];
0049 else
0050 arg_error = true;
0051 }
0052 if ( arg_error || output.empty() ) {
0053
0054 cout <<
0055 "Usage: -plugin <name> -arg [-arg] \n"
0056 " name: factory name DD4hep_PersistencyExample_write_cond \n"
0057 " -output <string> Geometry output file \n"
0058 " -iovs <number> Number of parallel IOV slots for processing. \n"
0059 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0060 ::exit(EINVAL);
0061 }
0062
0063 std::vector<Condition> conditions;
0064
0065
0066
0067 Condition int_data = make_condition<int> ("int_data", 12);
0068 Condition long_data = make_condition<long> ("long_data", 13);
0069 Condition dble_data = make_condition<double> ("dble_data", 14.222);
0070 Condition flt_data = make_condition<float> ("flt_data", 15.88);
0071 Condition str_data = make_condition<string> ("str_data", string("Hello"));
0072 Condition delta_data = make_condition<Delta> ("delta_data",Delta(Position(333.0,0,0)));
0073 Condition align_data = make_condition<AlignmentData> ("align_data",AlignmentData());
0074 Condition alignment = AlignmentCondition("Test#alignment");
0075
0076 Condition flt_vector = make_condition<vector<float> > ("float_vector",{0.,1.,2.,3.,4.,5.,6.,7.,8.,9.});
0077 Condition dbl_vector = make_condition<vector<double> > ("double_vector",{0.,1.,2.,3.,4.,5.,6.,7.,8.,9.});
0078
0079
0080 Condition int_vector = make_condition<vector<int> > ("int_vector",{0,10,20,30,40,50,60,70,80,90});
0081 Condition long_vector = make_condition<vector<long> > ("long_vector",{0,10,20,30,40,50,60,70,80,90});
0082 Condition str_vector = make_condition<vector<string> > ("str_vector",{"Hello","World","!","Here","I","am","!"});
0083 Condition string_map = make_condition<map<string,int> >("string_map",{{"A",10},{"B",20},{"C",30}});
0084
0085
0086
0087 conditions.push_back(int_data);
0088 conditions.push_back(long_data);
0089 conditions.push_back(dble_data);
0090 conditions.push_back(flt_data);
0091 conditions.push_back(str_data);
0092
0093 conditions.push_back(flt_vector);
0094 conditions.push_back(dbl_vector);
0095
0096 conditions.push_back(int_vector);
0097 conditions.push_back(long_vector);
0098 conditions.push_back(str_vector);
0099
0100 conditions.push_back(string_map);
0101
0102
0103 conditions.push_back(delta_data);
0104 conditions.push_back(align_data);
0105 conditions.push_back(alignment);
0106
0107 PersistencyIO io;
0108 printout(INFO,"Example","+++ Writing generic conditions vector to %s",output.c_str());
0109 int nbytes = io.write(output,"Conditions",conditions);
0110 printout(INFO,"Example","+++ Wrote %d bytes to file %s",nbytes,output.c_str());
0111 printout(INFO,"Example","+++ %s %ld conditions to file.",
0112 nbytes > 0 ? "PASSED Wrote" : "FAILED +++ Could not write",conditions.size());
0113
0114 return 1;
0115 }
0116
0117
0118 DECLARE_APPLY(DD4hep_PersistencyExample_write_cond,persistency_example)