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 #if 0
0014 // Framework include files
0015 #include "ConditionsTest.h"
0016 
0017 using namespace std;
0018 using namespace dd4hep;
0019 using namespace dd4hep::cond;
0020 
0021 namespace  {
0022 
0023   typedef ConditionKey _Key;
0024 
0025   void print_tpc_epoch_conditions(Test::TestEnv& env, const IOV& iov_epoch, bool check = true)   {
0026     DetConditions dc(env.detector);
0027     ConditionsAccess access(env.manager);
0028     Condition cond = access.get(_Key(env.detector,"AmbientTemperature"),iov_epoch);
0029     Test::print_condition<void>(cond);
0030     cond = dc.get("AmbientTemperature",iov_epoch);
0031     if ( check ) Test::check_discrete_condition(cond, iov_epoch);
0032     Test::print_condition<void>(cond);
0033     cond = dc.get("ExternalPressure",iov_epoch);
0034     if ( check ) Test::check_discrete_condition(cond, iov_epoch);
0035     Test::print_condition<void>(cond);
0036     cond = dc.get("SomeMultiParams",iov_epoch);
0037     if ( check ) Test::check_discrete_condition(cond, iov_epoch);
0038     Test::print_condition<void>(cond);
0039     cond->value = "[5,6,7,8,9,10,11,12,13,14]";
0040     cond.rebind();
0041     Test::print_condition<void>(cond);
0042   }
0043   void print_tpc_run_conditions(Test::TestEnv& env, const IOV& iov_run, bool check = true)   {
0044     DetConditions dc(env.detector);
0045     Condition cond = dc.get("alignment",iov_run);
0046     if ( check ) Test::check_discrete_condition(cond, iov_run);
0047     Test::print_condition<void>(cond);
0048     cond = dc.get("TPC_A_align",iov_run);
0049     if ( check ) Test::check_discrete_condition(cond, iov_run);
0050     Test::print_condition<void>(cond);
0051     cond = DetConditions(env.daughter("TPC_SideA")).get("alignment",iov_run);
0052     if ( check ) Test::check_discrete_condition(cond, iov_run);
0053     Test::print_condition<void>(cond);
0054   }
0055   void print_tpc_discrete_conditions(Test::TestEnv& env, const IOV& iov_epoch, const IOV& iov_run)   {
0056     print_tpc_epoch_conditions(env, iov_epoch);
0057     printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0058     printout(INFO,"Example","SUCCESS: +++ Conditions access OK for iov:%s!",iov_epoch.str().c_str());
0059     printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0060     print_tpc_run_conditions(env, iov_run);
0061     printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0062     printout(INFO,"Example","SUCCESS: +++ DISCRETE Conditions access OK for iov:%s!",iov_run.str().c_str());
0063     printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0064   }
0065 
0066   void print_tpc_discrete_conditions(Test::TestEnv& env, int epoch_min, int epoch_max, int run_min, int run_max)   {
0067     dd4hep_ptr<UserPool> pool_run, pool_epoch;
0068     IOV iov_epoch(env.epoch), iov_run(env.run);
0069     iov_epoch.set(epoch_min, epoch_max);
0070     iov_run.set(run_min, run_max);
0071 
0072     env.manager.prepare(iov_run, pool_run);
0073     env.manager.prepare(iov_epoch, pool_epoch);
0074     print_tpc_discrete_conditions(env, iov_epoch, iov_run);
0075   }
0076 
0077   void print_tpc_discrete_conditions(Test::TestEnv& env)   {
0078     print_tpc_discrete_conditions(env, 1396887257, 1396887257, 563543, 563543);
0079     print_tpc_discrete_conditions(env, 1396887257, 1396887257, 234567, 234567);
0080     print_tpc_discrete_conditions(env, 1396887257, 1396887257, 563543, 563543);
0081   }
0082 
0083   void print_tpc_range_conditions(Test::TestEnv& env, int run_min, int run_max)   {
0084     RangeConditions cond;
0085     IOV iov_run(env.run);
0086     iov_run.set(run_min, run_max);
0087     try {
0088       ConditionsAccess access(env.manager);
0089       cond = access.getRange(_Key(env.detector,"TPC_A_align"),iov_run);
0090       Test::print_conditions<void>(cond);
0091       printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0092       printout(INFO,"Example","SUCCESS: +++ RANGE Conditions access OK for iov:%s!",iov_run.str().c_str());
0093       printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0094     }
0095     catch(const std::exception& e)   {
0096       printout(INFO,"Example","FAILED:  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0097       printout(INFO,"Example","FAILED:  +++ RANGE Conditions access FAILED for iov:%s!",iov_run.str().c_str());
0098       printout(INFO,"Example","FAILED:  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0099     }
0100   }
0101 
0102   int example1(Detector& description, int, char** )  {
0103     printout(INFO,"Example1","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0104     printout(INFO,"Example1","+++ Executing Conditions example No. 1: Test conditions access.    ");
0105     printout(INFO,"Example1","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0106     Test::TestEnv env(description, "TPC");
0107 
0108     env.add_xml_data_source("/examples/Conditions/xml/TPC.xml","1396887257,1396887257#epoch");
0109     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_563543.xml","563543#run");
0110     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_234567.xml","234567#run");
0111     print_tpc_discrete_conditions(env);
0112     description.apply("DD4hep_ConditionsDump",0,0);
0113 
0114     print_tpc_range_conditions(env,234567,563543);  // Should fail !
0115     print_tpc_range_conditions(env,123456,563543);  // Should fail !
0116 
0117     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_filler.xml","0,999999#run");
0118     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_123456.xml","123456#run");
0119     print_tpc_range_conditions(env,123456,900000);  // Now it should succeed
0120     return 1;
0121   }
0122 
0123   int example2(Detector& description, int argc, char** argv)  {
0124     printout(INFO,"Example2","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0125     printout(INFO,"Example2","+++ Executing Conditions example No. 2: Dump conditions tree.      ");
0126     printout(INFO,"Example2","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0127     DetElement det = description.world();
0128     string args = "";
0129     for(int i=0; i<argc; ++i) { args += argv[i], args += " "; };
0130     printout(INFO,"Example2","Args: %s",args.c_str());
0131     Test::TestEnv::dump_conditions_tree(det);
0132     return 1;
0133   }
0134 
0135   int example3(Detector& description, int, char** )  {
0136     printout(INFO,"Example1","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0137     printout(INFO,"Example1","+++ Executing Conditions example No. 3: Conditions registration    ");
0138     printout(INFO,"Example1","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0139     Test::TestEnv env(description, "TPC");
0140     
0141     env.add_xml_data_source("/examples/Conditions/xml/TPC.xml","1396887257,1396887257#epoch");
0142     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_563543.xml","563543#run");
0143     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_234567.xml","234567#run");
0144     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_filler.xml","0,999999#run");
0145     env.add_xml_data_source("/examples/Conditions/xml/TPC_run_123456.xml","123456#run");
0146 
0147     
0148     IOV iov_epoch(env.epoch), iov_run(env.run);
0149     dd4hep_ptr<UserPool> pool_run, pool_epoch;
0150     iov_epoch.set(1396887257);
0151     iov_run.set(563543);
0152 
0153     env.manager.prepare(iov_run, pool_run);
0154     env.manager.prepare(iov_epoch, pool_epoch);
0155     print_tpc_epoch_conditions(env, iov_epoch);
0156     print_tpc_run_conditions(env, iov_run, true);
0157     printout(INFO,"Example1","===================================================================");
0158 
0159     printout(INFO,"Example1","===================================================================");
0160     iov_run.set(123456);
0161     env.manager.prepare(iov_run, pool_run);
0162     iov_run.set(563543);
0163     print_tpc_run_conditions(env, iov_run, false);
0164     printout(INFO,"Example1","===================================================================");
0165 
0166     printout(INFO,"Example1","===================================================================");
0167     iov_run.set(123456);
0168     print_tpc_run_conditions(env, iov_run, true);
0169     return 1;
0170   }
0171 
0172   struct Callee  {
0173     int m_param;
0174     Callee() : m_param(0) {}
0175     void call(unsigned long tags, DetElement& det, void* param)    {
0176       if ( (tags&DetElement::CONDITIONS_CHANGED) )
0177         printout(INFO,"Callee","+++ Conditions update %s param:%p",det.path().c_str(),param);
0178       if ( (tags&DetElement::PLACEMENT_CHANGED) )  
0179         printout(INFO,"Callee","+++ Alignment update %s param:%p",det.path().c_str(),param);
0180     }
0181   };
0182 
0183   /// Callback conditions tree of a detector element
0184   void callback_install(DetElement elt, Callee* c) {
0185     Position local, global;
0186     const DetElement::Children& children = elt.children();
0187     elt.localToWorld(local, global);
0188     elt.callAtUpdate(DetElement::CONDITIONS_CHANGED|DetElement::PLACEMENT_CHANGED,c,&Callee::call);
0189     for(DetElement::Children::const_iterator j=children.begin(); j!=children.end(); ++j)
0190       callback_install((*j).second,c);
0191   }
0192 
0193   int dd4hep_CallbackInstallTest(Detector& description, int argc, char** argv)  {
0194     printout(INFO,"Example3","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0195     printout(INFO,"Example3","+++ Executing dd4hepCallbackInstallTest: Install user callbacks.   ");
0196     printout(INFO,"Example3","+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
0197     string args = "";
0198     for(int i=0; i<argc; ++i) { args += argv[i], args += " "; };
0199     printout(INFO,"Example3","Args: %s",args.c_str());
0200     DetElement det = description.world();
0201     callback_install(det, new Callee());
0202     return 1;
0203   }
0204 }
0205 
0206 
0207 DECLARE_APPLY(DD4hep_Test_ConditionsAccess,example1)
0208 DECLARE_APPLY(DD4hep_Test_ConditionsExample3,example3)
0209 DECLARE_APPLY(DD4hep_Test_ConditionsTreeDump,example2)
0210 DECLARE_APPLY(DD4hep_Test_CallbackInstall,dd4hep_CallbackInstallTest)
0211 #endif