Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:54

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 // DDDB is a detector description convention developed by the LHCb experiment.
0015 // For further information concerning the DTD, please see:
0016 // http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf
0017 //
0018 //==========================================================================
0019 
0020 // Framework includes
0021 #include "DD4hep/Plugins.h"
0022 #include "DD4hep/Printout.h"
0023 #include "DD4hep/Factories.h"
0024 #include "DD4hep/DetectorTools.h"
0025 #include "DD4hep/ConditionsPrinter.h"
0026 #include "DD4hep/DetectorProcessor.h"
0027 
0028 #include "DDCond/ConditionsSlice.h"
0029 #include "DDCond/ConditionsIOVPool.h"
0030 #include "DDCond/ConditionsCleanup.h"
0031 #include "DDCond/ConditionsManager.h"
0032 
0033 #include "DDDB/DDDBHelper.h"
0034 #include "DDDB/DDDBReader.h"
0035 #include "DDDB/DDDBConversion.h"
0036 
0037 #include "Detector/DeVelo.h"
0038 #include "Detector/DeAlignmentCall.h"
0039 #include "Detector/DeVeloConditionCalls.h"
0040 
0041 using namespace std;
0042 using namespace gaudi;
0043 
0044 
0045 /// Anonymous namespace for plugins
0046 namespace {
0047   dd4hep::PrintLevel s_PrintLevel = INFO;
0048 }
0049 
0050 //==========================================================================
0051 /// Anonymous namespace for plugins
0052 namespace {
0053 
0054   /// Basic entry point to print out the detector element hierarchy
0055   /**
0056    *  \author  M.Frank
0057    *  \version 1.0
0058    *  \date    01/04/2014
0059    */
0060   long dump_det(dd4hep::Detector& description, int argc, char** argv) {
0061 
0062     /// Callback object to print selective information
0063     /**
0064      *  \author  M.Frank
0065      *  \version 1.0
0066      *  \date    01/04/2014
0067      */
0068     struct DumpActor {
0069       dd4hep::Detector&                             m_detDesc;
0070       dd4hep::DetElement                            m_de;
0071       unique_ptr<VeloUpdateContext>                 m_context;
0072       dd4hep::cond::ConditionsManager               m_manager;
0073       shared_ptr<dd4hep::cond::ConditionsContent>   m_content;
0074       const dd4hep::IOVType*                        m_iovtype = 0;
0075       dd4hep::DDDB::DDDBReader*                     m_reader = 0;
0076 
0077       /// Configure file based reader
0078       void configReader(long iov_start, long iov_end)   {
0079         try   {
0080           dd4hep::IOV iov_range(m_iovtype);
0081           iov_range.keyData.first  = iov_start;
0082           iov_range.keyData.second = iov_end;
0083           m_reader->property("ValidityLower").set(iov_range.keyData.first);
0084           m_reader->property("ValidityUpper").set(iov_range.keyData.second);
0085           printout(INFO,"ConditionsManager","+++ Configure file based reader for IOV:%s", 
0086                    iov_range.str().c_str());
0087         }
0088         catch(...)  {
0089         }
0090       }
0091 
0092 
0093       /// Standard constructor
0094       DumpActor(dd4hep::Detector& dsc, const string& path) : m_detDesc(dsc)     {
0095         dd4hep::DDDB::DDDBHelper* helper = dsc.extension<dd4hep::DDDB::DDDBHelper>(false);
0096         shared_ptr<dd4hep::cond::ConditionsSlice>   slice;
0097         shared_ptr<dd4hep::cond::ConditionsContent> cont;
0098         vector<pair<dd4hep::DetElement, int> >      elts;
0099 
0100         m_de      = dd4hep::detail::tools::findElement(m_detDesc, path);
0101         m_manager = dd4hep::cond::ConditionsManager::from(m_detDesc);
0102         m_iovtype = m_manager.iovType("epoch");
0103         m_reader  = helper->reader<dd4hep::DDDB::DDDBReader>();
0104         configReader(dd4hep::detail::makeTime(2008,1,1), dd4hep::detail::makeTime(2018,12,31));
0105 
0106         dd4hep::IOV iov(m_iovtype, 0);
0107         cont.reset(new dd4hep::cond::ConditionsContent());
0108         slice.reset(new dd4hep::cond::ConditionsSlice(m_manager,cont));
0109         dd4hep::cond::fill_content(m_manager, *cont, *m_iovtype);
0110         dd4hep::cond::ConditionsManager::Result res = m_manager.prepare(iov, *slice);
0111         printout(dd4hep::ALWAYS,"ConditionsManager","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0112                  res.total(), res.selected, res.loaded, res.computed, res.missing, iov.str().c_str());
0113 
0114         m_context.reset(new VeloUpdateContext());
0115         m_content.reset(new dd4hep::cond::ConditionsContent());
0116         dd4hep::DetectorScanner(dd4hep::detElementsCollector(elts), m_de);    
0117         dd4hep::cond::DependencyBuilder align_builder(m_detDesc.world(),
0118                                                       Keys::alignmentsComputedKey,
0119                                                       make_shared<DeAlignmentCall>(m_de));
0120         auto* dep = align_builder.release();
0121         dep->target.hash = Keys::alignmentsComputedKey;
0122         m_content->addDependency(dep);
0123 
0124         auto static_update = make_shared<DeVeloStaticConditionCall>();
0125         for(const auto& e : elts)   {
0126           dd4hep::DetElement de = e.first;
0127           dd4hep::DDDB::DDDBCatalog* cat = de.extension<dd4hep::DDDB::DDDBCatalog>();
0128           dd4hep::Condition::detkey_type det_key = de.key();
0129           dd4hep::ConditionKey::KeyMaker lower(det_key, dd4hep::Condition::FIRST_ITEM_KEY);
0130           dd4hep::ConditionKey::KeyMaker upper(det_key, dd4hep::Condition::LAST_ITEM_KEY);
0131           printout(DEBUG, "DeVeloTest","Processing %ld class %d  -> %s",
0132                    e.second, cat->classID, de.path().c_str());
0133           m_context->detectors.insert(make_pair(det_key,make_pair(de,cat)));
0134           {
0135             auto first = cont->conditions().lower_bound(lower.hash);
0136             for(; first != cont->conditions().end() && (*first).first <= upper.hash; ++first)
0137               m_content->addLocationInfo((*first).first, (*first).second->addRef());
0138           }
0139           {
0140             auto first = cont->derived().lower_bound(lower.hash);
0141             for(; first != cont->derived().end() && (*first).first <= upper.hash; ++first)
0142               m_content->addDependency((*first).second);
0143           }
0144 
0145           dd4hep::cond::DependencyBuilder static_builder(de, Keys::staticKey, static_update);
0146           m_content->addDependency(static_builder.release());
0147 
0148           shared_ptr<dd4hep::cond::ConditionUpdateCall> call = (e.first == m_de)
0149             ? make_shared<DeVeloConditionCall>(de, cat, m_context.get())
0150             : make_shared<DeVeloIOVConditionCall>(de, cat, m_context.get());
0151           dd4hep::cond::DependencyBuilder iov_builder(de, Keys::deKey, call);
0152           m_content->addDependency(iov_builder.release());
0153         }
0154         m_manager.clear();
0155       }
0156 
0157       /// Standard destructor
0158       ~DumpActor()  {
0159       }
0160 
0161       /// __________________________________________________________________________________
0162       long dump()  {
0163         shared_ptr<dd4hep::cond::ConditionsSlice> slice;
0164         dd4hep::cond::ConditionsIOVPool* iovp = m_manager.iovPool(*m_iovtype);
0165         dd4hep::cond::ConditionsManager::Result total;
0166         printout(INFO,"ConditionsManager","+++ Dump pools at dump:");
0167         for(const auto& e : iovp->elements)
0168           e.second->print();
0169         printout(INFO,"ConditionsManager","+++ Starting conditions dump loop");
0170         long daq_start = dd4hep::detail::makeTime(2016,5,20,0,0,0);
0171         for(size_t i=0; i<10; ++i)   {
0172           long stamp = daq_start + i*3600 + 1800; // Middle of 1 hour run
0173           dd4hep::IOV iov(m_iovtype, stamp);
0174           configReader(stamp-1800, stamp+1799);    // Run duration 1 hour - 1 second
0175           slice.reset(new dd4hep::cond::ConditionsSlice(m_manager, m_content));
0176           m_context->alignments_done = dd4hep::Condition();
0177           dd4hep::cond::ConditionsManager::Result res = m_manager.prepare(iov, *slice, m_context.get());
0178           printout(dd4hep::ALWAYS,"ConditionsManager","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0179                    res.total(), res.selected, res.loaded, res.computed, res.missing, iov.str().c_str());
0180           total += res;
0181           for(const auto& e : iovp->elements)
0182             e.second->print();
0183           DeVelo devp = slice->get(m_de,Keys::deKey);
0184           devp.print(0,DePrint::ALL);
0185 
0186           DetectorElement<DeVelo> detVP = devp;
0187           cout << "TEST: Got detector element:"
0188                << " " << detVP.conditions().size()
0189                << " " << detVP.detector().path()
0190                << " " << detVP.detectorAlignment().name()
0191                << " " << detVP.conditions().size()
0192                << endl;
0193           try  {
0194             DeVeloGeneric deGEN = devp;
0195             cout << " " << deGEN.conditions().size()
0196                  << " " << deGEN.children().size()
0197                  << endl;
0198           }
0199           catch(const exception& e)  {
0200             cout << "Exception(This is GOOD!): " << e.what() << endl;
0201           }
0202         }
0203         m_manager.clean(dd4hep::cond::ConditionsFullCleanup());
0204         printout(dd4hep::ALWAYS,"TestSummary","Total %ld conditions load summary (S:%ld,L:%ld,C:%ld,M:%ld)",
0205                  total.total(), total.selected, total.loaded, total.computed, total.missing);
0206         printout(dd4hep::ALWAYS,"DeVeloTest","Test finished....");
0207         return 1;
0208       }
0209     };
0210 
0211     dd4hep::setPrintFormat("%-18s %5s %s");
0212     for(int i=0; i<argc; ++i)  {
0213       if ( ::strcmp(argv[i],"-print")==0 )  {
0214         s_PrintLevel = dd4hep::printLevel(argv[++i]);
0215         printout(INFO,"DDDB","Setting print level for %s to %s [%d]",__FILE__,argv[i-1],s_PrintLevel);
0216       }
0217       else if ( ::strcmp(argv[i],"--help")==0 )      {
0218         printout(INFO,"Plugin-Help","Usage: DDDB_DeVeloTest --opt [--opt]            ");
0219         printout(INFO,"Plugin-Help","  -print <value>      Printlevel for output      ");
0220         printout(INFO,"Plugin-Help","  -help               Print this help message    ");
0221         return 0;
0222       }
0223     }
0224     DumpActor actor(description, "/world/LHCb/BeforeMagnetRegion/Velo");
0225     return actor.dump();
0226   }
0227 } /* End anonymous namespace  */
0228 
0229 using namespace dd4hep;
0230 DECLARE_APPLY(DDDB_DeVeloTest,dump_det)
0231 //==========================================================================