Install the product sam_client_api using ups/upd: it is available for IRIX with qualifier KAI-4.0f, for Linux with qualifier GCC-3.1
You can browse the code by
1) login on d0mino
2) setup sam_client_api -q "KAI-4.0f"
3) setup sam
4) cd $SAM_CLIENT_API_DIR/
5) read the file demo/README
There are a couple of tests that you can run to see that everything works properly. Then you can take inspiration from APIdemo.cpp to write your program.
The purpose of this package is providing a user interface to sam that can be called from compiled C++ or used from root. In this directory the user can find one example for compiled C++ and one for Root. The examples are commented below in greater detail.
Both examples simply loop through all the files in a dataset and print their names out, as soon as they are in the sam cache. This is achieved by first configuring an "option" object (SAMAPIOpts), which specifies parameters like Application Name and Application Version; then instanciating the interface to sam (SAMcppClientAPI) passing the configured options at creation time. The method nextInputFile() send to sam a request to bring to cache the next available input file in the dataset; the method currentInputFile() returns a string with the name of the file. Note that currently it is possible only to retrieve files. The interface to the store methods are not implemented, yet.
You can get more information on the project at http://projects.fnal.gov/act/kdi.html and http://d0db.fnal.gov/sam/doc/userdocs/SamRoot.html As mentioned above, the only two methods available to the interface are nextInputFile() and currentInputFile(). For a complete list of the methods available to SAMAPIOpts, I ask the user to look at the header file sam_client_api/SAMAPIOpts.hpp: the method names are inspired to the sam_manager configuration methods. Also, a list of the exeptions thrown by the interface can be seen by executing
grep Exception sam_client_api/SAMcppClientAPI.hpp
In this example, APIdemo makes use of the library sam_client_api to interface itself to sam. The GNUmakefile provide examples to link the library statically (sam_client_api.a) or dynamically (sam_client_api.so) to the demo program.
You can use this product on IRIX building your job with kai v4.0 or on Linux with gcc v3.1.
Setup up the build environment as follows
(Note: the BFARCH variable is used in the makefile demo exmple only)
| IRIX (tested on d0mino) | LINUX (tested on sammy) |
|
> setup kai > setup n32 > setup orbacus v3_3_4 -q KAI-4.0f > setup sam_lib -q KAI-4.0f > setup sam_client_api -q KAI-4.0f > setenv BFARCH IRIX6-KCC |
>setup gcc v3_1 >setup orbacus v3_3_4p1 -q GCC-3.1 >setup sam_lib v4_6_0 -q GCC-3.1 >setup sam_client_api -q GCC-3.1 >setenv BFARCH LINUX2-GCC3 |
Then
> cd ${SAM_CLIENT_API}/demo (...or cp the whole dir where you have write privileges)
This is the real build log on d0mino:
> gmake *** D *** APIdemo.d *** C *** APIdemo.o KCC --exceptions --thread_safe --no_implicit_include --one_instantiation_per_object +K0 -D__KAI_STRICT -DKCC -DDEFECT_TEMPLATE_INSTANTIATION -n32 -I/usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/include/ -I/home/garzogli/sam_root/sam_client_api/ -I/usr/products/sam_lib/IRIX-6-5/v4_1_0KAI-4-0f/ -o APIdemo.o -c APIdemo.cpp *** L *** APIdemo KCC --exceptions --thread_safe +K0 --COMPO_pl -v -n32 -L/usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib -L/usr/products/sam_lib/IRIX-6-5/v4_1_0KAI-4-0f/lib/so -L/home/garzogli/sam_root/sam_client_api/lib/so -o APIdemo APIdemo.o -lsam_client_api -lsam_corba -lsam_util -lOB -lCosNaming -lJTC -lm /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleTThis is the real build log on sammy:&JTCHandleT ::operator =(const JTCHandleT &) [with T1=JTCThread] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::~JTCHandleT () [with T1=JTCThread] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::JTCHandleT (T1 *) [with T1=JTCThread] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::~JTCHandleT () [with T1=JTCRunnable] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::JTCHandleT (T1 *) [with T1=JTCRunnable] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT &JTCHandleT ::operator =(const JTCHandleT &) [with T1=JTCThreadGroup] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::~JTCHandleT () [with T1=JTCThreadGroup] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::JTCHandleT (const JTCHandleT &) [with T1=JTCThreadGroup] /usr/products/orbacus/IRIX-6-5/v3_3_4KAI-4-0f/lib/libJTC.so will instantiate JTCHandleT ::JTCHandleT (T1 *) [with T1=JTCThreadGroup] Once built, the program can be submitted to sam as follows (real log): > sam submit job --defname=ggroot2 --dataset-version=new --cpu-per-event=1s --interactive --script=APIdemo --group=demo >>>>>> Starting project with the Station Master Station Master contacted, result: Started project 80395(garzogli_80395) for group demo Waiting for the project to initialize... Callback from server: 'OK|Project is ready' >>>>>> Creating SAM_BATCH wrapper script >>>>>> Executing job in the foreground >>>>>> Executing: /home/garzogli/SAM_BATCH.garzogli_80395 Welcome to the execution of /home/garzogli/SAM_BATCH.garzogli_80395 Initializing UPS environment Setting up default SAM suite. Overriding default sam_user instance. Overriding default sam_config instance. SAM configuration: sam v4_2_0 -f NULL -z /usr/products/upsdb sam_user v4_1_7 -f NULL -z /usr/products/upsdb sam_config v4_2_2 -f NULL -z /usr/products/upsdb -q user_prd Incrementing the job count. JOBS_AT_NODE: 1 JOBS_ALL: 1 Invoking user application: APIdemo SAMcppClientInstance Initializing... SAMcppClientInstance ENV variable: SAM_PROJECT = garzogli_80395 SAMcppClientInstance ENV variable: SAM_STATION = central-analysis SAMcppClientInstance Could not find input parameter FileRequestTimeout. Using default value: indefinite SAMcppClientInstance Input option: ApplicationName = generic SAMcppClientInstance Input option: ApplicationVersion = 1 SAMcppClientInstance Input option: WorkGroup = demo SAMcppClientInstance Consumer established: CID = 70998 SAMcppClientInstance Process established: CPID = 843085 SAMcppClientInstance Initialized. SAMcppClientInstance Getting next input file... SAMcppClientInstance Established socket for the project master callbacks (port: 14599). SAMcppClientInstance Project master will call back. SAMcppClientInstance Received message from the project master SAMcppClientInstance Input file delivered: /sam/cache50/boo/reco_all_0000127714_002.raw_t01.54.00_000 API: Got file/sam/cache50/boo/reco_all_0000127714_002.raw_t01.54.00_000 SAMcppClientInstance Input file released: reco_all_0000127714_002.raw_t01.54.00_000 SAMcppClientInstance Getting next input file... SAMcppClientInstance End of stream encountered. SAMcppClientInstance Process ended: CPID = 843085 SAMcppClientInstance Destroyed. Exiting... Decrementing the job count. Stopping the project. Cleaning up by removing temporary batch script /home/garzogli/SAM_BATCH.garzogli_80395
>gmake
*** D *** APIdemo.d
*** C *** APIdemo.o
g++ -DHAVE_JTC_STOP -I/fnal/ups/prd/orbacus/Linux-2-4/v3_3_4p1GCC-3-1/include/ -I/home/garzogli/sam_root/sam_client_api/ -I/fnal/ups/prd/sam_lib/Linux-2-4/v4_6_0GCC-3-1/ -o APIdemo.o -c APIdemo.cpp
*** L *** APIdemo
g++ -L/fnal/ups/prd/orbacus/Linux-2-4/v3_3_4p1GCC-3-1/lib -L/fnal/ups/prd/sam_lib/Linux-2-4/v4_6_0GCC-3-1/lib -L/home/garzogli/sam_root/sam_client_api/lib -o APIdemo APIdemo.o -lsam_client_api -lsam_corba -lsam_util -lOB -lCosNaming -lJTC -lm -lpthread
[garzogli@sammy demo]$ sam submit job --defname=jim_test_sammy_ds1 --dataset-version=new --cpu-per-event=1s --interactive --script=APIdemo --group=demo
>>>>>> Starting project with the Station Master
Station Master contacted, result: Started project 70591(garzogli_70591) for group demo
Waiting for the project to initialize...
Callback from server: 'OK|Project is ready'
>>>>>> Creating SAM_BATCH wrapper script
>>>>>> Executing job in the foreground
>>>>>> Executing: /home/garzogli/SAM_BATCH.garzogli_70591
Welcome to the execution of /home/garzogli/SAM_BATCH.garzogli_70591
Initializing UPS environment
Setting up default SAM suite.
Overriding default sam_user instance.
Overriding default sam_config instance.
SAM configuration:
sam v4_2_0 -f NULL -z /samdisk/products/db
sam_user v4_1_6 -f NULL -z /samdisk/products/db
sam_config v4_2_19 -f NULL -z /samdisk/products/db -q dev
Incrementing the job count.
JOBS_AT_NODE: 1
JOBS_ALL: 1
Invoking user application: APIdemo
SAMcppClientInstance Initializing...
SAMcppClientInstance ENV variable: SAM_PROJECT = garzogli_70591
SAMcppClientInstance ENV variable: SAM_STATION = sammy
SAMcppClientInstance Could not find input parameter FileRequestTimeout.
Using default value: indefinite
SAMcppClientInstance Input option: ApplicationName = demo
SAMcppClientInstance Input option: ApplicationVersion = 1
SAMcppClientInstance Input option: WorkGroup = demo
SAMcppClientInstance Consumer established: CID = 50731
SAMcppClientInstance Process established: CPID = 235066
SAMcppClientInstance Initialized.
SAMcppClientInstance Getting next input file...
SAMcppClientInstance Established socket for the project master callbacks (port: 4339).
SAMcppClientInstance Project master will call back.
SAMcppClientInstance Received message from the project master
SAMcppClientInstance Input file delivered: /cache/sam/boo/Stream_2_0037600167_002.raw
API: Got file/cache/sam/boo/Stream_2_0037600167_002.raw
SAMcppClientInstance Input file released: Stream_2_0037600167_002.raw
SAMcppClientInstance Getting next input file...
SAMcppClientInstance Project master will call back.
SAMcppClientInstance Received message from the project master
SAMcppClientInstance Input file delivered: /cache/sam/boo/Jun_04_2001_16_58_10__Stream_1_0037095238_001.raw
API: Got file/cache/sam/boo/Jun_04_2001_16_58_10__Stream_1_0037095238_001.raw
SAMcppClientInstance Input file released: Jun_04_2001_16_58_10__Stream_1_0037095238_001.raw
SAMcppClientInstance Getting next input file...
SAMcppClientInstance Project master will call back.
SAMcppClientInstance Received message from the project master
SAMcppClientInstance Input file delivered: /cache/sam/boo/Jun_04_2001_20_06_28__Stream_1_0037606892_001.raw
[.......]
API: Got file/cache/sam/boo/Stream_4_0069729157_001.raw
SAMcppClientInstance Input file released: Stream_4_0069729157_001.raw
SAMcppClientInstance Getting next input file...
SAMcppClientInstance End of stream encountered.
SAMcppClientInstance Process ended: CPID = 235066
SAMcppClientInstance Destroyed.
Exiting...
Decrementing the job count.
Stopping the project.
Cleaning up by removing temporary batch script /home/garzogli/SAM_BATCH.garzogli_70591
[garzogli@sammy demo]$
In this example, SAMRootDemo.csh is the file submitted to sam. The script
essentially calls "root SAMRootClientDemo.cpp". The program at the beginning
loads the symbols used by sam_client_api.so via orbacus and sam_util
shared libraries. It then loads the root interface to sam_client_api.so
(libsam_root_client.so). Please, read the comments in the code to see
how the interface can be used.
The following is the log of a real sam submission:
% sam submit job --defname=ggroot2 --dataset-version=new --cpu-per-event=1s --interactive --group=demo --script=SAMRootDemo.csh
********** in submit method
********** arg= --interactive
********** arg= --cpu-per-event=1s
********** arg= --dataset-version=new
********** arg= --defname=ggroot2
********** arg= --script=SAMRootDemo.csh
********** arg= --group=demo
>>>>>> Starting project with the Station Master
Station Master contacted, result: Started project 57587(57587_sam_) for group demo
Waiting for the project to initialize...
Callback from server: 'OK|Project is ready'
>>>>>> Executing job in the foreground
>>>>>> Executing: /usr/products/sam_user/NULL/v4_1_1/bin/samscript.sh SAMRootDemo.csh 57587_sam_ central-analysis
JOBS_AT_NODE: 1
JOBS_ALL: 1
SAM script: calling user script SAMRootDemo.csh
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.02/07 18 January 2002 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
FreeType Engine v1.x used to render TrueType fonts.
Compiled for sgikcc with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.25, Jan 6 2002
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing /home/garzogli/sam_root/sam_client_api/demo/SAMRootClientDemo.cpp...
Starting SAM Root Client Demo
SAMcppClientInstance Initializing...
SAMcppClientInstance ENV variable: SAM_PROJECT = 57587_sam_
SAMcppClientInstance ENV variable: SAM_STATION = central-analysis
SAMcppClientInstance Could not find input parameter FileRequestTimeout.
Using default value: indefinite
SAMcppClientInstance Input option: ApplicationName = generic
SAMcppClientInstance Input option: ApplicationVersion = 1
SAMcppClientInstance Input option: WorkGroup = demo
SAMcppClientInstance Consumer established: CID = 49734
SAMcppClientInstance Process established: CPID = 615917
SAMcppClientInstance Initialized.
SAMcppClientInstance Getting next input file...
SAMcppClientInstance Established socket for the project master callbacks (port: 48112).
SAMcppClientInstance Project master will call back.
SAMcppClientInstance Received message from the project master
SAMcppClientInstance Input file delivered: /sam/cache26/boo/reco_all_0000127714_002.raw_t01.54.00_000
The current file is /sam/cache26/boo/reco_all_0000127714_002.raw_t01.54.00_000
SAMcppClientInstance Input file released: reco_all_0000127714_002.raw_t01.54.00_000
SAMcppClientInstance Getting next input file...
SAMcppClientInstance End of stream encountered.
SAMcppClientInstance Process ended: CPID = 615917
Exiting...
SAMcppClientInstance Destroyed.
SAM script stopping the project... (jobCount = 0)
#!/bin/csh root.exe $SAM_CLIENT_API_DIR/demo/SAMRootClientDemo.cpp
{
// Load libraries
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libJTC.so");
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libOB.so");
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libIDL.so");
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libCosNaming.so");
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libCosProperty.so");
gROOT->ProcessLine(".L $ORBACUS_DIR/lib/libCosEvent.so");
gROOT->ProcessLine(".L $SAM_LIB_LIBDIR/so/libsam_util.so");
gROOT->ProcessLine(".L $SAM_LIB_LIBDIR/so/libsam_corba.so");
gROOT->ProcessLine(".L $SAM_CLIENT_API_LIBDIR/so/libsam_client_api.so");
gROOT->ProcessLine(".L $SAM_CLIENT_API_LIBDIR/so/libsam_root_client.so");
// Executes SAM Demo
{
cout << "DEMO: Starting SAM Root Client Demo" << endl;
SAMRootClientOpts myOpts;
myOpts.setAppName("generic");
myOpts.setAppVersion("1");
myOpts.setWorkGroup("demo");
// This is a good place to instantiate a histogram for example.
// NOTE: if you are certain that all the files of the dataset that you are
// considering are pinned into cache, here you can instanciate a TChain if
// you want.
try {
SAMRootClient myAPI(&myOpts);
while(myAPI.nextInputFile()) {
// do something with the file name myAPI.currentInputFile(), like opening
// the file, go through the events and filling the histogram.
// NOTE: here you can add files to the TChain with the add method. BEWARE:
// if the files are NOT pinned in the cache, sam may delete the file next
// time that myAPI.nextInputFile() is called and disrupt you analysis.
// this version of root has problems with the << operators.
printf("DEMO: The current file is %s\n",myAPI.currentInputFile().c_str()); }
}
catch(SAMRootClient::ProjectMasterError& ex) {
cout << ex.error() << endl;
}
catch(SAMRootClient::ConsumerError& ex) {
cout << ex.error() << endl;
}
catch(SAMRootClient::StagerError& ex) {
cout << ex.error() << endl;
}
catch(SAMRootClient::CorbaError& ex) {
cout << ex.error() << endl;
}
catch(SAMRootClient::UnknownError& ex) {
cout << ex.error() << endl;
}
catch(...) {
cout << "DEMO: Error in the API" << endl;
exit(1);
}
// here you can display your histogram or use the TChain. If you want to
// do TChain to do an interactive analysis at this point, get rid od the
// line "gROOT->ProcessLine(".q");" at the end of the file.
cout << "DEMO: Exiting..." << endl;
}
// Quit root
gROOT->ProcessLine(".q");
}
=============================================================================
Project : SAM
Package : sam_doc
$Id: SamRoot.html,v 1.6 2003/02/10 17:21:55 garzogli Exp $
This work is part of a development project, called SAM, which consists
of a
number of coordinated packages each named sam_xxxx .
Notice of authorship, copyright status, and terms and conditions,
should
the software eventually become available for use outside Fermilab,
can be
found in the README and LICENCE files in the top level directory
of the main
sam package.
==============================================================================