A Few Recent Updates To DANA GlueX Software meeting July 26, 2005

Download Report

Transcript A Few Recent Updates To DANA GlueX Software meeting July 26, 2005

A Few Recent Updates To
DANA
GlueX Software meeting
July 26, 2005
David Lawrence
Shared Objects
DANA can use shared objects for:
• Event Sources
• Factories
It does this using the libdl library
(dlopen, dlsym, …)
Shared Objects
Command line:
Attaching a single object:
hd_ana --so=libhddm_shlib.a hdgeant.hddm
Attaching all objects in a directory:
hd_ana --sodir=/tmp/myshlibs hdgeant.hddm
• sodir can be a relative or full path
• filenames of the form lib*.so will be attached
Shared Objects
Creating a shared object:
Makefile
PACKAGES = ROOT:DANA
MODULE_NAME = hddm_shlib
include $(HALLD_HOME)/src/BMS/Makefile.shlib
Makes the file libhddm_shlib.so from all
files in directory.
Shared Objects
Source code for shared object:
#include “DApplication.h”
extern "C" {
extern GetDEventSourceType_t GetDEventSourceType;
extern MakeDEventSource_t MakeDEventSource;
extern InitFactories_t InitFactories;
}
const char* GetDEventSourceType(void){return "DEventSourceHDDM";}
DEventSource* MakeDEventSource(const char* name){
return new DEventSourceHDDM(name);
}
void InitFactories(DEventLoop* eventLoop) {
eventLoop->AddFactory(new DFactory_DBCALHit());
}
Shared Objects
Using shared objects can be dangerous!
• The shared object mechanism in DANA is not
intended for normal use.
• It could potentially provide a lot of benefit
during code development or in certain
circumstances, a more convenient path to
legacy compatibility.
Using Multiple Threads
Command Line:
hd_ana --nthreads=4 hdgeant.hddm
C++ Source:
// Instantiate a DApplication object
DApplication app(narg, argv);
// Run though all events
app.Run(&myproc, 10);
Command line takes precedence!
Using Multiple Threads
Writing thread-safe code:
• Don’t use static or global variables
• Wrap ROOT calls in TThread::Lock()
and TThread::UnLock()
• Don’t wrap your whole routine (or even
a single factory) with a mutex!!
Factory Tags
• Tags can be used to distinguish two factories
which produce the same data type.
For example:
vector<const DParticle*> particles;
vector<const DParticle*> kaons;
loop->Get(particles);
loop->Get(kaons, “kaons”);
Factory Tags
Tagging a factory:
in the factory’s header file…
DFactory_Kaon.h
const char* Tag(void){return ”kaons";}
Class Creation Scripts
located in $HALLD_HOME/scripts
• mkclass - makes a class
– myclass.h
– myclass.cc
• mkfactory - makes a factory
– mydata.h
– DFactory_mydata.h
– DFactory_mydata.cc
• mkprocessor - makes an event processor
– DEventProcessor_name.h
– DEventProcessor_name.cc