source: Sophya/trunk/ArchTOIPipe/Kernel/cgt.cc@ 2331

Last change on this file since 2331 was 2207, checked in by aubourg, 23 years ago

mgr/cgt

File size: 4.9 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5
6// -------------------------------------------------------------------------
7// classe CGT : Compagnie Generale des Tuyaux
8// Gestionnaire de tuyaux (toi) et d'unites de traitements (TOIProcessor)
9// R. Ansari / Mai 2002
10// -------------------------------------------------------------------------
11
12#include "cgt.h"
13#include <typeinfo>
14#include "toiseqbuff.h"
15#include "toisegment.h"
16#include "fitstoiwtr.h"
17#include "toimanager.h"
18
19#ifdef WITH_SOPHYA
20#include "pexceptions.h"
21#else
22#include "apexceptions.h"
23#endif
24
25#include <pthread.h>
26
27CGT::CGT(bool fgsegmented, int bufsz, int maxseg)
28{
29 if (fgsegmented) {
30 SelectTOISeqBuffered(bufsz);
31 SelectTOISegmented(bufsz, maxseg);
32 }
33 else {
34 SelectTOISegmented(bufsz, maxseg);
35 SelectTOISeqBuffered(bufsz);
36 }
37 SetDebugLevel();
38}
39
40CGT::~CGT()
41{
42 vector< tuyau >::iterator it;
43 if (dbgLevel > 0)
44 cout << " CGT::~CGT() - deleting TOI's " << endl;
45 for(it = lesTuyaux.begin(); it != lesTuyaux.end(); it++) {
46 if (dbgLevel > 1)
47 cout << " ... deleting TOI " << (*it).toi->getName() << endl;
48 delete (*it).toi;
49 }
50}
51
52
53void CGT::SelectTOISegmented(int bufsz, int maxseg)
54{
55 fgSegmented = true;
56 fgSeqbuff = false;
57 segBuffsz = bufsz;
58 segMaxseg = maxseg;
59}
60
61void CGT::SelectTOISeqBuffered(int wsz)
62{
63 fgSeqbuff = true;
64 fgSegmented = false;
65 seqWsz = wsz;
66}
67
68TOI& CGT::Connect(TOIProcessor& prout, string out,
69 TOIProcessor& prin, string in, string nom, int wbsz, bool withFlag)
70{
71 int id1 = findProcId(&prout);
72 int id2 = findProcId(&prin);
73 struct tuyau tuy;
74 tuy.pr1id = id1;
75 tuy.pr2id = id2;
76 TOI* toi;
77 if (nom.length() < 1) {
78 char buff[128];
79 sprintf(buff, "TOI%d_C[%d-%d]", (int)lesTuyaux.size(), id1, id2);
80 nom = buff;
81 }
82 if (wbsz < 16) wbsz = (fgSegmented) ? segBuffsz : seqWsz;
83 if (fgSegmented) toi = new TOISegmented(nom, wbsz, segMaxseg);
84 else toi = new TOISeqBuffered(nom, wbsz);
85 tuy.toi = toi;
86 lesTuyaux.push_back(tuy);
87 prout.addOutput(out, toi);
88 if (withFlag) { // Si c'est un FITSTOIWriter
89 FITSTOIWriter* ftw = dynamic_cast< FITSTOIWriter* >(&prin);
90 if (ftw) ftw->addInput(in, toi, withFlag);
91 else prin.addInput(in, toi);
92 }
93 else prin.addInput(in, toi);
94 if (dbgLevel > 1)
95 cout << " CGT::Connect() TOI " << toi->getName() << " created " << endl;
96 return(*toi);
97}
98
99TOI& CGT::Connect(TOIProcessor& prout, const char* out,
100 TOIProcessor& prin, const char* in, string nom, int wbsz, bool withFlag)
101{
102 string outs = out;
103 string ins = in;
104 return Connect(prout, outs, prin, ins, nom, wbsz, withFlag);
105}
106
107void CGT::ListProcs(::ostream& os, bool prstat) // const plus tard
108{
109 os << " --- CGT::ListProcs() , NbProcs=" << lesProcs.size() << " ----- " << endl;
110 // vector< TOIProcessor* >::const_iterator it;
111 // for(it = lesProcs.begin(); it != lesProcs.end(); it++) {
112 for(int i=0; i< lesProcs.size(); i++) {
113 os << " >> Proc Id= " << i << " @ " << hex << lesProcs[i] << dec ;
114 string ctyp = typeid(*lesProcs[i]).name();
115 os << " Type= " << ctyp << endl;
116 if (prstat) lesProcs[i]->PrintStatus(os);
117 }
118}
119
120void CGT::ListTOIs(::ostream& os, bool prstat)
121{
122 os << " --- CGT::ListTOIs() , NbTOIs=" << lesTuyaux.size();
123 if ( fgSegmented ) os << " Default TOI: TOISegmented " << endl;
124 else os << " Default TOI: TOISeqBuffered " << endl;
125 for(int i=0; i< lesTuyaux.size(); i++) {
126 os << " >> TOI " << lesTuyaux[i].toi->getName() << " Connecting Procs (Id): "
127 << lesTuyaux[i].pr1id << " <---> " << lesTuyaux[i].pr2id << endl;
128 if (prstat > 1) lesTuyaux[i].toi->PrintStatus(os);
129 else if (prstat == 1)
130 os << " PutCountWait= " << lesTuyaux[i].toi->getCountWaitPut()
131 << " GetCountWait= " << lesTuyaux[i].toi->getCountWaitGet() << endl;
132 }
133}
134
135void CGT::PrintStatus(::ostream & os, bool prstat)
136{
137 ListProcs(os, prstat);
138 ListTOIs(os, prstat);
139}
140
141void CGT::DeleteProcs()
142{
143 vector< TOIProcessor* >::iterator it;
144 cout << " CGT::DeleteProcs() - deleting TOIProcessors - NProc="
145 << lesProcs.size() << endl;
146 for(it = lesProcs.begin(); it != lesProcs.end(); it++) {
147 if (dbgLevel > 1)
148 cout << " ... deleting TOIProcessors @ " << hex << *it << dec << endl;
149 delete *it;
150 }
151}
152
153void CGT::Start()
154{
155 cout << " CGT::Start() starting TOIProcessors ... NProc="
156 << lesProcs.size() << endl;
157 /* for(int i=0; i< lesProcs.size(); i++) {
158 if (dbgLevel > 1)
159 cout << " Staring Proc Id= " << i << " @ " << hex << lesProcs[i] << dec << endl;
160 lesProcs[i]->start();
161 }
162 */
163 TOIManager::getManager()->startAll();
164}
165
166int CGT::findProcId(TOIProcessor* pr)
167{
168 for(int i=0; i< lesProcs.size(); i++)
169 if (lesProcs[i] == pr) return(i);
170
171 lesProcs.push_back(pr);
172 return(lesProcs.size()-1);
173}
Note: See TracBrowser for help on using the repository browser.