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_ConditionExample_save \
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/ConditionsManager.h"
0030 #include "DDCond/ConditionsIOVPool.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 /// Plugin function: Condition program example
0039 /**
0040  *  Factory: DD4hep_ConditionExample_save
0041  *
0042  *  \author  M.Frank
0043  *  \version 1.0
0044  *  \date    01/12/2016
0045  */
0046 static int condition_example (Detector& description, int argc, char** argv)  {
0047   string input, conditions;
0048   int    num_iov = 10;
0049   bool   arg_error = false;
0050   bool   output_iovpool  = true;
0051   bool   output_userpool = true;
0052   bool   output_condpool = true;
0053 
0054   for(int i=0; i<argc && argv[i]; ++i)  {
0055     if ( 0 == ::strncmp("-input",argv[i],4) )
0056       input = argv[++i];
0057     else if ( 0 == ::strncmp("-conditions",argv[i],4) )
0058       conditions = argv[++i];
0059     else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0060       num_iov = ::atol(argv[++i]);
0061     else
0062       arg_error = true;
0063   }
0064   if ( arg_error || input.empty() || conditions.empty() )   {
0065     /// Help printout describing the basic command line interface
0066     cout <<
0067       "Usage: -plugin <name> -arg [-arg]                                             \n"
0068       "     name:   factory name     DD4hep_ConditionExample_save                    \n"
0069       "     -input       <string>    Geometry file                                   \n"
0070       "     -conditions  <string>    Conditions output file                          \n"
0071       "     -iovs        <number>    Number of parallel IOV slots for processing.    \n"
0072       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0073     ::exit(EINVAL);
0074   }
0075 
0076   // First we load the geometry
0077   description.fromXML(input);
0078 
0079   /******************** Initialize the conditions manager *****************/
0080   ConditionsManager manager = installManager(description);
0081   const IOVType*    iov_typ = manager.registerIOVType(0,"run").second;
0082   if ( 0 == iov_typ )
0083     except("ConditionsPrepare","++ Unknown IOV type supplied.");
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   Scanner(ConditionsKeys(*content,INFO),description.world());
0089   // Setup for persistency
0090   Scanner(ConditionsDependencyCreator(*content,DEBUG,true),description.world());
0091 
0092   /******************** Save the conditions store *********************/
0093   // Have 10 run-slices [11,20] .... [91,100]
0094   for(int i=0; i<num_iov; ++i)  {
0095     IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0096     ConditionsPool*   iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0097     // Create conditions with all deltas. Use a generic creator
0098     Scanner(ConditionsCreator(*slice, *iov_pool, INFO),description.world(),0,true);
0099   }
0100 
0101   char text[132];
0102   size_t count = 0, total_count = 0;
0103   auto* persist = new cond::ConditionsRootPersistency("DD4hep Conditions");
0104   // ++++++++++++++++++++++++ Now compute the conditions for each of these IOVs
0105   ConditionsManager::Result total;
0106   for(int i=0; i<num_iov; ++i)  {
0107     IOV req_iov(iov_typ,i*10+5);
0108     // Select the proper set of conditions and attach them to the user pool
0109     ConditionsManager::Result r = manager.prepare(req_iov,*slice);
0110     total += r;
0111     if ( 0 == i )  { // First one we print...
0112       Scanner(ConditionsPrinter(slice.get(),"Example"),description.world());
0113     }
0114     // Now compute the tranformation matrices
0115     printout(ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0116              r.total(), r.selected, r.loaded, r.computed, r.missing, req_iov.str().c_str());
0117     if ( output_userpool )  {
0118       /// Add the conditions UserPool to the persistent file
0119       ::snprintf(text,sizeof(text),"User pool %s:[%ld]",iov_typ->name.c_str(),long(req_iov.key().first));
0120       count = persist->add(text,*slice->pool);
0121       total_count += count;
0122       printout(ALWAYS,"Example","+++ Added %ld conditions to persistent user pool.",count);
0123     }
0124   }
0125   if ( output_condpool )  {
0126     int npool = 0;
0127     cond::ConditionsIOVPool* iov_pool = manager.iovPool(*iov_typ);
0128     for( const auto& p : iov_pool->elements )  {
0129       ::snprintf(text,sizeof(text),"Conditions pool %s:[%ld,%ld]",
0130                  iov_typ->name.c_str(),long(p.second->iov->key().first),long(p.second->iov->key().second));
0131       if ( (npool%2) == 0 )  { /// Check here saving ConditionsPool objects
0132         count = persist->add(text,*p.second);
0133         printout(ALWAYS,"Example",
0134                  "+++ ConditionsPool:         Added %ld conditions "
0135                  "to persistent conditions pool.",count);
0136       }
0137       else   {                 /// Check here saving std::vector<Condition>
0138         vector<Condition> entries;
0139         p.second->select_all(entries);
0140         count = persist->add(text,*p.second->iov,entries);
0141         printout(ALWAYS,"Example",
0142                  "+++ std::vector<Condition>: Added %ld conditions "
0143                  "to persistent conditions pool.",count);
0144       }
0145       total_count += count;
0146       ++npool;
0147     }
0148   }
0149   if ( output_iovpool )  {
0150     count = persist->add("ConditionsIOVPool No 1",*manager.iovPool(*iov_typ));
0151     total_count += count;
0152     printout(ALWAYS,"Example","+++ Added %ld conditions to persistent IOV pool.",count);
0153     //count = persist->add("ConditionsIOVPool No 2",*manager.iovPool(*iov_typ));
0154     //total_count += count;
0155     printout(ALWAYS,"Example","+++ Added %ld conditions to persistent IOV pool.",count);
0156   }
0157   int nBytes = persist->save(conditions.c_str());
0158   printout(ALWAYS,"Example",
0159            "+++ Wrote %d Bytes (%ld conditions) of data to '%s'  [%8.3f seconds].",
0160            nBytes, total_count, conditions.c_str(), persist->duration);
0161   if ( nBytes > 0 )  {
0162     printout(ALWAYS,"Example",
0163              "+++ Successfully saved %ld condition to file.",total_count);
0164   }
0165   delete persist;
0166   
0167   printout(ALWAYS,"Statistics","+=========================================================================");
0168   printout(ALWAYS,"Statistics","+  Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld)",
0169            total.total(), total.selected, total.loaded, total.computed, total.missing);
0170   printout(ALWAYS,"Statistics","+=========================================================================");
0171 
0172   // All done.
0173   return 1;
0174 }
0175 
0176 // first argument is the type from the xml file
0177 DECLARE_APPLY(DD4hep_ConditionExample_save,condition_example)