forked from sPHENIX-Collaboration/coresoftware
/
Fun4AllPrdfOutputManager.cc
112 lines (92 loc) · 3.15 KB
/
Fun4AllPrdfOutputManager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Fun4AllPrdfOutputManager.h"
#include <fun4all/Fun4AllOutputManager.h> // for Fun4AllOutputManager
#include <phoolraw/PHRawOManager.h>
#include <phool/PHCompositeNode.h>
#include <phool/PHNode.h> // for PHNode
#include <phool/PHNodeIterator.h>
#include <phool/recoConsts.h>
#include <iostream>
using namespace std;
//______________________________________________________
Fun4AllPrdfOutputManager::Fun4AllPrdfOutputManager(const string &myname, const string &fname)
: Fun4AllOutputManager(myname, fname)
, m_PrdfNode(nullptr)
, m_PrdfOutManager(nullptr)
{
return;
}
//______________________________________________________
Fun4AllPrdfOutputManager::~Fun4AllPrdfOutputManager()
{
delete m_PrdfOutManager;
return;
}
//______________________________________________________
int Fun4AllPrdfOutputManager::InitPrdfNode(PHCompositeNode *top_node, const string &nodeName)
{
PHNodeIterator topIter(top_node);
m_PrdfNode = dynamic_cast<PHCompositeNode *>(topIter.findFirst("PHCompositeNode", nodeName.c_str()));
if (m_PrdfNode)
{
// the m_PrdfNode already exists (Pisa Input Mgr creates one also)
return 0;
}
// check name wrt default
if (nodeName != "SIMPRDF")
cout << "Fun4AllPrdfOutputManager::InitPrdfNode - WARNING: nodeName is \"" << nodeName << "\". most systems expect \"SIMPRDF\" and this is most likely not going to work" << endl;
// create node
m_PrdfNode = new PHCompositeNode(nodeName.c_str());
top_node->addNode(m_PrdfNode);
return 0;
}
//______________________________________________________
int Fun4AllPrdfOutputManager::outfileopen(const string &fname)
{
if (m_PrdfOutManager)
{
if (Verbosity()) cout << "Fun4AllPrdfOutputManager::outfileopen - closing file \"" << OutFileName() << "\"" << endl;
delete m_PrdfOutManager;
m_PrdfOutManager = nullptr;
}
OutFileName(fname);
if (Verbosity()) cout << "Fun4AllPrdfOutputManager::outfileopen - writing to file \"" << OutFileName() << "\"" << endl;
return 0;
}
//______________________________________________________
int Fun4AllPrdfOutputManager::Write(PHCompositeNode * /*node*/)
{
// check m_PrdfNode
if (!m_PrdfNode)
{
cout << "Fun4AllPrdfOutputManager::Write - prdfNode not initialized" << endl;
return -1;
}
// check m_PrdfOutManager
if (!m_PrdfOutManager) InitPrdfManager();
if (!m_PrdfOutManager)
{
cout << "Fun4AllPrdfOutputManager::Write - prdf manager not initialized" << endl;
return -1;
}
// write prdfNode to prdfManager
bool prdf_status = m_PrdfOutManager->write(m_PrdfNode);
return prdf_status ? 0 : -1;
}
//______________________________________________________
int Fun4AllPrdfOutputManager::InitPrdfManager(void)
{
if (m_PrdfOutManager) return -1;
// retrieve run number from recoConsts
recoConsts *rc = recoConsts::instance();
// retrieve run number
int run_number = -1;
if (rc->FlagExist("RUNNUMBER"))
{
run_number = rc->get_IntFlag("RUNNUMBER");
}
// buffer length (taken from offline/framework/simReco/PrdfReco.C)
static const int buffer_length(8 * 1024 * 1024 / 4);
// create output manager
m_PrdfOutManager = new PHRawOManager(OutFileName(), run_number, buffer_length);
return 0;
}