Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeSimpleTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MakeSimpleTree.cc
1 #include "MakeSimpleTree.h"
2 #include "MySimpleTree.h"
3 #include "MyTClonesArray.h"
4 
6 
7 #include <phool/getClass.h>
9 #include <phool/PHIODataNode.h>
10 #include <phool/PHNodeIterator.h>
11 
13 {
14  return;
15 }
16 
17 int
19 {
20  PHNodeIterator iter(topNode);
21 
22  PHCompositeNode *dstNode;
23  dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
24  if (!dstNode)
25  {
26  std::cout << PHWHERE << "DST Node missing doing nothing" << std::endl;
27  return -1;
28  }
29 
30  // this creates your objects and puts them on the node tree for
31  // later saving. The "PHObject" argument is needed since phool still defaults
32  // to the old staf tables. The second argument is the name you give to that node. It
33  // makes ones life easier if the name is identical or related to the object you store
34  // but it can be anything.
35  // The name of the Node will be reflected in the branch name inside the root file
36  // Keep that in mind if you want to analyze the root file standalone
37  MySimpleTree *mytree = new MySimpleTree();
38  PHIODataNode <PHObject> *newNode = new PHIODataNode <PHObject>(mytree,"MYSIMPLETREE","PHObject");
39  dstNode->addNode(newNode);
40  MyTClonesArray *mycontainer = new MyTClonesArray();
41  newNode = new PHIODataNode <PHObject>(mycontainer,"MYTCARRAY","PHObject");
42  dstNode->addNode(newNode);
43  return 0;
44 }
45 
46 int
48 {
49  static int i = 0;
50  MySimpleTree *mytree = findNode::getClass<MySimpleTree>(topNode,"MYSIMPLETREE");
51  float f = i;
52  mytree->MyFloat(f);
53  mytree->MyInt(i);
54  MyTClonesArray *mycontainer = findNode::getClass<MyTClonesArray>(topNode,"MYTCARRAY");
55  for (int j=0; j<i;j++)
56  {
57  MySimpleTree *item = mycontainer->GetNewItem();
58  item->MyFloat(f);
59  item->MyInt(i);
60  }
61  mycontainer->MyEventInt(i);
62  mycontainer->MyEventFloat(f);
63  i++;
64  // Fun4All looks at the return codes from each module
65  // DISCARDEVENT tells an output manager which has this module
66  // added to its "EventSelector" not to write this event out
67  // You should use this if you don't want to store data from
68  // this event (even "empty" objects take space and make the looping
69  // over it inefficient)
70  //
71  // EVENT_OK tells Fun4All all went well
72  // This code just drops every other event from the output
73  if (i % 2)
74  {
76  }
78 }