Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:21:37

0001 #include "MakeSimpleTree.h"
0002 #include "MySimpleTree.h"
0003 #include "MyTClonesArray.h"
0004 
0005 #include <fun4all/Fun4AllReturnCodes.h>
0006 
0007 #include <phool/getClass.h>
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/PHIODataNode.h>
0010 #include <phool/PHNodeIterator.h>
0011 
0012 MakeSimpleTree::MakeSimpleTree(const std::string &name): SubsysReco(name)
0013 {
0014   return;
0015 }
0016 
0017 int
0018 MakeSimpleTree::Init(PHCompositeNode *topNode)
0019 {
0020   PHNodeIterator iter(topNode);
0021 
0022   PHCompositeNode *dstNode;
0023   dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0024   if (!dstNode)
0025     {
0026       std::cout << PHWHERE << "DST Node missing doing nothing" << std::endl;
0027       return -1;
0028     }
0029 
0030   // this creates your objects and puts them on the node tree for
0031   // later saving. The "PHObject" argument is needed since phool still defaults
0032   // to the old staf tables. The second argument is the name you give to that node. It
0033   // makes ones life easier if the name is identical or related to the object you store
0034   // but it can be anything.
0035   // The name of the Node will be reflected in the branch name inside the root file
0036   // Keep that in mind if you want to analyze the root file standalone
0037   MySimpleTree *mytree = new MySimpleTree();
0038   PHIODataNode <PHObject> *newNode = new PHIODataNode <PHObject>(mytree,"MYSIMPLETREE","PHObject");
0039   dstNode->addNode(newNode);
0040   MyTClonesArray *mycontainer = new MyTClonesArray();
0041   newNode = new PHIODataNode <PHObject>(mycontainer,"MYTCARRAY","PHObject");
0042   dstNode->addNode(newNode);
0043   return 0;
0044 }
0045 
0046 int
0047 MakeSimpleTree::process_event(PHCompositeNode *topNode)
0048 {
0049   static int i = 0;
0050   MySimpleTree *mytree = findNode::getClass<MySimpleTree>(topNode,"MYSIMPLETREE");
0051   float f = i;
0052   mytree->MyFloat(f);
0053   mytree->MyInt(i);
0054    MyTClonesArray *mycontainer = findNode::getClass<MyTClonesArray>(topNode,"MYTCARRAY");
0055    for (int j=0; j<i;j++)
0056      {
0057        MySimpleTree *item = mycontainer->GetNewItem();
0058        item->MyFloat(f);
0059        item->MyInt(i);
0060      }
0061    mycontainer->MyEventInt(i);
0062    mycontainer->MyEventFloat(f);
0063    i++;
0064    // Fun4All looks at the return codes from each module
0065    // DISCARDEVENT tells an output manager which has this module
0066    // added to its "EventSelector" not to write this event out
0067    // You should use this if you don't want to store data from
0068    // this event (even "empty" objects take space and make the looping
0069    // over it inefficient)
0070    // 
0071    // EVENT_OK tells Fun4All all went well
0072    // This code just drops every other event from the output
0073    if (i % 2)
0074      {
0075        return Fun4AllReturnCodes::DISCARDEVENT;
0076      }
0077    return Fun4AllReturnCodes::EVENT_OK;
0078 }