File indexing completed on 2025-08-02 08:21:01
0001
0002
0003 #include <iostream>
0004 #include <sstream>
0005 #include <fstream>
0006
0007 #include <daq_device_filenumbers.h>
0008 #include <sys/types.h>
0009 #include <unistd.h>
0010 #include <sys/stat.h>
0011 #include <sys/types.h>
0012 #include <fcntl.h>
0013
0014
0015
0016 using namespace std;
0017
0018 daq_device_filenumbers::daq_device_filenumbers(const int eventtype
0019 , const int subeventid
0020 , const char *fn
0021 , const int delete_flag
0022 , const int maxlength)
0023
0024 {
0025
0026 m_eventType = eventtype;
0027 m_subeventid = subeventid;
0028 filename = fn;
0029 _maxlength = maxlength;
0030 _delete_flag = 0;
0031 if ( delete_flag) _delete_flag = 1;
0032
0033 }
0034
0035 daq_device_filenumbers::~daq_device_filenumbers()
0036 {
0037
0038 }
0039
0040
0041
0042
0043
0044 int daq_device_filenumbers::put_data(const int etype, int * adr, const int length )
0045 {
0046
0047 if (etype != m_eventType )
0048 {
0049 return 0;
0050 }
0051
0052 ifstream sarg (filename.c_str());
0053
0054 if ( !sarg.is_open()) return 0;
0055
0056 string line;
0057
0058 if ( daq_getEventFormat() )
0059 {
0060
0061 formatPacketHdr(adr);
0062
0063 packetdata_ptr sevt = (packetdata_ptr) adr;
0064
0065
0066 sevt->sub_id = m_subeventid;
0067 sevt->sub_type=4;
0068 sevt->sub_decoding = 30000 + ID4EVT;
0069
0070 int *d = (int *) &sevt->data;
0071 int i = 0;
0072 int go_on = 1;
0073
0074 while ( sarg.good() && go_on )
0075 {
0076 getline ( sarg, line);
0077
0078 istringstream is ( line);
0079 if ( is >> d[i])
0080 {
0081 i++;
0082 if ( i + 6 + 1 >= length)
0083 {
0084 cout << __FILE__ << " " << __LINE__
0085 <<" too large payload in Packet " << m_subeventid
0086 << " current size " << i + 6 +1
0087 << " max is " << length << endl;
0088 go_on = 0;
0089 }
0090 }
0091 }
0092
0093 sarg.close();
0094 if ( _delete_flag) unlink (filename.c_str());
0095
0096 int padding = i%1;
0097 sevt->structureinfo += padding;
0098 sevt->sub_length += (i + padding);
0099 return sevt->sub_length;
0100 }
0101
0102 else
0103 {
0104 sevt = (subevtdata_ptr) adr;
0105
0106 sevt->sub_length = SEVTHEADERLENGTH;
0107
0108
0109 sevt->sub_id = m_subeventid;
0110 sevt->sub_type=4;
0111 sevt->sub_decoding = ID4EVT;
0112 sevt->reserved[0] = 0;
0113 sevt->reserved[1] = 0;
0114
0115
0116 int *d = (int *) &sevt->data;
0117 int i = 0;
0118 int go_on = 1;
0119
0120 while ( sarg.good() && go_on )
0121 {
0122 getline ( sarg, line);
0123
0124 istringstream is ( line);
0125 if ( is >> d[i])
0126 {
0127 i++;
0128 if ( i + SEVTHEADERLENGTH + 1 >= length)
0129 {
0130 cout << __FILE__ << " " << __LINE__
0131 <<" too large payload in Packet " << m_subeventid
0132 << " current size " << i +SEVTHEADERLENGTH +1
0133 << " max is " << length << endl;
0134 go_on = 0;
0135 }
0136 }
0137 }
0138
0139 sarg.close();
0140 if ( _delete_flag) unlink (filename.c_str());
0141
0142 sevt->sub_padding = i%2;
0143 sevt->sub_length += (i + sevt->sub_padding);
0144 return sevt->sub_length;
0145 }
0146
0147 }
0148
0149
0150 void daq_device_filenumbers::identify(std::ostream& os) const
0151 {
0152
0153 os << "File Number Reader Event Type: " << m_eventType
0154 << " Subevent id: " << m_subeventid;
0155 if ( _delete_flag ) os << " reading from and deleting ";
0156 else os << " reading from ";
0157 os << filename << endl;
0158
0159 }
0160
0161 int daq_device_filenumbers::max_length(const int etype) const
0162 {
0163 if (etype != m_eventType) return 0;
0164 return _maxlength + SEVTHEADERLENGTH + 1;
0165 }
0166
0167