Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0015    Plugin invocation:
0016    ==================
0017    This plugin behaves like a main program.
0018    Invoke the plugin with something like this:
0019 
0020    geoPluginRun -volmgr -destroy -plugin DD4hep_ConditionExample_manual_load \
0021    -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml \
0022    -conditions Conditions.root -runs 10
0023 
0024    Save the conditions store by hand for a set of IOVs.
0025    Then compute the corresponding alignment entries....
0026 
0027 */
0028 // Framework include files
0029 #include "ConditionExampleObjects.h"
0030 #include "DDCond/ConditionsIOVPool.h"
0031 #include "DDCond/ConditionsManager.h"
0032 #include "DDCond/ConditionsDataLoader.h"
0033 #include "DDCond/ConditionsRootPersistency.h"
0034 #include "DD4hep/Factories.h"
0035 
0036 using namespace std;
0037 using namespace dd4hep;
0038 using namespace dd4hep::ConditionExamples;
0039 
0040 static void help(int argc, char** argv)  {
0041   /// Help printout describing the basic command line interface
0042   cout <<
0043     "Usage: -plugin <name> -arg [-arg]                                             \n"
0044     "     name:   factory name     DD4hep_ConditionExample_manual_load             \n"
0045     "     -input       <string>    Geometry file                                   \n"
0046     "     -conditions  <string>    Conditions input file                           \n"
0047     "     -runs        <number>    Number of parallel IOV slots for processing.    \n"
0048     "\tArguments given: " << arguments(argc,argv) << endl << flush;
0049   ::exit(EINVAL);
0050 }
0051 
0052 /// Plugin function: Condition program example
0053 /**
0054  *  Factory: DD4hep_ConditionExample_manual_load
0055  *
0056  *  \author  M.Frank
0057  *  \version 1.0
0058  *  \date    01/12/2016
0059  */
0060 static int condition_example (Detector& description, int argc, char** argv)  {
0061   string input, conditions;
0062   int    num_runs = 10;
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 if ( 0 == ::strncmp("-conditions",argv[i],4) )
0068       conditions = argv[++i];
0069     else if ( 0 == ::strncmp("-runs",argv[i],4) )
0070       num_runs = ::atol(argv[++i]);
0071     else
0072       arg_error = true;
0073   }
0074   if ( arg_error || input.empty() || conditions.empty() ) help(argc,argv);
0075 
0076   // First we load the geometry
0077   description.fromXML(input);
0078 
0079   // Now we instantiate and initialize the conditions manager
0080   description.apply("DD4hep_ConditionsManagerInstaller",0,(char**)0);
0081 
0082   ConditionsManager manager = ConditionsManager::from(description);
0083   manager["PoolType"]       = "DD4hep_ConditionsLinearPool";
0084   manager["UserPoolType"]   = "DD4hep_ConditionsMapUserPool";
0085   manager["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool";
0086   manager["LoaderType"]     = "DD4hep_Conditions_root_Loader";
0087   manager.initialize();
0088 
0089   printout(ALWAYS,"Example","Load conditions data from file:%s",conditions.c_str());
0090   manager.loader().addSource(conditions);
0091 
0092   /// Create the container with the desired conditions content and an empty conditions slice
0093   shared_ptr<ConditionsContent> content(new ConditionsContent());
0094   shared_ptr<ConditionsSlice>   slice(new ConditionsSlice(manager,content));
0095   
0096   // Populate the content of required conditions:
0097   // We scan the DetElement hierarchy and add a couple of conditions
0098   // for each DetElement
0099   Scanner(ConditionsKeys(*content,INFO),description.world());
0100 
0101   // Add for each DetElement 3 derived conditions,
0102   // which all depend on the persistent condition "derived_data"
0103   // (In the real world this would be very specific derived actions)
0104   Scanner(ConditionsDependencyCreator(*content,DEBUG),description.world());
0105 
0106   // Now emulate a pseudo event loop: Our conditions are of type "run"
0107   const IOVType* iov_typ = manager.iovType("run");
0108   ConditionsManager::Result total;
0109   for ( int irun=0; irun < num_runs; ++irun )  {
0110     IOV req_iov(iov_typ,irun*10+5);
0111     // Select the proper set of conditions from the store (or load them if needed)
0112     // Attach the selected conditions to the user pool
0113     ConditionsManager::Result r = manager.prepare(req_iov,*slice);
0114     total += r;
0115     if ( 0 == irun )  { // First one we print...
0116       // We can access the conditions directly from the slice, since the slice
0117       // implements the ConditionsMap interface.
0118       Scanner(ConditionsPrinter(slice.get(),"Example"),description.world());
0119     }
0120     // Print summary
0121     printout(ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0122              r.total(), r.selected, r.loaded, r.computed, r.missing, req_iov.str().c_str());
0123   }  
0124   printout(ALWAYS,"Statistics","+=========================================================================");
0125   printout(ALWAYS,"Statistics","+  Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld)",
0126            total.total(), total.selected, total.loaded, total.computed, total.missing);
0127   printout(ALWAYS,"Statistics","+=========================================================================");
0128   // All done.
0129   return 1;
0130 }
0131 
0132 // first argument is the type from the xml file
0133 DECLARE_APPLY(DD4hep_ConditionExample_manual_load,condition_example)