Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4AllPrdfOutputManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4AllPrdfOutputManager.cc
2 
3 #include <fun4all/Fun4AllOutputManager.h> // for Fun4AllOutputManager
4 
6 
8 #include <phool/PHNode.h> // for PHNode
9 #include <phool/PHNodeIterator.h>
10 #include <phool/recoConsts.h>
11 
12 #include <iostream>
13 
14 using namespace std;
15 
16 //______________________________________________________
17 Fun4AllPrdfOutputManager::Fun4AllPrdfOutputManager(const string &myname, const string &fname)
18  : Fun4AllOutputManager(myname, fname)
19  , m_PrdfNode(nullptr)
20  , m_PrdfOutManager(nullptr)
21 {
22  return;
23 }
24 
25 //______________________________________________________
27 {
28  delete m_PrdfOutManager;
29  return;
30 }
31 
32 //______________________________________________________
33 int Fun4AllPrdfOutputManager::InitPrdfNode(PHCompositeNode *top_node, const string &nodeName)
34 {
35  PHNodeIterator topIter(top_node);
36  m_PrdfNode = dynamic_cast<PHCompositeNode *>(topIter.findFirst("PHCompositeNode", nodeName.c_str()));
37  if (m_PrdfNode)
38  {
39  // the m_PrdfNode already exists (Pisa Input Mgr creates one also)
40  return 0;
41  }
42 
43  // check name wrt default
44  if (nodeName != "SIMPRDF")
45  {
46  cout << "Fun4AllPrdfOutputManager::InitPrdfNode - WARNING: nodeName is \"" << nodeName << "\". most systems expect \"SIMPRDF\" and this is most likely not going to work" << endl;
47  }
48 
49  // create node
50  m_PrdfNode = new PHCompositeNode(nodeName.c_str());
51  top_node->addNode(m_PrdfNode);
52  return 0;
53 }
54 
55 //______________________________________________________
57 {
58  if (m_PrdfOutManager)
59  {
60  if (Verbosity())
61  {
62  cout << "Fun4AllPrdfOutputManager::outfileopen - closing file \"" << OutFileName() << "\"" << endl;
63  }
64  delete m_PrdfOutManager;
65  m_PrdfOutManager = nullptr;
66  }
67 
68  OutFileName(fname);
69  if (Verbosity())
70  {
71  cout << "Fun4AllPrdfOutputManager::outfileopen - writing to file \"" << OutFileName() << "\"" << endl;
72  }
73 
74  return 0;
75 }
76 
77 //______________________________________________________
79 {
80  // check m_PrdfNode
81  if (!m_PrdfNode)
82  {
83  cout << "Fun4AllPrdfOutputManager::Write - prdfNode not initialized" << endl;
84  return -1;
85  }
86 
87  // check m_PrdfOutManager
88  if (!m_PrdfOutManager)
89  {
91  }
92  if (!m_PrdfOutManager)
93  {
94  cout << "Fun4AllPrdfOutputManager::Write - prdf manager not initialized" << endl;
95  return -1;
96  }
97 
98  // write prdfNode to prdfManager
99  bool prdf_status = m_PrdfOutManager->write(m_PrdfNode);
100  return prdf_status ? 0 : -1;
101 }
102 
103 //______________________________________________________
105 {
106  if (m_PrdfOutManager)
107  {
108  return -1;
109  }
110 
111  // retrieve run number from recoConsts
113 
114  // retrieve run number
115  int run_number = -1;
116  if (rc->FlagExist("RUNNUMBER"))
117  {
118  run_number = rc->get_IntFlag("RUNNUMBER");
119  }
120  // buffer length (taken from offline/framework/simReco/PrdfReco.C)
121  static const int buffer_length(8 * 1024 * 1024 / 4);
122 
123  // create output manager
124  m_PrdfOutManager = new PHRawOManager(OutFileName(), run_number, buffer_length);
125  return 0;
126 }