ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4AllRolloverFileOutStream.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4AllRolloverFileOutStream.cc
2 
4 
5 #include <Event/Event.h>
6 #include <Event/oBuffer.h> // for oBuffer
7 #include <Event/ospBuffer.h>
8 
9 #include <phool/phool.h>
10 
11 #include <fcntl.h>
12 #include <sys/stat.h>
13 #include <unistd.h> // for close
14 #include <cstdio> // for snprintf
15 #include <cstdlib> // for exit
16 #include <iostream>
17 
18 using namespace std;
19 
21  const unsigned int sizeInMB,
22  const int offset,
23  const int increment,
24  const string &name)
25  : Fun4AllFileOutStream(frule, name)
26 
27 {
28  m_Offset = offset;
30  m_MaxFileFize = sizeInMB;
31  m_MaxFileFize = m_MaxFileFize * 1024 * 1024;
32  if (m_MaxFileFize == 0 || m_MaxFileFize > MaxSize())
33  {
34  if (m_MaxFileFize > MaxSize())
35  {
36  unsigned long long maxmb = MaxSize() / (1024 * 1024);
37  cout << "setting maximum size to current max (in MB): " << maxmb << endl;
38  }
40  }
41  m_Increment = increment;
42  if (m_Increment <= 0)
43  {
44  m_Increment = 1; //safety belt against overwriting files
45  }
46 }
47 
49 {
50  if (!GetoBuffer())
51  {
52  int irun = evt->getRunNumber();
53  unsigned filenamesize = FileRule().size() + 15;
54 
55  char *outfilename = new char[filenamesize];
57  int snprintfbytes = snprintf(outfilename, filenamesize, FileRule().c_str(), irun, iSeq());
58  if (static_cast<unsigned>(snprintfbytes) > filenamesize)
59  {
60  cout << PHWHERE << " " << Name() << ": filename exceeds length " << filenamesize
61  << ", tried " << snprintfbytes
62  << ". probably it is the filerule" << FileRule()
63  << " which uses other than %010d-%04d for runnumber/segment" << endl;
64  exit(1);
65  }
67  OutFileDescriptor(open(outfilename, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE,
68  S_IRWXU | S_IROTH | S_IRGRP));
69  if (OutFileDescriptor() == -1) // failure to open
70  {
71  cout << "could not open " << outfilename << " quitting" << endl;
72  exit(1);
73  }
74  if (Verbosity() > 0)
75  {
76  cout << "Fun4AllRolloverFileOutStream: opening new file " << outfilename << endl;
77  }
78  MyManager()->SetOutfileName(outfilename);
79  SetoBuffer(new ospBuffer(OutFileDescriptor(), xb(), LENGTH, irun, iSeq()));
80  delete[] outfilename;
81  }
82 
83  int status = GetoBuffer()->addEvent(evt);
84  if (status)
85  {
86  cout << Name() << ": ERROR WRITING OUT FILTERED EVENT "
87  << evt->getEvtSequence() << " FOR RUN "
88  << evt->getRunNumber() << " Status: " << status << endl;
89  }
90  BytesWritten(GetoBuffer()->getBytesWritten());
91  if (BytesWritten() >= m_MaxFileFize)
92  {
93  DeleteoBuffer();
94  BytesWritten(0);
97  }
98  return 0;
99 }
100 
102 {
103  os << "Fun4AllRolloverFileOutStream writing to " << FileRule()
104  << " current sequence " << m_CurrentSequence << endl;
105  return;
106 }