Index: trunk/AddOn/TAcq/brparam.cc
===================================================================
--- trunk/AddOn/TAcq/brparam.cc	(revision 3911)
+++ trunk/AddOn/TAcq/brparam.cc	(revision 3913)
@@ -42,33 +42,75 @@
 }
 
+#define PMAXNBFIBRES 64
 /* --Methode-- */
 BRConfList::BRConfList()
-  : basedir_("./")
-{
+  : basedir_("./"), fiberIds_(PMAXNBFIBRES), tmpdir_("/tmp")
+{
+  InitFromEnv();
 }
 
 /* --Methode-- */
 BRConfList::BRConfList(string basedir)
-  : basedir_(basedir)
-{
+  : basedir_("./"), fiberIds_(PMAXNBFIBRES), tmpdir_("/tmp")
+{
+  InitFromEnv();
+  SetBaseDirectory(basedir);
 }
 
 /* --Methode-- */
 BRConfList::BRConfList(string basedir, vector<ADCBoardDesc> boards)
-  : basedir_(basedir), boards_(boards)
-{
-  size_t len = basedir_.length();
-  if ((len>1)&&(basedir_[len-1]!='/')) basedir_ += '/';
+  : basedir_("./"), fiberIds_(PMAXNBFIBRES), tmpdir_("/tmp")
+{
+  InitFromEnv();
+  SetBaseDirectory(basedir);
+  boards_=boards;
 }
 
 /* --Methode-- */
 BRConfList::BRConfList(BRConfList const & cf)
-  : basedir_(cf.basedir_), boards_(cf.boards_)
-{
-}
-
-/* --Methode-- */
-void BRConfList::SetBaseDirectory(string basedir)
-{
+  : basedir_(cf.basedir_), boards_(cf.boards_), fiberIdsS_(cf.fiberIdsS_), fiberIds_(cf.fiberIds_), tmpdir_(cf.tmpdir_)
+{
+}
+
+/* --Methode-- */
+void BRConfList::InitFromEnv()
+{
+  const char* venvp = NULL; 
+  venvp=getenv("BRACQ_TMPDIR");
+  if (venvp!=NULL) tmpdir_=venvp;
+  else {
+    if (venvp!=NULL) tmpdir_=venvp;
+    venvp = getenv("TMPDIR");
+  }
+  venvp=getenv("BRACQ_BASEDIR");
+  if (venvp!=NULL) { 
+    string ebd=venvp;
+    SetBaseDirectory(ebd);
+  }
+  string fibids="1,2,3,4,5,6,7,8";
+  venvp=getenv("BRACQ_FIBERIDS");
+  if (venvp!=NULL)  fibids=venvp;
+  SetFiberIds(fibids);
+}
+
+/* --Methode-- */
+int BRConfList::SetFiberIds(string& sfids)
+{
+  fiberIdsS_=sfids;
+  vector<string> fibids;
+  FillVStringFrString(sfids, fibids, ',');
+  int rc=0;
+  for (size_t fib=0; fib<fibids.size(); fib++) {
+    if (fib>fiberIds_.size())  break;
+    fiberIds_[fib]=atoi(fibids[fib].c_str()); 
+    rc++;
+  }
+  return rc;
+}
+
+/* --Methode-- */
+void BRConfList::SetBaseDirectory(string& basedir)
+{
+  if (basedir.length()<1)  return;
   basedir_=basedir;
   size_t len = basedir_.length();
@@ -77,8 +119,12 @@
 
 /* --Methode-- */
-void BRConfList::Set(BRConfList const & cf)
+BRConfList& BRConfList::Set(BRConfList const & cf)
 {
   basedir_=cf.basedir_;
   boards_=cf.boards_;
+  fiberIdsS_=cf.fiberIdsS_;
+  fiberIds_=cf.fiberIds_;
+  tmpdir_=cf.tmpdir_;
+  return (*this);
 }
 
@@ -86,6 +132,8 @@
 ostream& BRConfList::Print(ostream& os)
 {
-  os << " ----- BRConfList:: BaseDir:" << basedir_ << " NBoards= " << boards_.size() << endl;
+  os << " ----- BRConfList:: BaseDir=" << basedir_ << " TmpDir=" << tmpdir_ 
+     << " NBoards= " << boards_.size() << endl;
   for(size_t k=0; k<boards_.size(); k++)  boards_[k].Print(os);
+  os << " FiberIdString=" << fiberIdsS_ << endl;
   return os;
 }
@@ -98,5 +146,4 @@
 
 // Classe qui memorise tous les parametres importants de l'acquisition
-#define PMAXNBFIBRES 64
 
 /* --Methode-- */
@@ -110,6 +157,4 @@
 
   FiberListS=fibres;
-  FiberIdsS="1,2,3,4,5,6,7,8";
-  for (int ii=0; ii<PMAXNBFIBRES; ii++)  FiberIds.push_back(ii+1); 
 
   PaqSize=paqsz;
@@ -188,7 +233,5 @@
 
   FiberListS=p.FiberListS;
-  FiberNum=p.FiberNum;
-  FiberIdsS=p.FiberIdsS;
-  FiberIds=p.FiberIds;
+  fiberNum_=p.fiberNum_;
 
   PaqSize=p.PaqSize;
@@ -222,4 +265,7 @@
   pci2eth_fgdirect=p.pci2eth_fgdirect;
   eths_targets=p.eths_targets;
+  eths_stargs=p.eths_stargs;
+  eths_fibtargs=p.eths_fibtargs;
+
   ethr_nlink=p.ethr_nlink;
   ethr_forcesamefc_=p.ethr_forcesamefc_;
@@ -254,6 +300,4 @@
   else if(conf.HasKey("fibers")) 
     FiberListS= conf.SParam("fibers",0,"1");
-  if(conf.HasKey("fiberids"))   
-    FiberIdsS= conf.SParam("fiberids",0,"1");
 
   OutPathName= conf.SParam("outpathname",0,"TstAcq");
@@ -280,8 +324,21 @@
   tcpportid=conf.IParam("tcpportid",0,BRSPORTID);
   if (conf.HasKey("pci2ethdirect"))  pci2eth_fgdirect = true;   // Transfer direct DMA -> Ethernet
-  if (conf.HasKey("ethrtargets")) {    // Machines destinations des paquets 
+  if (conf.HasKey("ethrtargets")) {    // Machines destinations des paquets - memes destinations pour toutes les fibres
     for(int it=0; it<conf.NbParam("ethrtargets"); it++) 
-      eths_targets.push_back(conf.SParam("ethrtargets",it));
-  }
+      eths_stargs.push_back(conf.SParam("ethrtargets",it));
+  }
+
+  const char* ethtf[9]={"ethrtargetsf1","ethrtargetsf2","ethrtargetsf3","ethrtargetsf4",
+                        "ethrtargetsf5","ethrtargetsf6","ethrtargetsf7","ethrtargetsf8"};
+  for(int jj=0;jj<8;jj++) {
+    if (conf.HasKey( ethtf[jj] )) {
+      vector<string> ftargs;
+      int fid=jj+1;
+      for(int it=0; it<conf.NbParam( ethtf[jj] ); it++)
+	ftargs.push_back(conf.SParam( ethtf[jj] ,it));
+      eths_fibtargs[fid]=ftargs;      
+    }
+  }
+
   ethr_nlink=conf.IParam("ethrnlink",0,0);   // Nombre de sources de paquets en reception ethernet 
   if (conf.HasKey("ethrforcesamefc"))  {
@@ -328,12 +385,14 @@
   vector<string> fiblist;
   FillVStringFrString(FiberListS, fiblist, ',');
-  FiberNum.resize(fiblist.size());
+  fiberNum_.resize(fiblist.size());
   for (int fib=0; fib<fiblist.size(); fib++) {
-    FiberNum[fib]=atoi(fiblist[fib].c_str()); 
-  }
-  vector<string> fibids;
-  FillVStringFrString(FiberIdsS, fibids, ',');
-  for (int fib=0; fib<fibids.size(); fib++) {
-    FiberIds[fib]=atoi(fibids[fib].c_str()); 
+    fiberNum_[fib]=atoi(fiblist[fib].c_str()); 
+  }
+
+  eths_targets.resize(fiberNum_.size());
+  for (int fib=0; fib<fiberNum_.size(); fib++) {
+    map< int, vector<string> >::const_iterator itm=eths_fibtargs.find(fiberNum_[fib]);
+    if (itm != eths_fibtargs.end())   eths_targets[fib]=itm->second;
+    else eths_targets[fib]=eths_stargs;
   }
 
@@ -414,8 +473,4 @@
   os << " ------ BRParList::Print() ----- " << endl;
   os << " FiberListS=" << FiberListS ;
-  os << " FiberIdsS=" << FiberIdsS ;
-  os << " Fibers (Num->Id): ";
-  for(size_t f=0; f<NbFibers(); f++)   cout << FiberNum[f] << " -> " << FiberIds[f] << " ; " ;
-  os << endl;
   os << " PaqSize=" <<PaqSize;
   os << " DMA_Size_kb=" <<dmasizekb << " (EndDMA: Maxkw=" << maxkwedma_ << " NRetry=" << nretrydma_ 
@@ -432,17 +487,22 @@
     os << " PaquetSize Reduction, ReducedSize=" << redpqsize << " Offset=" << reducoffset << endl;
   }
-  if (eths_targets.size()>0)   {
-    cout << " DMA->Ethernet NbTargets=" << eths_targets.size() 
-	 << ((pci2eth_fgdirect)?" (DirectTransferMode) " : " " ) << " :";
-    for(size_t it=0; it<eths_targets.size(); it++) cout << eths_targets[it] << " , ";
-    cout << endl;
-  }
-  cout << " TCP-PortId=" << tcpportid << " EthernetRead NbSources (=NbLinks)= " << ethr_nlink << endl;
+  if ((eths_stargs.size()>0)||(eths_fibtargs.size()>0))   {
+    os << " DMA->Ethernet Targets=" << eths_targets.size() 
+	 << ((pci2eth_fgdirect)?" (DirectTransferMode) " : " " ) << endl;
+    
+    for(size_t fib=0; fib<eths_targets.size(); fib++) {
+      os << " Fiber Num=" << fiberNum_[fib] << " --> eth_targets: ";
+      for(size_t it=0; it<eths_targets[fib].size(); it++)
+	os << eths_targets[fib][it] << " ; ";
+    os << endl;
+    }
+  }
+  os << " TCP-PortId=" << tcpportid << " EthernetRead NbSources (=NbLinks)= " << ethr_nlink << endl;
   if (ethr_forcesamefc_)
-    cout << "EthernetReader mode: ForceSameFrameCounter read mode with Max_PaquetCounterDiff= " 
+    os << "EthernetReader mode: ForceSameFrameCounter read mode with Max_PaquetCounterDiff= " 
 	 << ethr_sfc_maxdpc_ << " MaxNbResync=" << ethr_sfc_maxresync_ 
 	 << ((ethr_waitendmsg_)?" Wait_For_END_Message_Before_Terminate ":" ") << endl;
   else
-    cout << "EthernetReader mode: AllOKPaquets read mode " 
+    os << "EthernetReader mode: AllOKPaquets read mode " 
 	 << ((ethr_waitendmsg_)?" Wait_For_END_Message_Before_Terminate ":" ") << endl;
 
@@ -483,4 +543,8 @@
   config_->Print(os);
   param_->Print(os); 
+  os << " Fibers f: Num->Id  ";
+  for(size_t f=0; f<NbFibers(); f++)   
+    os << f << ": " << FiberNum(f) << " -> " << FiberId(f) << " ; " ;
+  os << endl;
   os << " ----------------------------------------------------- " << endl;
 }
@@ -501,5 +565,5 @@
     memset(cmd,0,1024); 
     for (int  i= 0; i< NFibers() ; i++)  {
-      sprintf(cmd,"mkdir %s%s/Fiber%d",config_->BaseDirectory().c_str(), param_->OutPathName.c_str(),param_->FiberNum[i]);
+      sprintf(cmd,"mkdir %s%s/Fiber%d",config_->BaseDirectory().c_str(), param_->OutPathName.c_str(),param_->fiberNum_[i]);
       if (system(cmd) < 0) {
 	cout << "CreateOutputDirectories()/Error: Can not create subdirectory " 
@@ -529,5 +593,5 @@
 {
   char buff[24];
-  sprintf(buff,"Fiber%d/",param_->FiberNum[ifib]);
+  sprintf(buff,"Fiber%d/",param_->fiberNum_[ifib]);
   return ( config_->BaseDirectory() + param_->OutPathName + buff );
 }
