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