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