File indexing completed on 2025-01-30 09:17:44
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
0029
0030
0031
0032 #include "AlignmentExampleObjects.h"
0033 #include "DD4hep/AlignmentsNominalMap.h"
0034 #include "DD4hep/Factories.h"
0035
0036 using namespace std;
0037 using namespace dd4hep;
0038 using namespace dd4hep::AlignmentExamples;
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 static int alignment_example (Detector& description, int argc, char** argv) {
0049 class Collector {
0050 public:
0051 map<DetElement, Delta>& deltas;
0052 ConditionsMap& mapping;
0053 Collector(map<DetElement, Delta>& del, ConditionsMap& cond_map)
0054 : deltas(del), mapping(cond_map) {}
0055
0056 int operator()(DetElement de, int ) const {
0057 Alignment a = mapping.get(de, align::Keys::alignmentKey);
0058 deltas.insert(make_pair(de,a.delta()));
0059 return 1;
0060 }
0061 };
0062 string input;
0063 bool arg_error = false;
0064 for(int i=0; i<argc && argv[i]; ++i) {
0065 if ( 0 == ::strncmp("-input",argv[i],4) )
0066 input = argv[++i];
0067 else
0068 arg_error = true;
0069 }
0070 if ( arg_error || input.empty() ) {
0071
0072 cout <<
0073 "Usage: -plugin <name> -arg [-arg] \n"
0074 " name: factory name DD4hep_AlignmentExample1 \n"
0075 " -input <string> Geometry file \n"
0076 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0077 ::exit(EINVAL);
0078 }
0079
0080
0081 description.fromXML(input);
0082
0083
0084
0085 AlignmentsNominalMap nominal(description.world());
0086
0087
0088 map<DetElement, Delta> deltas;
0089
0090 int num_delta = Scanner().scan(Collector(deltas,nominal),description.world());
0091
0092 int num_printed = Scanner().scan(AlignmentsPrinter(&nominal),description.world());
0093 printout(ALWAYS,"Prepare","Got a total of %ld Deltas (Nominals: %d , Printed: %d)",
0094 deltas.size(), num_delta, num_printed);
0095
0096
0097 ConditionsTreeMap slice;
0098
0099 AlignmentsCalculator calculator;
0100 AlignmentsCalculator::Result ares = calculator.compute(deltas,slice);
0101 printout(ALWAYS,"Compute","Total %ld conditions inserted. Alignments:(C:%ld,M:%ld)",
0102 slice.data.size(), ares.computed, ares.missing);
0103 if ( ares.missing > 0 ) {
0104 printout(ERROR,"Compute","Failed tro compute %ld alignments.",ares.missing);
0105 }
0106 printout(ALWAYS,"Summary","Printed %d, scanned %d and computed a total of %ld alignments (C:%ld,M:%ld).",
0107 num_printed, num_delta, slice.data.size(), ares.computed, ares.missing);
0108
0109 return 1;
0110 }
0111
0112
0113 DECLARE_APPLY(DD4hep_AlignmentExample_nominal,alignment_example)