Back to home page

EIC code displayed by LXR

 
 

    


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

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_stress \
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 "ConditionExampleObjects.h"
0028 #include "DD4hep/Factories.h"
0029 #include "TStatistic.h"
0030 #include "TTimeStamp.h"
0031 #include "TRandom3.h"
0032 
0033 using namespace std;
0034 using namespace dd4hep;
0035 using namespace dd4hep::ConditionExamples;
0036 
0037 /// Plugin function: Condition program example
0038 /**
0039  *  Factory: DD4hep_ConditionExample_stress
0040  *
0041  *  \author  M.Frank
0042  *  \version 1.0
0043  *  \date    01/12/2016
0044  */
0045 static int condition_example (Detector& description, int argc, char** argv)  {
0046   string input;
0047   int    num_iov = 10, num_runs = 10;
0048   bool   arg_error = false;
0049   for(int i=0; i<argc && argv[i]; ++i)  {
0050     if ( 0 == ::strncmp("-input",argv[i],4) )
0051       input = argv[++i];
0052     else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0053       num_iov = ::atol(argv[++i]);
0054     else if ( 0 == ::strncmp("-runs",argv[i],4) )
0055       num_runs = ::atol(argv[++i]);
0056     else
0057       arg_error = true;
0058   }
0059   if ( arg_error || input.empty() )   {
0060     /// Help printout describing the basic command line interface
0061     cout <<
0062       "Usage: -plugin <name> -arg [-arg]                                             \n"
0063       "     name:   factory name     DD4hep_AlignmentExample1                        \n"
0064       "     -input   <string>        Geometry file                                   \n"
0065       "     -iovs    <number>        Number of parallel IOV slots for processing.    \n"
0066       "     -runs    <number>        Number of collision loads to be performed.      \n"
0067       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0068     ::exit(EINVAL);
0069   }
0070 
0071   // First we load the geometry
0072   description.fromXML(input);
0073 
0074   /******************** Initialize the conditions manager *****************/
0075   ConditionsManager manager = installManager(description);
0076   const IOVType*    iov_typ = manager.registerIOVType(0,"run").second;
0077   if ( 0 == iov_typ )  {
0078     except("ConditionsPrepare","++ Unknown IOV type supplied.");
0079   }
0080 
0081   /******************** Now as usual: create the slice ********************/
0082   shared_ptr<ConditionsContent> content(new ConditionsContent());
0083   shared_ptr<ConditionsSlice>   slice(new ConditionsSlice(manager,content));
0084   Scanner(ConditionsKeys(*content,INFO),description.world());
0085   Scanner(ConditionsDependencyCreator(*content,DEBUG),description.world());
0086 
0087   TStatistic cr_stat("Creation"), acc_stat("Access");
0088   /******************** Populate the conditions store *********************/
0089   // Have 10 run-slices [11,20] .... [91,100]
0090   size_t total_created = 0;
0091   for(int i=0; i<num_iov; ++i)  {
0092     TTimeStamp start;
0093     IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0094     ConditionsPool*   iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0095     // Create conditions with all deltas.  Use a generic creator
0096     int count = Scanner().scan(ConditionsCreator(*slice, *iov_pool, DEBUG), description.world());
0097     TTimeStamp stop;
0098     cr_stat.Fill(stop.AsDouble()-start.AsDouble());
0099     printout(INFO,"Example", "Setup %ld conditions for IOV:%s [%8.3f sec]",
0100              count, iov.str().c_str(), stop.AsDouble()-start.AsDouble());
0101     total_created += count;
0102   }
0103 
0104   // ++++++++++++++++++++++++ Now compute the conditions for each of these IOVs
0105   TRandom3 random;
0106   ConditionsManager::Result total;
0107   for(int i=0; i<num_runs; ++i)  {
0108     TTimeStamp start;
0109     unsigned int rndm = 1+random.Integer(num_iov*10);
0110     IOV req_iov(iov_typ,rndm);
0111     // Attach the proper set of conditions to the user pool
0112     ConditionsManager::Result res = manager.prepare(req_iov,*slice);
0113     TTimeStamp stop;
0114     total += res;
0115     acc_stat.Fill(stop.AsDouble()-start.AsDouble());
0116     // Now compute the tranformation matrices
0117     printout(INFO,"Prepare","Total %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld) of type %s [%8.3f sec]",
0118              res.total(), res.selected, res.loaded, res.computed, res.missing,
0119              req_iov.str().c_str(), stop.AsDouble()-start.AsDouble());
0120   }
0121   printout(INFO,"Statistics","+======= Summary: # of IOV: %3d  # of Runs: %3d ===========================", num_iov, num_runs);
0122   printout(INFO,"Statistics","+  %-12s:  %11.5g +- %11.4g  RMS = %11.5g  N = %lld",
0123            cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN());
0124   printout(INFO,"Statistics","+  %-12s:  %11.5g +- %11.4g  RMS = %11.5g  N = %lld",
0125            acc_stat.GetName(), acc_stat.GetMean(), acc_stat.GetMeanErr(), acc_stat.GetRMS(), acc_stat.GetN());
0126   printout(INFO,"Statistics","+  Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld). Created:%ld",
0127            total.total(), total.selected, total.loaded, total.computed, total.missing, total_created);
0128   printout(INFO,"Statistics","+=========================================================================");
0129   // All done.
0130   return 1;
0131 }
0132 
0133 // first argument is the type from the xml file
0134 DECLARE_APPLY(DD4hep_ConditionExample_stress,condition_example)