Simple initialization macros

1. Example

This macro reads the parameter container HWallRefWinPar , a parameter container of the Forward Wall, for the run id 1347612441 ( a run in beam time APR07) and writes it to an ASCII file.
It shows the parameters on the screen and at the end also prints information about the content of the runtime database. %begin c++% { // create an Hades object and get the pointer to the runtime database Hades* myHades=new Hades; HRuntimeDb* rtdb=gHades->getRuntimeDb();

// define the input HParOraIo* ora=new HParOraIo; ora->open(); rtdb->setFirstInput(ora);

// define the output HParAsciiFileIo* output=new HParAsciiFileIo; output->open("wallParams.txt","out"); rtdb->setOutput(output);

// create the parameter container HWallRefWinPar* pPar=(HWallRefWinPar*)(rtdb->getContainer("WallRefWinPar"));

// initialize the parameter container rtdb->initContainers(1347612441);

// print the parameters on the screen pPar->printParams();

// save the output (writes the data to the file) rtdb->saveOutput();

// print content of the runtime database on the screen rtdb->print();

// delete the Hades object delete myHades; } %end% ALERT! In this example it is not necessary to create the detector for the Forward Wall, because the parameter container is a condition-style parameter container and used the base class I/O interface HCondParIo.

Output on screen

When initContainers is called the first time the history date is set in Oracle. Here it is set to "now" (the time I run the macro) because no parameter release exists for APR07.
Then the parameter container is initialized from Oracle.
************************************************************

   info<HRuntimeDb>:  initialisation for run id 1347612441
************************************************************

*************************************************************
     Oracle history date: 29-JUN-2007 13:59:29
*************************************************************
WallRefWinPar initialized from Oracle
Output from printParams:
---------------------------------------------
-----  WallRefWinPar  -----
--  Context/Purpose:  WallOneHitProduction
--  Description:      Read from Oracle
             Valid for Run Id 1347612441
             Status at 29-JUN-2007 13:59:29
---------------------------------------------
time_ref_win_low: -10.000
time_ref_win_high: 40000.000

The parameter container is written to output when saveOutput is called
   info<HRuntimeDb>: WallRefWinPar written to output

Output of rtdb->print():
------------------------------------------------------------

   info<HRuntimeDb>: actual containers in runtime database
   info<HRuntimeDb>: WallRefWinPar     Reference time windows parameters for Forward Wall
   info<HRuntimeDb>: runs, versions
--------------------------------------------------------------------------------

   info<HRuntimeDb>: run id
----------------------------------------
   info<HRuntimeDb>: container              1st-input  2nd-input    output
   info<1347612441>: run: 1347612441
   info<1347612441>: WallRefWinPar         1347612441         -1        1
--------------------------------------------------------------------------------

   info<HRuntimeDb>: input/output
----------------------------------------

   info<HRuntimeDb>: first Input:
Oracle-Database: db-hades    Username: hades_ana
History date: 29-JUN-2007 13:59:29
detector I/Os:  HCondParIo HSpecParIo
--------------------------------------------------------------------------------

   info<HRuntimeDb>: second Input: none
--------------------------------------------------------------------------------

   info<HRuntimeDb>: Output:
Ascii I/O is open
detector I/Os:  HCondParIo HSpecParIo
--------------------------------------------------------------------------------
It shows
  1. the parameter containers with name and title
  2. the version table with input/output versions for the parameter container
    (The input version is, when reading from Oracle, typically the first run id for which the parameters are initialized.)
  3. the first input (here Oracle with history date and connected user) with the available detector I/O
  4. the second input (here not set)
  5. the output (here the content of the ROOT file using TFile::ls())

Now you may for example change the data in the ASCII file using an editor and continue with the second example.

2. Example

This macro initializes two parameter containers from two different inputs for two different runs and creates a parameter ROOT file.
It reads the parameter container WallRefWinPar from the ASCII file created in the first example and eventually changed (set as first input).
It also reads the data for the calibration parameters for the Forward Wall HWallCalPar from Oracle (set as second input) for two runs having different versions for the parameters. The history date is set to "now", which guarantees to get the newest parameter versions for these runs.

ALERT! Because the parameter container WallCalPar is a tree-style parameter container with an individual read function, also the detector object must be created. %begin c++% { // create an Hades object // and get the pointers to the runtime database and the spectrometer Hades* myHades=new Hades; HSpectrometer* spec=gHades->getSetup(); HRuntimeDb* rtdb=gHades->getRuntimeDb();

// create the detector and its setup and add it in the spectrometer HWallDetector* wall=new HWallDetector; Int_t mods[]={1}; wall->setModules(-1,mods); spec->addDetector(wall);

// define the inputs HParAsciiFileIo* input=new HParAsciiFileIo; input->open("wallParams.txt"); rtdb->setFirstInput(input);

HParOraIo* ora=new HParOraIo; ora->open(); ora->setHistoryDate("now"); rtdb->setSecondInput(ora);

// define the output HParRootFileIo* output=new HParRootFileIo; output->open("wallParams.root","RECREATE"); rtdb->setOutput(output);

// create the parameter containers rtdb->getContainer("WallRefWinPar"); rtdb->getContainer("WallCalPar");

// initialize the parameter containers rtdb->initContainers(1620123104); rtdb->initContainers(1347612441);

// save the output (writes the data to the file) rtdb->saveOutput();

// print content of the runtime database on the screen rtdb->print();

// delete the Hades object delete myHades; } %end% In this example the pointers to the containers are not needed, because no functions of the parameter containers are called (for example the print functions).

Output on screen

Calling initContainers the first time:
*************************************************************
     Oracle history date: 29-JUN-2007 14:06:03
*************************************************************
************************************************************

   info<HRuntimeDb>:  initialisation for run id 1620123104
************************************************************

WallRefWinPar initialized from Ascii file
WallCalPar initialized from Oracle
Calling initContainers the second time:
The containers are first written to the output and then the containers are initialized a second time.
   info<HRuntimeDb>: WallRefWinPar written to ROOT file, version: 1
   info<HRuntimeDb>: WallCalPar written to ROOT file, version: 1
************************************************************

   info<HRuntimeDb>:  initialisation for run id 1347612441
************************************************************

WallRefWinPar initialized from Ascii file
WallCalPar initialized from Oracle
The changed parameter containers are written to output when saveOutput is called. Only the second version of the WallCalPar is written. The output of WallRefWinPar is supressed, because this version is already in the ROOT file.
   info<HRuntimeDb>: WallCalPar written to ROOT file, version: 2

Output of rtdb->print():
------------------------------------------------------------

   info<HRuntimeDb>: actual containers in runtime database
   info<HRuntimeDb>: WallRefWinPar      Reference time windows parameters for Forward Wall
   info<HRuntimeDb>: WallCalPar         Calibration parameters for Forward Wall
   info<HRuntimeDb>: runs, versions
--------------------------------------------------------------------------------

   info<HRuntimeDb>: run id
----------------------------------------

   info<HRuntimeDb>: container              1st-input 2nd-input    output
   info<1620123104>: run: 1620123104
   info<1620123104>: WallRefWinPar                  1         -1        1
   info<1620123104>: WallCalPar                    -1 1620123104        1
   info<1347612441>: run: 1347612441
   info<1347612441>: WallRefWinPar                  1         -1        1
   info<1347612441>: WallCalPar                    -1 1347612441        2
--------------------------------------------------------------------------------

   info<HRuntimeDb>: input/output
----------------------------------------

   info<HRuntimeDb>: first Input:
Ascii I/O is open
detector I/Os:  HCondParIo HSpecParIo HWallParIo
--------------------------------------------------------------------------------

   info<HRuntimeDb>: second Input:
Oracle-Database: db-hades    Username: hades_ana
History date: 29-JUN-2007 14:06:03
detector I/Os:  HCondParIo HSpecParIo HWallParIo
--------------------------------------------------------------------------------

   info<HRuntimeDb>: Output:
HParRootFile**          wallParams.root
 HParRootFile*          wallParams.root
  KEY: HWallRefWinPar   WallRefWinPar;1 Reference time windows parameters for Forward Wall
  KEY: HWallCalPar      WallCalPar;2    Calibration parameters for Forward Wall
  KEY: HWallCalPar      WallCalPar;1    Calibration parameters for Forward Wall
  KEY: HWallDetector    Wall;1  The Forward Wall detector
  KEY: HRun     1620123104;1
  KEY: HRun     1347612441;1
detector I/Os:  HCondParIo HSpecParIo HWallParIo
--------------------------------------------------------------------------------

ALERT!This ROOT file can be used as input to initialize both containers for the two run ids in the ROOT file.
Other runs can be only initialized by using one of these run ids as a reference run id, for example %begin c++% Int_t refRunId=1620123104; rtdb->initContainers(431216643,refRunId); %end% The containers will be initialized for run 431216643 with the same data as for run 1620123104.

-- IlseKoenig - 27 Jun 2007
Topic revision: r2 - 29 Jun 2007, IlseKoenig
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Hades Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)