Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4AllSpillDstOutputManager.cc
Go to the documentation of this file.
1 #include <sstream>
2 #include <TSystem.h>
4 #include <phool/getClass.h>
7 using namespace std;
8 
9 Fun4AllSpillDstOutputManager::Fun4AllSpillDstOutputManager(const string &dir_base, const string &myname)
10  : Fun4AllDstOutputManager(myname, "")
11  , m_dir_base(dir_base)
12  , m_sp_step(10)
13  , m_run_id(0)
14  , m_sp_id(0)
15 {
16  ;
17 }
18 
20 {
21  ;
22 }
23 
25 {
26  SQEvent* evt = findNode::getClass<SQEvent>(startNode, "SQEvent");
27  if (! evt) {
28  cout << PHWHERE << "SQEvent not found. Abort." << endl;
29  exit(1);
30  }
31  int run_id = evt->get_run_id();
32  int sp_id = (evt->get_spill_id() / m_sp_step) * m_sp_step;
33  if (m_run_id != run_id || m_sp_id != sp_id) {
34  m_run_id = run_id;
35  m_sp_id = sp_id;
36 
37  if (dstOut) {
38  PHNodeIterator nodeiter(Fun4AllServer::instance()->topNode());
39  PHCompositeNode* run = dynamic_cast<PHCompositeNode*>(nodeiter.findFirst("PHCompositeNode", "RUN"));
40  if (! run) {
41  cout << PHWHERE << "RUN not found. Abort." << endl;
42  exit(1);
43  }
44  WriteNode(run); // dstOut is deleted at the beginning of this function.
45  }
46 
48  ostringstream oss;
49  oss << m_dir_base << "/run_" << setfill('0') << setw(6) << run_id;
50  gSystem->mkdir(oss.str().c_str(), true);
51  oss << "/run_" << setw(6) << run_id << "_spill_" << setw(9) << sp_id << "_spin.root";
52  outfilename = oss.str();
53  dstOut = new PHNodeIOManager(outfilename.c_str(), PHWrite);
54  if (!dstOut->isFunctional()) {
55  delete dstOut;
56  dstOut = 0;
57  cout << PHWHERE << "Could not open " << oss.str() << ". Abort." << endl;
58  exit(1);
59  }
61  }
62  return Fun4AllDstOutputManager::Write(startNode);
63 }
Fun4AllSpillDstOutputManager(const std::string &dir_base, const std::string &myname="SPILLDSTOUT")
virtual int get_run_id() const =0
Return the run ID.
PHNode * findFirst(const std::string &, const std::string &)
#define PHWHERE
Definition: phool.h:23
PHBoolean SetCompressionLevel(const int level)
static Fun4AllServer * instance()
virtual int Write(PHCompositeNode *startNode)
write starting from given node
virtual int get_spill_id() const =0
Return the spill ID.
int run(const int nEvents=1)
Definition: run.C:10
int isFunctional() const
std::string outfilename
output file name
int Write(PHCompositeNode *startNode)
write starting from given node
Definition: phool.h:15
An SQ interface class to hold one event header.
Definition: SQEvent.h:17
virtual int WriteNode(PHCompositeNode *thisNode)
write specified node