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