-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplug_pop.cpp
223 lines (160 loc) · 6.88 KB
/
plug_pop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#define POPDEBUG 0
#include "xml_attr.h" // bude xml
#include "log_term.h" // bude xml
#include "mut_queue.h"
#include "acq_core.h"
#include "cuts_manip.h" //loadcuts,savecut,rmcut,cpcut.......
#include "ZH_data.h"
#include <stdlib.h> /* atof */
//#include <iostream> //#include <math.h>
#include <stdio.h>
#include "TROOT.h" // Main INCLUDE !!!!
#include "TSystem.h"
#include "TFile.h"
#include "TH1F.h"
#include "TCanvas.h" //i cannot draw in standalone???
#include "TRandom.h"
#include "TVector3.h"
//#include <pthread.h>
// I DONT WANT THIS ANYMORE #include "nano_acquis_pureconvert.C"
#include "TSocket.h" //net thread
//---------------------------try server (for a client with txt...)
#include "TServerSocket.h"
#include "TMonitor.h"
//----------------------------with mmap ------------------------
#include <err.h>
#include <sys/mman.h>
/****
IF C++ => care about namemangling....
// because of mixing c and c++, namemangling.....
*/
#ifdef __cplusplus
extern "C" {
#endif
// ===
// ========= Here I have something for mmap=============================MMAP
// ===
int mmapfd; // =-1 file handle for mmap
char *mmap_file; // pointer to mmap
/*****************************************************************ZH DATA
* I USE====================================
* ZH_data.C
* void ZH_data(int events);
*
*
*/
int* PLUG(int* par, int* par2){// POP ... nanot ZD data 4*int system
int datum=0;// one word from the concurent queue
char chL[500];
concurrent_queue<int> *buffer=(concurrent_queue<int>*)par;
sprintf(chL,"POP: pop_ZH : buff==%lld",(Long64_t)buffer);table_log(1,chL);
//=============
//HERE I DEFINE NEXT QUEUE
concurrent_queue<int> *BUFANAL=(concurrent_queue<int>*)par2; // empty queue(..,chan,..)
sprintf(chL,"POP: pop_ZH :buff2==%lld",(Long64_t)BUFANAL);table_log(1,chL);
// send it by (int*)&buffer
//=============
//STANDARD XML READ-------------
FILE *outfile; char fname[400];
int buffer4;
long long int cnt=0;
size_t result;
//-------- here I will control with control.mmap file------
if ((mmapfd = open("control.mmap", O_RDWR, 0)) == -1) err(1, "open");
mmap_file=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd, 0);
if (mmap_file == MAP_FAILED) errx(1, "either mmap");
char mmap_result[100];
//-------- here I will control with control.mmap file------
char acqxml2[100];
char pushis[100];
char definitions[2000];// channel definitions
TokenGet( "file=" , mmap_file , acqxml2 ); // takes a value from mmap
double respush=1.0;// PUSH is running "push=" token.....
TSmallish_xml xml( acqxml2 );
xml.DisplayTele( xml.mainnode, 0, "plugins","poper","definitions" );
sprintf( definitions ,"%s", xml.output );
// things from 20130820
// OverrideFileOUT=NULL;// NO filename out override
// and 20141115
char runnumc[100];
int runnum=0;
TokenGet( "runnum=" , mmap_file , runnumc );
if ( atoi(runnumc)>0){
sprintf( OverrideFileOUT, "run%s", runnumc );
printf("----- new filename override %s\n", OverrideFileOUT );
}else{
sprintf( OverrideFileOUT, "%s", "" );
}
ZHbuffer = (int*) malloc ( 10000 );
OEBmax=1000;// ONE EVENT LIMIT !!!!!!!!!!
DataRead=0; // HowMuch was read to buffer
cnt_evt=0; // event number
// I dont understand.....this should be in *.o
cTIME=0.0; // current data TIME (always>0)
bTIME=0.0; // buffered time (mostly 0)
sTIME=0.0; // startup time
dTIME=0.0; // difference
reset_chan_table();
sprintf(chL,"POP_ZH: loading the channel table%s", "");table_log(1,chL);
printf("definitions to load\n%s","");
load_chan_table( definitions );
printf("definitions loaded succesfully\n%s","");
// load_chan_table("circtree=100000,c001=1,c002=2,c003=3,c004=4,c005=5,c006=6,c007=7,c008=8,c017=17,c018=18,c019=19,c020=20,c021=21,c022=22,c023=23,c024=24,c032=32,c1024=t1,c1025=t2,c1026=t3,c1027=t4,c033=s001,c035=s002,c037=s003,c039=s004" );
// int pos=0;// this is position in the buffer...
int c=0;// position in OEbuffer..............
while (respush>=1.0){//run while push is running........
if (POPDEBUG!=0){sprintf(chL,"POP: entering while/buffer c=%d", c);table_log(1,chL);}
// usleep(15000000);
while( !buffer->empty() ){// concurent queue "buffer" is an object HERE
buffer->wait_and_pop(datum);
if (cnt %100 == 0){usleep(10);} // no delay@572k
if (POPDEBUG!=0){sprintf(chL,"POP: datum; cnt==%lld /c=%d", cnt,c);table_log(1,chL);}
if ((cnt%25000)==0){
sprintf(chL,"POP:%7.1f MB %9lld evts; %d",
4.*cnt/1000000, cnt_evt_data, buffer->size() );table_log(1,chL);
} //printout every MB
cnt++;
OEbuf[c] = datum;
if (POPDEBUG!=0){sprintf(chL,"POP:oebuf[c]=%08x %4d", OEbuf[c] ,c);table_log(1,chL);}
//buffer [c] is either EOE or NOT
if (OEbuf[c]==EOE){//END OF EVENT
if (POPDEBUG!=0){sprintf(chL,"POP: proc ONE cnt==%lld", cnt);table_log(1,chL);}
if (POPDEBUG!=0){sprintf(chL,"POP:oebuf=%08x %08x %08x", OEbuf[0],OEbuf[1],OEbuf[2]);table_log(1,chL);}
if (POPDEBUG!=0){sprintf(chL,"POP:oebuf=%08x %08x %08x", OEbuf[c-2],OEbuf[c-1],OEbuf[c]);table_log(1,chL);}
process_ONE_EVENT(OEbuf, (int*)BUFANAL );
if (POPDEBUG!=0){sprintf(chL,"POP: proc ONE cnt==%lld ok", cnt);table_log(1,chL);}
c=0;// reset position in the buffer
}//END OF EVENT
else{
c++;
}
}//BUFFER NOT EMPTY
usleep(1000*10); // wait 100ms and retry again..
respush=TokenGet( "run=" , mmap_file , pushis ); //takes a value
// if ( 0.0==TokenGet( "run=" , mmap_file , pushis ) ){
// respush=0.0;
// } //takes a value
if (respush<1.0){break;}
if (POPDEBUG!=0){sprintf(chL,"POP:respush!=0 c=%d size==%d",c,buffer->size() );table_log(1,chL);}
}//WHILE respush==0....push running...
// sprintf(chL,"Ending: respush==%1.0f; /%s/ ... \n/%s/", respush, pushis,mmap_file);table_log(1,chL);
// if (respush<1.0){break;}
if (ftree!=NULL){
// ZH_tree->Write();
ftree->Write();
ftree->Close();
}
sprintf(chL,"EXITING POP-ZH (bytes=%lld)", 4*cnt );table_log(1,chL);
if (ZHbuffer != NULL){
printf( "%s\n","...freeing the memory /ZHbuffer/ (pop)\n");
// printf( "%s\n","...freeing the memory\n");
// printf( "%s\n","...freeing the memory\n");
free (ZHbuffer);
}
sprintf(chL,"EXITING POP-ZH (evnts=%lld)",cnt_evt );table_log(1,chL);
sprintf(chL,"EXITING POP-ZH (data =%lld)",cnt_evt_data );table_log(1,chL);
}//pop_ZH_____________________________________________________________END___
//============================== EXPORTED FUNCTIONS STOP =========
#ifdef __cplusplus
}
#endif