Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:44

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 /* 
0014    Plugin invocation:
0015    ==================
0016    This plugin behaves like a main program.
0017    Invoke the plugin with something like this:
0018 
0019    geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_populate \
0020    -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
0021 
0022    Populate the conditions store by hand for a set of IOVs.
0023    Then compute the corresponding alignment entries....
0024 
0025 */
0026 // Framework include files
0027 #include "AlignmentExampleObjects.h"
0028 #include "DD4hep/Factories.h"
0029 
0030 using namespace std;
0031 using namespace dd4hep;
0032 using namespace dd4hep::AlignmentExamples;
0033 
0034 /// Plugin function: Alignment program example
0035 /**
0036  *  Factory: DD4hep_AlignmentExample_populate
0037  *
0038  *  \author  M.Frank
0039  *  \version 1.0
0040  *  \date    01/12/2016
0041  */
0042 static int alignment_example (Detector& description, int argc, char** argv)  {
0043 
0044   string input;
0045   int    num_iov = 10;
0046   bool   arg_error = false;
0047   for(int i=0; i<argc && argv[i]; ++i)  {
0048     if ( 0 == ::strncmp("-input",argv[i],4) )
0049       input = argv[++i];
0050     else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0051       num_iov = ::atol(argv[++i]);
0052     else
0053       arg_error = true;
0054   }
0055   if ( arg_error || input.empty() )   {
0056     /// Help printout describing the basic command line interface
0057     cout <<
0058       "Usage: -plugin <name> -arg [-arg]                                             \n"
0059       "     name:   factory name     DD4hep_AlignmentExample1                        \n"
0060       "     -input   <string>        Geometry file                                   \n"
0061       "     -iovs    <number>        Number of parallel IOV slots for processing.    \n"
0062       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0063     ::exit(EINVAL);
0064   }
0065 
0066   // First we load the geometry
0067   description.fromXML(input);
0068 
0069   /******************** Initialize the conditions manager *****************/
0070   ConditionsManager manager = installManager(description);
0071   const IOVType*    iov_typ = manager.registerIOVType(0,"run").second;
0072   if ( 0 == iov_typ )
0073     except("ConditionsPrepare","++ Unknown IOV type supplied.");
0074 
0075   /******************** Populate the conditions store *********************/
0076   // Have 10 run-slices [1001,2000] .... [9001,10000]
0077   size_t total_created = 0;
0078   for(int i=0; i<num_iov; ++i)  {
0079     IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0080     ConditionsPool* iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0081     // Create conditions with all deltas. Use a generic creator
0082     total_created += Scanner().scan(AlignmentCreator(manager, *iov_pool),description.world());
0083   }
0084 
0085   /******************** Now as usual: create the slice ********************/
0086   shared_ptr<ConditionsContent> content(new ConditionsContent());
0087   shared_ptr<ConditionsSlice>   slice(new ConditionsSlice(manager,content));
0088   cond::fill_content(manager,*content,*iov_typ);
0089 
0090   /******************** Register alignments *******************************/
0091   // Note: We have to load one set of conditions in order to auto-populate
0092   //       because we need to see if a detector element actually has alignment
0093   //       conditions. For this we must access the conditions data.
0094   //       Unfortunate, but unavoidable.
0095   //
0096   IOV iov(iov_typ,10+5);
0097   manager.prepare(iov,*slice);
0098   slice->pool->flags |= cond::UserPool::PRINT_INSERT;
0099 
0100   // Collect all the delta conditions and make proper alignment conditions out of them
0101   map<DetElement, Delta> deltas;
0102   Scanner(deltaCollector(*slice,deltas),description.world());
0103   printout(INFO,"Prepare","Got a total of %ld Deltas",deltas.size());
0104 
0105   // ++++++++++++++++++++++++ Now compute the alignments for each of these IOVs
0106   ConditionsManager::Result cond_total;
0107   AlignmentsCalculator::Result align_total;
0108   for(int i=0; i<num_iov; ++i)  {
0109     IOV req_iov(iov_typ,i*10+5);
0110     shared_ptr<ConditionsSlice> sl(new ConditionsSlice(manager,content));
0111     // Attach the proper set of conditions to the user pool
0112     ConditionsManager::Result cres = manager.prepare(req_iov,*sl);
0113     sl->pool->flags |= cond::UserPool::PRINT_INSERT;
0114     cond_total += cres;
0115     // Now compute the tranformation matrices
0116     AlignmentsCalculator calculator;
0117     AlignmentsCalculator::Result ares = calculator.compute(deltas,*sl);
0118     printout(INFO,"Prepare","Total %ld/%ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of type %s. Alignments:(C:%ld,M:%ld)",
0119              slice->conditions().size(), cres.total(), cres.selected, cres.loaded,
0120              cres.computed, cres.missing, iov_typ->str().c_str(), ares.computed, ares.missing);
0121     align_total += ares;
0122     if ( ares.missing > 0 ) {
0123       printout(ERROR,"Compute","Failed tro compute %ld alignments of type %s.",
0124                ares.missing, iov_typ->str().c_str());
0125     }
0126     if ( i == 0 )  {
0127       // What else ? let's access/print the current selection
0128       Scanner(AlignedVolumePrinter(sl.get(),"Example"),description.world());
0129     }
0130   }
0131   printout(INFO,"Summary","Processed a total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) and (C:%ld,M:%ld) alignments. Created:%ld.",
0132            cond_total.total(), cond_total.selected, cond_total.loaded, cond_total.computed, cond_total.missing,
0133            align_total.computed, align_total.missing, total_created);
0134    
0135   // All done.
0136   return 1;
0137 }
0138 
0139 // first argument is the type from the xml file
0140 DECLARE_APPLY(DD4hep_AlignmentExample_populate,alignment_example)