StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fzd2bin.C
1 #include <iostream.h>
2 
3 class St_geant_Maker;
4 class EEmcMCData;
5 
6 //#define WRITE_SOCKET
7 #define WRITE_FILE
8 
9 TBrowser *b = 0;
10 St_geant_Maker *geant= 0;
11 // reads .fzd file and writes EEevents to a binary file or socket
12 
13 // ______________________________________________
14 void fzd2bin(const Int_t Nevents=5, const Char_t *fzfile ="muon.fzd",int socketID=9093) {
15  Int_t i=0;
16 
17  gSystem->Load("EEmc.so");
18  gROOT->LoadMacro("bfc.C");
19  bfc(0,"fzin sim_T gen_T",fzfile);
20 
21 #ifdef WRITE_SOCKET
22  cout<<"opening socket="<<socketID<<"\n";
23  TServerSocket *ss = new TServerSocket(socketID, kTRUE);
24  cout<<"waits for client1...\n";
25  // Accept a connection and return a full-duplex communication socket.
26  TSocket *s0 = ss->Accept();
27  cout<<"waits 2...\n";
28 #endif
29 
30  for (i=1; i<=Nevents; i++ ) {
31  chain->Clear();
32  if (chain->Make(i)>=kStEOF) break;
33  printf("%2d ====================================\n",i);
34  St_g2t_ctf_hit *emc_hit = (St_g2t_ctf_hit *) chain->FindObject("g2t_eem_hit");
35  if (emc_hit==0) continue;
36 
37 #ifdef WRITE_SOCKET// ...... use socket to transport data
38  cout<<"sending this event via socket ...\n";
39  // tell the clients to start
41  const int mx=1<<14;
42  char hitBuf[mx];
43  int nh = data.decode(emc_hit);
44  cerr << "actual hits " << nh << endl;
45  int nbw = ev->write(hitBuf,mx);
46  int ret=s0->SendRaw(hitBuf,nbw);
47  cout<<ret<<" char sent\n";
48  if(ret!=nbw) {
49  cerr<<"socekt Error1 "<<ret<<" "<<nbw<<endl;
50  }
51 #endif
52 
53 #ifdef WRITE_FILE // ...... write events to bin file
54  static FILE *fd=0;
55  if(fd==0) {fd=fopen("data.bin","w"); assert(fd);}
56  EEmcMCData data;
57  const int mx=1<<14;
58  char hitBuf[mx];
59  int nh = data.decode(emc_hit);
60  cerr << "actual hits " << nh << endl;
61  int nbw = data->write(hitBuf,mx);
62  char *cnbw=&nbw;
63  int j;
64  for(j=0;j<sizeof(int);j++) fputc(cnbw[j],fd);
65  for(j=0;j<nbw;j++) fputc(hitBuf[j],fd);
66 #endif
67 
68  // .............. do sth with data locally
69  EEuse1 jan(emc_hit);
70  jan.work();
71 
72 
73  }
74 }
75 
76 
77 
78 #if 0
79 
80  EEmcMCData *ev = new EEmcMCData;
81  EEmcMCData *evcopy = new EEmcMCData;
82 
83  char *hitBuf = new char[16384];
84 
85 
86 
87  int nh = ev->decode(emc_hit);
88  cerr << "actual hits " << nh << endl;
89  ev->print();
90  int nbw = ev->write(hitBuf,4096);
91  cerr << "actual writ " << nbw << " bytes " << endl;
92  int nbr = evcopy->read(hitBuf,nbw);
93  cerr << "actual read " << nbr << " bytes " << endl;
94  evcopy->print();
95 #endif
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
Definition: Stypes.h:43
virtual Int_t Make()
Definition: StChain.cxx:110