CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CommonTools/TrackerMap/src/TrackerMap.cc

Go to the documentation of this file.
00001 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00002 #include "CommonTools/TrackerMap/interface/TmModule.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/ParameterSet/interface/FileInPath.h"
00005 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00006 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00007 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00008 #include "CommonTools/TrackerMap/interface/TmApvPair.h"
00009 #include "CommonTools/TrackerMap/interface/TmCcu.h"
00010 #include "CommonTools/TrackerMap/interface/TmPsu.h"
00011 #include <fstream>
00012 #include <vector>
00013 #include <iostream>
00014 #include <sstream>
00015 #include "TCanvas.h"
00016 #include "TPolyLine.h"
00017 #include "TStyle.h"
00018 #include "TColor.h"
00019 #include "TROOT.h"
00020 #include "TGaxis.h"
00021 #include "TLatex.h"
00022 #include "TArrow.h"
00023 
00024 
00025 /**********************************************************
00026 Allocate all the modules in a map of TmModule
00027 The filling of the values for each module is done later
00028 when the user starts to fill it.
00029 **********************************************************/
00030 
00031 TrackerMap::TrackerMap(const edm::ParameterSet & tkmapPset,const SiStripFedCabling* tkFed) {
00032 
00033  psetAvailable=true;
00034   xsize=340;ysize=200;
00035 
00036   title=" ";
00037   jsPath="";
00038   jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00039   infilename="CommonTools/TrackerMap/data/tracker.dat";
00040   saveAsSingleLayer=false;
00041   tkMapLog = false;
00042   //  if(tkmapPset.exists("trackermaptxtPath")){
00043   jsPath=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath","CommonTools/TrackerMap/data/");
00044   jsfilename=jsPath+"trackermap.txt";
00045   std::cout << jsfilename << std::endl;
00046   infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","CommonTools/TrackerMap/data/")+"tracker.dat";
00047   std::cout << infilename << std::endl;
00048   saveWebInterface=tkmapPset.getUntrackedParameter<bool>("saveWebInterface",false);
00049   saveGeoTrackerMap=tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap",true);
00050   ncrates=0;
00051   firstcrate=0;
00052   enableFedProcessing=tkmapPset.getUntrackedParameter<bool>("loadFedCabling",false);
00053   if(tkFed==0 && enableFedProcessing){enableFedProcessing=false;std::cout << "ERROR:fed trackermap requested but no valid fedCabling is available!!!"<<std::endl;}
00054   nfeccrates=0;
00055   enableFecProcessing=tkmapPset.getUntrackedParameter<bool>("loadFecCabling",false);
00056   if(tkFed==0 && enableFecProcessing){enableFecProcessing=false;std::cout << "ERROR:fec trackermap requested but no valid fedCabling is available!!!"<<std::endl;} 
00057  // std::cout << "loadFecCabling " << enableFecProcessing << std::endl;
00058   npsuracks=0;
00059   enableLVProcessing=tkmapPset.getUntrackedParameter<bool>("loadLVCabling",false);
00060  // std::cout << "loadLVCabling " << enableLVProcessing << std::endl;
00061   enableHVProcessing=tkmapPset.getUntrackedParameter<bool>("loadHVCabling",false);
00062  // std::cout << "loadHVCabling " << enableHVProcessing << std::endl;
00063   tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale",false);
00064   //  } else std::cout << "no parameters found" << std::endl;
00065 
00066  init();
00067 // Now load fed cabling information
00068  if(enableFedProcessing){
00069  const std::vector<unsigned short> feds = tkFed->feds();
00070   std::cout<<"SiStripFedCabling has "<< feds.size()<<" active FEDS"<<std::endl;
00071   //    int num_board=0;
00072     //    int num_crate=0;
00073   for(std::vector<unsigned short>::const_iterator ifed = feds.begin();ifed<feds.end();ifed++){
00074     const std::vector<FedChannelConnection> theconn = tkFed->connections( *ifed );
00075     int num_conn=0;
00076     for(std::vector<FedChannelConnection>::const_iterator iconn = theconn.begin();iconn<theconn.end();iconn++){
00077 
00078       if( iconn->fedId()== sistrip::invalid_    ||  
00079           iconn->detId() == sistrip::invalid_   ||  
00080           iconn->detId() == sistrip::invalid32_ ||  
00081           iconn->apvPairNumber() == sistrip::invalid_  ||
00082           iconn->nApvPairs() == sistrip::invalid_ ) {
00083         continue;
00084       }
00085         
00086       TmModule *imod = imoduleMap[iconn->detId()];
00087       int key = iconn->fedId()*1000+iconn->fedCh();
00088       TmApvPair* apvpair = apvMap[key];
00089       if(apvpair!=0)std::cout << "Fed "<< iconn->fedId() << " channel " << iconn->fedCh() << " seem to be already loaded!"<<std::endl;
00090       else
00091         {
00092           num_conn++;
00093           if(num_conn==1){
00094             //      if(fedMap[iconn->fedId()]==0){num_crate=num_board/18+1;fedMap[iconn->fedId()]=num_crate;num_board++;}
00095             if(fedMap[iconn->fedId()]==0){fedMap[iconn->fedId()]=iconn->fedCrate();}
00096             if(slotMap[iconn->fedId()]==0){slotMap[iconn->fedId()]=iconn->fedSlot();}
00097             if(ncrates==0 || ncrates < iconn->fedCrate()) ncrates = iconn->fedCrate();
00098             if(firstcrate==0 || firstcrate > iconn->fedCrate()) firstcrate = iconn->fedCrate();
00099           }
00100 
00101           //      apvpair = new TmApvPair(key,num_crate);
00102           apvpair = new TmApvPair(key,iconn->fedCrate());
00103           apvpair->mod=imod;
00104           apvpair->mpos=iconn->apvPairNumber();
00105           apvMap[key] = apvpair;        
00106           apvModuleMap.insert(std::make_pair(iconn->detId(),apvpair));
00107           std::stringstream s;
00108           iconn->print(s);  
00109           apvpair->text=s.str();
00110         }
00111     }
00112   }
00113   //  ncrates=num_crate;
00114   std::cout << "from " << firstcrate << " to " << ncrates << " crates used "<< std::endl;
00115 //Now add APv information to module name
00116     std::map<int , TmModule *>::iterator i_mod;
00117     for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
00118       TmModule *  mod= i_mod->second;
00119       if(mod!=0) {
00120         std::ostringstream outs,outs1;
00121        outs << " connected to ";
00122        outs1 << "(";
00123 
00124       int idmod=mod->idex;
00125        int nchan=0;
00126        std::multimap<const int, TmApvPair*>::iterator pos;
00127        for (pos = apvModuleMap.lower_bound(idmod);
00128          pos != apvModuleMap.upper_bound(idmod); ++pos) {
00129        TmApvPair* apvpair = pos->second;
00130        if(apvpair!=0){
00131        outs << apvpair->mpos << " " <<apvpair->getFedId() << "/"<<apvpair->getFedCh()<<" ";
00132        outs1 << apvpair->idex+apvpair->crate*1000000<<",";
00133       nchan++;
00134     }
00135 
00136   }
00137        outs<< "("<<nchan<<")";
00138       mod->name=mod->name + outs.str(); 
00139       std::string s = outs1.str(); s.erase(s.end()-1,s.end());
00140       mod->capvids=s+")";
00141   }
00142   }
00143 }
00144 // Now load fec cabling information
00145  if(enableFecProcessing){
00146    int nfec=0; int nccu; int nmod;
00147    int crate,slot,ring,addr,pos;
00148    SiStripFecCabling* fecCabling_;
00149    fecCabling_ = new SiStripFecCabling( *tkFed );
00150    std::string Ccufilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"cculist.txt";
00151    ifstream Ccufile(edm::FileInPath(Ccufilename).fullPath().c_str(),std::ios::in);
00152    std::string dummys;
00153    while(!Ccufile.eof()) {
00154      Ccufile >> crate >> slot >> ring >> addr >> pos;
00155      getline(Ccufile,dummys);
00156      int key =crate*10000000+slot*100000+ring*1000+addr;
00157      TmCcu * ccu = ccuMap[key];
00158      if(ccu==0){
00159        ccu = new TmCcu(crate,slot,ring,addr);
00160        ccu->mpos=pos,
00161          ccuMap[key]=ccu;
00162      }
00163    }
00164 
00165    for ( std::vector<SiStripFecCrate>::const_iterator icrate = fecCabling_->crates().begin(); icrate != fecCabling_->crates().end(); icrate++ ) {
00166      for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
00167        for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
00168          nccu=0;nfec++;
00169          for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
00170            nccu++; nmod=0;
00171            int key = icrate->fecCrate()*10000000+ifec->fecSlot()*100000+iring->fecRing()*1000+iccu->ccuAddr();
00172            int layer=0;
00173            TmCcu * ccu = ccuMap[key];
00174            for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
00175              nmod++;
00176              TmModule *imod1 = imoduleMap[imod->detId()];
00177              layer=imod1->layer;
00178              fecModuleMap.insert(std::make_pair(ccu,imod1));
00179              if(imod1!=0)imod1->CcuId=key;//imod1->ccuId=key+Crate*1000000
00180            }
00181            if(ccu==0)std::cout <<key<< " This ccu seems to have not been stored! " << std::endl; else{ ccu->nmod=nmod;ccu->layer=layer;}
00182            //std::cout <<nfec<<" "<< nccu << " " << nmod << std::endl;
00183 
00184          }
00185        }
00186      }
00187    }
00188 
00189    std::map<int , TmCcu *>::iterator i_ccu;
00190    std::multimap<TmCcu*, TmModule*>::iterator it;
00191    std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
00192    nccu=0;
00193    for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
00194      TmCcu *  ccu= i_ccu->second;
00195      nccu++;
00196      if(ccu!=0){
00197        std::ostringstream outs;
00198        std::ostringstream outs1;
00199        outs << "CCU "<<ccu->idex <<" connected to fec,ring " << ccu->getCcuSlot() <<","<<ccu->getCcuRing()<< " in crate " <<ccu->getCcuCrate()<<" at position "<< ccu->mpos << " with  " << ccu->nmod << " modules: ";
00200         outs1<<"(";
00201         ret = fecModuleMap.equal_range(ccu);
00202         for (it = ret.first; it != ret.second; ++it)
00203           {
00204             outs << (*it).second->idex << " ";
00205             outs1 << (*it).second->getKey() <<",";
00206           }
00207         outs1 << ")";
00208         ccu->text=outs.str();
00209         ccu->cmodid=outs1.str();
00210         //std::cout << ccu->text << std::endl;
00211      }
00212 
00213    }
00214    nfeccrates=4;
00215    std::cout << nccu << " ccu stored in " <<nfeccrates<< " crates"<< std::endl;
00216 
00217    delete fecCabling_ ;
00218 
00219  }
00220 //load Psu cabling info
00221  //load Psu cabling info 
00222  if(enableLVProcessing || enableHVProcessing){
00223 
00224    SiStripDetCabling* detCabling = 0;
00225    if(enableFedProcessing) detCabling = new SiStripDetCabling( *tkFed );
00226 
00227 
00228    int npsu=0; int nmod,nmodHV2,nmodHV3;
00229    int modId1, dcuId; // ,modId2;
00230    int dcs,branch,crate,board;
00231    int rack=0;
00232    std::string channelstr1;
00233    short int channel;
00234    std::string psinfo;
00235    std::string psIdinfo;
00236    int rack_order[54]={0,1,0,2,0,3,0,
00237                          4,0,5,6,0,7,
00238                          8,0,9,10,0,11,
00239                          12,0,13,14,0,15,
00240                          0,0,0,0,0,0,
00241                          16,0,17,18,0,19,
00242                          20,0,21,0,22,0,
00243                          23,0,24,25,0,26,
00244                          27,0,28,0,29};
00245  //  ifstream *LVfile;
00246  //  ifstream *HVfile;
00247    
00248   
00249  
00250   std::string LVfilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","CommonTools/TrackerMap/data/")+"psdcumap.dat";
00251   //std::string HVfilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"hvmap.dat";
00252   
00253   ifstream LVfile(edm::FileInPath(LVfilename).fullPath().c_str(),std::ios::in);
00254   
00255   std::cout<<LVfilename<<std::endl;
00256   
00257  /* 
00258    if(enableHVProcessing){
00259             ifstream HVfile(edm::FileInPath(HVfilename).fullPath().c_str(),std::ios::in);
00260             while(!HVfile.eof()) {
00261             HVfile >> modId2 >> channelstr1;
00262             std::string channelstr2 = channelstr1.substr(9,1);
00263             channel= atoi(channelstr2.c_str());
00264             TmModule *imod = imoduleMap[modId2];
00265            // if(modId1==modId2){
00266             imod->HVchannel=channel;      
00267            
00268               } 
00269                 
00270             }
00271 */
00272         
00273   
00274    while(!LVfile.eof()) {
00275       LVfile >> modId1  >> dcuId >> psIdinfo >> psinfo;
00276       
00277       if(detCabling && detCabling->getConnections(modId1).size()==0) continue;
00278 
00279       //      int length=psinfo.length();
00280       std::string dcsinfo = psinfo.substr(39,1);
00281       std::string branchinfo = psinfo.substr(57,2);
00282       std::string crateinfo= psinfo.substr(69,1);
00283       std::string boardinfo = psinfo.substr(80,2);
00284       std::string channelinfo = psinfo.substr(90,3);
00285     
00286       dcs= atoi(dcsinfo.c_str());
00287       branch= atoi(branchinfo.c_str());
00288       crate= atoi(crateinfo.c_str())+1;
00289       board= atoi(boardinfo.c_str())+1;
00290       rack = (branch+1)+(dcs-1)*6; 
00291       rack = rack_order[rack]; 
00292       channel = atoi(channelinfo.c_str());
00293       //      std::cout << dcs << " " << branch<< " " <<crate<< " " << board<<" " << rack << std::endl;
00294       int key = rack*1000+crate*100+board;
00295       
00296       TmPsu *psu = psuMap[key];
00297       TmModule *imod = imoduleMap[modId1];
00298       if(psu==0){
00299         psu = new TmPsu(dcs,branch,rack,crate,board);
00300         psuMap[key]=psu;
00301         psu->psId=psIdinfo;
00302       }
00303    
00304       psuModuleMap.insert(std::make_pair(psu,imod));
00305       if(imod!=0){imod->PsuId=psIdinfo;imod->psuIdex=psu->idex;imod->HVchannel=channel;}
00306        
00307    }
00308       
00309    
00310  //  int nmax=0; 
00311    std::map<int , TmPsu *>::iterator ipsu;
00312    std::multimap<TmPsu*, TmModule*>::iterator it;
00313    std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
00314    npsu=0;
00315   
00316    for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
00317      TmPsu *  psu= ipsu->second;
00318      npsu++;
00319     
00320     if(psu!=0){
00321         
00322       std::ostringstream outs;
00323       std::ostringstream outs1;
00324         
00325       std::ostringstream outs3;
00326       std::ostringstream outs4;
00327         
00328       std::ostringstream outs5;
00329       std::ostringstream outs6;
00330         
00331         outs <<"PSU "<<psu->psId<<" connected to Mainframe "<<psu->getPsuDcs()<<" BranchController "<<psu->getPsuBranch()<<" (Rack "<<psu->getPsuRack()<<"), crate "<<psu->getPsuCrate()<<" in position "<< psu->getPsuBoard()<< " with modules: ";
00332         outs1<<"(";
00333         
00334         if(enableHVProcessing){
00335           outs3 <<"PSU "<<psu->psId<<" connected to Mainframe "<<psu->getPsuDcs()<<" BranchController "<<psu->getPsuBranch()<<" (Rack "<<psu->getPsuRack()<<"),crate "<<psu->getPsuCrate()<<" in position "<< psu->getPsuBoard()<<" and HV channel 002 with modules: ";
00336           outs4<<"(";
00337         
00338           outs5 <<"PSU "<<psu->psId<<" connected to Mainframe "<<psu->getPsuDcs()<<" BranchController "<<psu->getPsuBranch()<<" (Rack "<<psu->getPsuRack()<<"), crate "<<psu->getPsuCrate()<<" in position "<< psu->getPsuBoard()<<" and HV channel 002 with modules: ";
00339           outs6<<"(";}
00340         
00341         
00342         ret = psuModuleMap.equal_range(psu);
00343         nmod=0;
00344         nmodHV2=0;
00345         nmodHV3=0;
00346         for (it = ret.first; it != ret.second; ++it)
00347           {
00348             nmod++; 
00349             outs << (*it).second->idex << ", ";
00350             outs1 << (*it).second->getKey() <<",";
00351         
00352             if(enableHVProcessing){
00353               if((*it).second->HVchannel==2){
00354               nmodHV2++;
00355               outs3 << (*it).second->idex << ", ";
00356               outs4 << (*it).second->getKey() <<",";}
00357               else if((*it).second->HVchannel==3){
00358               nmodHV3++;
00359               outs5 << (*it).second->idex << ", ";
00360               outs6 << (*it).second->getKey() <<",";}
00361         
00362               }
00363           }
00364 
00365         outs1 << ")";
00366         psu->nmod=nmod;
00367         outs << "(" << psu->nmod << ")";
00368         psu->text=outs.str();
00369         psu->cmodid_LV=outs1.str();
00370         if(enableHVProcessing){
00371         outs4 << ")";
00372         outs6 << ")";
00373         psu->nmodHV2=nmodHV2;
00374         psu->nmodHV3=nmodHV3;
00375         outs3 << "(" << psu->nmodHV2 << ")";
00376         outs5 << "(" << psu->nmodHV3 << ")";
00377         psu->textHV2=outs3.str();
00378         psu->textHV3=outs5.str();
00379         psu->cmodid_HV2=outs4.str();
00380         psu->cmodid_HV3=outs6.str();
00381         }
00382     }
00383    }
00384   
00385   
00386    npsuracks=29;
00387    std::cout << npsu << " psu stored in " <<npsuracks<<" racks"<<std::endl;
00388   }
00389 }
00390 
00391 TrackerMap::TrackerMap(const edm::ParameterSet & tkmapPset) {
00392  psetAvailable=true;
00393   xsize=340;ysize=200;
00394   title=" ";
00395   jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00396   infilename="CommonTools/TrackerMap/data/tracker.dat";
00397   enableFedProcessing=true;ncrates=0;firstcrate=0;
00398   saveAsSingleLayer=false;
00399   tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale",false);
00400   saveWebInterface=tkmapPset.getUntrackedParameter<bool>("saveWebInterface",false);
00401   saveGeoTrackerMap=tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap",true);
00402   //  if(tkmapPset.exists("trackermaptxtPath")){
00403   jsfilename=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath","CommonTools/TrackerMap/data/")+"trackermap.txt";
00404   std::cout << jsfilename << std::endl;
00405   infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","CommonTools/TrackerMap/data/")+"tracker.dat";
00406   std::cout << infilename << std::endl;
00407   //  } else std::cout << "no parameters found" << std::endl;
00408  init();
00409 }
00410 
00411 TrackerMap::TrackerMap(std::string s,int xsize1,int ysize1) {
00412  psetAvailable=false;
00413   xsize=xsize1;ysize=ysize1;
00414   title=s;
00415   jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00416   infilename="CommonTools/TrackerMap/data/tracker.dat";
00417   saveWebInterface=false;
00418   saveGeoTrackerMap=true;
00419   tkMapLog=false;
00420   jsPath="CommonTools/TrackerMap/data/";
00421   enableFedProcessing=false; 
00422   enableFecProcessing=false; 
00423   enableLVProcessing=false; 
00424   enableHVProcessing=false; 
00425   saveAsSingleLayer=false;
00426  init();
00427 
00428 }
00429 
00430 void TrackerMap::reset() {
00431 std::map<int , TmModule *>::iterator i_mod;
00432     for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
00433       TmModule *  mod= i_mod->second;
00434       mod->count=0;mod->value=0;mod->red=-1;
00435       }
00436 }
00437 
00438 void TrackerMap::init() {
00439   
00440   int ntotmod=0;
00441   ix=0;iy=0; //used to compute the place of each layer in the tracker map
00442   firstcall = true;
00443   minvalue=0.; maxvalue=minvalue;
00444   posrel=true;
00445   palette = 1;
00446   printflag=true;
00447   addPixelFlag=false;
00448   temporary_file=false;
00449   gminvalue=0.; gmaxvalue=0.;//default global range for online rendering
00450 
00451   ndet = 3; // number of detectors: pixel, inner silicon, outer silicon
00452   npart = 3; // number of detector parts: endcap -z, barrel, endcap +z
00453 
00454   //allocate module map
00455   for (int subdet=1; subdet < ndet+1; subdet++){//loop on subdetectors
00456     for (int detpart=1; detpart < npart+1; detpart++){//loop on subdetectors parts
00457       int nlayers = getlayerCount(subdet,detpart); // compute number of layers
00458       for(int layer=1; layer < nlayers+1; layer++){//loop on layers
00459         int nrings = getringCount(subdet,detpart,layer);// compute number of rings
00460         //fill arrays used to do the loop on the rings  
00461         int layer_g = nlayer(subdet,detpart,layer);
00462         ntotRing[layer_g-1]=nrings;
00463         firstRing[layer_g-1]=1;
00464         if(subdet==3 && detpart!=2)  firstRing[layer_g-1]= 8-nrings; //special numbering for TEC 
00465         for (int ring=firstRing[layer_g-1]; ring < ntotRing[layer_g-1]+firstRing[layer_g-1];ring++){//loop on rings
00466           int nmodules = getmoduleCount(subdet,detpart,layer,ring);// compute number of modules
00467           int key=0;
00468           TmModule *smodule; 
00469           for(int module=1; module < nmodules+1; module++){//loop on modules
00470             smodule = new TmModule(module,ring,layer_g);
00471             key=layer_g*100000+ring*1000+module;//key identifying module
00472             smoduleMap[key]=smodule;
00473             ntotmod++;
00474           }
00475           if(isRingStereo(key))for(int module=1; module < nmodules+1; module++){//loop on stereo modules
00476             smodule = new TmModule(module+100,ring,layer_g);
00477             int key=layer_g*100000+ring*1000+module+100;
00478             smoduleMap[key]=smodule;
00479             ntotmod++;
00480           }
00481         }
00482       }
00483     }
00484   }
00485  build();
00486 }
00487 
00488 TrackerMap::~TrackerMap() {
00489  
00490 for (int layer=1; layer < 44; layer++){
00491     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00492       for (int module=1;module<200;module++) {
00493         int key=layer*100000+ring*1000+module;
00494         TmModule * mod = smoduleMap[key];
00495         if(mod !=0 ) delete mod;
00496       }
00497     }
00498   }
00499 
00500 //std::map<int , TmModule *>::iterator i_mod;
00501 //   for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
00502 //      TmModule *  mod= i_mod->second;
00503 //      delete mod;
00504 //      }
00505 std::map<int , TmApvPair *>::iterator i_apv;
00506   for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
00507       TmApvPair *  apvPair= i_apv->second;
00508       delete apvPair;
00509       }
00510 
00511 
00512 std::map<int , TmCcu *>::iterator i_ccu;
00513    for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
00514      TmCcu *  ccu= i_ccu->second;
00515      delete ccu;
00516      }
00517 
00518 std::map<int , TmPsu *>::iterator ipsu;
00519     for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
00520      TmPsu *  psu= ipsu->second;
00521      delete psu;
00522      }
00523 
00524 gROOT->Reset();
00525 
00526 
00527 //for(std::vector<TColor*>::iterator col1=vc.begin();col1!=vc.end();col1++){
00528 //     std::cout<<(*col1)<<std::endl;}
00529 }
00530 
00531 
00532 
00533 
00534 
00535 void TrackerMap::drawModule(TmModule * mod, int key,int mlay, bool print_total, std::ofstream * svgfile){
00536   //int x,y;
00537   nlay = mlay;
00538   double phi,r,dx,dy, dy1;
00539   double xp[4],yp[4],xp1,yp1;
00540   double vhbot,vhtop,vhapo;
00541   double rmedio[]={0.041,0.0701,0.0988,0.255,0.340,0.430,0.520,0.610,0.696,0.782,0.868,0.965,1.080};
00542   double xt1,yt1,xs1=0.,ys1=0.,xt2,yt2,xs2,ys2,pv1,pv2;
00543   int green = 0;
00544   int red = 0;
00545   int blue = 0;
00546   double xd[4],yd[4];
00547   int np = 4;
00548   //int numrec=0;
00549   int numod=0;
00550   phi = phival(mod->posx,mod->posy);
00551   r = sqrt(mod->posx*mod->posx+mod->posy*mod->posy);
00552   vhbot = mod->width;
00553   vhtop=mod->width;
00554   vhapo=mod->length;
00555   if(mlay < 31){ //endcap
00556     vhbot = mod->widthAtHalfLength/2.-(mod->width/2.-mod->widthAtHalfLength/2.);
00557     vhtop=mod->width/2.;
00558     vhapo=mod->length/2.;
00559     if(mlay >12 && mlay <19){
00560       if(posrel)r = r+r;
00561       xp[0]=r-vhtop;yp[0]=-vhapo;
00562       xp[1]=r+vhtop;yp[1]=-vhapo;
00563       xp[2]=r+vhtop;yp[2]=vhapo;
00564       xp[3]=r-vhtop;yp[3]=vhapo;
00565     }else{
00566       if(posrel)r = r + r/3.;
00567       xp[0]=r-vhapo;yp[0]=-vhbot;
00568       xp[1]=r+vhapo;yp[1]=-vhtop;
00569       xp[2]=r+vhapo;yp[2]=vhtop;
00570       xp[3]=r-vhapo;yp[3]=vhbot;
00571     }
00572     for(int j=0;j<4;j++){
00573       xp1 = xp[j]*cos(phi)-yp[j]*sin(phi);
00574       yp1 = xp[j]*sin(phi)+yp[j]*cos(phi);
00575       xp[j] = xp1;yp[j]=yp1;
00576     }
00577   } else { //barrel
00578     numod=mod->idModule;if(numod>100)numod=numod-100;
00579     int vane = mod->ring;
00580     if(posrel){
00581       dx = vhapo;
00582       phi=M_PI;
00583       xt1=rmedio[mlay-31]; yt1=-vhtop/2.;
00584       xs1 = xt1*cos(phi)-yt1*sin(phi);
00585       ys1 = xt1*sin(phi)+yt1*cos(phi);
00586       xt2=rmedio[mlay-31]; yt2=vhtop/2.;
00587       xs2 = xt2*cos(phi)-yt2*sin(phi);
00588       ys2 = xt2*sin(phi)+yt2*cos(phi);
00589       dy=phival(xs2,ys2)-phival(xs1,ys1);
00590          dy1 = dy;
00591       if(mlay==31)dy1=0.39;
00592       if(mlay==32)dy1=0.23;
00593       if(mlay==33)dy1=0.16;
00594       xp[0]=vane*(dx+dx/8.);yp[0]=numod*(dy1);
00595       xp[1]=vane*(dx+dx/8.)+dx;yp[1]=numod*(dy1);
00596       xp[2]=vane*(dx+dx/8.)+dx;yp[2]=numod*(dy1)+dy;
00597       xp[3]=vane*(dx+dx/8.);yp[3]=numod*(dy1)+dy;
00598     }else{
00599       xt1=r; yt1=-vhtop/2.;
00600       xs1 = xt1*cos(phi)-yt1*sin(phi);
00601       ys1 = xt1*sin(phi)+yt1*cos(phi);
00602       xt2=r; yt2=vhtop/2.;
00603       xs2 = xt2*cos(phi)-yt2*sin(phi);
00604       ys2 = xt2*sin(phi)+yt2*cos(phi);
00605       pv1=phival(xs1,ys1);
00606       pv2=phival(xs2,ys2);
00607       if(fabs(pv1-pv2)>M_PI && numod==1)pv1=pv1-2.*M_PI;
00608       if(fabs(pv1-pv2)>M_PI && numod!=1)pv2=pv2+2.*M_PI;
00609       xp[0]=mod->posz-vhapo/2.;yp[0]=4.2*pv1;
00610       xp[1]=mod->posz+vhapo/2.;yp[1]=4.2*pv1;
00611       xp[2]=mod->posz+vhapo/2. ;yp[2]=4.2*pv2;
00612           xp[3]=mod->posz-vhapo/2.;yp[3]=4.2*pv2;
00613     }
00614   }
00615   if(isRingStereo(key))
00616         {
00617           np = 3;
00618           if(mod->idModule>100 ){for(int j=0;j<3;j++){
00619               xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00620             }
00621           }else {
00622             xd[0]=xdpixel(xp[2]);yd[0]=ydpixel(yp[2]);
00623             xd[1]=xdpixel(xp[3]);yd[1]=ydpixel(yp[3]);
00624             xd[2]=xdpixel(xp[0]);yd[2]=ydpixel(yp[0]);
00625           }
00626         } else {
00627     for(int j=0;j<4;j++){
00628       xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00629     }
00630   }
00631   char buffer [20];
00632    sprintf(buffer,"%X",mod->idex);
00633 
00634  if(mod->red < 0){ //use count to compute color
00635  int color = getcolor(mod->value,palette);
00636      red=(color>>16)&0xFF;
00637      green=(color>>8)&0xFF;
00638      blue=(color)&0xFF;
00639   
00640 if(!print_total)mod->value=mod->value*mod->count;//restore mod->value
00641   
00642   if(mod->count > 0)
00643     if(temporary_file) *svgfile << red << " " << green << " " << blue << " "; else
00644     *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" lv=\""<<mod->psuIdex<<"\" hv=\""<<mod->psuIdex*10 + mod->HVchannel<<"\" fec=\""<<mod->CcuId<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00645   else
00646     if(temporary_file) *svgfile << 255 << " " << 255 << " " << 255 << " "; else
00647     *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" lv=\""<<mod->psuIdex<<"\" hv=\""<<mod->psuIdex*10 + mod->HVchannel<<"\" fec=\""<<mod->CcuId<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"white\" points=\"";
00648   if(temporary_file) *svgfile << np << " ";
00649   for(int k=0;k<np;k++){
00650     if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
00651     *svgfile << xd[k] << "," << yd[k] << " " ;
00652   }
00653   if(temporary_file)*svgfile << std::endl; else *svgfile <<"\" />" <<std::endl;
00654  } else {//color defined with fillc
00655   if(mod->red>255)mod->red=255;
00656   if(mod->green>255)mod->green=255;
00657   if(mod->blue>255)mod->blue=255;
00658     if(temporary_file) *svgfile << mod->red << " " << mod->green << " " << mod->blue << " "; else
00659     *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" lv=\""<<mod->psuIdex<<"\" hv=\""<<mod->psuIdex*10 + mod->HVchannel<<"\" fec=\""<<mod->CcuId<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"rgb("<<mod->red<<","<<mod->green<<","<<mod->blue<<")\" points=\"";
00660   if(temporary_file) *svgfile << np << " ";
00661   for(int k=0;k<np;k++){
00662     if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
00663     *svgfile << xd[k] << "," << yd[k] << " " ;
00664   }
00665   if(temporary_file)*svgfile << std::endl; else *svgfile <<"\" />" <<std::endl;
00666  }
00667   
00668 }
00669 void TrackerMap::setRange(float min,float max){gminvalue=min;gmaxvalue=max;
00670 if(tkMapLog) {gminvalue=pow(10.,min);gmaxvalue=pow(10.,max);}
00671 }
00672 
00673 std::pair<float,float> TrackerMap::getAutomaticRange(){
00674   float minval,maxval;
00675   minval=9999999.;
00676   maxval=-9999999.;
00677   for (int layer=1; layer < 44; layer++){
00678     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00679       for (int module=1;module<200;module++) {
00680         int key=layer*100000+ring*1000+module;
00681         TmModule * mod = smoduleMap[key];
00682         if(mod !=0 && !mod->notInUse()  && mod->count>0){
00683           if (minval > mod->value)minval=mod->value;
00684           if (maxval < mod->value)maxval=mod->value;
00685         }
00686       }
00687     }
00688   }
00689 if(tkMapLog) {minval=log(minval)/log(10);maxval=log(maxval)/log(10);}
00690  return std::make_pair(minval,maxval);
00691 
00692 }
00693 
00694 //export  tracker map
00695 //print_total = true represent in color the total stored in the module
00696 //print_total = false represent in color the average  
00697 void TrackerMap::save(bool print_total,float minval, float maxval,std::string s,int width, int height){
00698 
00699   printflag=true;
00700   bool rangefound = true; 
00701   if(saveGeoTrackerMap){ 
00702   std::string filetype=s,outputfilename=s;
00703   std::vector<TPolyLine*> vp;
00704   TGaxis *axis = 0 ;
00705   size_t found=filetype.find_last_of(".");
00706   filetype=filetype.substr(found+1);
00707   found=outputfilename.find_last_of(".");
00708   outputfilename=outputfilename.substr(0,found);
00709   //outputfilename.erase(outputfilename.begin()+outputfilename.find("."),outputfilename.end());
00710   temporary_file=true;
00711   if(filetype=="svg")temporary_file=false;
00712   std::ostringstream outs;
00713   minvalue=minval; maxvalue=maxval;
00714   outs << outputfilename << ".coor";
00715   savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
00716   if(!print_total){
00717     for (int layer=1; layer < 44; layer++){
00718       for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00719         for (int module=1;module<200;module++) {
00720           int key=layer*100000+ring*1000+module;
00721           TmModule * mod = smoduleMap[key];
00722           if(mod !=0 && !mod->notInUse()){
00723             mod->value = mod->value / mod->count;
00724           }
00725         }
00726       }
00727     }
00728   }
00729   
00730   if(minvalue>=maxvalue){
00731     minvalue=9999999.;
00732     maxvalue=-9999999.;
00733     rangefound=false;
00734     for (int layer=1; layer < 44; layer++){
00735       for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00736         for (int module=1;module<200;module++) {
00737           int key=layer*100000+ring*1000+module;
00738           TmModule * mod = smoduleMap[key];
00739           if(mod !=0 && !mod->notInUse()  && mod->count>0){
00740             rangefound=true;
00741             if (minvalue > mod->value)minvalue=mod->value;
00742             if (maxvalue < mod->value)maxvalue=mod->value;
00743           }
00744         }
00745       }
00746     }
00747   }
00748   if ((title==" Tracker Map from  QTestAlarm") || (maxvalue == minvalue)||!rangefound) printflag = false;
00749   if(!temporary_file){
00750     *savefile << "<?xml version=\"1.0\"  standalone=\"no\" ?>"<<std::endl;
00751     *savefile << "<svg  xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
00752     *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<std::endl;
00753     *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<std::endl;
00754     *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3100 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
00755     *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3100\" height=\"1600\" /> "<<std::endl; 
00756     *savefile << "<svg:g id=\"tracker\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
00757   }
00758   for (int layer=1; layer < 44; layer++){
00759     //    nlay=layer;
00760     defwindow(layer);
00761     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00762       for (int module=1;module<200;module++) {
00763         int key=layer*100000+ring*1000+module;
00764         TmModule * mod = smoduleMap[key];
00765         if(mod !=0 && !mod->notInUse()){
00766           drawModule(mod,key,layer,print_total,savefile);
00767         }
00768       }
00769     }
00770   }
00771   
00772   if(!temporary_file){
00773     *savefile << "</svg:g>"<<std::endl;
00774     *savefile << " <svg:text id=\"Title\" class=\"normalText\"  x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<std::endl;
00775   }
00776   
00777   if(printflag)drawPalette(savefile);
00778   if(!temporary_file){
00779     *savefile << "</svg:svg>"<<std::endl;
00780     *savefile << "</svg>"<<std::endl;
00781   }
00782   savefile->close(); delete savefile;
00783   
00784   const char * command1;
00785   std::string tempfilename = outputfilename + ".coor";
00786   if(filetype=="svg"){
00787     std::string command = "mv "+tempfilename +" " +outputfilename + ".svg";
00788     command1=command.c_str();
00789     std::cout << "Executing " << command1 << std::endl;
00790     system(command1);
00791   }
00792   
00793 
00794   if (temporary_file){ // create root trackermap image
00795     int red,green,blue,npoints,colindex,ncolor;
00796     double x[4],y[4];
00797     ifstream tempfile(tempfilename.c_str(),std::ios::in);
00798     TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
00799     gPad->SetFillColor(38);
00800     
00801     if(addPixelFlag)gPad->Range(0,0,3800,1600);else gPad->Range(800,0,3800,1600);
00802     
00803     //First  build palette
00804     ncolor=0;
00805     typedef std::map<int,int> ColorList;
00806     ColorList colorList;
00807     ColorList::iterator pos;
00808     TColor *col, *c;
00809     std::cout<<"tempfilename "<<tempfilename<<std::endl;
00810     while(!tempfile.eof()) {
00811       tempfile  >> red >> green  >> blue >> npoints; 
00812       colindex=red+green*1000+blue*1000000;
00813       pos=colorList.find(colindex); 
00814       if(pos == colorList.end()){ colorList[colindex]=ncolor+100; col =gROOT->GetColor(ncolor+100);
00815         if(col) col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.)); else c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));vc.push_back(c); ncolor++;}
00816       for (int i=0;i<npoints;i++){
00817         tempfile >> x[i] >> y[i];  
00818       }
00819     }
00820     
00821     if(ncolor>0 && ncolor<10000){
00822       Int_t colors[10000];
00823       for(int i=0;i<ncolor;i++){colors[i]=i+100;}
00824       gStyle->SetPalette(ncolor,colors);
00825     }
00826     
00827     tempfile.clear();
00828     tempfile.seekg(0,std::ios::beg);
00829     std::cout << "created palette with " << ncolor << " colors" << std::endl;
00830     
00831     while(!tempfile.eof()) {//create polylines
00832       tempfile  >> red >> green  >> blue >> npoints; 
00833       for (int i=0;i<npoints;i++){
00834         tempfile >> x[i] >> y[i];  
00835       }
00836       colindex=red+green*1000+blue*1000000;
00837       pos=colorList.find(colindex); 
00838       if(pos != colorList.end()){
00839         TPolyLine*  pline = new TPolyLine(npoints,y,x);
00840         vp.push_back(pline);
00841         pline->SetFillColor(colorList[colindex]);
00842         pline->SetLineWidth(0);
00843         pline->Draw("f");
00844       }
00845     }
00846     if (printflag) {
00847       float lminvalue=minvalue; float lmaxvalue=maxvalue;
00848       if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10);}
00849       axis = new TGaxis(3660,36,3660,1530,lminvalue,lmaxvalue,510,"+L");
00850       axis->SetLabelSize(0.02);
00851       axis->Draw();
00852     }
00853     TLatex l;
00854     l.SetTextSize(0.03);
00855     l.DrawLatex(950,1330,"TID");
00856     l.DrawLatex(2300,1330,"TEC");
00857     l.DrawLatex(300,1330,"FPIX");
00858     l.DrawLatex(20,560,"BPIX L1");
00859     l.DrawLatex(500,385,"BPIX L2");
00860     l.DrawLatex(500,945,"BPIX L3");
00861     l.SetTextSize(0.04);
00862     std::string fulltitle = title;
00863     if(tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos)) fulltitle += ": Log10 scale";
00864     l.DrawLatex(850,1500,fulltitle.c_str());
00865     l.DrawLatex(1730,40,"-z");
00866     l.DrawLatex(1730,1360,"+z");
00867     l.DrawLatex(1085,330,"TIB L1");
00868     l.DrawLatex(1085,1000,"TIB L2");
00869     l.DrawLatex(1585,330,"TIB L3");
00870     l.DrawLatex(1585,1000,"TIB L4");
00871     l.DrawLatex(2085,330,"TOB L1");
00872     l.DrawLatex(2085,1000,"TOB L2");
00873     l.DrawLatex(2585,330,"TOB L3");
00874     l.DrawLatex(2585,1000,"TOB L4");
00875     l.DrawLatex(3085,330,"TOB L5");
00876     l.DrawLatex(3085,1000,"TOB L6");
00877     TArrow arx(3448,1190,3448,1350,0.01,"|>");
00878     l.DrawLatex(3460,1350,"x");
00879     TArrow ary(3448,1190,3312,1190,0.01,"|>");
00880     l.DrawLatex(3312,1210,"y");
00881     TArrow arz(3485,373,3485,676,0.01,"|>");
00882     l.DrawLatex(3510,667,"z");
00883     TArrow arphi(3485,511,3037,511,0.01,"|>");
00884     l.DrawLatex(3023,520,"#Phi");
00885     arx.SetLineWidth(3);
00886     ary.SetLineWidth(3);
00887     arz.SetLineWidth(3);
00888     arphi.SetLineWidth(3);
00889     arx.Draw();
00890     ary.Draw();
00891     arz.Draw();
00892     arphi.Draw();
00893     MyC->Update();
00894     if(filetype=="png"){
00895       
00896       std::string filename = outputfilename + ".png";
00897       std::cout << "printing " <<filename<< std::endl;
00898       MyC->Print(filename.c_str());
00899     }
00900     if(filetype=="jpg"){
00901       std::string filename = outputfilename + ".jpg";
00902       MyC->Print(filename.c_str());
00903     }
00904     if(filetype=="pdf"){
00905       std::string filename = outputfilename + ".pdf";
00906       MyC->Print(filename.c_str());
00907     }
00908     std::string command = "rm "+tempfilename ;
00909     command1=command.c_str();
00910     std::cout << "Executing " << command1 << std::endl;
00911     system(command1);
00912     MyC->Clear();
00913     delete MyC;
00914     if (printflag)delete axis;
00915     for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
00916       delete (*pos1);}
00917     
00918   }
00919   }
00920   return;
00921 }
00922 void TrackerMap::drawApvPair(int crate, int numfed_incrate, bool print_total, TmApvPair* apvPair,std::ofstream * svgfile,bool useApvPairValue)
00923 {
00924   double xp[4],yp[4];
00925   int color;
00926   int green = 0;
00927   int red = 0;
00928   int blue = 0;
00929   double xd[4],yd[4];
00930   int np = 4;
00931   double boxinitx=0., boxinity=0.; 
00932   double dx=.9,dy=.9;
00933   /*
00934   int numfedch_incolumn = 12;
00935   int numfedch_inrow = 8;
00936   int numfed_incolumn = 6;
00937   int numfed_inrow = 4;
00938   */
00939   boxinitx=boxinitx+(NUMFED_INCOLUMN-1-(numfed_incrate-1)/NUMFED_INROW)*(NUMFEDCH_INCOLUMN+2);
00940   boxinity=boxinity+(NUMFED_INROW-1-(numfed_incrate-1)%NUMFED_INROW)*(NUMFEDCH_INROW+1);
00941   boxinity=boxinity+NUMFEDCH_INROW-(apvPair->getFedCh()/NUMFEDCH_INCOLUMN);
00942   boxinitx = boxinitx+NUMFEDCH_INCOLUMN-(int)(apvPair->getFedCh()%NUMFEDCH_INCOLUMN);
00943   //  std::cout << crate << " " << numfed_incrate << " " << apvPair->getFedCh()<<" "<<boxinitx<< " " << boxinity << std::endl; ;
00944   xp[0]=boxinitx;yp[0]=boxinity;
00945   xp[1]=boxinitx+dx;yp[1]=boxinity;
00946   xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
00947   xp[3]=boxinitx;yp[3]=boxinity + dy;
00948   for(int j=0;j<4;j++){
00949     xd[j]=xdpixelc(xp[j]);yd[j]=ydpixelc(yp[j]);
00950     //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
00951   }
00952   
00953   char buffer [20];
00954   sprintf(buffer,"%X",apvPair->mod->idex);
00955   std::string s = apvPair->mod->name;
00956   s.erase(s.begin()+s.find("connected"),s.end());
00957 
00958   if(useApvPairValue){ 
00959     if(apvPair->red < 0){ //use count to compute color
00960       if(apvPair->count > 0) {
00961         color = getcolor(apvPair->value,palette);
00962         red=(color>>16)&0xFF;
00963         green=(color>>8)&0xFF;
00964         blue=(color)&0xFF;
00965         if(!print_total)apvPair->value=apvPair->value*apvPair->count;//restore mod->value
00966         if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
00967            else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00968       } else {
00969         if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
00970          else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\"  cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"white\" points=\"";
00971       }
00972     } else {//color defined with fillc
00973       if(apvPair->red>255)apvPair->red=255;
00974       if(apvPair->green>255)apvPair->green=255;
00975       if(apvPair->blue>255)apvPair->blue=255;
00976       if(temporary_file)*svgfile << apvPair->red << " " << apvPair->green << " " << apvPair->blue << " ";
00977          else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<apvPair->red<<","<<apvPair->green<<","<<apvPair->blue<<")\" points=\"";
00978     }
00979   }else{
00980     if(apvPair->mod->red < 0){ //use count to compute color
00981       if(apvPair->mod->count > 0) {
00982         color = getcolor(apvPair->mod->value,palette);
00983         red=(color>>16)&0xFF;
00984         green=(color>>8)&0xFF;
00985         blue=(color)&0xFF;
00986         if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
00987            else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00988       } else {
00989         if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
00990          else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\"  cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"white\" points=\"";
00991       }
00992     } else {//color defined with fillc
00993       if(apvPair->mod->red>255)apvPair->mod->red=255;
00994       if(apvPair->mod->green>255)apvPair->mod->green=255;
00995       if(apvPair->mod->blue>255)apvPair->mod->blue=255;
00996       if(temporary_file)*svgfile << apvPair->mod->red << " " << apvPair->mod->green << " " << apvPair->mod->blue << " ";
00997          else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<apvPair->mod->red<<","<<apvPair->mod->green<<","<<apvPair->mod->blue<<")\" points=\"";
00998     }
00999   }
01000   if(temporary_file)*svgfile << np << " ";
01001   for(int k=0;k<np;k++){
01002     if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; 
01003       else *svgfile << xd[k] << "," << yd[k] << " " ;
01004   }
01005   if(temporary_file)*svgfile << std::endl;
01006      else *svgfile <<"\" />" <<std::endl;
01007 }
01008 void TrackerMap::drawCcu(int crate, int numfec_incrate, bool print_total, TmCcu* ccu,std::ofstream * svgfile,bool useCcuValue)
01009 {
01010   double xp[4],yp[4];
01011   int color;
01012   int green = 0;
01013   int red = 0;
01014   int blue = 0;
01015   double xd[4],yd[4];
01016   int np = 4;
01017   double boxinitx=0., boxinity=0.;
01018   double dx=.9,dy=.9;
01019   int numccu_incolumn = 8;
01020   int numccu_inrow = 15;
01021   int numfec_incolumn = 5;
01022   int numfec_inrow = 4;
01023   boxinitx=boxinitx+(numfec_incolumn-(numfec_incrate-1)/numfec_inrow)*14.;
01024   boxinity=boxinity+(numfec_inrow-(numfec_incrate-1)%numfec_inrow)*16.;
01025   boxinity=boxinity+numccu_inrow-ccu->mpos;
01026   boxinitx = boxinitx+numccu_incolumn-(int)(ccu->getCcuRing()%numccu_incolumn);
01027   //std::cout << crate << " " << numfec_incrate << " " << ccu->getCcuRing()<<" "<<ccu->mpos<<" "<<boxinitx<< " " << boxinity << std::endl; ;
01028   xp[0]=boxinitx;yp[0]=boxinity;
01029   xp[1]=boxinitx+dx;yp[1]=boxinity;
01030   xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
01031   xp[3]=boxinitx;yp[3]=boxinity + dy;
01032   for(int j=0;j<4;j++){
01033     xd[j]=xdpixelfec(xp[j]);yd[j]=ydpixelfec(yp[j]);
01034     //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
01035   }
01036 
01037   char buffer [20];
01038   sprintf(buffer,"%X",ccu->idex);
01039   //sprintf(buffer,"%X",ccu->mod->idex);
01040   //std::string s = ccu->mod->name;
01041   std::string s = ccu->text;
01042   s.erase(s.begin()+s.find("connected"),s.end());
01043 
01044   if(ccu->red < 0){ //use count to compute color
01045     if(ccu->count > 0) {
01046       color = getcolor(ccu->value,palette);
01047       red=(color>>16)&0xFF;
01048       green=(color>>8)&0xFF;
01049       blue=(color)&0xFF;
01050       if(!print_total)ccu->value=ccu->value*ccu->count;//restore mod->value
01051       if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
01052       else *svgfile <<"<svg:polygon detid=\""<<ccu->idex<<"\" count=\""<<ccu->count <<"\" value=\""<<ccu->value<<"\" id=\""<<ccu->idex+crate*1000000<<"\" cmodid=\""<<ccu->cmodid<<"\" layer=\""<<ccu->layer<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Slot/Ring"<<ccu->getCcuSlot()<<"/"<<ccu->getCcuRing()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
01053     } else {
01054       if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
01055       else *svgfile <<"<svg:polygon detid=\""<<ccu->idex<<"\" count=\""<<ccu->count <<"\" value=\""<<ccu->value<<"\" id=\""<<ccu->idex+crate*1000000<<"\"  cmodid=\""<<ccu->cmodid<<"\" layer=\""<<ccu->layer<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Slot/Ring "<<ccu->getCcuSlot()<<"/"<<ccu->getCcuRing()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"white\" points=\"";
01056     }
01057   } else {//color defined with fillc
01058     if(ccu->red>255)ccu->red=255;
01059     if(ccu->green>255)ccu->green=255;
01060     if(ccu->blue>255)ccu->blue=255;
01061     if(temporary_file)*svgfile << ccu->red << " " << ccu->green << " " << ccu->blue << " ";
01062     else *svgfile <<"<svg:polygon detid=\""<<ccu->idex<<"\" count=\""<<ccu->count <<"\" value=\""<<ccu->value<<"\" id=\""<<ccu->idex+crate*1000000<<"\" cmodid=\""<<ccu->cmodid<<"\" layer=\""<<ccu->layer<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Slot/Ring "<<ccu->getCcuSlot()<<"/"<<ccu->getCcuRing()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<ccu->red<<","<<ccu->green<<","<<ccu->blue<<")\" points=\"";
01063   }
01064 if(temporary_file)*svgfile << np << " ";
01065 for(int k=0;k<np;k++){
01066   if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
01067   else *svgfile << xd[k] << "," << yd[k] << " " ;
01068 }
01069 if(temporary_file)*svgfile << std::endl;
01070 else *svgfile <<"\" />" <<std::endl;
01071 
01072 }
01073 void TrackerMap::drawPsu(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
01074 {
01075   double xp[4],yp[4];
01076   int color;
01077   int green = 0;
01078   int red = 0;
01079   int blue = 0;
01080   double xd[4],yd[4];
01081   int np = 4;
01082   double boxinitx=0., boxinity=0.; 
01083   double dx=.9,dy=.9;
01084 
01085   boxinitx=boxinitx+(NUMPSUCRATE_INCOLUMN-psu->getPsuCrate())*1.5;
01086   boxinity=boxinity+(NUMPSUCH_INROW-psu->getPsuBoard());
01087 
01088   xp[0]=boxinitx;yp[0]=boxinity;
01089   xp[1]=boxinitx+dx;yp[1]=boxinity;
01090   xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
01091   xp[3]=boxinitx;yp[3]=boxinity + dy;
01092  
01093  
01094   for(int j=0;j<4;j++){
01095     xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
01096     //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
01097   }
01098 
01099   // lines needed to prepare the clickable maps: understand why I get twice the full list of channels (HV1 and HV0?)
01100   /*
01101   double scalex=2695./2700.;
01102   double scaley=1520./1550.;
01103   std::cout << "<area shape=\"rect\" coords=\" " 
01104             << int(scalex*yd[2]) << "," << int(1520-scaley*xd[2]) 
01105             << "," << int(scalex*yd[0]) << "," << int(1520-scaley*xd[0]) 
01106             << "\" title=\" " << psu->psId << "\" /> " << std::endl;
01107   */
01108   //
01109   
01110   char buffer [20];
01111   sprintf(buffer,"%X",psu->idex);
01112   std::string s = psu->text;
01113   s.erase(s.begin()+s.find("connected"),s.end());
01114    
01115   if(psu->red < 0){ //use count to compute color
01116     if(psu->count > 0){
01117       color = getcolor(psu->value,palette);
01118       red=(color>>16)&0xFF;
01119       green=(color>>8)&0xFF;
01120       blue=(color)&0xFF;
01121       if(!print_total)psu->value=psu->value*psu->count;//restore mod->value
01122       if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
01123       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->count <<"\" value=\""<<psu->value<<"\" id=\""<< psu->idex <<"\" cmodid=\""<<psu->cmodid_LV<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
01124       } 
01125       else{
01126      
01127       if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
01128       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->count <<"\" value=\""<<psu->value<<"\" id=\""<< psu->idex <<"\"  cmodid=\""<<psu->cmodid_LV<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"white\" points=\"";
01129       }
01130     } 
01131    
01132     else {//color defined with fillc
01133     if(psu->red>255)psu->red=255;
01134     if(psu->green>255)psu->green=255;
01135     if(psu->blue>255)psu->blue=255;
01136     if(temporary_file)*svgfile << psu->red << " " << psu->green << " " << psu->blue << " ";
01137     else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->count <<"\" value=\""<<psu->value<<"\" id=\""<< psu->idex <<"\" cmodid=\""<<psu->cmodid_LV<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<psu->red<<","<<psu->green<<","<<psu->blue<<")\" points=\"";
01138   }
01139 
01140 if(temporary_file)*svgfile << np << " ";
01141 for(int k=0;k<np;k++){
01142   if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; 
01143   else *svgfile << xd[k] << "," << yd[k] << " " ;
01144 }
01145 if(temporary_file)*svgfile << std::endl;
01146 else *svgfile <<"\" />" <<std::endl;
01147 
01148 }
01149 
01150 void TrackerMap::drawHV2(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
01151 {
01152   double xp[4],yp[4];
01153   int color;
01154   int greenHV2 = 0;
01155   int redHV2 = 0;
01156   int blueHV2 = 0;
01157   double xd[4],yd[4];
01158   int np = 4;
01159   double boxinitx=35, boxinity=12; 
01160   double dx=1.1,dy=1.3;
01161   
01162   boxinitx= boxinitx+(5 - psu->getPsuCrate())*5;
01163   boxinity= boxinity+(18 - psu->getPsuBoard())*1.75;
01164 
01165   xp[0]=boxinitx;yp[0]=boxinity;
01166   xp[1]=boxinitx+dx;yp[1]=boxinity;
01167   xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
01168   xp[3]=boxinitx;yp[3]=boxinity + dy;
01169  
01170  
01171   for(int j=0;j<4;j++){
01172     xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
01173     //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
01174   }
01175   
01176   char buffer [20];
01177   sprintf(buffer,"%X",psu->idex);
01178   std::string s = psu->textHV2;
01179   s.erase(s.begin()+s.find("connected"),s.end());
01180    
01181   if(psu->redHV2 < 0){ //use count to compute color
01182     
01183     if(psu->valueHV2 > 0){
01184       color = getcolor(psu->valueHV2,palette);
01185       redHV2=(color>>16)&0xFF;
01186       greenHV2=(color>>8)&0xFF;
01187       blueHV2=(color)&0xFF;
01188       if(!print_total)psu->valueHV2=psu->valueHV2*psu->countHV2;//restore mod->value
01189       if(temporary_file)*svgfile << redHV2 << " " << greenHV2 << " " << blueHV2 << " ";
01190       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV2 <<"\" value=\""<<psu->valueHV2<<"\" id=\""<< psu->idex*10+2 <<"\" cmodid=\""<<psu->cmodid_HV2<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<redHV2<<","<<greenHV2<<","<<blueHV2<<")\" points=\"";
01191       } 
01192       else{
01193       if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
01194       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV2 <<"\" value=\""<<psu->valueHV2<<"\" id=\""<< psu->idex*10+2 <<"\"  cmodid=\""<<psu->cmodid_HV2<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"white\" points=\"";
01195       }
01196     } 
01197    
01198     else {//color defined with fillc
01199     if(psu->redHV2>255)psu->redHV2=255;
01200     if(psu->greenHV2>255)psu->greenHV2=255;
01201     if(psu->blueHV2>255)psu->blueHV2=255;
01202     if(temporary_file)*svgfile << psu->redHV2 << " " << psu->greenHV2 << " " << psu->blueHV2 << " ";
01203     else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV2 <<"\" value=\""<<psu->valueHV2<<"\" id=\""<< psu->idex*10+2 <<"\" cmodid=\""<<psu->cmodid_HV2<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<psu->redHV2<<","<<psu->greenHV2<<","<<psu->blueHV2<<")\" points=\"";
01204   }
01205 
01206 if(temporary_file)*svgfile << np << " ";
01207 for(int k=0;k<np;k++){
01208   if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; 
01209   else *svgfile << xd[k] << "," << yd[k] << " " ;
01210 }
01211 if(temporary_file)*svgfile << std::endl;
01212 else *svgfile <<"\" />" <<std::endl;
01213 
01214 }
01215 
01216 
01217 void TrackerMap::drawHV3(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
01218 {
01219   double xp[4],yp[4];
01220   int color;
01221   int greenHV3 = 0;
01222   int redHV3 = 0;
01223   int blueHV3 = 0;
01224   double xd[4],yd[4];
01225   int np = 4;
01226   double boxinitx=36.5, boxinity=12; 
01227   double dx=1.1,dy=1.3;
01228   
01229   boxinitx= boxinitx+(5 - psu->getPsuCrate())*5;
01230   boxinity= boxinity+(18 - psu->getPsuBoard())*1.75;
01231 
01232   xp[0]=boxinitx;yp[0]=boxinity;
01233   xp[1]=boxinitx+dx;yp[1]=boxinity;
01234   xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
01235   xp[3]=boxinitx;yp[3]=boxinity + dy;
01236  
01237  
01238   for(int j=0;j<4;j++){
01239     xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
01240     //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
01241   }
01242   
01243   char buffer [20];
01244   sprintf(buffer,"%X",psu->idex);
01245   std::string s = psu->textHV3;
01246   s.erase(s.begin()+s.find("connected"),s.end());
01247    
01248   if(psu->redHV3 < 0){ //use count to compute color
01249     if(psu->valueHV3 > 0){
01250       color = getcolor(psu->valueHV3,palette);
01251       redHV3=(color>>16)&0xFF;
01252       greenHV3=(color>>8)&0xFF;
01253       blueHV3=(color)&0xFF;
01254       if(!print_total)psu->valueHV3=psu->valueHV3*psu->countHV3;//restore mod->value
01255       if(temporary_file)*svgfile << redHV3 << " " << greenHV3 << " " << blueHV3 << " ";
01256       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV3 <<"\" value=\""<<psu->valueHV3<<"\" id=\""<< psu->idex*10+3 <<"\" cmodid=\""<<psu->cmodid_HV3<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard"<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<redHV3<<","<<greenHV3<<","<<blueHV3<<")\" points=\"";
01257       } 
01258       else{
01259       if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
01260       else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV3 <<"\" value=\""<<psu->valueHV3<<"\" id=\""<< psu->idex*10+3 <<"\"  cmodid=\""<<psu->cmodid_HV3<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"white\" points=\"";
01261       }
01262     } 
01263    
01264     else {//color defined with fillc
01265     if(psu->redHV3>255)psu->redHV3=255;
01266     if(psu->greenHV3>255)psu->greenHV3=255;
01267     if(psu->blueHV3>255)psu->blueHV3=255;
01268     if(temporary_file)*svgfile << psu->redHV3 << " " << psu->greenHV3 << " " << psu->blueHV3 << " ";
01269     else *svgfile <<"<svg:polygon detid=\""<<psu->idex<<"\" count=\""<<psu->countHV3 <<"\" value=\""<<psu->valueHV3<<"\" id=\""<< psu->idex*10+3 <<"\" cmodid=\""<<psu->cmodid_HV3<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"easyCrate/easyBoard "<<psu->getPsuCrate()<<"/"<<psu->getPsuBoard()<<" connected to "<<s<<" \" fill=\"rgb("<<psu->redHV3<<","<<psu->greenHV3<<","<<psu->blueHV3<<")\" points=\"";
01270   }
01271 
01272 if(temporary_file)*svgfile << np << " ";
01273 for(int k=0;k<np;k++){
01274   if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; 
01275   else *svgfile << xd[k] << "," << yd[k] << " " ;
01276 }
01277 if(temporary_file)*svgfile << std::endl;
01278 else *svgfile <<"\" />" <<std::endl;
01279 
01280 }
01281 
01282 void TrackerMap::save_as_fectrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
01283 
01284  if(enableFecProcessing){
01285   std::string filetype=s,outputfilename=s;
01286   std::vector<TPolyLine*> vp;
01287   TGaxis *axis = 0 ;
01288   size_t found=filetype.find_last_of(".");
01289   filetype=filetype.substr(found+1);
01290   found=outputfilename.find_last_of(".");
01291   outputfilename=outputfilename.substr(0,found); 
01292   temporary_file=true;
01293   if(filetype=="xml"||filetype=="svg")temporary_file=false;
01294   std::ostringstream outs;
01295   minvalue=minval; maxvalue=maxval;
01296   outs << outputfilename << ".coor";
01297   if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01298    std::map<int , TmCcu *>::iterator i_ccu;
01299    std::multimap<TmCcu*, TmModule*>::iterator it;
01300    std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
01301   //Decide if we must use Module or Ccu value
01302   bool useCcuValue=false;
01303   
01304   
01305   for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01306     TmCcu *  ccu= i_ccu->second;
01307     if(ccu!=0) {
01308         if(ccu->count > 0 || ccu->red!=-1) { useCcuValue=true; break;}
01309       }
01310     }
01311  
01312   
01313   if(!useCcuValue)//store mean of connected modules value{
01314     for(  i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01315     TmCcu *  ccu= i_ccu->second;
01316       if(ccu!=0) {
01317             ret = fecModuleMap.equal_range(ccu);
01318         for (it = ret.first; it != ret.second; ++it)
01319           {
01320            if( (*it).second->count>0){ccu->value=ccu->value+(*it).second->value;ccu->count++;}
01321           }
01322           if(ccu->count>0)ccu->value=ccu->value/ccu->count;
01323           if(ccu->nmod==0)  { ccu->red=0;ccu->green=0;ccu->blue=0;}
01324           }
01325           }
01326   
01327  
01328   if(title==" Tracker Map from  QTestAlarm"){
01329       for(  i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01330           TmCcu *  ccu= i_ccu->second;
01331           if(ccu!=0) {
01332             ret = fecModuleMap.equal_range(ccu);
01333             ccu->red=0;ccu->green=255;ccu->blue=0;
01334             for (it = ret.first; it != ret.second; ++it) {
01335               if( !( (*it).second->red==0 && (*it).second->green==255 && (*it).second->blue==0 ) && !( (*it).second->red==255 && (*it).second->green==255 && (*it).second->blue==255 ) ){
01336                 ccu->red=255;ccu->green=0;ccu->blue=0;
01337                 }
01338               }
01339            }
01340       }
01341    }
01342   
01343 
01344   
01345   if(!print_total){
01346     for(  i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01347     TmCcu *  ccu= i_ccu->second;
01348       if(ccu!=0) {
01349           if(useCcuValue) ccu->value = ccu->value / ccu->count;
01350 
01351         }
01352     }
01353   }
01354  
01355   if(minvalue>=maxvalue){
01356 
01357     minvalue=9999999.;
01358     maxvalue=-9999999.;
01359     for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01360        TmCcu *  ccu= i_ccu->second;
01361        if(ccu!=0 && ccu->count>0) {
01362               if (minvalue > ccu->value)minvalue=ccu->value;
01363               if (maxvalue < ccu->value)maxvalue=ccu->value;
01364         }
01365     }
01366   }
01367 
01368 
01369   
01370  if(filetype=="svg"){
01371       saveAsSingleLayer=false;
01372       std::ostringstream outs;
01373     outs << outputfilename<<".svg";
01374     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01375   *savefile << "<?xml version=\"1.0\"  standalone=\"no\" ?>"<<std::endl;
01376   *savefile << "<svg  xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01377   *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<std::endl;
01378   *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<std::endl;
01379   *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
01380   *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl;
01381   *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
01382      }
01383   for (int crate=1; crate < (nfeccrates+1); crate++){
01384     if(filetype=="xml"){
01385       saveAsSingleLayer=true;
01386       std::ostringstream outs;
01387     outs << outputfilename<<"feccrate" <<crate<< ".xml";
01388     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01389     *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
01390     *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01391     *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<std::endl;
01392     *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<std::endl;
01393     *savefile << "<script type=\"text/ecmascript\" xlink:href=\"feccrate.js\" />"<<std::endl;
01394     *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0  500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
01395     *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
01396     *savefile << "<g id=\"crate\" transform=\" translate(280,580) rotate(270) scale(.7,.8)\"  > "<<std::endl;
01397          }
01398     //    ncrate=crate;
01399     deffecwindow(crate);
01400  
01401     for ( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01402       TmCcu *  ccu= i_ccu->second;
01403       if(ccu!=0){
01404         if(ccu->getCcuCrate() == crate){
01405               
01406               drawCcu(crate,ccu->getCcuSlot()-2,print_total,ccu,savefile,useCcuValue);
01407         }
01408       }
01409     }
01410  
01411    if(!temporary_file){
01412     if(filetype=="xml"){
01413     *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
01414     *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
01415     *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
01416     *savefile << " </text> </svg>" << std::endl;
01417     savefile->close();
01418      saveAsSingleLayer=false;
01419       }
01420       }
01421     }
01422     if(filetype=="svg"){
01423     *savefile << "</g> </svg> </svg> " << std::endl;
01424     savefile->close();
01425       }
01426   if(!print_total && !useCcuValue){
01427 //Restore ccu value
01428     for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
01429        TmCcu *  ccu= i_ccu->second;
01430        if(ccu!=0) {
01431           ccu->value = ccu->value * ccu->count;
01432     }
01433 }
01434 }
01435  if(temporary_file){
01436  if(printflag&&!saveWebInterface)drawPalette(savefile);
01437   savefile->close();
01438 
01439   const char * command1;
01440   std::string tempfilename = outputfilename + ".coor";
01441     int red,green,blue,npoints,colindex,ncolor;
01442     double x[4],y[4];
01443     ifstream tempfile(tempfilename.c_str(),std::ios::in);
01444     TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
01445     gPad->SetFillColor(38);
01446 
01447     if(saveWebInterface)gPad->Range(0,0,3700,1600); else gPad->Range(0,0,3800,1600);
01448 
01449     //First  build palette
01450     ncolor=0;
01451     typedef std::map<int,int> ColorList;
01452     ColorList colorList;
01453     ColorList::iterator pos;
01454     TColor *col,*c;
01455     while(!tempfile.eof()) {
01456       tempfile  >> red >> green  >> blue >> npoints;
01457       colindex=red+green*1000+blue*1000000;
01458       pos=colorList.find(colindex);
01459       if(pos == colorList.end()){
01460         colorList[colindex]=ncolor+100;
01461         col =gROOT->GetColor(ncolor+100);
01462         if(col)
01463           col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
01464         else
01465           c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
01466           vc.push_back(c);
01467         ncolor++;
01468       }
01469       for (int i=0;i<npoints;i++){
01470         tempfile >> x[i] >> y[i];
01471       }
01472     }
01473     if(ncolor>0 && ncolor<10000){
01474       Int_t colors[10000];
01475       for(int i=0;i<ncolor;i++){colors[i]=i+100;}
01476       gStyle->SetPalette(ncolor,colors);
01477     }
01478     tempfile.clear();
01479     tempfile.seekg(0,std::ios::beg);
01480     std::cout << "created palette with " << ncolor << " colors" << std::endl;
01481     while(!tempfile.eof()) {//create polylines
01482       tempfile  >> red >> green  >> blue >> npoints;
01483       for (int i=0;i<npoints;i++){
01484         tempfile >> x[i] >> y[i];
01485       }
01486       colindex=red+green*1000+blue*1000000;
01487       pos=colorList.find(colindex);
01488       if(pos != colorList.end()){
01489         TPolyLine*  pline = new TPolyLine(npoints,y,x);
01490         vp.push_back(pline);
01491         pline->SetFillColor(colorList[colindex]);
01492         pline->SetLineWidth(0);
01493         pline->Draw("f");
01494       }
01495     }
01496         if (printflag&&!saveWebInterface) {
01497       float lminvalue=minvalue; float lmaxvalue=maxvalue;
01498       if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10);}
01499       axis = new TGaxis(3660,36,3660,1530,lminvalue,lmaxvalue,510,"+L");
01500       axis->SetLabelSize(0.02);
01501       axis->Draw();
01502     }
01503 
01504     if(!saveWebInterface){
01505     TLatex l;
01506     l.SetTextSize(0.05);
01507     std::string fulltitle = title;
01508     if(tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos)) fulltitle += ": Log10 scale";
01509     l.DrawLatex(50,1530,fulltitle.c_str());
01510        }
01511     MyC->Update();
01512     std::cout << "Filetype " << filetype << std::endl;
01513     if(filetype=="png"){
01514       std::string filename = outputfilename + ".png";
01515       MyC->Print(filename.c_str());
01516     }
01517     if(filetype=="jpg"){
01518       std::string filename = outputfilename + ".jpg";
01519       MyC->Print(filename.c_str());
01520     }
01521     if(filetype=="pdf"){
01522       std::string filename = outputfilename + ".pdf";
01523       MyC->Print(filename.c_str());
01524     }
01525     std::string command = "rm "+tempfilename ;
01526     command1=command.c_str();
01527     std::cout << "Executing " << command1 << std::endl;
01528     system(command1);
01529     MyC->Clear();
01530     delete MyC;
01531     if (printflag&&!saveWebInterface)delete axis;
01532     for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
01533          delete (*pos1);}
01534    
01535 
01536 
01537 
01538 }//if(temporary_file)
01539 }//if(enabledFecProcessing)
01540 }
01541 void TrackerMap::save_as_HVtrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
01542   
01543  if(enableHVProcessing){
01544   std::string filetype=s,outputfilename=s;
01545   std::vector<TPolyLine*> vp;
01546   TGaxis *axis = 0 ;
01547   size_t found=filetype.find_last_of(".");
01548   filetype=filetype.substr(found+1);
01549   found=outputfilename.find_last_of(".");
01550   outputfilename=outputfilename.substr(0,found);
01551 
01552   temporary_file=true;
01553   
01554 
01555   if(filetype=="xml"||filetype=="svg")temporary_file=false;
01556   
01557   std::ostringstream outs;
01558   minvalue=minval; maxvalue=maxval;
01559   outs << outputfilename << ".coor";
01560   if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01561   
01562   std::map<int , TmPsu *>::iterator ipsu;
01563   std::multimap<TmPsu*, TmModule*>::iterator it;
01564   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
01565  
01566   
01567   bool usePsuValue=false;
01568   
01569   for( ipsu=psuMap.begin();ipsu!=psuMap.end(); ipsu++){
01570     TmPsu*  psu= ipsu->second;
01571     if(psu!=0) {
01572       if(psu->countHV2 > 0 || psu->redHV2!=-1 || psu->countHV3 > 0 || psu->redHV3!=-1) { usePsuValue=true; break;}
01573       }
01574     }
01575    
01576   if(!usePsuValue){//store mean of connected modules value{
01577     
01578     for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01579        TmPsu *  psu= ipsu->second;
01580        if(psu!=0) {
01581        ret = psuModuleMap.equal_range(psu);
01582          int nconn1=0;int nconn2=0;
01583          for(it = ret.first; it != ret.second; ++it){
01584            if((*it).second->HVchannel==2&&(*it).second->count>0){ nconn1++;psu->valueHV2=psu->valueHV2+(*it).second->value;}
01585            if((*it).second->HVchannel==3&&(*it).second->count>0){ nconn2++;psu->valueHV3=psu->valueHV3+(*it).second->value;} 
01586             }
01587          if(psu->nmodHV2!=0 &&nconn1>0){psu->valueHV2=psu->valueHV2/psu->nmodHV2; psu->countHV2=1; }
01588          if(psu->nmodHV3!=0 &&nconn2>0){psu->valueHV3=psu->valueHV3/psu->nmodHV3; psu->countHV3=1; }
01589           
01590            }
01591          
01592          }
01593        }
01594    
01595    if(title==" Tracker Map from  QTestAlarm"){
01596       for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01597           TmPsu *  psu= ipsu->second;
01598           if(psu!=0) {
01599             ret = psuModuleMap.equal_range(psu);
01600             psu->redHV2=0;psu->greenHV2=255;psu->blueHV2=0;
01601             psu->redHV3=0;psu->greenHV3=255;psu->blueHV3=0;
01602             for (it = ret.first; it != ret.second; ++it) {
01603               if((*it).second->HVchannel==2){
01604                 if( !( (*it).second->red==0 && (*it).second->green==255 && (*it).second->blue==0 ) && !( (*it).second->red==255 && (*it).second->green==255 && (*it).second->blue==255 ) ){
01605                    psu->redHV2=255;psu->greenHV2=0;psu->blueHV2=0;
01606                    }
01607                 }
01608               if((*it).second->HVchannel==3){
01609                 if( !( (*it).second->red==0 && (*it).second->green==255 && (*it).second->blue==0 ) && !( (*it).second->red==255 && (*it).second->green==255 && (*it).second->blue==255 ) ){
01610                    psu->redHV3=255;psu->greenHV3=0;psu->blueHV3=0;
01611                    }
01612                 }
01613              }
01614            }
01615       }
01616    } 
01617  
01618   if(!print_total){
01619     for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01620     TmPsu *  psu= ipsu->second;
01621       if(psu!=0) {
01622           if(usePsuValue){ 
01623             psu->valueHV2 = psu->valueHV2 / psu->countHV2;
01624             psu->valueHV3 = psu->valueHV3 / psu->countHV3;
01625         }
01626     }
01627   }
01628  } 
01629   
01630   if(minvalue>=maxvalue){
01631     
01632     minvalue=9999999.;
01633     maxvalue=-9999999.;
01634     
01635     for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01636        TmPsu *  psu= ipsu->second;
01637        if(psu!=0 && psu->countHV2>0 && psu->countHV3 >0) {
01638 
01639               if (minvalue > psu->valueHV2 || minvalue > psu->valueHV3)minvalue=std::min(psu->valueHV2,psu->valueHV3);
01640               if (maxvalue < psu->valueHV2 || maxvalue < psu->valueHV3)maxvalue=std::max(psu->valueHV2,psu->valueHV3);
01641               
01642         
01643         }
01644     }
01645   }
01646   
01647      if(filetype=="svg"){
01648       saveAsSingleLayer=false;
01649       std::ostringstream outs;
01650     outs << outputfilename<<".svg";
01651     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01652   *savefile << "<?xml version=\"1.0\"  standalone=\"no\" ?>"<<std::endl;
01653   *savefile << "<svg  xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01654   *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<std::endl;
01655   *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<std::endl;
01656   *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
01657   *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl; 
01658   *savefile << "<svg:g id=\"HVtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
01659      }
01660    
01661   for (int irack=1; irack < (npsuracks+1); irack++){
01662     if(filetype=="xml"){
01663       saveAsSingleLayer=true;
01664       std::ostringstream outs;
01665     outs << outputfilename<<"HVrack" <<irack<< ".xml";
01666     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01667     *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
01668     *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01669     *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<std::endl;
01670     *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<std::endl;
01671     *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rackhv.js\" />"<<std::endl;
01672     *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0  500 500\" width=\"700\" height=\"700\" onload=\"TrackerRackhv.init()\">"<<std::endl;
01673     *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
01674     *savefile << "<g id=\"rackhv\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\"  > "<<std::endl;
01675          }
01676     
01677     // nrack=irack;
01678     defpsuwindow(irack);
01679     for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01680       TmPsu *  psu= ipsu->second;
01681       if(psu->getPsuRack() == irack){
01682               drawHV2(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
01683               drawHV3(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
01684       }
01685     }
01686    
01687   
01688    if(!temporary_file){
01689     if(filetype=="xml"){
01690     *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
01691     *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
01692     *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
01693     *savefile << " </text> </svg>" << std::endl;
01694     savefile->close();
01695      saveAsSingleLayer=false;
01696       }
01697       }
01698     }
01699     if(filetype=="svg"){
01700     *savefile << "</g> </svg> </svg> " << std::endl;
01701     savefile->close();
01702       }
01703  
01704     //Restore psu value
01705     if(!print_total && !usePsuValue){
01706      for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01707        TmPsu *psu = ipsu->second;
01708        if(psu!=0) {
01709           psu->valueHV2 = psu->valueHV2 * psu->countHV2;
01710           psu->valueHV3 = psu->valueHV3 * psu->countHV3;
01711           }
01712        }
01713      }
01714   
01715 
01716   if(temporary_file){
01717   if(printflag&&!saveWebInterface)drawPalette(savefile);
01718     savefile->close(); 
01719 
01720   const char * command1;
01721   std::string tempfilename = outputfilename + ".coor";
01722     int red,green,blue,npoints,colindex,ncolor;
01723     double x[4],y[4];
01724     ifstream tempfile(tempfilename.c_str(),std::ios::in);
01725     TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
01726     gPad->SetFillColor(38);
01727     
01728     if(saveWebInterface)gPad->Range(0,0,3700,1600); else gPad->Range(0,0,3800,1600);
01729     
01730     //First  build palette
01731     ncolor=0;
01732     typedef std::map<int,int> ColorList;
01733     ColorList colorList;
01734     ColorList::iterator pos;
01735     TColor *col,*c;
01736     while(!tempfile.eof()) {
01737       tempfile  >> red >> green  >> blue >> npoints; 
01738       colindex=red+green*1000+blue*1000000;
01739       pos=colorList.find(colindex); 
01740       if(pos == colorList.end()){ 
01741         colorList[colindex]=ncolor+100; 
01742         col =gROOT->GetColor(ncolor+100);
01743         if(col) 
01744           col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.)); 
01745         else 
01746           c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
01747           vc.push_back(c);
01748         ncolor++;
01749       }
01750       for (int i=0;i<npoints;i++){
01751         tempfile >> x[i] >> y[i];  
01752       }
01753     }
01754     if(ncolor>0 && ncolor<10000){
01755       Int_t colors[10000];
01756       for(int i=0;i<ncolor;i++){colors[i]=i+100;}
01757       gStyle->SetPalette(ncolor,colors);
01758     }
01759     tempfile.clear();
01760     tempfile.seekg(0,std::ios::beg);
01761     std::cout << "created palette with " << ncolor << " colors" << std::endl;
01762     while(!tempfile.eof()) {//create polylines
01763       tempfile  >> red >> green  >> blue >> npoints; 
01764       for (int i=0;i<npoints;i++){
01765         tempfile >> x[i] >> y[i];  
01766       }
01767       colindex=red+green*1000+blue*1000000;
01768       pos=colorList.find(colindex); 
01769       if(pos != colorList.end()){
01770         TPolyLine*  pline = new TPolyLine(npoints,y,x);
01771         vp.push_back(pline);
01772         pline->SetFillColor(colorList[colindex]);
01773         pline->SetLineWidth(0);
01774         pline->Draw("f");
01775       }
01776     }
01777         if (printflag&&!saveWebInterface) {
01778       float lminvalue=minvalue; float lmaxvalue=maxvalue;
01779       if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10);}
01780       axis = new TGaxis(3660,36,3660,1530,lminvalue,lmaxvalue,510,"+L");
01781       axis->SetLabelSize(0.02);
01782       axis->Draw();
01783     }
01784 
01785 
01786     if(!saveWebInterface){
01787     TLatex l;
01788     l.SetTextSize(0.05);
01789     std::string fulltitle = title;
01790     if(tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos)) fulltitle += ": Log10 scale";
01791     l.DrawLatex(50,1530,fulltitle.c_str());
01792        }
01793     MyC->Update();
01794     std::cout << "Filetype " << filetype << std::endl;
01795     if(filetype=="png"){
01796       std::string filename = outputfilename + ".png";
01797       MyC->Print(filename.c_str());
01798     }
01799     if(filetype=="jpg"){
01800       std::string filename = outputfilename + ".jpg";
01801       MyC->Print(filename.c_str());
01802     }
01803     if(filetype=="pdf"){
01804       std::string filename = outputfilename + ".pdf";
01805       MyC->Print(filename.c_str());
01806     }
01807     std::string command = "rm "+tempfilename ;
01808     command1=command.c_str();
01809     std::cout << "Executing " << command1 << std::endl;
01810     system(command1);
01811     MyC->Clear();
01812     delete MyC;
01813      if (printflag&&!saveWebInterface)delete axis;
01814     for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
01815          delete (*pos1);}
01816     
01817          
01818          }//if(temporary_file)
01819 }//if(enabledHVProcessing)
01820 }
01821 
01822 
01823 void TrackerMap::save_as_psutrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
01824 
01825  if(enableLVProcessing){
01826   
01827   printflag=true;
01828   bool rangefound=true;
01829   std::string filetype=s,outputfilename=s;
01830   std::vector<TPolyLine*> vp;
01831   TGaxis *axis = 0 ;
01832   
01833   size_t found=filetype.find_last_of(".");
01834   filetype=filetype.substr(found+1);
01835   found=outputfilename.find_last_of(".");
01836   outputfilename=outputfilename.substr(0,found);
01837   
01838   temporary_file=true;
01839   
01840 
01841   
01842   if(filetype=="xml"||filetype=="svg")temporary_file=false;
01843    
01844   std::ostringstream outs;
01845   minvalue=minval; maxvalue=maxval;
01846   outs << outputfilename << ".coor";
01847   if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01848   
01849   std::map<int , TmPsu *>::iterator ipsu;
01850   std::multimap<TmPsu*, TmModule*>::iterator it;
01851   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
01852  
01853   //Decide if we must use Module or Power Psupply value
01854   bool usePsuValue=false;
01855   
01856   for( ipsu=psuMap.begin();ipsu!=psuMap.end(); ipsu++){
01857     TmPsu*  psu= ipsu->second;
01858     if(psu!=0) {
01859       if(psu->count > 0 || psu->red!=-1) { usePsuValue=true; break;}
01860       }
01861     }
01862   
01863   if(!usePsuValue){//store mean of connected modules value{
01864     for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01865       TmPsu *  psu= ipsu->second;
01866       if(psu!=0) {
01867         ret = psuModuleMap.equal_range(psu);
01868         int nconn=0;
01869         for(it = ret.first; it != ret.second; ++it){
01870           if((*it).second->count>0){nconn++;psu->value=psu->value+(*it).second->value;}
01871           
01872         }
01873         if(nconn>0){ psu->value=psu->value/psu->nmod; psu->count=1;}
01874         
01875       }
01876     }
01877   }
01878   
01879   if(title==" Tracker Map from  QTestAlarm"){
01880     for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01881       TmPsu *  psu= ipsu->second;
01882       if(psu!=0) {
01883         ret = psuModuleMap.equal_range(psu);
01884         //      psu->red=255;psu->green=255;psu->blue=255;
01885         psu->red=-1;
01886         int nconn=0;
01887         for (it = ret.first; it != ret.second; ++it) {
01888           if( !( (*it).second->red==0 && (*it).second->green==255 && (*it).second->blue==0 ) && !( (*it).second->red==255 && (*it).second->green==255 && (*it).second->blue==255 ) ){
01889             nconn++;psu->value++;
01890           }
01891         }
01892         if(nconn>0){ psu->value=psu->value/psu->nmod; psu->count=1;}
01893       }
01894     }
01895   }
01896   
01897   
01898   
01899   if(!print_total){
01900     for(  ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01901     TmPsu *  psu= ipsu->second;
01902       if(psu!=0) {
01903           if(usePsuValue) psu->value = psu->value / psu->count;
01904 
01905         }
01906     }
01907   }
01908   
01909   if(minvalue>=maxvalue){
01910     
01911     minvalue=9999999.;
01912     maxvalue=-9999999.;
01913     rangefound=false;
01914     for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01915        TmPsu *  psu= ipsu->second;
01916        if(psu!=0 && psu->count>0) {
01917          rangefound = true;
01918               if (minvalue > psu->value)minvalue=psu->value;
01919               if (maxvalue < psu->value)maxvalue=psu->value;
01920         }
01921     }
01922   }
01923   if ((maxvalue == minvalue)||!rangefound) printflag = false;
01924 
01925   
01926      if(filetype=="svg"){
01927       saveAsSingleLayer=false;
01928       std::ostringstream outs;
01929     outs << outputfilename<<".svg";
01930     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01931   *savefile << "<?xml version=\"1.0\"  standalone=\"no\" ?>"<<std::endl;
01932   *savefile << "<svg  xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01933   *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<std::endl;
01934   *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<std::endl;
01935   *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
01936   *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl; 
01937   *savefile << "<svg:g id=\"psutrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
01938      }
01939   
01940   for (int irack=1; irack < (npsuracks+1); irack++){
01941     if(filetype=="xml"){
01942       saveAsSingleLayer=true;
01943       std::ostringstream outs;
01944     outs << outputfilename<<"psurack" <<irack<< ".xml";
01945     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
01946     *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
01947     *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
01948     *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<std::endl;
01949     *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<std::endl;
01950     *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rack.js\" />"<<std::endl;
01951     *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0  500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
01952     *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
01953     *savefile << "<g id=\"rack\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\"  > "<<std::endl;
01954          }
01955    
01956     
01957     // nrack=irack;
01958     defpsuwindow(irack);
01959     for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01960       TmPsu *  psu= ipsu->second;
01961       if(psu->getPsuRack() == irack){
01962               
01963               drawPsu(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
01964       }
01965     }
01966    
01967     
01968    if(!temporary_file){
01969     if(filetype=="xml"){
01970     *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
01971     *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
01972     *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
01973     *savefile << " </text> </svg>" << std::endl;
01974     savefile->close();
01975      saveAsSingleLayer=false;
01976       }
01977       }
01978     }
01979     if(filetype=="svg"){
01980     *savefile << "</g> </svg> </svg> " << std::endl;
01981     savefile->close();
01982       }
01983  
01984     //Restore psu value
01985     if(!print_total && !usePsuValue){
01986      for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
01987        TmPsu *psu = ipsu->second;
01988        if(psu!=0) {
01989           psu->value = psu->value * psu->count;
01990           }
01991        }
01992      }
01993 
01994     int rangex=YPSUOFFSET+(YPSURSIZE+YPSUOFFSET)*NUMPSURACK_INROW+300; 
01995     int rangey=XPSUOFFSET+(XPSURSIZE+XPSUOFFSET)*NUMPSURACK_INCOLUMN+300;
01996   
01997   
01998   if(temporary_file){
01999     if(printflag&&!saveWebInterface)drawPalette(savefile,rangex-140,rangey-100);
02000     savefile->close(); 
02001 
02002   const char * command1;
02003   std::string tempfilename = outputfilename + ".coor";
02004     int red,green,blue,npoints,colindex,ncolor;
02005     double x[4],y[4];
02006     ifstream tempfile(tempfilename.c_str(),std::ios::in);
02007     TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
02008     gPad->SetFillColor(38);
02009     
02010     //    if(saveWebInterface)gPad->Range(0,0,3700,1600); else gPad->Range(0,0,3800,1600);
02011     std::cout << " range x " <<  rangex << std::endl;
02012     std::cout << " range y " <<  rangey << std::endl;
02013     gPad->Range(0,0,rangex,rangey);
02014     
02015     //First  build palette
02016     ncolor=0;
02017     typedef std::map<int,int> ColorList;
02018     ColorList colorList;
02019     ColorList::iterator pos;
02020     TColor *col,*c;
02021     while(!tempfile.eof()) {
02022       tempfile  >> red >> green  >> blue >> npoints; 
02023       colindex=red+green*1000+blue*1000000;
02024       pos=colorList.find(colindex); 
02025       if(pos == colorList.end()){ 
02026         colorList[colindex]=ncolor+100; 
02027         col =gROOT->GetColor(ncolor+100);
02028         if(col) 
02029           col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.)); 
02030         else 
02031           c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
02032         vc.push_back(c);
02033         ncolor++;
02034       }
02035       for (int i=0;i<npoints;i++){
02036         tempfile >> x[i] >> y[i];  
02037       }
02038     }
02039     if(ncolor>0 && ncolor<10000){
02040       Int_t colors[10000];
02041       for(int i=0;i<ncolor;i++){colors[i]=i+100;}
02042       gStyle->SetPalette(ncolor,colors);
02043     }
02044     tempfile.clear();
02045     tempfile.seekg(0,std::ios::beg);
02046     std::cout << "created palette with " << ncolor << " colors" << std::endl;
02047     while(!tempfile.eof()) {//create polylines
02048       tempfile  >> red >> green  >> blue >> npoints; 
02049       for (int i=0;i<npoints;i++){
02050         tempfile >> x[i] >> y[i];  
02051       }
02052       colindex=red+green*1000+blue*1000000;
02053       pos=colorList.find(colindex); 
02054       if(pos != colorList.end()){
02055         TPolyLine*  pline = new TPolyLine(npoints,y,x);
02056         vp.push_back(pline);
02057         pline->SetFillColor(colorList[colindex]);
02058         pline->SetLineWidth(0);
02059         pline->Draw("f");
02060       }
02061     }
02062         if (printflag&&!saveWebInterface) {
02063       float lminvalue=minvalue; float lmaxvalue=maxvalue;
02064       if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10);}
02065       axis = new TGaxis(rangex-140,34,rangex-140,rangey-106,lminvalue,lmaxvalue,510,"+L");
02066       axis->SetLabelSize(0.02);
02067       axis->Draw();
02068     }
02069 
02070     if(!saveWebInterface){
02071     TLatex l;
02072     l.SetTextSize(0.05);
02073     std::string fulltitle = title;
02074     if(tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos)) fulltitle += ": Log10 scale";
02075     l.DrawLatex(50,rangey-200,fulltitle.c_str());
02076        }
02077     MyC->Update();
02078     std::cout << "Filetype " << filetype << std::endl;
02079     if(filetype=="png"){
02080       std::string filename = outputfilename + ".png";
02081       MyC->Print(filename.c_str());
02082     }
02083     if(filetype=="jpg"){
02084       std::string filename = outputfilename + ".jpg";
02085       MyC->Print(filename.c_str());
02086     }
02087     if(filetype=="pdf"){
02088       std::string filename = outputfilename + ".pdf";
02089       MyC->Print(filename.c_str());
02090     }
02091     std::string command = "rm "+tempfilename ;
02092     command1=command.c_str();
02093     std::cout << "Executing " << command1 << std::endl;
02094     system(command1);
02095     MyC->Clear();
02096     delete MyC;
02097      if (printflag&&!saveWebInterface)delete axis;
02098     for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
02099          delete (*pos1);}
02100    
02101 }//if(temporary_file)
02102 }//if(enabledFedProcessing)
02103 }
02104 
02105 void TrackerMap::save_as_fedtrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
02106  if(enableFedProcessing){
02107   printflag=true;
02108    bool rangefound = true; 
02109   std::string filetype=s,outputfilename=s;
02110   std::vector<TPolyLine*> vp;
02111   TGaxis *axis = 0 ;
02112   
02113   size_t found=filetype.find_last_of(".");
02114   filetype=filetype.substr(found+1);
02115   found=outputfilename.find_last_of(".");
02116   outputfilename=outputfilename.substr(0,found);
02117   
02118   temporary_file=true;
02119   if(filetype=="xml"||filetype=="svg")temporary_file=false;
02120   std::ostringstream outs;
02121   minvalue=minval; maxvalue=maxval;
02122   outs << outputfilename << ".coor";
02123   if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
02124   std::map<int , TmApvPair *>::iterator i_apv;
02125   std::map<int , int>::iterator i_fed;
02126   //Decide if we must use Module or ApvPair value
02127   bool useApvPairValue=false;
02128   for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
02129     TmApvPair *  apvPair= i_apv->second;
02130     if(apvPair!=0) {
02131       TmModule * apv_mod = apvPair->mod;
02132       if(apv_mod !=0 && !apv_mod->notInUse()){
02133         if(apvPair->count > 0 || apvPair->red!=-1) { useApvPairValue=true; break;}
02134       }
02135     }
02136   }
02137   if(!print_total){
02138     for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
02139       TmApvPair *  apvPair= i_apv->second;
02140       if(apvPair!=0) {
02141         TmModule * apv_mod = apvPair->mod;
02142         if(apv_mod !=0 && !apv_mod->notInUse() ){
02143           if(useApvPairValue) apvPair->value = apvPair->value / apvPair->count;
02144           else if(apvPair->mpos==0 && apv_mod->count>0)apv_mod->value = apv_mod->value / apv_mod->count; 
02145         }
02146       }
02147     }
02148   }
02149   if(minvalue>=maxvalue){
02150     
02151     minvalue=9999999.;
02152     maxvalue=-9999999.;
02153     rangefound=false;
02154     for(i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
02155         TmApvPair *  apvPair= i_apv->second;
02156         if(apvPair!=0 ) {
02157           TmModule * apv_mod = apvPair->mod;
02158           if( apv_mod !=0 && !apv_mod->notInUse() ){
02159             if(useApvPairValue){
02160               rangefound=true;
02161               if (minvalue > apvPair->value)minvalue=apvPair->value;
02162               if (maxvalue < apvPair->value)maxvalue=apvPair->value;
02163             } else {
02164               if(apv_mod->count>0){
02165               rangefound=true;
02166               if (minvalue > apv_mod->value)minvalue=apv_mod->value;
02167               if (maxvalue < apv_mod->value)maxvalue=apv_mod->value;}
02168             }
02169           }
02170         }
02171     }
02172   }
02173   if ((title==" Tracker Map from  QTestAlarm") || (maxvalue == minvalue)||!rangefound) printflag = false;
02174 
02175      if(filetype=="svg"){
02176       saveAsSingleLayer=false;
02177       std::ostringstream outs;
02178     outs << outputfilename<<".svg";
02179     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
02180   *savefile << "<?xml version=\"1.0\"  standalone=\"no\" ?>"<<std::endl;
02181   *savefile << "<svg  xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
02182   *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<std::endl;
02183   *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<std::endl;
02184   *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
02185   *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl; 
02186   *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
02187      }
02188   for (int crate=firstcrate; crate < (ncrates+1); crate++){
02189     if(filetype=="xml"){
02190       saveAsSingleLayer=true;
02191       std::ostringstream outs;
02192     outs << outputfilename<<"crate" <<crate<< ".xml";
02193     savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
02194     *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
02195     *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
02196     *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<std::endl;
02197     *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<std::endl;
02198     *savefile << "<script type=\"text/ecmascript\" xlink:href=\"crate.js\" />"<<std::endl;
02199     *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0  500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
02200     *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
02201     *savefile << "<g id=\"crate\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\"  > "<<std::endl;
02202         }
02203     //    ncrate=crate;
02204     defcwindow(crate);
02205     int numfed_incrate=0;
02206     for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
02207       if(i_fed->second == crate){
02208         int fedId = i_fed->first;
02209         //      numfed_incrate++;
02210         numfed_incrate = slotMap[fedId];
02211         // the following piece of code is used to prepare the HTML clickable map
02212         /*      
02213         double scalex=6285./6290.;
02214         double scaley=3510./3540.;
02215         double boxinitix=(NUMFED_INCOLUMN-1-(numfed_incrate-1)/NUMFED_INROW)*(NUMFEDCH_INCOLUMN+2)+NUMFEDCH_INCOLUMN+0.9;
02216         double boxinitiy=(NUMFED_INROW-1-(numfed_incrate-1)%NUMFED_INROW)*(NUMFEDCH_INROW+1)+NUMFEDCH_INROW+0.9;
02217         double boxendix=boxinitix-(NUMFEDCH_INCOLUMN-1)-0.9;
02218         double boxendiy=boxinitiy-(NUMFEDCH_INROW-1)-0.9;
02219 
02220         std::cout << "<area shape=\"rect\" coords=\" " 
02221                   << int(scalex*ydpixelc(boxinitiy)) << "," << int(3510-scaley*xdpixelc(boxinitix)) 
02222                   << "," << int(scalex*ydpixelc(boxendiy)) << "," << int(3510-scaley*xdpixelc(boxendix)) 
02223                   << "\" href=\"\" title=\"crate " << crate << " slot " << numfed_incrate << " FED " << fedId << "\" /> " << std::endl;
02224         */
02225         //
02226         for (int nconn=0;nconn<96;nconn++){
02227           int key = fedId*1000+nconn; 
02228           TmApvPair *  apvPair= apvMap[key];
02229           if(apvPair !=0){
02230             TmModule * apv_mod = apvPair->mod;
02231             if(apv_mod !=0 && !apv_mod->notInUse()){
02232               drawApvPair(crate,numfed_incrate,print_total,apvPair,savefile,useApvPairValue);
02233             }
02234           } 
02235         }
02236       }
02237     }
02238    if(!temporary_file){
02239     if(filetype=="xml"){
02240     *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
02241     *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
02242     *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
02243     *savefile << " </text> </svg>" << std::endl;
02244     savefile->close();delete savefile;
02245      saveAsSingleLayer=false;
02246       }
02247       }
02248   }
02249     if(filetype=="svg"){
02250     *savefile << "</g> </svg> </svg> " << std::endl;
02251     savefile->close();delete savefile;
02252       }
02253   if(!print_total && !useApvPairValue){
02254 //Restore module value
02255     for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
02256       TmApvPair *  apvPair= i_apv->second;
02257       if(apvPair!=0) {
02258         TmModule * apv_mod = apvPair->mod;
02259         if(apv_mod !=0 && apvPair->mpos==0 && !apv_mod->notInUse()){
02260           apv_mod->value = apv_mod->value * apv_mod->count;
02261         }
02262       }
02263     }
02264 }
02265   
02266   int rangex = YFEDOFFSET+(YFEDCSIZE+YFEDOFFSET)*NUMFEDCRATE_INROW+300;
02267   int rangey = XFEDOFFSET+(XFEDCSIZE+XFEDOFFSET)*NUMFEDCRATE_INCOLUMN+300;
02268     
02269     if(temporary_file){
02270       if(printflag&&!saveWebInterface)drawPalette(savefile,rangex-140,rangey-100);
02271   savefile->close(); delete savefile;
02272 
02273   const char * command1;
02274   std::string tempfilename = outputfilename + ".coor";
02275     int red,green,blue,npoints,colindex,ncolor;
02276     double x[4],y[4];
02277     ifstream tempfile(tempfilename.c_str(),std::ios::in);
02278     TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
02279     gPad->SetFillColor(38);
02280 
02281     //    if(saveWebInterface)gPad->Range(0,0,3750,1600); else gPad->Range(0,0,3800,1600);
02282     std::cout << " range x " <<  rangex << std::endl;
02283     std::cout << " range y " <<  rangey << std::endl;
02284     gPad->Range(0,0,rangex,rangey);
02285     
02286     //First  build palette
02287     ncolor=0;
02288     typedef std::map<int,int> ColorList;
02289     ColorList colorList;
02290     ColorList::iterator pos;
02291     TColor *col,*c;
02292     while(!tempfile.eof()) {
02293       tempfile  >> red >> green  >> blue >> npoints; 
02294       colindex=red+green*1000+blue*1000000;
02295       pos=colorList.find(colindex); 
02296       if(pos == colorList.end()){ 
02297         colorList[colindex]=ncolor+100; 
02298         col =gROOT->GetColor(ncolor+100);
02299         if(col) 
02300           col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.)); 
02301         else 
02302           c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
02303         vc.push_back(c);
02304         ncolor++;
02305       }
02306       for (int i=0;i<npoints;i++){
02307         tempfile >> x[i] >> y[i];  
02308       }
02309     }
02310     if(ncolor>0 && ncolor<10000){
02311       Int_t colors[10000];
02312       for(int i=0;i<ncolor;i++){colors[i]=i+100;}
02313       gStyle->SetPalette(ncolor,colors);
02314     }
02315     tempfile.clear();
02316     tempfile.seekg(0,std::ios::beg);
02317     std::cout << "created palette with " << ncolor << " colors" << std::endl;
02318     while(!tempfile.eof()) {//create polylines
02319       tempfile  >> red >> green  >> blue >> npoints; 
02320       for (int i=0;i<npoints;i++){
02321         tempfile >> x[i] >> y[i];  
02322       }
02323       colindex=red+green*1000+blue*1000000;
02324       pos=colorList.find(colindex); 
02325       if(pos != colorList.end()){
02326         TPolyLine*  pline = new TPolyLine(npoints,y,x);
02327         vp.push_back(pline);
02328         pline->SetFillColor(colorList[colindex]);
02329         pline->SetLineWidth(0);
02330         pline->Draw("f");
02331       }
02332     }
02333         if (printflag&&!saveWebInterface) {
02334       float lminvalue=minvalue; float lmaxvalue=maxvalue;
02335       if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10);}
02336       axis = new TGaxis(rangex-140,34,rangex-140,rangey-106,lminvalue,lmaxvalue,510,"+L");
02337       axis->SetLabelSize(0.02);
02338       axis->Draw();
02339     }
02340 
02341     if(!saveWebInterface){
02342     TLatex l;
02343     l.SetTextSize(0.05);
02344     std::string fulltitle = title;
02345     if(tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos)) fulltitle += ": Log10 scale";
02346     l.DrawLatex(50,rangey-200,fulltitle.c_str());
02347        }
02348     MyC->Update();
02349     std::cout << "Filetype " << filetype << std::endl;
02350     if(filetype=="png"){
02351       std::string filename = outputfilename + ".png";
02352       MyC->Print(filename.c_str());
02353     }
02354     if(filetype=="jpg"){
02355       std::string filename = outputfilename + ".jpg";
02356       MyC->Print(filename.c_str());
02357     }
02358     if(filetype=="pdf"){
02359       std::string filename = outputfilename + ".pdf";
02360       MyC->Print(filename.c_str());
02361     }
02362     std::string command = "rm "+tempfilename ;
02363     command1=command.c_str();
02364     std::cout << "Executing " << command1 << std::endl;
02365     system(command1);
02366     MyC->Clear();
02367     delete MyC;
02368      if (printflag&&!saveWebInterface)delete axis;
02369     for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
02370          delete (*pos1);}
02371    
02372   
02373 }//if(temporary_file)
02374 }//if(enabledFedProcessing)
02375 }
02376 
02377 void TrackerMap::load(std::string inputfilename){
02378   inputfile = new ifstream(inputfilename.c_str(),std::ios::in);
02379   std::string line,value;
02380   int ipos,ipos1,ipos2,id=0,val=0;
02381   int nline=0;
02382   while (getline( *inputfile, line ))
02383         {
02384         ipos1 = line.find("value=\"");
02385         if(ipos1 > 0)      {
02386              value = line.substr(ipos1+7,10);
02387              ipos = value.find("\"");
02388              value = value.substr(0,ipos); 
02389              val=atoi(value.c_str());
02390              }
02391         ipos2 = line.find("detid=\"");
02392         if(ipos2 > 0)      {
02393              value = line.substr(ipos2+7,10);
02394              ipos = value.find("\"");
02395              value = value.substr(0,ipos); 
02396              id = atoi(value.c_str());
02397              }
02398         if(ipos1>0 && ipos2>0 && val>0)this->fill(id,val);
02399         if(ipos1>0 && ipos2>0)nline++;
02400         //if(ipos1>0 && ipos2>0)std::cout << nline << " " << id << " " << val << std::endl; 
02401 
02402         }
02403        std::cout << nline << " modules found in this svg file " << std::endl;
02404        inputfile->close();delete inputfile;
02405  }
02406 
02407 
02408 
02409 //print in svg format tracker map
02410 //print_total = true represent in color the total stored in the module
02411 //print_total = false represent in color the average  
02412 void TrackerMap::print(bool print_total, float minval, float maxval, std::string outputfilename){
02413   temporary_file=false;
02414   std::ostringstream outs;
02415   minvalue=minval; maxvalue=maxval;
02416   outs << outputfilename << ".xml";
02417   svgfile = new std::ofstream(outs.str().c_str(),std::ios::out);
02418   jsfile = new ifstream(edm::FileInPath(jsfilename).fullPath().c_str(),std::ios::in);
02419 
02420   //copy javascript interface from trackermap.txt file
02421   std::string line;
02422   while (getline( *jsfile, line ))
02423         {
02424             *svgfile << line << std::endl;
02425         }
02426   jsfile->close();delete jsfile;
02427   //
02428  if(!print_total){
02429   for (int layer=1; layer < 44; layer++){
02430     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
02431       for (int module=1;module<200;module++) {
02432         int key=layer*100000+ring*1000+module;
02433         TmModule * mod = smoduleMap[key];
02434         if(mod !=0 && !mod->notInUse()){
02435           mod->value = mod->value / mod->count;
02436         }
02437       }
02438     }
02439   }
02440   }
02441   if(minvalue>=maxvalue){
02442   minvalue=9999999.;
02443   maxvalue=-9999999.;
02444   for (int layer=1; layer < 44; layer++){
02445     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
02446       for (int module=1;module<200;module++) {
02447         int key=layer*100000+ring*1000+module;
02448         TmModule * mod = smoduleMap[key];
02449         if(mod !=0 && !mod->notInUse()){
02450           if (minvalue > mod->value)minvalue=mod->value;
02451           if (maxvalue < mod->value)maxvalue=mod->value;
02452         }
02453       }
02454     }
02455   }
02456 }
02457   for (int layer=1; layer < 44; layer++){
02458     //    nlay=layer;
02459     defwindow(layer);
02460     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
02461       for (int module=1;module<200;module++) {
02462         int key=layer*100000+ring*1000+module;
02463         TmModule * mod = smoduleMap[key];
02464         if(mod !=0 && !mod->notInUse()){
02465           drawModule(mod,key,layer,print_total,svgfile);
02466         }
02467       }
02468     }
02469   }
02470   *svgfile << "</svg:g></svg:svg>"<<std::endl;
02471   *svgfile << " <svg:text id=\"Title\" class=\"normalText\"  x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<std::endl;
02472   if(printflag)drawPalette(svgfile);
02473   *svgfile << "</svg:svg>"<<std::endl;
02474   *svgfile << "</body></html>"<<std::endl;
02475    svgfile->close();delete svgfile;
02476 
02477 }
02478 
02479 void TrackerMap::drawPalette(std::ofstream * svgfile,int xoffset, int yoffset){
02480   std::cout << "preparing the palette" << std::endl;
02481   int color,red, green, blue;
02482   float val=minvalue;
02483   int paletteLength = 250;
02484   int width=50*(yoffset-40)/1500;
02485   float dval = (maxvalue-minvalue)/(float)paletteLength;
02486   bool rtkMapLog = tkMapLog; if (tkMapLog)tkMapLog=false;
02487   float step = float(yoffset-40)/float(paletteLength);
02488   for(int i=1;i<paletteLength+1;i++){
02489   color = getcolor(val,palette);
02490      red=(color>>16)&0xFF;
02491      green=(color>>8)&0xFF;
02492      blue=(color)&0xFF;
02493  //   if(!temporary_file)*svgfile <<"<svg:rect  x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"6\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n"; 
02494   //  else *svgfile << red << " " << green << " " << blue << " 4 " << (6*i)+40 << " 3010. " <<//
02495    //           (6*i)+40 << " 3060. " <<//
02496     //          (6*(i-1))+40 << " 3060. " <<//
02497      //         (6*(i-1))+40 <<" 3010. " << std::endl; //
02498 
02499    // if(i%50 == 0){
02500     //  if(!temporary_file)*svgfile <<"<svg:rect  x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"1\" fill=\"black\" />\n";
02501      // if(i%50==0&&!temporary_file)*svgfile << " <svg:text  class=\"normalText\"  x=\"3060\" y=\""<<(1560-6*i)<<"\">" <<val<<"</svg:text>"<<std::endl;
02502 
02503     if(!temporary_file)*svgfile <<"<svg:rect  x=\"3610\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"6\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n"; 
02504     else *svgfile << red << " " << green << " " << blue << " 4 " << int(step*i)+34 << " " << xoffset-width << ". " <<//
02505       int(step*i)+34 << " " << xoffset << ". " <<//
02506       int(step*(i-1))+34 << " " << xoffset << ". " <<//
02507       int(step*(i-1))+34 << " " << xoffset-width << ". " << std::endl; //
02508 
02509     if(i%50 == 0){
02510      if(!temporary_file)*svgfile <<"<svg:rect  x=\"3610\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"1\" fill=\"black\" />\n";
02511       if(i%50==0&&!temporary_file)*svgfile << " <svg:text  class=\"normalText\"  x=\"3660\" y=\""<<(1560-6*i)<<"\">" <<val<<"</svg:text>"<<std::endl;
02512        }
02513     val = val + dval;
02514    }
02515   tkMapLog=rtkMapLog;
02516 } 
02517 void TrackerMap::fillc_fed_channel(int fedId,int fedCh, int red, int green, int blue  )
02518 {
02519   int key = fedId*1000+fedCh;
02520   TmApvPair* apvpair = apvMap[key];
02521   
02522   if(apvpair!=0){
02523     apvpair->red=red; apvpair->green=green; apvpair->blue=blue;
02524     return;
02525   }
02526   std::cout << "*** error in FedTrackerMap fillc method ***";
02527 }
02528 
02529 void TrackerMap::fill_fed_channel(int idmod, float qty  )
02530 {
02531   std::multimap<const int, TmApvPair*>::iterator pos;
02532   for (pos = apvModuleMap.lower_bound(idmod);
02533          pos != apvModuleMap.upper_bound(idmod); ++pos) {
02534   TmApvPair* apvpair = pos->second;
02535   if(apvpair!=0){
02536     apvpair->value=apvpair->value+qty;
02537     apvpair->count++;
02538   }
02539   }
02540     return;
02541   std::cout << "*** error in FedTrackerMap fill by module method ***";
02542   }
02543 
02544 void TrackerMap::fill_current_val_fed_channel(int fedId, int fedCh, float current_val )
02545 {
02546   int key = fedId*1000+fedCh;
02547   TmApvPair* apvpair = apvMap[key];
02548   
02549   if(apvpair!=0)  {apvpair->value=current_val; apvpair->count=1; apvpair->red=-1;}
02550   else 
02551     std::cout << "*** error in FedTrackerMap fill_current_val method ***";
02552 }
02553 
02554 
02555 void TrackerMap::fillc_fec_channel(int crate,int slot, int ring, int addr, int red, int green, int blue  )
02556  {
02557  int key =crate*10000000+slot*100000+ring*1000+addr;
02558 
02559  TmCcu *ccu = ccuMap[key];
02560  
02561  if(ccu!=0){
02562     ccu->red=red; ccu->green=green; ccu->blue=blue;
02563     return;
02564   }
02565   std::cout << "*** error in FecTrackerMap fillc method ***";
02566 }
02567 
02568 void TrackerMap::fill_fec_channel(int crate,int slot, int ring, int addr, float qty  )
02569 {
02570  int key =crate*10000000+slot*100000+ring*1000+addr;
02571  TmCcu *ccu = ccuMap[key];
02572   if(ccu!=0){
02573     ccu->count++; ccu->value=ccu->value+qty;
02574     return;
02575  
02576   }
02577   
02578   std::cout << "*** error in FecTrackerMap fill by module method ***";
02579   }
02580 
02581  
02582 
02583 void TrackerMap::fillc_lv_channel(int rack,int crate, int board, int red, int green, int blue  )
02584 {
02585  
02586  int key = rack*1000+crate*100+board;
02587  
02588  TmPsu *psu = psuMap[key];
02589   
02590   if(psu!=0){
02591     psu->red=red; psu->green=green; psu->blue=blue;
02592     return;
02593   }
02594   std::cout << "*** error in LVTrackerMap fillc method ***";
02595 }
02596 
02597 void TrackerMap::fill_lv_channel(int rack,int crate, int board, float qty  )
02598 {
02599  int key = rack*1000+crate*100+board;
02600  TmPsu *psu = psuMap[key];
02601   if(psu!=0){
02602     psu->count++; psu->value=psu->value+qty;
02603     return;
02604  
02605   }
02606   
02607   std::cout << "*** error in LVTrackerMap fill by module method ***";
02608   }
02609 
02610 void TrackerMap::fillc_hv_channel2(int rack,int crate, int board, int red, int green, int blue  )
02611 {
02612  
02613  int key = rack*1000+crate*100+board;
02614  
02615  TmPsu *psu = psuMap[key];
02616   
02617   if(psu!=0){
02618     psu->redHV2=red; psu->greenHV2=green; psu->blueHV2=blue;
02619     return;
02620   }
02621   std::cout << "*** error in HVTrackerMap (channel 2) fillc method ***";
02622 }
02623 void TrackerMap::fillc_hv_channel3(int rack,int crate, int board, int red, int green, int blue  )
02624 {
02625  
02626  int key = rack*1000+crate*100+board;
02627  
02628  TmPsu *psu = psuMap[key];
02629   
02630   if(psu!=0){
02631     psu->redHV3=red; psu->greenHV3=green; psu->blueHV3=blue;
02632     return;
02633   }
02634   std::cout << "*** error in HVTrackerMap (channel 3) fillc method ***";
02635 }
02636 
02637 
02638 void TrackerMap::fill_hv_channel2(int rack,int crate, int board, float qty  )
02639 {
02640  int key = rack*1000+crate*100+board;
02641  TmPsu *psu = psuMap[key];
02642   if(psu!=0){
02643     psu->countHV2++; psu->valueHV2=psu->valueHV2+qty;
02644     return;
02645  
02646   }
02647   
02648   std::cout << "*** error in HVTrackerMap fill by module method ***";
02649   }
02650 void TrackerMap::fill_hv_channel3(int rack,int crate, int board, float qty  )
02651 {
02652  int key = rack*1000+crate*100+board;
02653  TmPsu *psu = psuMap[key];
02654   if(psu!=0){
02655     psu->countHV3++; psu->valueHV3=psu->valueHV3+qty;
02656     return;
02657  
02658   }
02659   
02660   std::cout << "*** error in HVTrackerMap fill by module method ***";
02661   }
02662 
02663 
02664 
02665 
02666 
02667 int TrackerMap::module(int fedId, int fedCh)
02668 {
02669   int key = fedId*1000+fedCh;
02670   TmApvPair* apvpair = apvMap[key];
02671   if(apvpair!=0){
02672     return(apvpair->mod->idex);
02673   }
02674   return(0);
02675   std::cout << "*** error in FedTrackerMap module method ***";
02676 }
02677 void TrackerMap::fill_fed_channel(int fedId, int fedCh, float qty )
02678 {
02679   int key = fedId*1000+fedCh;
02680   TmApvPair* apvpair = apvMap[key];
02681   if(apvpair!=0){
02682     apvpair->value=apvpair->value+qty;
02683     apvpair->count++;
02684     return;
02685   }
02686   std::cout << "*** error inFedTrackerMap fill method ***";
02687 }
02688 
02689 
02690 void TrackerMap::fillc(int idmod, int red, int green, int blue  ){
02691 
02692   TmModule * mod = imoduleMap[idmod];
02693   if(mod!=0){
02694      mod->red=red; mod->green=green; mod->blue=blue;
02695      return;
02696   }
02697   std::cout << "**************************error in fill method **************module "<<idmod<<std::endl;
02698 }
02699 void TrackerMap::fillc(int layer, int ring, int nmod, int red, int green, int blue  ){
02700   
02701   int key = layer*10000+ring*1000+nmod;
02702   TmModule * mod = smoduleMap[key];
02703 
02704   if(mod!=0){
02705      mod->red=red; mod->green=green; mod->blue=blue;
02706     return;
02707   }
02708   std::cout << "**************************error in fill method **************"<< std::endl;
02709 }
02710 
02711 void TrackerMap::fillc_all_blank(){
02712 
02713   std::map<const int  , TmModule *>::iterator imod;
02714    for( imod=imoduleMap.begin();imod !=imoduleMap.end(); imod++){
02715    fillc(imod->first,255,255,255); 
02716    }
02717 }
02718 
02719 void TrackerMap::fill_all_blank(){
02720 
02721   std::map<const int  , TmModule *>::iterator imod;
02722    for( imod=imoduleMap.begin();imod !=imoduleMap.end(); imod++){
02723    fill_current_val(imod->first,0); 
02724    }
02725 }
02726 
02727 
02728 
02729 void TrackerMap::fill_current_val(int idmod, float current_val ){
02730 
02731   TmModule * mod = imoduleMap[idmod];
02732   if(mod!=0)  {mod->value=current_val; mod->count=1;  mod->red=-1;}
02733   else std::cout << "**error in fill_current_val method ***module "<<idmod<<std::endl;
02734 }
02735 
02736 void TrackerMap::fill(int idmod, float qty ){
02737 
02738   TmModule * mod = imoduleMap[idmod];
02739   if(mod!=0){
02740     mod->value=mod->value+qty;
02741     mod->count++;
02742     return;
02743   }else{
02744    TmModule * mod1 = imoduleMap[idmod+1];
02745    TmModule * mod2 = imoduleMap[idmod+2];
02746    if(mod1!=0 && mod2!=0){
02747     mod1->value=mod1->value+qty;
02748     mod1->count++;
02749     mod2->value=mod2->value+qty;
02750     mod2->count++;
02751     return;
02752    }}
02753   std::cout << "**************************error in fill method **************module "<<idmod<<std::endl;
02754 }
02755 
02756 void TrackerMap::fill(int layer, int ring, int nmod,  float qty){
02757 
02758   int key = layer*100000+ring*1000+nmod;
02759   TmModule * mod = smoduleMap[key];
02760   if(mod!=0){
02761      mod->value=mod->value+qty;
02762      mod->count++;
02763   }
02764   else std::cout << "**************************error in SvgModuleMap **************";
02765 } 
02766 
02767 void TrackerMap::setText(int idmod, std::string s){
02768 
02769   TmModule * mod = imoduleMap[idmod];
02770   if(mod!=0){
02771      mod->text=s;
02772   }
02773   else std::cout << "**************************error in IdModuleMap **************";
02774 }
02775 
02776 
02777 void TrackerMap::setText(int layer, int ring, int nmod, std::string s){
02778 
02779   int key = layer*100000+ring*1000+nmod;
02780   TmModule * mod = smoduleMap[key];
02781   if(mod!=0){
02782      mod->text=s;
02783   }
02784   else std::cout << "**************************error in SvgModuleMap **************";
02785 } 
02786 
02787 void TrackerMap::build(){
02788   //  ifstream* infile;
02789 
02790   int nmods, pix_sil, fow_bar, ring, nmod, layer;
02791   unsigned int idex;
02792   float posx, posy, posz, length, width, thickness, widthAtHalfLength;
02793   int iModule=0,old_layer=0, ntotMod =0;
02794   std::string name,dummys;
02795   ifstream infile(edm::FileInPath(infilename).fullPath().c_str(),std::ios::in);
02796   while(!infile.eof()) {
02797     infile >> nmods >> pix_sil >> fow_bar >> layer >> ring >> nmod >> posx >> posy
02798            >> posz>> length >> width >> thickness
02799            >> widthAtHalfLength >> idex ;
02800     getline(infile,dummys); //necessary to reach end of record
02801     getline(infile,name); 
02802     if(old_layer!=layer){old_layer=layer;iModule=0;}
02803     iModule++;
02804     ntotMod++;
02805     int key=layer*100000+ring*1000+nmod;
02806     TmModule * mod = smoduleMap[key];
02807     
02808     imoduleMap[idex]=mod;
02809 
02810     if(mod==0) std::cout << "error in module "<<key <<std::endl;
02811     else
02812       {
02813           mod->posx = posx;
02814           mod->posy = posy;
02815           mod->setUsed();
02816           mod->value=0;
02817           mod->count=0;
02818           mod->posz = posz;
02819           mod->length = length;
02820           mod->width = width;
02821           mod->thickness = thickness;
02822           mod->widthAtHalfLength = widthAtHalfLength;
02823           mod->idex = idex;
02824           mod->name = name;
02825       }
02826   }
02827   infile.close();
02828   number_modules = ntotMod-1;
02829 }
02830 int TrackerMap::getcolor(float value,int palette){
02831    int red,green,blue;
02832    float lminvalue, lmaxvalue;
02833    lminvalue=minvalue; lmaxvalue=maxvalue;
02834    if(tkMapLog) {lminvalue=log(minvalue)/log(10);lmaxvalue=log(maxvalue)/log(10); value=log(value)/log(10);}
02835 
02836    
02837    red=0;green=0;blue=0;
02838    if(palette==1){//palette1 1 - raibow
02839    float delta=(lmaxvalue-lminvalue);
02840    float x =(value-lminvalue);
02841    if(value<lminvalue){red=0;green=0;blue=255;}
02842    if(value>lmaxvalue){red=255;green=0;blue=0;}
02843    if(value>=lminvalue&&value<=lmaxvalue){ 
02844    red = (int) ( x<(delta/2) ? 0 : ( x > ((3./4.)*delta) ?  255 : 255/(delta/4) * (x-(2./4.)*delta)  ) );
02845    green= (int) ( x<delta/4 ? (x*255/(delta/4)) : ( x > ((3./4.)*delta) ?  255-255/(delta/4) *(x-(3./4.)*delta) : 255 ) );
02846    blue = (int) ( x<delta/4 ? 255 : ( x > ((1./2.)*delta) ?  0 : 255-255/(delta/4) * (x-(1./4.)*delta) ) );
02847      }
02848      }
02849      if (palette==2){//palette 2 yellow-green
02850      green = (int)((value-lminvalue)/(lmaxvalue-lminvalue)*256.);
02851          if (green > 255) green=255;
02852          red = 255; blue=0;green=255-green;  
02853         } 
02854   // std::cout<<red<<" "<<green<<" "<<blue<<" "<<value <<" "<<lminvalue<<" "<< lmaxvalue<<std::endl;
02855    return(blue|(green<<8)|(red<<16));
02856 }
02857 void TrackerMap::printonline(){
02858 //Copy interface
02859   std::ofstream * ofilename;
02860   std::ifstream * ifilename;
02861   std::ostringstream ofname;
02862   std::string ifname;
02863   std::string command;
02864   std::string line;
02865   std::string outputfilename="dqmtmap";
02866   ifilename=findfile("viewerHeader.xhtml");
02867   ofname << outputfilename << "viewer.html";
02868   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02869   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02870 *ofilename <<"    var tmapname=\"" <<outputfilename << "\""<<std::endl;
02871 *ofilename <<"    var tmaptitle=\"" <<title << "\""<<std::endl;
02872 *ofilename <<"    var ncrates=" <<ncrates << ";"<<std::endl;
02873 *ofilename <<"    var nfeccrates=" <<nfeccrates << ";"<<std::endl;
02874  *ofilename <<"    var npsuracks=" <<npsuracks << ";"<<std::endl;
02875  
02876    ifilename->close();delete ifilename;
02877 
02878   ifilename=findfile("viewerTrailer.xhtml");
02879   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02880    ofilename->close();delete ofilename;
02881    command = "sed -i \"s/XtmapnameX/"+outputfilename+"/g\" "+ ofname.str();
02882     std::cout << "Executing " << command << std::endl;
02883     system(command.c_str());
02884    command = "sed -i \"s/XtmaptitleX/"+title+"/g\" "+ ofname.str();
02885     std::cout << "Executing " << command << std::endl;
02886     system(command.c_str());
02887   ofname.str("");
02888    ifilename->close();delete ifilename;
02889 
02890   ifilename=findfile("jqviewer.js");
02891   ofname << "jqviewer.js";
02892   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02893   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02894   ofname.str("");
02895    ofilename->close();delete ofilename;
02896    ifilename->close();delete ifilename;
02897 
02898   ifilename=findfile("crate.js");
02899   ofname <<  "crate.js";
02900   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02901   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02902   ofname.str("");
02903    ofilename->close();delete ofilename;
02904    ifilename->close();delete ifilename;
02905 
02906   ifilename=findfile("feccrate.js");
02907   ofname <<  "feccrate.js";
02908   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02909   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02910   ofname.str("");
02911    ofilename->close();delete ofilename;
02912    ifilename->close();delete ifilename;
02913   
02914   ifilename=findfile("layer.js");
02915   ofname <<  "layer.js";
02916   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02917   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02918    ofname.str("");
02919    ofilename->close();delete ofilename;
02920    ifilename->close();delete ifilename;
02921   
02922   ifilename=findfile("rack.js");
02923   ofname <<  "rack.js";
02924   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02925   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02926    ofname.str("");
02927    ofilename->close();delete ofilename;
02928    ifilename->close();delete ifilename;
02929    ofname.str("");
02930   
02931   ifilename=findfile("rackhv.js");
02932   ofname <<  "rackhv.js";
02933   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
02934   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
02935    ofname.str("");
02936    ofilename->close();delete ofilename;
02937    ifilename->close();delete ifilename;
02938     
02939     
02940     
02941     
02942    std::ostringstream outs,outs1,outs2;
02943     outs << outputfilename<<".png";
02944 save(true,gminvalue,gmaxvalue,outs.str(),3000,1600);
02945 temporary_file=false;
02946 printlayers(true,gminvalue,gmaxvalue,outputfilename);
02947 
02948 //Now print a text file for each layer 
02949   std::ofstream * txtfile;
02950 for (int layer=1; layer < 44; layer++){
02951   std::ostringstream outs;
02952     outs << outputfilename <<"layer"<<layer<< ".html";
02953     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
02954     *txtfile << "<html><head></head> <body>" << std::endl;
02955     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
02956       for (int module=1;module<200;module++) {
02957         int key=layer*100000+ring*1000+module;
02958         TmModule * mod = smoduleMap[key];
02959         if(mod !=0 && !mod->notInUse()){
02960             int idmod=mod->idex;
02961             int nchan=0;
02962             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
02963              std::multimap<const int, TmApvPair*>::iterator pos;
02964              for (pos = apvModuleMap.lower_bound(idmod);
02965                 pos != apvModuleMap.upper_bound(idmod); ++pos) {
02966                TmApvPair* apvpair = pos->second;
02967                if(apvpair!=0){
02968                    nchan++;
02969                    *txtfile  <<  apvpair->text << std::endl;
02970                     }
02971 
02972                     }
02973                    *txtfile  << "</pre><h3>"<< mod->name<<"</h3>"<<std::endl;
02974                   }
02975                 }
02976                 }
02977     *txtfile << "</body></html>" << std::endl;
02978     txtfile->close();delete txtfile;
02979                 }
02980 if(enableFedProcessing){
02981     outs1 << outputfilename<<"fed.png";
02982 save_as_fedtrackermap(true,gminvalue,gmaxvalue,outs1.str(),6000,3200);
02983     outs2 << outputfilename<<".xml";
02984 save_as_fedtrackermap(true,gminvalue,gmaxvalue,outs2.str(),3000,1600);
02985 //And a text file for each crate 
02986   std::map<int , int>::iterator i_fed;
02987   std::ofstream * txtfile;
02988   for (int crate=firstcrate; crate < (ncrates+1); crate++){
02989     std::ostringstream outs;
02990     outs << outputfilename <<"crate"<<crate<< ".html";
02991     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
02992     *txtfile << "<html><head></head> <body>" << std::endl;
02993     for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
02994       if(i_fed->second == crate){
02995         int fedId = i_fed->first;
02996         for (int nconn=0;nconn<96;nconn++){
02997           int key = fedId*1000+nconn; 
02998           TmApvPair *  apvPair= apvMap[key];
02999           if(apvPair !=0){
03000             int idmod=apvPair->idex;
03001             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
03002             *txtfile  <<  apvPair->text << std::endl;
03003             std::ostringstream outs;
03004             outs << "fedchannel "  <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module  " << apvPair->mod->idex ;
03005             *txtfile  << "</pre><h3>"<< outs.str()<<"</h3>"<<std::endl;
03006              }
03007           }
03008       }
03009       }
03010     *txtfile << "</body></html>" << std::endl;
03011     txtfile->close();delete txtfile;
03012                 }
03013   }
03014 if(enableFecProcessing){
03015   std::ostringstream outs1,outs2;
03016     outs1 << outputfilename<<"fec.png";
03017 save_as_fectrackermap(true,gminvalue,gmaxvalue,outs1.str(),6000,3200);
03018     outs2 << outputfilename<<".xml";
03019 save_as_fectrackermap(true,gminvalue,gmaxvalue,outs2.str(),3000,1600);
03020 //And a text file for each crate
03021   std::ofstream * txtfile;
03022   std::map<int , TmCcu *>::iterator i_ccu;
03023   std::multimap<TmCcu*, TmModule*>::iterator it;
03024   std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
03025   for (int crate=1; crate < (nfeccrates+1); crate++){
03026     std::ostringstream outs;
03027     outs << outputfilename <<"feccrate"<<crate<< ".html";
03028     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03029     *txtfile << "<html><head></head> <body>" << std::endl;
03030     for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
03031      TmCcu *  ccu= i_ccu->second;
03032       if(ccu!=0&&ccu->getCcuCrate() == crate){
03033             int idmod=ccu->idex;
03034             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
03035             *txtfile  <<  ccu->text << std::endl;
03036             std::ostringstream outs;
03037             if(ccu->nmod==0)outs << "ccu  is in position" << ccu->mpos<<"in ring but doesn't seem to have any module connected"; else
03038             {
03039             outs << "ccu  is in position " << ccu->mpos<<" in ring and connects  " <<ccu->nmod<< " modules" << std::endl;
03040             ret = fecModuleMap.equal_range(ccu);
03041         for (it = ret.first; it != ret.second; ++it)
03042           {
03043            outs << (*it).second->idex<<" " << (*it).second->name <<" value= "<< (*it).second->value<<"\n\n";
03044           }
03045 
03046             *txtfile  << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
03047           }//ifccu->nmod==0
03048       }//if ccu!=0
03049       }//for i_ccu
03050     *txtfile << "</body></html>" << std::endl;
03051     txtfile->close();delete txtfile;
03052                 }//for int crate
03053   }
03054 if(enableLVProcessing){
03055   std::ostringstream outs3,outs4;
03056     outs3 << outputfilename<<"psu.png";
03057 save_as_psutrackermap(true,gminvalue,gmaxvalue,outs3.str(),6000,3200);
03058 
03059     outs4 << outputfilename<<".xml";
03060 save_as_psutrackermap(true,gminvalue,gmaxvalue,outs4.str(),3000,1600);
03061 //And a text file for each rack 
03062   
03063   std::ofstream * txtfile;
03064   std::map<int , TmPsu *>::iterator ipsu;
03065   std::multimap<TmPsu*, TmModule*>::iterator it;
03066   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
03067   for (int rack=1; rack < (npsuracks+1); rack++){
03068     std::ostringstream outs;
03069     
03070     outs << outputfilename <<"psurack"<<rack<< ".html";
03071     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03072     *txtfile << "<html><head></head> <body>" << std::endl;
03073      for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
03074       TmPsu *  psu= ipsu->second;
03075       if(psu!=0 && psu->getPsuRack() == rack){
03076         *txtfile  << "<a name="<<psu->idex<<"><pre>"<<std::endl;      
03077         *txtfile  <<  psu->text << std::endl;
03078         std::ostringstream outs;
03079         if(psu->nmod==0)outs << "Ps is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03080         {
03081         outs<< "PS is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmod<<" modules. "<<std::endl;
03082         
03083         ret = psuModuleMap.equal_range(psu);
03084         for (it = ret.first; it != ret.second; ++it)
03085           {
03086            outs <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;
03087            
03088           }
03089         *txtfile  << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
03090      }
03091     }
03092   }
03093   *txtfile << "</body></html>" << std::endl;
03094    txtfile->close();delete txtfile;
03095   }
03096  } 
03097 
03098 
03099 if(enableHVProcessing){
03100   std::ostringstream outs5,outs6;
03101     outs5 << outputfilename<<"hv.png";
03102 save_as_HVtrackermap(true,gminvalue,gmaxvalue,outs5.str(),6000,3200);
03103 
03104     outs6 << outputfilename<<".xml";
03105 save_as_HVtrackermap(true,gminvalue,gmaxvalue,outs6.str(),3000,1600);
03106 //And a text file for each rack 
03107 
03108  std::ofstream * txtfile;
03109   std::map<int , TmPsu *>::iterator ipsu;
03110   std::multimap<TmPsu*, TmModule*>::iterator it;
03111   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
03112   for (int rack=1; rack < (npsuracks+1); rack++){
03113     std::ostringstream outs;
03114     
03115     outs << outputfilename <<"HVrack"<<rack<< ".html";
03116     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03117     *txtfile << "<html><head></head> <body>" << std::endl;
03118      for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
03119       TmPsu *  psu= ipsu->second;
03120       if(psu!=0 && psu->getPsuRack() == rack){
03121         *txtfile  << "<a name="<<psu->idex<<"><pre>"<<std::endl;      
03122         *txtfile  <<  psu->textHV2 << std::endl;
03123         std::ostringstream outsHV2;
03124         if(psu->nmodHV2==0)outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03125         {
03126         outsHV2<< "HV Channel002 is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV2<<" modules. "<<" <br>"<<std::endl;
03127         
03128         ret = psuModuleMap.equal_range(psu);
03129         for (it = ret.first; it != ret.second; ++it)
03130           {
03131            if((*it).second->HVchannel==2){outsHV2 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
03132           }
03133         *txtfile  << "</pre><h4>"<< outsHV2.str()<<"</h4>"<<std::endl;
03134      }
03135     
03136         *txtfile  <<  psu->textHV3 << std::endl;
03137         std::ostringstream outsHV3;
03138         if(psu->nmodHV3==0)outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03139         {
03140         outsHV3<< "HV Channel003 is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV3<<" modules. "<<" <br>"<<std::endl;
03141         
03142         ret = psuModuleMap.equal_range(psu);
03143         for (it = ret.first; it != ret.second; ++it)
03144           {
03145            if((*it).second->HVchannel==3){outsHV3 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
03146           }
03147         *txtfile  << "</pre><h4>"<< outsHV3.str()<<"</h4>"<<std::endl;
03148      }
03149    
03150     }
03151   }
03152   *txtfile << "</body></html>" << std::endl;
03153    txtfile->close();delete txtfile;
03154   }
03155  } 
03156  
03157 }
03158 void TrackerMap::printall(bool print_total, float minval1, float maxval1, std::string s,int width, int height){
03159 //Copy interface
03160  float minval,maxval; minval=minval1; maxval=maxval1; 
03161   if(tkMapLog && (minval<maxval)) {minval=pow(10.,minval1);maxval=pow(10.,maxval1);}
03162   std::string filetype=s,outputfilename=s;
03163   if(saveWebInterface){width=6000;height=3200;}
03164   else{ 
03165   size_t found=filetype.find_last_of(".");
03166   filetype=filetype.substr(found+1);
03167   found=outputfilename.find_last_of(".");
03168   outputfilename=outputfilename.substr(0,found);
03169   }
03170   std::ofstream * ofilename;
03171   std::ifstream * ifilename;
03172   std::ostringstream ofname;
03173   std::string ifname;
03174   std::string line;
03175   std::string command;
03176   if(saveWebInterface){
03177   ifilename=findfile("viewerHeader.xhtml");
03178   ofname << outputfilename << "viewer.html";
03179   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03180   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03181 *ofilename <<"    var tmapname=\"" <<outputfilename << "\""<<std::endl;
03182 *ofilename <<"    var tmaptitle=\"" <<title << "\""<<std::endl;
03183 *ofilename <<"    var ncrates=" <<ncrates << ";"<<std::endl;
03184 *ofilename <<"    var nfeccrates=" <<nfeccrates << ";"<<std::endl;
03185 *ofilename <<"    var npsuracks=" <<npsuracks << ";"<<std::endl;
03186    ifilename->close();delete ifilename;
03187   ifilename=findfile("viewerTrailer.xhtml");
03188   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03189    ofilename->close();delete ofilename;
03190    ifilename->close();delete ifilename;
03191    command = "sed -i \"s/XtmapnameX/"+outputfilename+"/g\" "+ ofname.str();
03192     std::cout << "Executing " << command << std::endl;
03193     system(command.c_str());
03194    command = "sed -i \"s/XtmaptitleX/"+title+"/g\" "+ ofname.str();
03195     std::cout << "Executing " << command << std::endl;
03196     system(command.c_str());
03197   ofname.str("");
03198   
03199 ifilename=findfile("jqviewer.js");
03200   ofname << "jqviewer.js";
03201   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03202   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03203    ofilename->close();delete ofilename;
03204    ifilename->close();delete ifilename;
03205  
03206   ofname.str("");
03207   ifilename=findfile("crate.js");
03208   ofname <<  "crate.js";
03209   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03210   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03211    ofilename->close();delete ofilename;
03212    ifilename->close();delete ifilename;
03213  
03214   ofname.str("");
03215   ifilename=findfile("feccrate.js");
03216   ofname <<  "feccrate.js";
03217   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03218   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03219    ofilename->close();delete ofilename;
03220    ifilename->close();delete ifilename;
03221  
03222   ofname.str("");
03223   ifilename=findfile("rack.js");
03224   ofname <<  "rack.js";
03225   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03226   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03227    ofilename->close();delete ofilename;
03228    ifilename->close();delete ifilename;
03229  
03230    ofname.str("");
03231   ifilename=findfile("rackhv.js");
03232   ofname <<  "rackhv.js";
03233   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03234   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03235    ofilename->close();delete ofilename;
03236    ifilename->close();delete ifilename;
03237    
03238    ofname.str("");
03239   ifilename=findfile("layer.js");
03240   ofname <<  "layer.js";
03241   ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
03242   while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
03243    ofilename->close();delete ofilename;
03244    ifilename->close();delete ifilename;
03245   
03246    command = "scp -r ../../DQM/TrackerCommon/test/jquery/ .";
03247     std::cout << "Executing " << command << std::endl;
03248     system(command.c_str());
03249    command = "scp -r ../../CommonTools/TrackerMap/data/images/ .";
03250     std::cout << "Executing " << command << std::endl;
03251     system(command.c_str());
03252 }
03253  
03254     std::ostringstream outs;
03255     outs << outputfilename<<".png";
03256     if(saveWebInterface)save(true,minval,maxval,outs.str(),3000,1600);
03257     else {if(saveGeoTrackerMap)save(true,minval,maxval,s,width,height);}
03258   if(saveWebInterface){
03259     std::ostringstream outs;
03260     outs << outputfilename<<".png";
03261 temporary_file=false;
03262 printlayers(true,minval,maxval,outputfilename);
03263 
03264 //Now print a text file for each layer 
03265   std::ofstream * txtfile;
03266 for (int layer=1; layer < 44; layer++){
03267   std::ostringstream outs;
03268     outs << outputfilename <<"layer"<<layer<< ".html";
03269     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03270     *txtfile << "<html><head></head> <body>" << std::endl;
03271     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
03272       for (int module=1;module<200;module++) {
03273         int key=layer*100000+ring*1000+module;
03274         TmModule * mod = smoduleMap[key];
03275         if(mod !=0 && !mod->notInUse()){
03276             int idmod=mod->idex;
03277             int nchan=0;
03278             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
03279              std::multimap<const int, TmApvPair*>::iterator pos;
03280              for (pos = apvModuleMap.lower_bound(idmod);
03281                 pos != apvModuleMap.upper_bound(idmod); ++pos) {
03282                TmApvPair* apvpair = pos->second;
03283                if(apvpair!=0){
03284                    nchan++;
03285                    *txtfile  <<  apvpair->text << std::endl;
03286                     }
03287 
03288                     }
03289                    *txtfile  << "</pre><h3>"<< mod->name<<"</h3>"<<std::endl;
03290                   }
03291                 }
03292                 }
03293     *txtfile << "</body></html>" << std::endl;
03294     txtfile->close();delete txtfile;
03295 }
03296                 }
03297 if(enableFedProcessing){
03298   std::ostringstream outs1,outs2;
03299     if(saveWebInterface)outs1 << outputfilename<<"fed.png";
03300         else outs1 << outputfilename<<"fed."<<filetype;
03301 save_as_fedtrackermap(true,0.,0.,outs1.str(),width,height);
03302   if(saveWebInterface){
03303     outs2 << outputfilename<<".xml";
03304 save_as_fedtrackermap(true,0.,0.,outs2.str(),3000,1600);
03305 //And a text file for each crate 
03306   std::map<int , int>::iterator i_fed;
03307   std::ofstream * txtfile;
03308   for (int crate=firstcrate; crate < (ncrates+1); crate++){
03309     std::ostringstream outs;
03310     outs << outputfilename <<"crate"<<crate<< ".html";
03311     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03312     *txtfile << "<html><head></head> <body>" << std::endl;
03313     for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
03314       if(i_fed->second == crate){
03315         int fedId = i_fed->first;
03316         for (int nconn=0;nconn<96;nconn++){
03317           int key = fedId*1000+nconn; 
03318           TmApvPair *  apvPair= apvMap[key];
03319           if(apvPair !=0){
03320             int idmod=apvPair->idex;
03321             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
03322             *txtfile  <<  apvPair->text << std::endl;
03323             std::ostringstream outs;
03324             outs << "fedchannel "  <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module  " << apvPair->mod->idex ;
03325             *txtfile  << "</pre><h3>"<< outs.str()<<"</h3>"<<std::endl;
03326              }
03327           }
03328       }
03329       }
03330     *txtfile << "</body></html>" << std::endl;
03331     txtfile->close();delete txtfile;
03332                 }
03333    }
03334   }
03335 if(enableFecProcessing){
03336   std::ostringstream outs1,outs2;
03337     if(saveWebInterface)outs1 << outputfilename<<"fec.png";
03338         else outs1 << outputfilename<<"fec."<<filetype;
03339 save_as_fectrackermap(true,0.,0.,outs1.str(),width,height);
03340   if(saveWebInterface){
03341     outs2 << outputfilename<<".xml";
03342 save_as_fectrackermap(true,0.,0.,outs2.str(),3000,1600);
03343 //And a text file for each crate
03344   std::ofstream * txtfile;
03345   std::map<int , TmCcu *>::iterator i_ccu;
03346   std::multimap<TmCcu*, TmModule*>::iterator it;
03347   std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
03348   for (int crate=1; crate < (nfeccrates+1); crate++){
03349     std::ostringstream outs;
03350     outs << outputfilename <<"feccrate"<<crate<< ".html";
03351     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03352     *txtfile << "<html><head></head> <body>" << std::endl;
03353     for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
03354      TmCcu *  ccu= i_ccu->second;
03355       if(ccu!=0&&ccu->getCcuCrate() == crate){
03356             int idmod=ccu->idex;
03357             *txtfile  << "<a name="<<idmod<<"><pre>"<<std::endl;
03358             *txtfile  <<  ccu->text << std::endl;
03359             std::ostringstream outs;
03360             if(ccu->nmod==0)outs << "ccu  is in position" << ccu->mpos<<"in ring but doesn't seem to have any module connected"; else
03361             {
03362             outs << "ccu  is in position " << ccu->mpos<<" in ring and connects  " <<ccu->nmod<< " modules" << std::endl;
03363             ret = fecModuleMap.equal_range(ccu);
03364         for (it = ret.first; it != ret.second; ++it)
03365           {
03366            outs << (*it).second->idex<<" " << (*it).second->name <<" value= "<< (*it).second->value<<"\n\n";
03367           }
03368 
03369             *txtfile  << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
03370           }//ifccu->nmod==0
03371       }//if ccu!=0
03372       }//for i_ccu
03373     *txtfile << "</body></html>" << std::endl;
03374     txtfile->close();
03375                 }//for int crate
03376   }
03377   }
03378 if(enableLVProcessing){
03379   std::ostringstream outs3,outs4;
03380     if(saveWebInterface)outs3 << outputfilename<<"psu.png";
03381         else outs3 << outputfilename<<"psu."<<filetype;
03382 save_as_psutrackermap(true,0.,0.,outs3.str(),width,height);
03383   if(saveWebInterface){
03384     outs4 << outputfilename<<".xml";
03385 save_as_psutrackermap(true,0.,0.,outs4.str(),3000,1600);
03386 //And a text file for each rack 
03387   
03388   std::ofstream * txtfile;
03389   std::map<int , TmPsu *>::iterator ipsu;
03390   std::multimap<TmPsu*, TmModule*>::iterator it;
03391   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
03392   for (int rack=1; rack < (npsuracks+1); rack++){
03393     std::ostringstream outs;
03394     
03395     outs << outputfilename <<"psurack"<<rack<< ".html";
03396     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03397     *txtfile << "<html><head></head> <body>" << std::endl;
03398      for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
03399       TmPsu *  psu= ipsu->second;
03400       if(psu!=0 && psu->getPsuRack() == rack){
03401         *txtfile  << "<a name="<<psu->idex<<"><pre>"<<std::endl;      
03402         *txtfile  <<  psu->text << std::endl;
03403         std::ostringstream outs;
03404         if(psu->nmod==0)outs << "Ps is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03405         {
03406         outs<< "PS is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmod<<" modules. "<<std::endl;
03407         
03408         ret = psuModuleMap.equal_range(psu);
03409         for (it = ret.first; it != ret.second; ++it)
03410           {
03411            outs <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;
03412            
03413           }
03414         *txtfile  << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
03415      }
03416     }
03417   }
03418   *txtfile << "</body></html>" << std::endl;
03419    txtfile->close();
03420   }
03421   }
03422  } 
03423 
03424 
03425 if(enableHVProcessing){
03426   std::ostringstream outs5,outs6;
03427     if(saveWebInterface)outs5 << outputfilename<<"hv.png";
03428         else outs5 << outputfilename<<"hv."<<filetype;
03429 save_as_HVtrackermap(true,0.,0.,outs5.str(),width,height);
03430   if(saveWebInterface){
03431     outs6 << outputfilename<<".xml";
03432 save_as_HVtrackermap(true,0.,0.,outs6.str(),3000,1600);
03433 //And a text file for each rack 
03434 
03435   std::ofstream * txtfile;
03436   std::map<int , TmPsu *>::iterator ipsu;
03437   std::multimap<TmPsu*, TmModule*>::iterator it;
03438   std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
03439   for (int rack=1; rack < (npsuracks+1); rack++){
03440     std::ostringstream outs;
03441     
03442     outs << outputfilename <<"HVrack"<<rack<< ".html";
03443     txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03444     *txtfile << "<html><head></head> <body>" << std::endl;
03445      for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
03446       TmPsu *  psu= ipsu->second;
03447       if(psu!=0 && psu->getPsuRack() == rack){
03448         *txtfile  << "<a name="<<psu->idex<<"><pre>"<<std::endl;      
03449         *txtfile  <<  psu->textHV2 << std::endl;
03450         std::ostringstream outsHV2;
03451         if(psu->nmodHV2==0)outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03452         {
03453         outsHV2<< "HV Channel002 is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV2<<" modules. "<<" <br>"<<std::endl;
03454         
03455         ret = psuModuleMap.equal_range(psu);
03456         for (it = ret.first; it != ret.second; ++it)
03457           {
03458            if((*it).second->HVchannel==2){outsHV2 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
03459           }
03460         *txtfile  << "</pre><h4>"<< outsHV2.str()<<"</h4>"<<std::endl;
03461      }
03462     
03463         *txtfile  <<  psu->textHV3 << std::endl;
03464         std::ostringstream outsHV3;
03465         if(psu->nmodHV3==0)outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
03466         {
03467         outsHV3<< "HV Channel003 is in position "  <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV3<<" modules. "<<" <br>"<<std::endl;
03468         
03469         ret = psuModuleMap.equal_range(psu);
03470         for (it = ret.first; it != ret.second; ++it)
03471           {
03472            if((*it).second->HVchannel==3){outsHV3 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
03473           }
03474         *txtfile  << "</pre><h4>"<< outsHV3.str()<<"</h4>"<<std::endl;
03475      }
03476    
03477     }
03478   }
03479   *txtfile << "</body></html>" << std::endl;
03480    txtfile->close();
03481   }
03482  } 
03483  } 
03484 
03485 
03486 }
03487 
03488 
03489 std::ifstream * TrackerMap::findfile(std::string filename) {
03490   std::ifstream * ifilename;
03491   std::string ifname;
03492   if(jsPath!=""){
03493   ifname=jsPath+filename;
03494   ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
03495   if(!ifilename){
03496   ifname="CommonTools/TrackerMap/data/"+filename;
03497   ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
03498   }
03499   }else {
03500   ifname="CommonTools/TrackerMap/data/"+filename;
03501   ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
03502  }
03503   if(!ifilename)std::cout << "File " << filename << " missing" << std::endl;
03504   return ifilename;
03505  }
03506 void TrackerMap::printlayers(bool print_total, float minval, float maxval, std::string outputfilename){
03507   std::ofstream * xmlfile;
03508 saveAsSingleLayer=true;
03509 if(!print_total){
03510     for (int layer=1; layer < 44; layer++){
03511       for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
03512         for (int module=1;module<200;module++) {
03513           int key=layer*100000+ring*1000+module;
03514           TmModule * mod = smoduleMap[key];
03515           if(mod !=0 && !mod->notInUse()){
03516             mod->value = mod->value / mod->count;
03517           }
03518         }
03519       }
03520     }
03521   }
03522   if(minvalue>=maxvalue){
03523     minvalue=9999999.;
03524     maxvalue=-9999999.;
03525     for (int layer=1; layer < 44; layer++){
03526       for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
03527         for (int module=1;module<200;module++) {
03528           int key=layer*100000+ring*1000+module;
03529           TmModule * mod = smoduleMap[key];
03530           if(mod !=0 && !mod->notInUse()){
03531             if (minvalue > mod->value)minvalue=mod->value;
03532             if (maxvalue < mod->value)maxvalue=mod->value;
03533           }
03534         }
03535       }
03536     }
03537   }
03538 for (int layer=1; layer < 44; layer++){
03539   std::ostringstream outs;
03540     outs << outputfilename <<"layer"<<layer<< ".xml";
03541     xmlfile = new std::ofstream(outs.str().c_str(),std::ios::out);
03542     *xmlfile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
03543     *xmlfile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<std::endl;
03544     *xmlfile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<std::endl;
03545     *xmlfile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<std::endl;
03546     *xmlfile << "<script type=\"text/ecmascript\" xlink:href=\"layer.js\" />"<<std::endl;
03547     *xmlfile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0  500 500\" width=\"700\" height=\"700\" onload=\"TrackerLayer.init()\">"<<std::endl;
03548     if(layer<31)*xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,1.)\"  > "<<std::endl;
03549     else *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,0.8)\"  > "<<std::endl;
03550     *xmlfile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
03551     *xmlfile << "<svg:polygon id=\"fed\" mapAttribute=\"fed\" points=\"250,40 250,10 230,10 230,40\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" fill=\"rgb(0,127,255)\"/>"<<std::endl;
03552     *xmlfile << "<svg:polygon id=\"fec\" mapAttribute=\"fec\" points=\"228,40 228,10 208,10 208,40\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" fill=\"rgb(0,127,255)\"/>"<<std::endl;
03553     *xmlfile << "<svg:polygon id=\"lv\" mapAttribute=\"lv\" points=\"206,40 206,10 186,10 186,40\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" fill=\"rgb(0,127,255)\"/>"<<std::endl;
03554     *xmlfile << "<svg:polygon id=\"hv\" mapAttribute=\"hv\" points=\"184,40 184,10 164,10 164,40\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" fill=\"rgb(0,127,255)\"/>"<<std::endl;
03555     *xmlfile << "<svg:polygon id=\"plot\" mapAttribute=\"plot\" points=\"155,45 155,5 135,5 135,45\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" fill=\"rgb(200,0,0)\"/>"<<std::endl;
03556   
03557     //    nlay=layer;
03558     defwindow(layer);
03559     for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
03560       for (int module=1;module<200;module++) {
03561         int key=layer*100000+ring*1000+module;
03562         TmModule * mod = smoduleMap[key];
03563         if(mod !=0 && !mod->notInUse()){
03564           drawModule(mod,key,layer,print_total,xmlfile);
03565         }
03566       }
03567     }
03568     *xmlfile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\">" << std::endl;
03569     *xmlfile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
03570     *xmlfile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
03571     *xmlfile << "<tspan id=\"line3\" x=\"40\" y=\"90\"> </tspan> " << std::endl;
03572     *xmlfile << "<tspan id=\"line4\" x=\"40\" y=\"120\"> </tspan> " << std::endl;
03573     if(layer > 33){
03574     *xmlfile << "<tspan  mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"228\" font-size=\"12\" font-family=\"arial\" fill=\"white\">FED</tspan> " <<std::endl;
03575     *xmlfile << "<tspan  mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"258\" font-size=\"12\" font-family=\"arial\" fill=\"white\">FEC</tspan> " <<std::endl;
03576     *xmlfile << "<tspan  mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"289\" font-size=\"12\" font-family=\"arial\" fill=\"white\">LV</tspan> " <<std::endl;
03577     *xmlfile << "<tspan  mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"319\" font-size=\"12\" font-family=\"arial\" fill=\"white\">HV</tspan> " <<std::endl;
03578     *xmlfile << "<tspan  mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"12\" y=\"360\" font-size=\"12\" font-family=\"arial\" fill=\"white\">PLOT</tspan> " <<std::endl;
03579     }
03580     else{
03581     *xmlfile << "<tspan   mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"228\" font-size=\"12\" font-family=\"arial\" fill=\"white\">FED</tspan> " <<std::endl;
03582     *xmlfile << "<tspan   mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"258\" font-size=\"12\" font-family=\"arial\" fill=\"white\">FEC</tspan> " <<std::endl;
03583     *xmlfile << "<tspan   mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"289\" font-size=\"12\" font-family=\"arial\" fill=\"white\">LV</tspan> " <<std::endl;
03584     *xmlfile << "<tspan   mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"319\" font-size=\"12\" font-family=\"arial\" fill=\"white\">HV</tspan> " <<std::endl;
03585     *xmlfile << "<tspan   mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" x=\"17\" y=\"360\" font-size=\"12\" font-family=\"arial\" fill=\"white\">PLOT</tspan> " <<std::endl;
03586     }
03587     *xmlfile << " </text> </svg>" << std::endl;
03588     xmlfile->close();delete xmlfile;
03589   }
03590 saveAsSingleLayer=false;
03591 }