Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:20:18

0001 //==============================================================================
0002 //  AIDA Detector description implementation for LHCb
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   Markus Frank
0011 //  \date     2018-03-08
0012 //  \version  1.0
0013 //
0014 //==============================================================================
0015 
0016 // Framework include files
0017 #include "Detector/DetectorElement.h"
0018 #include "DD4hep/Printout.h"
0019 #include "DD4hep/Alignments.h"
0020 #include "DD4hep/ConditionsMap.h"
0021 #include "DD4hep/ConditionsDebug.h"
0022 #include "DD4hep/AlignmentsPrinter.h"
0023 #include "DD4hep/detail/AlignmentsInterna.h"
0024 
0025 #include "Detector/DetectorElement_inl.h"
0026 namespace gaudi {
0027   template std::map<dd4hep::DetElement, gaudi::detail::DeIOVObject*>
0028   DeHelpers::getChildConditions<gaudi::detail::DeIOVObject>(ConditionsMap& m, DetElement de, itemkey_type key, int flags);
0029 }
0030 
0031 #include <sstream>
0032 
0033 using namespace gaudi;
0034 using namespace gaudi::detail;
0035 
0036 /// Helper to initialize the basic information
0037 DeIOVObject* DeIOVObject::fill_info(DetElement de, Catalog* /* cat */)   {
0038 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
0039   name      = Keys::deKeyName;
0040 #endif
0041   item_key  = Keys::deKey;
0042   detector  = de;
0043   hash      = dd4hep::ConditionKey::KeyMaker(de, Keys::deKey).hash;
0044   return this;
0045 }
0046 
0047 /// Initialization of sub-classes
0048 void DeIOVObject::initialize()    {
0049   if ( (de_flags&DeInit::INITIALIZED) == 0 )   {
0050     auto i = conditions.find(dd4hep::align::Keys::alignmentKey);
0051     de_flags |= DeInit::INITIALIZED;
0052     detectorAlignment = (i==conditions.end()) ? Condition() : (*i).second;
0053     if ( detectorAlignment.isValid() )   {
0054       toLocalMatrix = detectorAlignment.worldTransformation().Inverse();
0055       detectorAlignment.delta().computeMatrix(deltaMatrix);
0056     }
0057     return;
0058   }
0059   except("DeIov","initialize> Modifying a condition after initialization is not allowed!");
0060 }
0061 
0062 /// Printout method to stdout
0063 void DeIOVObject::print(int indent, int flg)  const   {
0064   std::string prefix = DE::indent(indent);
0065   if ( flg&DePrint::STATIC)  {
0066     de_static.print(indent, flg&~DePrint::CHILDREN);
0067   }
0068   printout(INFO, "DeIOV",
0069            "%s+ Name:%s Hash:%016lX Type:%s Flags:%08X IOV:%s",
0070            prefix.c_str(), dd4hep::cond::cond_name(this).c_str(), hash,
0071            is_bound() ? data.dataType().c_str() : "<UNBOUND>",
0072            flags, iov ? iov->str().c_str()      : "--");
0073   if ( flg&DePrint::DETAIL)  { 
0074    printout(INFO, "DeIOV","%s+  >> Conditions:%ld Alignment:%s VolAlign:%ld",
0075              prefix.c_str(), conditions.size(),
0076              yes_no(detectorAlignment.isValid()),
0077              volumeAlignments.size());
0078     for(const auto& cc : conditions)  {
0079       Condition c = cc.second;
0080       printout(INFO, "DeIOV","%s+  >> Condition [%08X] %s Hash:%016X Flags:%08X Type:%s",
0081                prefix.c_str(), cc.first, dd4hep::cond::cond_name(c).c_str(), c.key(), c.flags(),
0082                c.is_bound() ? c.data().dataType().c_str() : "<UNBOUND>");
0083       if ( c->iov )  {
0084         printout(INFO, "DeIOV","%s+  >> + IOV:%s",
0085                  prefix.c_str(), c->iov ? c.iov().str().c_str()   : "--");
0086       }
0087     }
0088     if ( detectorAlignment.isValid() )   {
0089       char txt1[64], txt2[64], txt3[64];
0090       std::stringstream str;
0091       dd4hep::Alignment::Object* ptr = detectorAlignment.ptr();
0092       const dd4hep::AlignmentData& alignment_data = detectorAlignment.data();
0093       const dd4hep::Delta& D = alignment_data.delta;
0094 
0095       if ( D.hasTranslation() )
0096         ::snprintf(txt1,sizeof(txt1),"Tr: x:%g y:%g z:%g ",D.translation.x(), D.translation.Y(), D.translation.Z());
0097       else
0098         ::snprintf(txt1,sizeof(txt1),"Tr:    ------- ");
0099       if ( D.hasRotation() )
0100         ::snprintf(txt2,sizeof(txt2),"Rot: phi:%g psi:%g theta:%g ",D.rotation.Phi(), D.rotation.Psi(), D.rotation.Theta());
0101       else
0102       ::snprintf(txt2,sizeof(txt2),"Rot:   ------- ");
0103       if ( D.hasPivot() )
0104         ::snprintf(txt3,sizeof(txt3),"Rot: x:%g y:%g z:%g ",D.pivot.Vect().X(), D.pivot.Vect().Y(), D.pivot.Vect().Z());
0105       else
0106       ::snprintf(txt3,sizeof(txt3),"Pivot: ------- ");
0107 
0108       printout(INFO,"DeIOV","%s+  >> Aligment [%p] Typ:%s \tData:(%11s-%8s-%5s)",
0109                prefix.c_str(), detectorAlignment.ptr(),
0110                dd4hep::typeName(typeid(*ptr)).c_str(),
0111                D.hasTranslation() ? "Translation" : "",
0112                D.hasRotation() ? "Rotation" : "",
0113                D.hasPivot() ? "Pivot" : "");
0114       if ( D.hasTranslation() || D.hasRotation() || D.hasPivot() )  {
0115         printout(INFO,"DeIOV","%s+  >> Aligment-Delta %s %s %s",prefix.c_str(), txt1,txt2,txt3);
0116       }
0117     }
0118   }
0119 }
0120 
0121 /// Check (enforce) the validity of the alignment object if required
0122 void DeIOVObject::checkAlignment()  const  {
0123   if ( !detectorAlignment.isValid() )   {
0124     dd4hep::except("DeIOVObject",
0125                    "Invalid alignment object! Cannot compute derived quantities.");
0126   }
0127 }
0128 
0129 /// Fill the child cache. May only be called while the condition is NOT active
0130 void DeIOVObject::fillCache(ConditionsMap& m)    {
0131   if ( (de_flags&DeInit::INITIALIZED) == 0 )   {
0132     childCache = DeHelpers::getChildConditions<DeIOVObject>(m, detector, Keys::deKey, DeHelpers::ALL);
0133     return;
0134   }
0135   except("DeIov","fillCache> Modifying %d (%s) after initialization is not allowed!",
0136          Keys::deKeyName.c_str(), detector.path().c_str());
0137 }
0138 
0139 /// Access daughter elements: IOV dependent part
0140 DeIOVObject* DeIOVObject::child(DetElement de)   const   {
0141   auto i = childCache.find(de);
0142   if ( i == childCache.end() )  {
0143     except("DeIOV","No such condition:%s for detector element:%s",
0144            Keys::deKeyName.c_str(), de.path().c_str());
0145   }
0146   return (*i).second;
0147 }
0148 
0149 /// Access condition by name
0150 DeIOV::Condition DeIOVObject::condition(const std::string& nam)  const   {
0151   return this->condition(dd4hep::ConditionKey::itemCode(nam));
0152 }
0153 
0154 /// Access condition by name
0155 DeIOV::Condition DeIOVObject::condition(const std::string& nam, bool throw_if)  const   {
0156   return this->condition(dd4hep::ConditionKey::itemCode(nam), throw_if);
0157 }
0158 
0159 /// Access condition by name
0160 DeIOV::Condition DeIOVObject::condition(itemkey_type k)  const   {
0161   auto i = conditions.find(k);
0162   return (i == conditions.end()) ? (*i).second : Condition();
0163 }
0164 
0165 /// Access condition by name
0166 DeIOV::Condition DeIOVObject::condition(itemkey_type k, bool throw_if)  const   {
0167   auto i = conditions.find(k);
0168   if (i != conditions.end())  {
0169     return (*i).second;
0170   }
0171   if ( throw_if )  {
0172     except("DeIOV","Attempt to access non-existing condition with key: %d.",k);
0173   }
0174  return Condition();
0175 }