FACT++  1.0
DataProcessorImp.cc
Go to the documentation of this file.
1 #include "DataProcessorImp.h"
2 
3 #include <boost/filesystem.hpp>
4 
5 #include "HeadersFAD.h"
6 #include "EventBuilder.h"
7 #include "tools.h"
8 
9 using namespace std;
10 
11 
12 // --------------------------------------------------------------------------
13 //
18 //
19 string DataProcessorImp::FormFileName(const string &path, uint64_t night, uint32_t runid, const string &extension)
20 {
21  ostringstream name;
22 
23  if (!path.empty())
24  {
25  name << path;
26  if (path[path.length()-1] != '/')
27  name << '/';
28  }
29 
30  name << Tools::Form("%04d/%02d/%02d/", night/10000, (night/100)%100, night%100);
31 
32  try
33  {
34  boost::filesystem::create_directories(name.str());
35  }
36  catch (const runtime_error &)
37  {
38  // File creation will fail anyway
39  //Error(e.what());
40  }
41 
42  name << night << '_' << setfill('0') << setw(3) << runid << '.' << extension;
43  return name.str();
44 }
45 
46 // =======================================================================
47 
48 bool DataDump::Open(const RUN_HEAD &h, const FAD::RunDescription &d)
49 {
50  fFileName = "/dev/null";
51 
52  ostringstream str;
53  str << this << " - "
54  << "OPEN_FILE #" << GetRunId() << ":"
55  << " Ver=" << h.Version
56  << " Nb=" << h.NBoard
57  << " Np=" << h.NPix
58  << " NTm=" << h.NTm
59  << " roi=" << h.Nroi
60  << " Typ=" << d.name;
61 
62  Debug(str);
63 
64  fTime = Time();
65 
66  return true;
67 }
68 
70 {
71  const Time now;
72  if (now-fTime<boost::posix_time::seconds(5))
73  return true;
74 
75  fTime = now;
76 
77  ostringstream str;
78  str << this << " - EVENT #" << e.evNum << " / " << e.trgNum;
79  Debug(str);
80 
81  return true;
82 }
83 
85 {
86  ostringstream str;
87  str << this << " - CLOSE FILE #" << GetRunId();
88 
89  Debug(str);
90 
91  return true;
92 }
93 
94 // =======================================================================
95 
97 {
98  cout << "WRITE_EVENT #" << GetRunId() << " (" << e.evNum << ")" << endl;
99  cout << " Typ=" << e.trgTyp << endl;
100  cout << " roi=" << e.nRoi << endl;
101  cout << " tim=" << e.time.tv_sec << endl;
102 
103  return true;
104 }
105 
uint16_t NTm
Definition: FAD.h:100
uint32_t evNum
Definition: EventBuilder.h:116
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
bool Open(const RUN_HEAD &h, const FAD::RunDescription &d)
STL namespace.
uint16_t nRoi
Definition: EventBuilder.h:126
uint32_t trgTyp
Definition: EventBuilder.h:119
bool WriteEvt(const EVT_CTRL2 &)
Definition: FAD.h:92
uint32_t Version
Definition: FAD.h:94
uint16_t Nroi
Definition: FAD.h:101
uint16_t NBoard
Definition: FAD.h:98
std::string Form(const char *fmt,...)
Definition: tools.cc:45
timeval time
Definition: EventBuilder.h:129
bool Close(const EVT_CTRL2 &)
uint32_t trgNum
Definition: EventBuilder.h:118
uint16_t NPix
Definition: FAD.h:99
static int Debug
Definition: dns.c:78
bool WriteEvt(const EVT_CTRL2 &)
static std::string FormFileName(const std::string &path, uint64_t night, uint32_t runid, const std::string &extension)