RootTalk


ROOT Discussion Forums

Using Scan in macro

Discuss installing and running ROOT here. Please post bug reports here.

Moderator: rootdev

Using Scan in macro

Unread postby jgennaro » Sun Feb 27, 2011 20:45

Hello,

Normally using TTree::Scan, if there are arrays as branches, then if one performs a cut on a non-array variable, Scan will output a separate row for each Instance, up to the maximum size of any shown array.

Example from the root prompt (the tree in the root file is named 't'):
Code: Select all
phoenix% root -l ../CreeperR4/TestRun.root
root [0]
Attaching file ../CreeperR4/TestRun.root as _file0...
[root [1] t->Scan("fEventNum:fSTACId","fEventNum==314379")
***********************************************
*    Row   * Instance * fEventNum *   fSTACId *
***********************************************
*   314379 *        0 *    314379 *        13 *
*   314379 *        1 *    314379 *         0 *
*   314379 *        2 *    314379 *         2 *
*   314379 *        3 *    314379 *         7 *
*   314379 *        4 *    314379 *         5 *
*   314379 *        5 *    314379 *         2 *
*   314379 *        6 *    314379 *         7 *
*   314379 *        7 *    314379 *         7 *
*   314379 *        8 *    314379 *        11 *
*   314379 *        9 *    314379 *         6 *
*   314379 *       10 *    314379 *        13 *
*   314379 *       11 *    314379 *         3 *
*   314379 *       12 *    314379 *        14 *
*   314379 *       13 *    314379 *         4 *
*   314379 *       14 *    314379 *        14 *
*   314379 *       15 *    314379 *         7 *
*   314379 *       16 *    314379 *        15 *
*   314379 *       17 *    314379 *         4 *
*   314379 *       18 *    314379 *         1 *
*   314379 *       19 *    314379 *         2 *
*   314379 *       20 *    314379 *         1 *
*   314379 *       21 *    314379 *         1 *
*   314379 *       22 *    314379 *         2 *
*   314379 *       23 *    314379 *         4 *
*   314379 *       24 *    314379 *         5 *
Type <CR> to continue or q to quit ==>


Now suppose I have used t->MakeClass() to create a tree reader skeleton, and defined a function within that class. Here the tree pointer is now called 'fChain.'
Code: Select all
void makeclassobject::RootScan() {
 fChain->Scan("fEventNum:fSTACId","fEventNum==314379");
}


Then suppose I create an un-named Macro.C which instantiates the makeclassobject and calls the makeclassobject::RootScan() function. When I run that macro, the output is then:

Code: Select all
***********************************************
*    Row   * Instance * fEventNum *   fSTACId *
***********************************************
*   314379 *        0 *    314379 *        13 *
***********************************************
==> 1 selected entry


If I want the scan to appear to the user just as if he/she had entered the Scan command from the root prompt, what parameters to I need to pass to Scan in order to make it appear as normal?

Thanks,

Joe
jgennaro
 
Posts: 49
Joined: Wed Jul 22, 2009 21:55
Location: Michigan

Re: Using Scan in macro

Unread postby pcanal » Mon Feb 28, 2011 18:40

When I run that macro, the output is then ... :
A priori the result should have been the same in both case. Can you send a complete running example showing the problem?

Philippe.
pcanal
 
Posts: 6288
Joined: Wed Aug 27, 2003 14:22
Location: Fermilab

Re: Using Scan in macro

Unread postby jgennaro » Tue Mar 01, 2011 6:18

Yes I can. I attach some files:

Root version: 5.29/01
treeshort.root - truncated version of my root file, containing tree 't'
ScanIssue.C/.h: result of t->MakeClass("ScanIssue") with one function added, ScanIssue::UserScan()
StartScanIssue.C: un-named macro code.

Usage: do root StartScanIssue.C
My results (pasted below): I get '1 selected entry' when executing the UserScan function from a root prompt, and the regular, functioning Scan when doing 't->Scan("...","..") from the root prompt. Let me know if you need anything else.

Thanks!

Joe

Code: Select all
battlezone% root -l StartScanIssue.C
root [0]
Processing StartScanIssue.C...
Executing script in 'StartScanIssue.C'
Warning in <TClass::TClass>: no dictionary for class UC_FreezeCycle is available

Constructed si with tree from file located at ./treeshort.root.
 (entries = 1000)
root [1] si.UserScan()     
***********************************************
*    Row   * Instance * fEventNum *   fSTACId *
***********************************************
*      358 *        0 *       358 *         8 *
***********************************************
==> 1 selected entry
root [2] .q
battlezone% root -l treeshort.root
root [0]
Attaching file treeshort.root as _file0...
Warning in <TClass::TClass>: no dictionary for class UC_FreezeCycle is available
root [1] t->Scan("fEventNum:fSTACId","fEventNum==358")
***********************************************
*    Row   * Instance * fEventNum *   fSTACId *
***********************************************
*      358 *        0 *       358 *         8 *
*      358 *        1 *       358 *         8 *
*      358 *        2 *       358 *         8 *
*      358 *        3 *       358 *         8 *
*      358 *        4 *       358 *         8 *
*      358 *        5 *       358 *         8 *
*      358 *        6 *       358 *         8 *
*      358 *        7 *       358 *         8 *
*      358 *        8 *       358 *         8 *
*      358 *        9 *       358 *         8 *
*      358 *       10 *       358 *         8 *
*      358 *       11 *       358 *         8 *
*      358 *       12 *       358 *         8 *
*      358 *       13 *       358 *         8 *
*      358 *       14 *       358 *         8 *
*      358 *       15 *       358 *         8 *
*      358 *       16 *       358 *         8 *
*      358 *       17 *       358 *         8 *
*      358 *       18 *       358 *         8 *
*      358 *       19 *       358 *         8 *
*      358 *       20 *       358 *         8 *
*      358 *       21 *       358 *         8 *
*      358 *       22 *       358 *         8 *
*      358 *       23 *       358 *         8 *
*      358 *       24 *       358 *         8 *
Type <CR> to continue or q to quit ==>
Attachments
ScanIssue.zip
Contains treeshort.root, ScanIssue.C/.h, StartScanIssue.C. Unzip and do root -l StartScanIssue.C
(114.92 KiB) Downloaded 62 times
jgennaro
 
Posts: 49
Joined: Wed Jul 22, 2009 21:55
Location: Michigan

Re: Using Scan in macro

Unread postby pcanal » Tue Mar 01, 2011 18:36

Hi,

Thanks for reporting this issue, it is fixed in revision 38262 and up of the trunk.

Cheers,
Philippe.
pcanal
 
Posts: 6288
Joined: Wed Aug 27, 2003 14:22
Location: Fermilab


Return to ROOT Support

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests