CMS 3D CMS Logo

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