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

Last change on this file since 2058 was 2049, checked in by ansari, 23 years ago

Correction mineure ds la classe CGT - Reza 10/6/2002

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