Skip to content
Snippets Groups Projects
dumpDetectorData.py 2.88 KiB
Newer Older
#!/bin/python
#==========================================================================
Marko Petric's avatar
Marko Petric committed
#  AIDA Detector description implementation
#--------------------------------------------------------------------------
# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
# All rights reserved.
#
# For the licensing terms see $DD4hepINSTALL/LICENSE.
# For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
#
#==========================================================================

from __future__ import absolute_import, unicode_literals
Marko Petric's avatar
Marko Petric committed
import sys
import errno
import optparse
import logging
logging.basicConfig(format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Marko Petric's avatar
Marko Petric committed

def dumpData(det):
  try:
    dat = DDRec.FixedPadSizeTPCData(det)
  except:
    pass
  try:
    dat = DDRec.ZPlanarData(det)
  except:
    pass
  try:
    dat = DDRec.ZDiskPetalsData(det)
  except:
    pass
  try:
    dat = DDRec.ConicalSupportData(det)
  except:
    pass
  try:
    dat = DDRec.LayeredCalorimeterData(det)
  except:
    pass
  try:
    dat = DDRec.NeighbourSurfacesStruct(det)
  except:
    pass


parser = optparse.OptionParser()
parser.formatter.width = 132
parser.description = "Dump detector data objects from DDRec"
parser.add_option("-c", "--compact", dest="compact", default=None,
                  help="Define LCCDD style compact xml input",
Marko Petric's avatar
Marko Petric committed
                  metavar="<FILE>")

(opts, args) = parser.parse_args()

if opts.compact is None:
Marko Petric's avatar
Marko Petric committed
  logger.info("    %s", parser.format_help())
  sys.exit(1)

try:
  import ROOT
  from ROOT import gROOT
  gROOT.SetBatch(1)
except ImportError as X:
Marko Petric's avatar
Marko Petric committed
  logger.error('PyROOT interface not accessible: %s', str(X))
  logger.error("%s", parser.format_help())
  sys.exit(errno.ENOENT)

try:
  import dd4hep
except ImportError as X:
Marko Petric's avatar
Marko Petric committed
  logger.error('dd4hep python interface not accessible: %s', str(X))
  logger.error("%s", parser.format_help())
  sys.exit(errno.ENOENT)
#
try:
  import DDRec
except ImportError as X:
Marko Petric's avatar
Marko Petric committed
  logger.error('ddrec python interface not accessible: %s', str(X))
  logger.error("%s", parser.format_help())
  sys.exit(errno.ENOENT)
#

dd4hep.setPrintLevel(dd4hep.OutputLevel.ERROR)
Marko Petric's avatar
Marko Petric committed
logger.info('+++%s\n+++ Loading compact geometry:%s\n+++%s', 120 * '=', opts.compact, 120 * '=')
description = dd4hep.Detector.getInstance()
description.fromXML(opts.compact)


Marko Petric's avatar
Marko Petric committed
# ------ loop over detectors and print their detector data objects
Marko Petric's avatar
Marko Petric committed
for n, d in description.detectors():
Marko Petric's avatar
Marko Petric committed
  logger.info("")
  logger.info(" ------------- detector :  %s", d.name())
  logger.info("")
Marko Petric's avatar
Marko Petric committed
  det = description.detector(n)
Marko Petric's avatar
Marko Petric committed
  dumpData(det)
Marko Petric's avatar
Marko Petric committed
# -----------------------------------------------------------------
sys.exit(0)