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    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_ConditionExample_load \
0020    -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml \
0021    -conditions Conditions.root
0022 
0023    Save the conditions store by hand for a set of IOVs.
0024    Then compute the corresponding alignment entries....
0025 
0026 */
0027 // Framework include files
0028 #include "ConditionExampleObjects.h"
0029 #include "DDCond/ConditionsIOVPool.h"
0030 #include "DDCond/ConditionsManager.h"
0031 #include "DDCond/ConditionsRootPersistency.h"
0032 #include "DD4hep/Factories.h"
0033 
0034 using namespace std;
0035 using namespace dd4hep;
0036 using namespace dd4hep::ConditionExamples;
0037 
0038 static void help(int argc, char** argv)  {
0039   /// Help printout describing the basic command line interface
0040   cout <<
0041     "Usage: -plugin <name> -arg [-arg]                                             \n"
0042     "     name:   factory name     DD4hep_ConditionExample_load                    \n"
0043     "     -input       <string>    Geometry file                                   \n"
0044     "     -conditions  <string>    Conditions input file                           \n"
0045     "     -iovs        <number>    Number of parallel IOV slots for processing.    \n"
0046     "     -restore     <string>    Restore strategy: iovpool, userpool or condpool.\n"
0047     "\tArguments given: " << arguments(argc,argv) << endl << flush;
0048   ::exit(EINVAL);
0049 }
0050 
0051 /// Plugin function: Condition program example
0052 /**
0053  *  Factory: DD4hep_ConditionExample_load
0054  *
0055  *  \author  M.Frank
0056  *  \version 1.0
0057  *  \date    01/12/2016
0058  */
0059 static int condition_example (Detector& description, int argc, char** argv)  {
0060   string input, conditions, restore="iovpool";
0061   int    num_iov = 10, extend = 0;
0062   bool   arg_error = false;
0063   for(int i=0; i<argc && argv[i]; ++i)  {
0064     if ( 0 == ::strncmp("-input",argv[i],4) )
0065       input = argv[++i];
0066     else if ( 0 == ::strncmp("-conditions",argv[i],4) )
0067       conditions = argv[++i];
0068     else if ( 0 == ::strncmp("-restore",argv[i],4) )
0069       restore = argv[++i];
0070     else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0071       num_iov = ::atol(argv[++i]);
0072     else if ( 0 == ::strncmp("-extend",argv[i],4) )
0073       extend = ::atol(argv[++i]);
0074     else
0075       arg_error = true;
0076   }
0077   if ( arg_error || input.empty() || conditions.empty() ) help(argc,argv);
0078 
0079   // First we load the geometry
0080   description.fromXML(input);
0081 
0082   detail::have_condition_item_inventory(1);
0083   
0084   /******************** Initialize the conditions manager *****************/
0085   ConditionsManager manager = installManager(description);
0086   shared_ptr<ConditionsContent> content(new ConditionsContent());
0087   shared_ptr<ConditionsSlice>   slice(new ConditionsSlice(manager,content));
0088   Scanner(ConditionsKeys(*content,INFO),description.world());
0089   Scanner(ConditionsDependencyCreator(*content,DEBUG,false,extend),description.world());
0090 
0091   /******************** Load the conditions from file *********************/
0092   printout(INFO,"ConditionsExample","+  Start conditions import from ROOT object(s): %s",
0093            conditions.c_str());
0094   try  {
0095     auto pers = cond::ConditionsRootPersistency::load(conditions.c_str(),"DD4hep Conditions");
0096     printout(ALWAYS,"Statistics","+=========================================================================");
0097     printout(ALWAYS,"Statistics","+  Loaded conditions object from file %s. Took %8.3f seconds.",
0098              conditions.c_str(),pers->duration);
0099     size_t num_cond = 0;
0100     if      ( restore == "iovpool" )
0101       num_cond = pers->importIOVPool("ConditionsIOVPool No 1","run",manager);
0102     else if ( restore == "userpool" )
0103       num_cond = pers->importUserPool("*","run",manager);
0104     else if ( restore == "condpool" )
0105       num_cond = pers->importConditionsPool("*","run",manager);
0106     else
0107       help(argc,argv);
0108 
0109     printout(ALWAYS,"Statistics","+  Imported %ld conditions from %s to IOV pool. Took %8.3f seconds.",
0110              num_cond, restore.c_str(), pers->duration);
0111     printout(ALWAYS,"Statistics","+=========================================================================");
0112   }
0113   catch(const exception& e)    {
0114     printout(ERROR,"ConditionsExample","Failed to import ROOT object(s): %s",e.what());    
0115     throw;
0116   }
0117   
0118   // ++++++++++++++++++++++++ Now compute the conditions for each of these IOVs
0119   const IOVType* iov_typ = manager.iovType("run");
0120   cond::ConditionsIOVPool* pool = manager.iovPool(*iov_typ);
0121   for( const auto& p : pool->elements )
0122     p.second->print("*");
0123 
0124   ConditionsManager::Result total;
0125   for(int i=0; i<num_iov; ++i)  {
0126     IOV req_iov(iov_typ,i*10+5);
0127     // Select the proper set of conditions and attach them to the user pool
0128     ConditionsManager::Result r = manager.prepare(req_iov,*slice);
0129     total += r;
0130     if ( 0 == i )  { // First one we print...
0131       Scanner(ConditionsPrinter(slice.get(),"Example"),description.world());
0132     }
0133     printout(ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0134              r.total(), r.selected, r.loaded, r.computed, r.missing, req_iov.str().c_str());
0135   }  
0136   printout(ALWAYS,"Statistics","+=========================================================================");
0137   printout(ALWAYS,"Statistics","+  Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld)",
0138            total.total(), total.selected, total.loaded, total.computed, total.missing);
0139   printout(ALWAYS,"Statistics","+=========================================================================");
0140   // All done.
0141   return 1;
0142 }
0143 
0144 // first argument is the type from the xml file
0145 DECLARE_APPLY(DD4hep_ConditionExample_load,condition_example)