Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
daq_device_filenumbers.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file daq_device_filenumbers.cc
1 
2 
3 #include <iostream>
4 #include <sstream>
5 #include <fstream>
6 
8 #include <sys/types.h>
9 #include <unistd.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <fcntl.h>
13 
14 
15 
16 using namespace std;
17 
19  , const int subeventid
20  , const char *fn
21  , const int delete_flag
22  , const int maxlength)
23 
24 {
25 
26  m_eventType = eventtype;
27  m_subeventid = subeventid;
28  filename = fn;
29  _maxlength = maxlength;
30  _delete_flag = 0;
31  if ( delete_flag) _delete_flag = 1;
32 
33 }
34 
36 {
37 
38 }
39 
40 
41 
42 // the put_data function
43 
44 int daq_device_filenumbers::put_data(const int etype, int * adr, const int length )
45 {
46 
47  if (etype != m_eventType ) // not our id
48  {
49  return 0;
50  }
51 
52  ifstream sarg (filename.c_str());
53 
54  if ( !sarg.is_open()) return 0;
55 
56  string line;
57 
58  if ( daq_getEventFormat() ) // we are writing PRDF
59  {
60 
61  formatPacketHdr(adr);
62 
63  packetdata_ptr sevt = (packetdata_ptr) adr;
64 
65  // update id's etc
66  sevt->sub_id = m_subeventid;
67  sevt->sub_type=4;
68  sevt->sub_decoding = 30000 + ID4EVT;
69 
70  int *d = (int *) &sevt->data;
71  int i = 0;
72  int go_on = 1;
73 
74  while ( sarg.good() && go_on )
75  {
76  getline ( sarg, line);
77  // cout << "-- " << line << endl;
78  istringstream is ( line);
79  if ( is >> d[i])
80  {
81  i++;
82  if ( i + 6 + 1 >= length)
83  {
84  cout << __FILE__ << " " << __LINE__
85  <<" too large payload in Packet " << m_subeventid
86  << " current size " << i + 6 +1
87  << " max is " << length << endl;
88  go_on = 0;
89  }
90  }
91  }
92 
93  sarg.close();
94  if ( _delete_flag) unlink (filename.c_str());
95 
96  int padding = i%1;
97  sevt->structureinfo += padding;
98  sevt->sub_length += (i + padding);
99  return sevt->sub_length;
100  }
101 
102  else // the good format
103  {
104  sevt = (subevtdata_ptr) adr;
105  // set the initial subevent length
106  sevt->sub_length = SEVTHEADERLENGTH;
107 
108  // update id's etc
109  sevt->sub_id = m_subeventid;
110  sevt->sub_type=4;
111  sevt->sub_decoding = ID4EVT;
112  sevt->reserved[0] = 0;
113  sevt->reserved[1] = 0;
114 
115 
116  int *d = (int *) &sevt->data;
117  int i = 0;
118  int go_on = 1;
119 
120  while ( sarg.good() && go_on )
121  {
122  getline ( sarg, line);
123  // cout << "-- " << line << endl;
124  istringstream is ( line);
125  if ( is >> d[i])
126  {
127  i++;
128  if ( i + SEVTHEADERLENGTH + 1 >= length)
129  {
130  cout << __FILE__ << " " << __LINE__
131  <<" too large payload in Packet " << m_subeventid
132  << " current size " << i +SEVTHEADERLENGTH +1
133  << " max is " << length << endl;
134  go_on = 0;
135  }
136  }
137  }
138 
139  sarg.close();
140  if ( _delete_flag) unlink (filename.c_str());
141 
142  sevt->sub_padding = i%2;
143  sevt->sub_length += (i + sevt->sub_padding);
144  return sevt->sub_length;
145  }
146 
147 }
148 
149 
150 void daq_device_filenumbers::identify(std::ostream& os) const
151 {
152 
153  os << "File Number Reader Event Type: " << m_eventType
154  << " Subevent id: " << m_subeventid;
155  if ( _delete_flag ) os << " reading from and deleting ";
156  else os << " reading from ";
157  os << filename << endl;
158 
159 }
160 
161 int daq_device_filenumbers::max_length(const int etype) const
162 {
163  if (etype != m_eventType) return 0;
164  return _maxlength + SEVTHEADERLENGTH + 1;
165 }
166 
167