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

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

Corrections diverses et introduction d'une classe de calcul de ligne de
base par ajustement glissant d'un polynome (SimpleOffsetEstimator)
avec son programme test - Reza 14/5/2002

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