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 |
|
---|
18 | #ifdef WITH_SOPHYA
|
---|
19 | #include "pexceptions.h"
|
---|
20 | #else
|
---|
21 | #include "apexceptions.h"
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <pthread.h>
|
---|
25 |
|
---|
26 | CGT::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 | }
|
---|
36 | SetDebugLevel();
|
---|
37 | }
|
---|
38 |
|
---|
39 | CGT::~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 |
|
---|
52 | void CGT::SelectTOISegmented(int bufsz, int maxseg)
|
---|
53 | {
|
---|
54 | fgSegmented = true;
|
---|
55 | fgSeqbuff = false;
|
---|
56 | segBuffsz = bufsz;
|
---|
57 | segMaxseg = maxseg;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void CGT::SelectTOISeqBuffered(int wsz)
|
---|
61 | {
|
---|
62 | fgSeqbuff = true;
|
---|
63 | fgSegmented = false;
|
---|
64 | seqWsz = wsz;
|
---|
65 | }
|
---|
66 |
|
---|
67 | TOI& CGT::Connect(TOIProcessor& prout, string& out,
|
---|
68 | TOIProcessor& prin, string& in, string nom, int wbsz, bool withFlag)
|
---|
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);
|
---|
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);
|
---|
93 | if (dbgLevel > 1)
|
---|
94 | cout << " CGT::Connect() TOI " << toi->getName() << " created " << endl;
|
---|
95 | return(*toi);
|
---|
96 | }
|
---|
97 |
|
---|
98 | TOI& CGT::Connect(TOIProcessor& prout, const char* out,
|
---|
99 | TOIProcessor& prin, const char* in, string nom, int wbsz, bool withFlag)
|
---|
100 | {
|
---|
101 | string outs = out;
|
---|
102 | string ins = in;
|
---|
103 | return Connect(prout, outs, prin, ins, nom, wbsz, withFlag);
|
---|
104 | }
|
---|
105 |
|
---|
106 | void 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++) {
|
---|
112 | os << " >> Proc Id= " << i << " @ " << hex << lesProcs[i] << dec ;
|
---|
113 | string ctyp = typeid(*lesProcs[i]).name();
|
---|
114 | os << " Type= " << ctyp << endl;
|
---|
115 | if (prstat) lesProcs[i]->PrintStatus(os);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | void CGT::ListTOIs(::ostream& os, bool prstat)
|
---|
120 | {
|
---|
121 | os << " --- CGT::ListTOIs() , NbTOIs=" << lesTuyaux.size();
|
---|
122 | if ( fgSegmented ) os << " Default TOI: TOISegmented " << endl;
|
---|
123 | else os << " Default TOI: TOISeqBuffered " << endl;
|
---|
124 | for(int i=0; i< lesTuyaux.size(); i++) {
|
---|
125 | os << " >> TOI " << lesTuyaux[i].toi->getName() << " Connecting Procs (Id): "
|
---|
126 | << lesTuyaux[i].pr1id << " <---> " << lesTuyaux[i].pr2id << endl;
|
---|
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;
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | void CGT::PrintStatus(::ostream & os, bool prstat)
|
---|
135 | {
|
---|
136 | ListProcs(os, prstat);
|
---|
137 | ListTOIs(os, prstat);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void 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 |
|
---|
152 | void 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 |
|
---|
163 | int 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 | }
|
---|