Skip to content
Snippets Groups Projects
Unverified Commit 7bab404c authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn Committed by GitHub
Browse files

Merge pull request #3 from mirguest/lcg97-ecal

Add a service to retrieve the Decoder
parents 1d0795fd b140a9b8
No related branches found
No related tags found
No related merge requests found
dist: bionic
services:
- docker
language: cpp
env:
matrix:
- COMPILER=gcc; LCG_RELEASE=LCG_96c_LS; STANDARD=17; COMPILER_VERSION=gcc8;
before_install:
- wget --no-check-certificate https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest_all.deb
- sudo dpkg -i cvmfs-release-latest_all.deb
- sudo apt-get update
- sudo apt-get install cvmfs cvmfs-config-default
- rm -f cvmfs-release-latest_all.deb
- sudo mkdir -p /etc/cvmfs
- echo "CVMFS_QUOTA_LIMIT='32140'" | sudo tee /etc/cvmfs/default.local > /dev/null
- echo "CVMFS_HTTP_PROXY=DIRECT" | sudo tee -a /etc/cvmfs/default.local > /dev/null
- echo "CVMFS_CACHE_BASE='/var/lib/cvmfs'" | sudo tee -a /etc/cvmfs/default.local > /dev/null
- echo "CVMFS_FORCE_SIGNING='yes'" | sudo tee -a /etc/cvmfs/default.local > /dev/null
- echo "CVMFS_REPOSITORIES='sft.cern.ch,sw-nightlies.hsf.org'" | sudo tee -a /etc/cvmfs/default.local > /dev/null
- echo "CVMFS_SEND_INFO_HEADER=no" | sudo tee -a /etc/cvmfs/default.local > /dev/null
- cat /etc/cvmfs/default.local
- # change wrt dd4hep setup: don't manually mount cvmfs folders
- #sudo /etc/init.d/autofs stop
- sudo cvmfs_config setup
- sudo cvmfs_config probe
- sudo mkdir -p /cvmfs/sft.cern.ch
- sudo mkdir -p /cvmfs/sft-nightlies.cern.ch
- sudo mkdir -p /cvmfs/geant4.cern.ch
- sudo mkdir -p /cvmfs/sw-nightlies.hsf.org
- ls /cvmfs/sft.cern.ch
- ls /cvmfs/geant4.cern.ch
- ls /cvmfs/sw-nightlies.hsf.org
- export CVMFS_REPOS="-v /cvmfs/sft.cern.ch:/cvmfs/sft.cern.ch"
- export CVMFS_REPOS="${CVMFS_REPOS} -v /cvmfs/sw-nightlies.hsf.org:/cvmfs/sw-nightlies.hsf.org"
- export CVMFS_REPOS="${CVMFS_REPOS} -v /cvmfs/geant4.cern.ch:/cvmfs/geant4.cern.ch"
# command to install dependencies
install:
- shopt -s extglob dotglob
- mkdir package
- mv !(package) package
- shopt -u dotglob
- export PKGDIR=${PWD}/package
# command to run tests
script:
- docker run -ti --name CI_CONTAINER -v $PKGDIR:/workspace -e COMPILER_TYPE=$COMPILER -e LCG_RELEASE=${LCG_RELEASE} -e STANDARD=${STANDARD} -e COMPILER_VERSION=${COMPILER_VERSION} ${CVMFS_REPOS} -d clicdp/cc7-lcg bash
- docker exec -ti CI_CONTAINER /bin/bash -c "cd /workspace; ln -s /usr/lib64/liblzma.so.5.2.2 /usr/lib64/liblzma.so; echo 'hello world'"
# Don't send e-mail notifications
notifications:
email: false
......@@ -13,14 +13,18 @@
#include "GaudiKernel/IService.h"
namespace dd4hep {
class Detector;
class DetElement;
class Detector;
class DetElement;
namespace DDSegmentation {
class BitFieldCoder;
}
}
// class G4VUserDetectorConstruction;
class GAUDI_API IGeoSvc : virtual public IService {
public:
typedef dd4hep::DDSegmentation::BitFieldCoder Decoder;
public:
/// InterfaceID
DeclareInterfaceID(IGeoSvc, 1, 0);
......@@ -30,6 +34,9 @@ public:
// receive Geant4 Geometry
// virtual G4VUserDetectorConstruction* getGeant4Geo() = 0;
// short cut to retrieve the Decoder according to the Readout name
virtual Decoder* getDecoder(const std::string& readout_name) = 0;
virtual ~IGeoSvc() {}
};
......
......@@ -46,3 +46,34 @@ dd4hep::Detector*
GeoSvc::lcdd() {
return m_dd4hep_geo;
}
IGeoSvc::Decoder*
GeoSvc::getDecoder(const std::string& readout_name) {
IGeoSvc::Decoder* decoder = nullptr;
if (!lcdd()) {
error() << "Failed to get lcdd()" << endmsg;
return decoder;
}
auto readouts = m_dd4hep_geo->readouts();
if (readouts.find(readout_name) == readouts.end()) {
error() << "Failed to find readout name '" << readout_name << "'"
<< " in DD4hep::readouts. "
<< endmsg;
return decoder;
}
dd4hep::Readout readout = lcdd()->readout(readout_name);
auto m_idspec = readout.idSpec();
decoder = m_idspec.decoder();
if (!decoder) {
error() << "Failed to get the decoder with readout '"
<< readout_name << "'" << endmsg;
}
return decoder;
}
......@@ -28,6 +28,8 @@ public:
dd4hep::DetElement getDD4HepGeo() override;
dd4hep::Detector* lcdd() override;
Decoder* getDecoder(const std::string& readout_name) override;
private:
// DD4hep XML compact file path
......@@ -38,4 +40,4 @@ private:
};
#endif GeoSvc_h
#endif // GeoSvc_h
......@@ -6,6 +6,11 @@ find_package(podio REQUIRED)
find_package(LCIO REQUIRED)
find_package(EDM4HEP REQUIRED)
find_package(K4FWCore REQUIRED)
find_package(DD4hep COMPONENTS DDRec DDParsers REQUIRED)
gaudi_depends_on_subdirs(
Detector/DetInterface
)
set(Examples_srcs
src/HelloWorld/*.cpp
......@@ -13,6 +18,7 @@ set(Examples_srcs
src/SecondAlg/*.cpp
# src/PlcioTest/*.cpp
src/Edm4hepTest/*.cpp
src/DumpIDAlg/*.cpp
)
# Headers and Libraries
......@@ -23,6 +29,7 @@ gaudi_install_headers(Examples)
gaudi_add_module(Examples ${Examples_srcs}
INCLUDE_DIRS K4FWCore GaudiAlgLib GaudiKernel ${podio_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
LINK_LIBRARIES K4FWCore GaudiAlgLib GaudiKernel ${LCIO_LIBRARIES}
DD4hep ${DD4hep_COMPONENT_LIBRARIES}
# Force loading the libraries.
-Wl,--no-as-needed EDM4HEP::edm4hep EDM4HEP::edm4hepDict ${podio_LIBRARIES} podio::podioRootIO -Wl,--as-needed
)
......
#include "DumpIDAlg.h"
#include "edm4hep/EventHeaderCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "DD4hep/Detector.h"
#include "DD4hep/IDDescriptor.h"
#include "DD4hep/Plugins.h"
DECLARE_COMPONENT(DumpIDAlg)
DumpIDAlg::DumpIDAlg(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc), m_dd4hep_geo(nullptr), m_decoder(nullptr)
{
}
StatusCode DumpIDAlg::initialize()
{
m_geosvc = service<IGeoSvc>("GeoSvc");
if (!m_geosvc) {
error() << "Failed to find GeoSvc." << endmsg;
return StatusCode::FAILURE;
}
m_dd4hep_geo = m_geosvc->lcdd();
if (!m_dd4hep_geo) {
error() << "failed to retrieve dd4hep_geo: " << m_dd4hep_geo << endmsg;
return StatusCode::FAILURE;
}
// get the DD4hep readout
const std::string name_readout = "EcalBarrelCollection";
m_decoder = m_geosvc->getDecoder(name_readout);
if (!m_decoder) {
error() << "Failed to get the decoder. " << endmsg;
return StatusCode::FAILURE;
}
// Book N-tuple 1
NTuplePtr nt1( ntupleSvc(), "MyTuples/1" );
if ( nt1 ) {
m_tuple_id = nt1;
} else {
m_tuple_id = ntupleSvc()->book( "MyTuples/1", CLID_RowWiseTuple, "Row-wise N-Tuple example" );
if ( m_tuple_id ) {
m_tuple_id->addItem( "system", m_id_system ).ignore();
m_tuple_id->addItem( "module", m_id_module ).ignore();
m_tuple_id->addItem( "stave", m_id_stave ).ignore();
m_tuple_id->addItem( "tower", m_id_tower ).ignore();
m_tuple_id->addItem( "layer", m_id_layer ).ignore();
m_tuple_id->addItem( "wafer", m_id_wafer ).ignore();
m_tuple_id->addItem( "cellX", m_id_cellX ).ignore();
m_tuple_id->addItem( "cellY", m_id_cellY ).ignore();
} else { // did not manage to book the N tuple....
error() << " Cannot book N-tuple:" << long( m_tuple_id ) << endmsg;
return StatusCode::FAILURE;
}
}
return GaudiAlgorithm::initialize();
}
StatusCode DumpIDAlg::execute()
{
auto ecalBarrelCol = m_EcalBarrelCol.get();
for (auto calohit: *ecalBarrelCol) {
auto cellid = calohit.getCellID();
m_id_system = m_decoder->get(cellid, "system");
m_id_module = m_decoder->get(cellid, "module");
m_id_stave = m_decoder->get(cellid, "stave");
m_id_tower = m_decoder->get(cellid, "tower");
m_id_layer = m_decoder->get(cellid, "layer");
m_id_wafer = m_decoder->get(cellid, "wafer");
m_id_cellX = m_decoder->get(cellid, "cellX");
m_id_cellY = m_decoder->get(cellid, "cellY");
info() << "Calo hit cellid: " << cellid
<< " system: " << m_id_system
<< " module: " << m_id_module
<< " stave: " << m_id_stave
<< " tower: " << m_id_tower
<< " layer: " << m_id_layer
<< " wafer: " << m_id_wafer
<< " cellX: " << m_id_cellX
<< " cellY: " << m_id_cellY
<< endmsg;
// calculate I/J/K
m_tuple_id->write();
}
return StatusCode::SUCCESS;
}
StatusCode DumpIDAlg::finalize()
{
return GaudiAlgorithm::finalize();
}
#ifndef DumpIDAlg_h
#define DumpIDAlg_h
#include "FWCore/DataHandle.h"
#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/NTuple.h"
#include "DetInterface/IGeoSvc.h"
#include "DD4hep/Detector.h"
namespace edm4hep {
class EventHeaderCollection;
class MCParticleCollection;
class SimCalorimeterHitCollection;
class CaloHitContributionCollection;
}
class DumpIDAlg: public GaudiAlgorithm
{
public:
DumpIDAlg(const std::string& name, ISvcLocator* svcLoc);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
SmartIF<IGeoSvc> m_geosvc;
dd4hep::Detector* m_dd4hep_geo;
dd4hep::DDSegmentation::BitFieldCoder* m_decoder;
DataHandle<edm4hep::SimCalorimeterHitCollection> m_EcalBarrelCol{"EcalBarrelCollection",
Gaudi::DataHandle::Reader, this};
private:
// strore all the id for later analysis
NTuple::Tuple* m_tuple_id = nullptr;
NTuple::Item<int> m_id_system;
NTuple::Item<int> m_id_module;
NTuple::Item<int> m_id_stave;
NTuple::Item<int> m_id_tower;
NTuple::Item<int> m_id_layer;
NTuple::Item<int> m_id_wafer;
NTuple::Item<int> m_id_cellX;
NTuple::Item<int> m_id_cellY;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment