CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackerMap.cc
Go to the documentation of this file.
10 #include <fstream>
11 #include <vector>
12 #include <iostream>
13 #include <sstream>
14 #include "TCanvas.h"
15 #include "TPolyLine.h"
16 #include "TStyle.h"
17 #include "TColor.h"
18 #include "TROOT.h"
19 #include "TGaxis.h"
20 #include "TLatex.h"
21 #include "TArrow.h"
22 
23 
24 /**********************************************************
25 Allocate all the modules in a map of TmModule
26 The filling of the values for each module is done later
27 when the user starts to fill it.
28 **********************************************************/
29 
31 
32  psetAvailable=true;
33  xsize=340;ysize=200;
34  title=" ";
35  jsPath="";
36  jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
37  infilename="CommonTools/TrackerMap/data/tracker.dat";
38  saveAsSingleLayer=false;
39  if(tkmapPset.exists("trackermaptxtPath")){
40  jsPath=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath",""
41 );
42  jsfilename=jsPath+"trackermap.txt";
43  std::cout << jsfilename << std::endl;
44  infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"tracker.dat";
45  std::cout << infilename << std::endl;
46  ncrates=0;
47  enableFedProcessing=tkmapPset.getUntrackedParameter<bool>("loadFedCabling",false);
48  nfeccrates=0;
49  enableFecProcessing=tkmapPset.getUntrackedParameter<bool>("loadFecCabling",false);
50  // std::cout << "loadFecCabling " << enableFecProcessing << std::endl;
51  npsuracks=0;
52  enableLVProcessing=tkmapPset.getUntrackedParameter<bool>("loadLVCabling",false);
53  // std::cout << "loadLVCabling " << enableLVProcessing << std::endl;
54  enableHVProcessing=tkmapPset.getUntrackedParameter<bool>("loadHVCabling",false);
55  // std::cout << "loadHVCabling " << enableHVProcessing << std::endl;
56  } else std::cout << "no parameters found" << std::endl;
57 
58  init();
59 // Now load fed cabling information
61  const std::vector<unsigned short> feds = tkFed->feds();
62  std::cout<<"SiStripFedCabling has "<< feds.size()<<" active FEDS"<<std::endl;
63  int num_board=0;
64  int num_crate=0;
65  for(std::vector<unsigned short>::const_iterator ifed = feds.begin();ifed<feds.end();ifed++){
66  const std::vector<FedChannelConnection> theconn = tkFed->connections( *ifed );
67  int num_conn=0;
68  for(std::vector<FedChannelConnection>::const_iterator iconn = theconn.begin();iconn<theconn.end();iconn++){
69 
70  if( iconn->fedId()== sistrip::invalid_ ||
71  iconn->detId() == sistrip::invalid_ ||
72  iconn->detId() == sistrip::invalid32_ ||
73  iconn->apvPairNumber() == sistrip::invalid_ ||
74  iconn->nApvPairs() == sistrip::invalid_ ) {
75  continue;
76  }
77 
78  TmModule *imod = imoduleMap[iconn->detId()];
79  int key = iconn->fedId()*1000+iconn->fedCh();
80  TmApvPair* apvpair = apvMap[key];
81  if(apvpair!=0)std::cout << "Fed "<< iconn->fedId() << " channel " << iconn->fedCh() << " seem to be already loaded!"<<std::endl;
82  else
83  {
84  num_conn++;
85  if(num_conn==1){
86  if(fedMap[iconn->fedId()]==0){num_crate=num_board/18+1;fedMap[iconn->fedId()]=num_crate;num_board++;}
87  }
88  apvpair = new TmApvPair(key,num_crate);
89  apvpair->mod=imod;
90  apvpair->mpos=iconn->apvPairNumber();
91  apvMap[key] = apvpair;
92  apvModuleMap.insert(std::make_pair(iconn->detId(),apvpair));
93  std::stringstream s;
94  iconn->print(s);
95  apvpair->text=s.str();
96  }
97  }
98  }
99  ncrates=num_crate;
100  std::cout << num_crate << " crates used "<< std::endl;
101 //Now add APv information to module name
102  std::map<int , TmModule *>::iterator i_mod;
103  for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
104  TmModule * mod= i_mod->second;
105  if(mod!=0) {
106  std::ostringstream outs,outs1;
107  outs << " connected to ";
108  outs1 << "(";
109 
110  int idmod=mod->idex;
111  int nchan=0;
112  std::multimap<const int, TmApvPair*>::iterator pos;
113  for (pos = apvModuleMap.lower_bound(idmod);
114  pos != apvModuleMap.upper_bound(idmod); ++pos) {
115  TmApvPair* apvpair = pos->second;
116  if(apvpair!=0){
117  outs << apvpair->mpos << " " <<apvpair->getFedId() << "/"<<apvpair->getFedCh()<<" ";
118  outs1 << apvpair->idex+apvpair->crate*1000000<<",";
119  nchan++;
120  }
121 
122  }
123  outs<< "("<<nchan<<")";
124  mod->name=mod->name + outs.str();
125  std::string s = outs1.str(); s.erase(s.end()-1,s.end());
126  mod->capvids=s+")";
127  }
128  }
129 }
130 // Now load fec cabling information
132  int nfec=0; int nccu; int nmod;
133  int crate,slot,ring,addr,pos;
134  SiStripFecCabling* fecCabling_;
135  fecCabling_ = new SiStripFecCabling( *tkFed );
136  std::string Ccufilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"cculist.txt";
137  ifstream Ccufile(edm::FileInPath(Ccufilename).fullPath().c_str(),std::ios::in);
138  std::string dummys;
139  while(!Ccufile.eof()) {
140  Ccufile >> crate >> slot >> ring >> addr >> pos;
141  getline(Ccufile,dummys);
142  int key =crate*10000000+slot*100000+ring*1000+addr;
143  TmCcu * ccu = ccuMap[key];
144  if(ccu==0){
145  ccu = new TmCcu(crate,slot,ring,addr);
146  ccu->mpos=pos,
147  ccuMap[key]=ccu;
148  }
149  }
150 
151  for ( std::vector<SiStripFecCrate>::const_iterator icrate = fecCabling_->crates().begin(); icrate != fecCabling_->crates().end(); icrate++ ) {
152  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
153  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
154  nccu=0;nfec++;
155  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
156  nccu++; nmod=0;
157  int key = icrate->fecCrate()*10000000+ifec->fecSlot()*100000+iring->fecRing()*1000+iccu->ccuAddr();
158  int layer=0;
159  TmCcu * ccu = ccuMap[key];
160  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
161  nmod++;
162  TmModule *imod1 = imoduleMap[imod->detId()];
163  layer=imod1->layer;
164  fecModuleMap.insert(std::make_pair(ccu,imod1));
165  if(imod1!=0)imod1->CcuId=key;//imod1->ccuId=key+Crate*1000000
166  }
167  if(ccu==0)std::cout <<key<< " This ccu seems to have not been stored! " << std::endl; else{ ccu->nmod=nmod;ccu->layer=layer;}
168  //std::cout <<nfec<<" "<< nccu << " " << nmod << std::endl;
169 
170  }
171  }
172  }
173  }
174 
175  std::map<int , TmCcu *>::iterator i_ccu;
176  std::multimap<TmCcu*, TmModule*>::iterator it;
177  std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
178  nccu=0;
179  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
180  TmCcu * ccu= i_ccu->second;
181  nccu++;
182  if(ccu!=0){
183  std::ostringstream outs;
184  std::ostringstream outs1;
185  outs << "CCU "<<ccu->idex <<" connected to fec,ring " << ccu->getCcuSlot() <<","<<ccu->getCcuRing()<< " in crate " <<ccu->getCcuCrate()<<" at position "<< ccu->mpos << " with " << ccu->nmod << " modules: ";
186  outs1<<"(";
187  ret = fecModuleMap.equal_range(ccu);
188  for (it = ret.first; it != ret.second; ++it)
189  {
190  outs << (*it).second->idex << " ";
191  outs1 << (*it).second->getKey() <<",";
192  }
193  outs1 << ")";
194  ccu->text=outs.str();
195  ccu->cmodid=outs1.str();
196  //std::cout << ccu->text << std::endl;
197  }
198 
199  }
200  nfeccrates=4;
201  std::cout << nccu << " ccu stored in " <<nfeccrates<< " crates"<< std::endl;
202 
203  delete fecCabling_ ;
204 
205  }
206 //load Psu cabling info
207  //load Psu cabling info
209  int npsu=0; int nmod,nmodHV2,nmodHV3;
210  int modId1,modId2, dcuId;
211  int dcs,branch,crate,board;
212  int rack=0;
213  std::string channelstr1;
214  short int channel;
215  std::string psinfo;
216  // ifstream *LVfile;
217  // ifstream *HVfile;
218 
219 
220 
221  std::string LVfilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"psdcumap.dat";
222  std::string HVfilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"hvmap.dat";
223 
224  ifstream LVfile(edm::FileInPath(LVfilename).fullPath().c_str(),std::ios::in);
225 
226  std::cout<<LVfilename<<" "<<HVfilename<<std::endl;
227 
228 
229  if(enableHVProcessing){
230 
231  ifstream HVfile(edm::FileInPath(HVfilename).fullPath().c_str(),std::ios::in);
232  while(!HVfile.eof()) {
233  HVfile >> modId2 >> channelstr1;
234  std::string channelstr2 = channelstr1.substr(9,1);
235  channel= atoi(channelstr2.c_str());
236  TmModule *imod = imoduleMap[modId2];
237  // if(modId1==modId2){
238  imod->HVchannel=channel;
239 
240  }
241 
242  }
243 
244 
245  while(!LVfile.eof()) {
246  LVfile >> modId1 >> dcuId >> psinfo;
247 
248  int length=psinfo.length();
249  std::string dcsinfo = psinfo.substr(39,1);
250  std::string branchinfo = psinfo.substr(57,2);
251  std::string crateinfo= psinfo.substr(69,1);
252  std::string boardinfo = psinfo.substr(80,2);
253  std::string psIdinfo = psinfo.substr(83,length-83);
254 
255  dcs= atoi(dcsinfo.c_str());
256  branch= atoi(branchinfo.c_str());
257  crate= atoi(crateinfo.c_str())+1;
258  board= atoi(boardinfo.c_str())+1;
259 
260  if(dcs==1)rack=(branch+1)/2;
261  if(dcs==2)rack=(branch+1)/2 + 7;
262  if(dcs==3)rack=(branch+1)/2 + 15;
263  if(dcs==4)rack=(branch+1)/2 + 22;
264 
265  int key = rack*1000+crate*100+board;
266 
267  TmPsu *psu = psuMap[key];
268  TmModule *imod = imoduleMap[modId1];
269  if(psu==0){
270  psu = new TmPsu(dcs,branch,rack,crate,board);
271  psuMap[key]=psu;
272  psu->psId=psIdinfo;
273  }
274 
275  psuModuleMap.insert(std::make_pair(psu,imod));
276  if(imod!=0)imod->PsuId=psIdinfo;imod->psuIdex=psu->idex;
277 
278  }
279 
280 
281  // int nmax=0;
282  std::map<int , TmPsu *>::iterator ipsu;
283  std::multimap<TmPsu*, TmModule*>::iterator it;
284  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
285  npsu=0;
286 
287  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
288  TmPsu * psu= ipsu->second;
289  npsu++;
290 
291  if(psu!=0){
292 
293  std::ostringstream outs;
294  std::ostringstream outs1;
295 
296  std::ostringstream outs3;
297  std::ostringstream outs4;
298 
299  std::ostringstream outs5;
300  std::ostringstream outs6;
301 
302  outs <<"PSU "<<psu->psId<<" connected to Mainframe "<<psu->getPsuDcs()<<" BranchController "<<psu->getPsuBranch()<<" (Rack "<<psu->getPsuRack()<<"), crate "<<psu->getPsuCrate()<<" in position "<< psu->getPsuBoard()<< " with modules: ";
303  outs1<<"(";
304 
305  if(enableHVProcessing){
306  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: ";
307  outs4<<"(";
308 
309  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: ";
310  outs6<<"(";}
311 
312 
313  ret = psuModuleMap.equal_range(psu);
314  nmod=0;
315  nmodHV2=0;
316  nmodHV3=0;
317  for (it = ret.first; it != ret.second; ++it)
318  {
319  nmod++;
320  outs << (*it).second->idex << ", ";
321  outs1 << (*it).second->getKey() <<",";
322 
323  if(enableHVProcessing){
324  if((*it).second->HVchannel==2){
325  nmodHV2++;
326  outs3 << (*it).second->idex << ", ";
327  outs4 << (*it).second->getKey() <<",";}
328  else if((*it).second->HVchannel==3){
329  nmodHV3++;
330  outs5 << (*it).second->idex << ", ";
331  outs6 << (*it).second->getKey() <<",";}
332 
333  }
334  }
335 
336  outs1 << ")";
337  psu->nmod=nmod;
338  outs << "(" << psu->nmod << ")";
339  psu->text=outs.str();
340  psu->cmodid_LV=outs1.str();
341  if(enableHVProcessing){
342  outs4 << ")";
343  outs6 << ")";
344  psu->nmodHV2=nmodHV2;
345  psu->nmodHV3=nmodHV3;
346  outs3 << "(" << psu->nmodHV2 << ")";
347  outs5 << "(" << psu->nmodHV3 << ")";
348  psu->textHV2=outs3.str();
349  psu->textHV3=outs5.str();
350  psu->cmodid_HV2=outs4.str();
351  psu->cmodid_HV3=outs6.str();
352  }
353  }
354  }
355 
356 
357  npsuracks=29;
358  std::cout << npsu << " psu stored in " <<npsuracks<<" racks"<<std::endl;
359  }
360 }
361 
363  psetAvailable=true;
364  xsize=340;ysize=200;
365  title=" ";
366  jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
367  infilename="CommonTools/TrackerMap/data/tracker.dat";
369  saveAsSingleLayer=false;
370  if(tkmapPset.exists("trackermaptxtPath")){
371  jsfilename=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath","")+"trackermap.txt";
372  std::cout << jsfilename << std::endl;
373  infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"tracker.dat";
374  std::cout << infilename << std::endl;
375  } else std::cout << "no parameters found" << std::endl;
376  init();
377 }
378 
379 TrackerMap::TrackerMap(std::string s,int xsize1,int ysize1) {
380  psetAvailable=false;
381  xsize=xsize1;ysize=ysize1;
382  title=s;
383  jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
384  infilename="CommonTools/TrackerMap/data/tracker.dat";
385  enableFedProcessing=false;
386  saveAsSingleLayer=false;
387  init();
388 }
389 
391 std::map<int , TmModule *>::iterator i_mod;
392  for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
393  TmModule * mod= i_mod->second;
394  mod->count=0;mod->value=0;mod->red=-1;
395  }
396 }
397 
399 
400  int ntotmod=0;
401  ix=0;iy=0; //used to compute the place of each layer in the tracker map
402  firstcall = true;
404  posrel=true;
405  palette = 1;
406  printflag=true;
407  addPixelFlag=false;
408  temporary_file=false;
409  gminvalue=0.; gmaxvalue=0.;//default global range for online rendering
410 
411  ndet = 3; // number of detectors: pixel, inner silicon, outer silicon
412  npart = 3; // number of detector parts: endcap -z, barrel, endcap +z
413 
414  //allocate module map
415  for (int subdet=1; subdet < ndet+1; subdet++){//loop on subdetectors
416  for (int detpart=1; detpart < npart+1; detpart++){//loop on subdetectors parts
417  int nlayers = getlayerCount(subdet,detpart); // compute number of layers
418  for(int layer=1; layer < nlayers+1; layer++){//loop on layers
419  int nrings = getringCount(subdet,detpart,layer);// compute number of rings
420  //fill arrays used to do the loop on the rings
421  int layer_g = nlayer(subdet,detpart,layer);
422  ntotRing[layer_g-1]=nrings;
423  firstRing[layer_g-1]=1;
424  if(subdet==3 && detpart!=2) firstRing[layer_g-1]= 8-nrings; //special numbering for TEC
425  for (int ring=firstRing[layer_g-1]; ring < ntotRing[layer_g-1]+firstRing[layer_g-1];ring++){//loop on rings
426  int nmodules = getmoduleCount(subdet,detpart,layer,ring);// compute number of modules
427  int key=0;
428  TmModule *smodule;
429  for(int module=1; module < nmodules+1; module++){//loop on modules
430  smodule = new TmModule(module,ring,layer_g);
431  key=layer_g*100000+ring*1000+module;//key identifying module
432  smoduleMap[key]=smodule;
433  ntotmod++;
434  }
435  if(isRingStereo(key))for(int module=1; module < nmodules+1; module++){//loop on stereo modules
436  smodule = new TmModule(module+100,ring,layer_g);
437  int key=layer_g*100000+ring*1000+module+100;
438  smoduleMap[key]=smodule;
439  ntotmod++;
440  }
441  }
442  }
443  }
444  }
445  build();
446 }
447 
449 
450 for (int layer=1; layer < 44; layer++){
451  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
452  for (int module=1;module<200;module++) {
453  int key=layer*100000+ring*1000+module;
454  TmModule * mod = smoduleMap[key];
455  if(mod !=0 ) delete mod;
456  }
457  }
458  }
459 
460 //std::map<int , TmModule *>::iterator i_mod;
461 // for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
462 // TmModule * mod= i_mod->second;
463 // delete mod;
464 // }
465 std::map<int , TmApvPair *>::iterator i_apv;
466  for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
467  TmApvPair * apvPair= i_apv->second;
468  delete apvPair;
469  }
470 
471 
472 std::map<int , TmCcu *>::iterator i_ccu;
473  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
474  TmCcu * ccu= i_ccu->second;
475  delete ccu;
476  }
477 
478 std::map<int , TmPsu *>::iterator ipsu;
479  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
480  TmPsu * psu= ipsu->second;
481  delete psu;
482  }
483 
484 gROOT->Reset();
485 
486 
487 //for(std::vector<TColor*>::iterator col1=vc.begin();col1!=vc.end();col1++){
488 // std::cout<<(*col1)<<std::endl;}
489 }
490 
491 
492 
493 
494 
495 void TrackerMap::drawModule(TmModule * mod, int key,int nlay, bool print_total, std::ofstream * svgfile){
496  //int x,y;
497  double phi,r,dx,dy, dy1;
498  double xp[4],yp[4],xp1,yp1;
499  double vhbot,vhtop,vhapo;
500  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};
501  double xt1,yt1,xs1=0.,ys1=0.,xt2,yt2,xs2,ys2,pv1,pv2;
502  int green = 0;
503  int red = 0;
504  int blue = 0;
505  double xd[4],yd[4];
506  int np = 4;
507  //int numrec=0;
508  int numod=0;
509  phi = phival(mod->posx,mod->posy);
510  r = sqrt(mod->posx*mod->posx+mod->posy*mod->posy);
511  vhbot = mod->width;
512  vhtop=mod->width;
513  vhapo=mod->length;
514  if(nlay < 31){ //endcap
515  vhbot = mod->widthAtHalfLength/2.-(mod->width/2.-mod->widthAtHalfLength/2.);
516  vhtop=mod->width/2.;
517  vhapo=mod->length/2.;
518  if(nlay >12 && nlay <19){
519  if(posrel)r = r+r;
520  xp[0]=r-vhtop;yp[0]=-vhapo;
521  xp[1]=r+vhtop;yp[1]=-vhapo;
522  xp[2]=r+vhtop;yp[2]=vhapo;
523  xp[3]=r-vhtop;yp[3]=vhapo;
524  }else{
525  if(posrel)r = r + r/3.;
526  xp[0]=r-vhapo;yp[0]=-vhbot;
527  xp[1]=r+vhapo;yp[1]=-vhtop;
528  xp[2]=r+vhapo;yp[2]=vhtop;
529  xp[3]=r-vhapo;yp[3]=vhbot;
530  }
531  for(int j=0;j<4;j++){
532  xp1 = xp[j]*cos(phi)-yp[j]*sin(phi);
533  yp1 = xp[j]*sin(phi)+yp[j]*cos(phi);
534  xp[j] = xp1;yp[j]=yp1;
535  }
536  } else { //barrel
537  numod=mod->idModule;if(numod>100)numod=numod-100;
538  int vane = mod->ring;
539  if(posrel){
540  dx = vhapo;
541  phi=M_PI;
542  xt1=rmedio[nlay-31]; yt1=-vhtop/2.;
543  xs1 = xt1*cos(phi)-yt1*sin(phi);
544  ys1 = xt1*sin(phi)+yt1*cos(phi);
545  xt2=rmedio[nlay-31]; yt2=vhtop/2.;
546  xs2 = xt2*cos(phi)-yt2*sin(phi);
547  ys2 = xt2*sin(phi)+yt2*cos(phi);
548  dy=phival(xs2,ys2)-phival(xs1,ys1);
549  dy1 = dy;
550  if(nlay==31)dy1=0.39;
551  if(nlay==32)dy1=0.23;
552  if(nlay==33)dy1=0.16;
553  xp[0]=vane*(dx+dx/8.);yp[0]=numod*(dy1);
554  xp[1]=vane*(dx+dx/8.)+dx;yp[1]=numod*(dy1);
555  xp[2]=vane*(dx+dx/8.)+dx;yp[2]=numod*(dy1)+dy;
556  xp[3]=vane*(dx+dx/8.);yp[3]=numod*(dy1)+dy;
557  }else{
558  xt1=r; yt1=-vhtop/2.;
559  xs1 = xt1*cos(phi)-yt1*sin(phi);
560  ys1 = xt1*sin(phi)+yt1*cos(phi);
561  xt2=r; yt2=vhtop/2.;
562  xs2 = xt2*cos(phi)-yt2*sin(phi);
563  ys2 = xt2*sin(phi)+yt2*cos(phi);
564  pv1=phival(xs1,ys1);
565  pv2=phival(xs2,ys2);
566  if(fabs(pv1-pv2)>M_PI && numod==1)pv1=pv1-2.*M_PI;
567  if(fabs(pv1-pv2)>M_PI && numod!=1)pv2=pv2+2.*M_PI;
568  xp[0]=mod->posz-vhapo/2.;yp[0]=4.2*pv1;
569  xp[1]=mod->posz+vhapo/2.;yp[1]=4.2*pv1;
570  xp[2]=mod->posz+vhapo/2. ;yp[2]=4.2*pv2;
571  xp[3]=mod->posz-vhapo/2.;yp[3]=4.2*pv2;
572  }
573  }
574  if(isRingStereo(key))
575  {
576  np = 3;
577  if(mod->idModule>100 ){for(int j=0;j<3;j++){
578  xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
579  }
580  }else {
581  xd[0]=xdpixel(xp[2]);yd[0]=ydpixel(yp[2]);
582  xd[1]=xdpixel(xp[3]);yd[1]=ydpixel(yp[3]);
583  xd[2]=xdpixel(xp[0]);yd[2]=ydpixel(yp[0]);
584  }
585  } else {
586  for(int j=0;j<4;j++){
587  xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
588  }
589  }
590  char buffer [20];
591  sprintf(buffer,"%X",mod->idex);
592 
593  if(mod->red < 0){ //use count to compute color
594  int color = getcolor(mod->value,palette);
595  red=(color>>16)&0xFF;
596  green=(color>>8)&0xFF;
597  blue=(color)&0xFF;
598 
599 if(!print_total)mod->value=mod->value*mod->count;//restore mod->value
600 
601  if(mod->count > 0)
602  if(temporary_file) *svgfile << red << " " << green << " " << blue << " "; else
603  *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=\"";
604  else
605  if(temporary_file) *svgfile << 255 << " " << 255 << " " << 255 << " "; else
606  *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=\"";
607  if(temporary_file) *svgfile << np << " ";
608  for(int k=0;k<np;k++){
609  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
610  *svgfile << xd[k] << "," << yd[k] << " " ;
611  }
612  if(temporary_file)*svgfile << std::endl; else *svgfile <<"\" />" <<std::endl;
613  } else {//color defined with fillc
614  if(mod->red>255)mod->red=255;
615  if(mod->green>255)mod->green=255;
616  if(mod->blue>255)mod->blue=255;
617  if(temporary_file) *svgfile << mod->red << " " << mod->green << " " << mod->blue << " "; else
618  *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=\"";
619  if(temporary_file) *svgfile << np << " ";
620  for(int k=0;k<np;k++){
621  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
622  *svgfile << xd[k] << "," << yd[k] << " " ;
623  }
624  if(temporary_file)*svgfile << std::endl; else *svgfile <<"\" />" <<std::endl;
625  }
626 
627 }
628 
629 //export tracker map
630 //print_total = true represent in color the total stored in the module
631 //print_total = false represent in color the average
632 void TrackerMap::save(bool print_total,float minval, float maxval,std::string s,int width, int height){
633 
634  std::string filetype=s,outputfilename=s;
635  std::vector<TPolyLine*> vp;
636  TGaxis *axis = 0 ;
637  size_t found=filetype.find_last_of(".");
638  filetype=filetype.substr(found+1);
639  found=outputfilename.find_last_of(".");
640  outputfilename=outputfilename.substr(0,found);
641  //outputfilename.erase(outputfilename.begin()+outputfilename.find("."),outputfilename.end());
642  temporary_file=true;
643  if(filetype=="svg")temporary_file=false;
644  std::ostringstream outs;
645  minvalue=minval; maxvalue=maxval;
646  outs << outputfilename << ".coor";
647  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
648  if(!print_total){
649  for (int layer=1; layer < 44; layer++){
650  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
651  for (int module=1;module<200;module++) {
652  int key=layer*100000+ring*1000+module;
653  TmModule * mod = smoduleMap[key];
654  if(mod !=0 && !mod->notInUse()){
655  mod->value = mod->value / mod->count;
656  }
657  }
658  }
659  }
660  }
661 
662  if(minvalue>=maxvalue){
663  minvalue=9999999.;
664  maxvalue=-9999999.;
665  for (int layer=1; layer < 44; layer++){
666  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
667  for (int module=1;module<200;module++) {
668  int key=layer*100000+ring*1000+module;
669  TmModule * mod = smoduleMap[key];
670  if(mod !=0 && !mod->notInUse()){
671  if (minvalue > mod->value)minvalue=mod->value;
672  if (maxvalue < mod->value)maxvalue=mod->value;
673  }
674  }
675  }
676  }
677 }
678  if (maxvalue == minvalue) printflag = false;
679  if(!temporary_file){
680  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<std::endl;
681  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
682  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" "<<std::endl;
683  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">"<<std::endl;
684  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3100 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
685  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3100\" height=\"1600\" /> "<<std::endl;
686  *savefile << "<svg:g id=\"tracker\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
687  }
688  for (int layer=1; layer < 44; layer++){
689  nlay=layer;
690  defwindow(nlay);
691  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
692  for (int module=1;module<200;module++) {
693  int key=layer*100000+ring*1000+module;
694  TmModule * mod = smoduleMap[key];
695  if(mod !=0 && !mod->notInUse()){
696  drawModule(mod,key,layer,print_total,savefile);
697  }
698  }
699  }
700  }
701 
702  if(!temporary_file){
703  *savefile << "</svg:g>"<<std::endl;
704  *savefile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<std::endl;
705  }
706 
708  if(!temporary_file){
709  *savefile << "</svg:svg>"<<std::endl;
710  *savefile << "</svg>"<<std::endl;
711  }
712  savefile->close(); delete savefile;
713 
714  const char * command1;
715  std::string tempfilename = outputfilename + ".coor";
716  if(filetype=="svg"){
717  std::string command = "mv "+tempfilename +" " +outputfilename + ".svg";
718  command1=command.c_str();
719  std::cout << "Executing " << command1 << std::endl;
720  system(command1);
721  }
722 
723  if (temporary_file){ // create root trackermap image
724  int red,green,blue,npoints,colindex,ncolor;
725  double x[4],y[4];
726  ifstream tempfile(tempfilename.c_str(),std::ios::in);
727  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
728  gPad->SetFillColor(38);
729 
730  if(addPixelFlag)gPad->Range(0,0,3800,1600);else gPad->Range(800,0,3800,1600);
731 
732  //First build palette
733  ncolor=0;
734  typedef std::map<int,int> ColorList;
735  ColorList colorList;
736  ColorList::iterator pos;
737  TColor *col, *c;
738  std::cout<<"tempfilename "<<tempfilename<<std::endl;
739  while(!tempfile.eof()) {
740  tempfile >> red >> green >> blue >> npoints;
741  colindex=red+green*1000+blue*1000000;
742  pos=colorList.find(colindex);
743  if(pos == colorList.end()){ colorList[colindex]=ncolor+100; col =gROOT->GetColor(ncolor+100);
744  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++;}
745  for (int i=0;i<npoints;i++){
746  tempfile >> x[i] >> y[i];
747  }
748  }
749 
750  if(ncolor>0 && ncolor<10000){
751  Int_t colors[10000];
752  for(int i=0;i<ncolor;i++){colors[i]=i+100;}
753  gStyle->SetPalette(ncolor,colors);
754  }
755 
756  tempfile.clear();
757  tempfile.seekg(0,std::ios::beg);
758  std::cout << "created palette with " << ncolor << " colors" << std::endl;
759 
760  while(!tempfile.eof()) {//create polylines
761  tempfile >> red >> green >> blue >> npoints;
762  for (int i=0;i<npoints;i++){
763  tempfile >> x[i] >> y[i];
764  }
765  colindex=red+green*1000+blue*1000000;
766  pos=colorList.find(colindex);
767  if(pos != colorList.end()){
768  TPolyLine* pline = new TPolyLine(npoints,y,x);
769  vp.push_back(pline);
770  pline->SetFillColor(colorList[colindex]);
771  pline->SetLineWidth(0);
772  pline->Draw("f");
773  }
774  }
775  if (printflag) {
776  axis = new TGaxis(3660,36,3660,1530,minvalue,maxvalue,510,"+L");
777  axis->SetLabelSize(0.02);
778  axis->Draw();
779  }
780  TLatex l;
781  l.SetTextSize(0.03);
782  l.DrawLatex(950,1330,"TID");
783  l.DrawLatex(2300,1330,"TEC");
784  l.DrawLatex(300,1330,"FPIX");
785  l.DrawLatex(20,560,"BPIX L1");
786  l.DrawLatex(500,385,"BPIX L2");
787  l.DrawLatex(500,945,"BPIX L3");
788  l.SetTextSize(0.04);
789  l.DrawLatex(850,1500,title.c_str());
790  l.DrawLatex(1730,40,"-z");
791  l.DrawLatex(1730,1360,"+z");
792  l.DrawLatex(1085,330,"TIB L1");
793  l.DrawLatex(1085,1000,"TIB L2");
794  l.DrawLatex(1585,330,"TIB L3");
795  l.DrawLatex(1585,1000,"TIB L4");
796  l.DrawLatex(2085,330,"TOB L1");
797  l.DrawLatex(2085,1000,"TOB L2");
798  l.DrawLatex(2585,330,"TOB L3");
799  l.DrawLatex(2585,1000,"TOB L4");
800  l.DrawLatex(3085,330,"TOB L5");
801  l.DrawLatex(3085,1000,"TOB L6");
802  TArrow arx(3448,1190,3448,1350,0.01,"|>");
803  l.DrawLatex(3460,1350,"x");
804  TArrow ary(3448,1190,3312,1190,0.01,"|>");
805  l.DrawLatex(3312,1210,"y");
806  TArrow arz(3485,373,3485,676,0.01,"|>");
807  l.DrawLatex(3510,667,"z");
808  TArrow arphi(3485,511,3037,511,0.01,"|>");
809  l.DrawLatex(3023,520,"#Phi");
810  arx.SetLineWidth(3);
811  ary.SetLineWidth(3);
812  arz.SetLineWidth(3);
813  arphi.SetLineWidth(3);
814  arx.Draw();
815  ary.Draw();
816  arz.Draw();
817  arphi.Draw();
818  MyC->Update();
819  if(filetype=="png"){
820 
821  std::string filename = outputfilename + ".png";
822  std::cout << "printing " <<filename<< std::endl;
823  MyC->Print(filename.c_str());
824  }
825  if(filetype=="jpg"){
826  std::string filename = outputfilename + ".jpg";
827  MyC->Print(filename.c_str());
828  }
829  if(filetype=="pdf"){
830  std::string filename = outputfilename + ".pdf";
831  MyC->Print(filename.c_str());
832  }
833  std::string command = "rm "+tempfilename ;
834  command1=command.c_str();
835  std::cout << "Executing " << command1 << std::endl;
836  system(command1);
837  MyC->Clear();
838  delete MyC;
839  if (printflag)delete axis;
840  for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
841  delete (*pos1);}
842 
843  }
844 
845 
846 }
847 void TrackerMap::drawApvPair(int crate, int numfed_incrate, bool print_total, TmApvPair* apvPair,std::ofstream * svgfile,bool useApvPairValue)
848 {
849  double xp[4],yp[4];
850  int color;
851  int green = 0;
852  int red = 0;
853  int blue = 0;
854  double xd[4],yd[4];
855  int np = 4;
856  double boxinitx=0., boxinity=0.;
857  double dx=.9,dy=.9;
858  int numfedch_incolumn = 12;
859  int numfedch_inrow = 8;
860  int numfed_incolumn = 5;
861  int numfed_inrow = 4;
862  boxinitx=boxinitx+(numfed_incolumn-(numfed_incrate-1)/numfed_inrow)*14.;
863  boxinity=boxinity+(numfed_inrow-(numfed_incrate-1)%numfed_inrow)*9.;
864  boxinity=boxinity+numfedch_inrow-(apvPair->getFedCh()/numfedch_incolumn);
865  boxinitx = boxinitx+numfedch_incolumn-(int)(apvPair->getFedCh()%numfedch_incolumn);
866  //std::cout << crate << " " << numfed_incrate << " " << apvPair->getFedCh()<<" "<<boxinitx<< " " << boxinity << std::endl; ;
867  xp[0]=boxinitx;yp[0]=boxinity;
868  xp[1]=boxinitx+dx;yp[1]=boxinity;
869  xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
870  xp[3]=boxinitx;yp[3]=boxinity + dy;
871  for(int j=0;j<4;j++){
872  xd[j]=xdpixelc(xp[j]);yd[j]=ydpixelc(yp[j]);
873  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
874  }
875 
876  char buffer [20];
877  sprintf(buffer,"%X",apvPair->mod->idex);
878  std::string s = apvPair->mod->name;
879  s.erase(s.begin()+s.find("connected"),s.end());
880 
881  if(useApvPairValue){
882  if(apvPair->red < 0){ //use count to compute color
883  if(apvPair->count > 0) {
884  color = getcolor(apvPair->value,palette);
885  red=(color>>16)&0xFF;
886  green=(color>>8)&0xFF;
887  blue=(color)&0xFF;
888  if(!print_total)apvPair->value=apvPair->value*apvPair->count;//restore mod->value
889  if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
890  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=\"";
891  } else {
892  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
893  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=\"";
894  }
895  } else {//color defined with fillc
896  if(apvPair->red>255)apvPair->red=255;
897  if(apvPair->green>255)apvPair->green=255;
898  if(apvPair->blue>255)apvPair->blue=255;
899  if(temporary_file)*svgfile << apvPair->red << " " << apvPair->green << " " << apvPair->blue << " ";
900  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=\"";
901  }
902  }else{
903  if(apvPair->mod->red < 0){ //use count to compute color
904  if(apvPair->mod->count > 0) {
905  color = getcolor(apvPair->mod->value,palette);
906  red=(color>>16)&0xFF;
907  green=(color>>8)&0xFF;
908  blue=(color)&0xFF;
909  if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
910  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=\"";
911  } else {
912  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
913  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=\"";
914  }
915  } else {//color defined with fillc
916  if(apvPair->mod->red>255)apvPair->mod->red=255;
917  if(apvPair->mod->green>255)apvPair->mod->green=255;
918  if(apvPair->mod->blue>255)apvPair->mod->blue=255;
919  if(temporary_file)*svgfile << apvPair->mod->red << " " << apvPair->mod->green << " " << apvPair->mod->blue << " ";
920  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=\"";
921  }
922  }
923  if(temporary_file)*svgfile << np << " ";
924  for(int k=0;k<np;k++){
925  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
926  else *svgfile << xd[k] << "," << yd[k] << " " ;
927  }
928  if(temporary_file)*svgfile << std::endl;
929  else *svgfile <<"\" />" <<std::endl;
930 }
931 void TrackerMap::drawCcu(int crate, int numfec_incrate, bool print_total, TmCcu* ccu,std::ofstream * svgfile,bool useCcuValue)
932 {
933  double xp[4],yp[4];
934  int color;
935  int green = 0;
936  int red = 0;
937  int blue = 0;
938  double xd[4],yd[4];
939  int np = 4;
940  double boxinitx=0., boxinity=0.;
941  double dx=.9,dy=.9;
942  int numccu_incolumn = 8;
943  int numccu_inrow = 15;
944  int numfed_incolumn = 5;
945  int numfed_inrow = 4;
946  boxinitx=boxinitx+(numfed_incolumn-(numfec_incrate-1)/numfed_inrow)*14.;
947  boxinity=boxinity+(numfed_inrow-(numfec_incrate-1)%numfed_inrow)*16.;
948  boxinity=boxinity+numccu_inrow-ccu->mpos;
949  boxinitx = boxinitx+numccu_incolumn-(int)(ccu->getCcuRing()%numccu_incolumn);
950  //std::cout << crate << " " << numfec_incrate << " " << ccu->getCcuRing()<<" "<<ccu->mpos<<" "<<boxinitx<< " " << boxinity << std::endl; ;
951  xp[0]=boxinitx;yp[0]=boxinity;
952  xp[1]=boxinitx+dx;yp[1]=boxinity;
953  xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
954  xp[3]=boxinitx;yp[3]=boxinity + dy;
955  for(int j=0;j<4;j++){
956  xd[j]=xdpixelfec(xp[j]);yd[j]=ydpixelfec(yp[j]);
957  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
958  }
959 
960  char buffer [20];
961  sprintf(buffer,"%X",ccu->idex);
962  //sprintf(buffer,"%X",ccu->mod->idex);
963  //std::string s = ccu->mod->name;
964  std::string s = ccu->text;
965  s.erase(s.begin()+s.find("connected"),s.end());
966 
967  if(ccu->red < 0){ //use count to compute color
968  if(ccu->count > 0) {
969  color = getcolor(ccu->value,palette);
970  red=(color>>16)&0xFF;
971  green=(color>>8)&0xFF;
972  blue=(color)&0xFF;
973  if(!print_total)ccu->value=ccu->value*ccu->count;//restore mod->value
974  if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
975  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=\"";
976  } else {
977  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
978  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=\"";
979  }
980  } else {//color defined with fillc
981  if(ccu->red>255)ccu->red=255;
982  if(ccu->green>255)ccu->green=255;
983  if(ccu->blue>255)ccu->blue=255;
984  if(temporary_file)*svgfile << ccu->red << " " << ccu->green << " " << ccu->blue << " ";
985  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=\"";
986  }
987 if(temporary_file)*svgfile << np << " ";
988 for(int k=0;k<np;k++){
989  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
990  else *svgfile << xd[k] << "," << yd[k] << " " ;
991 }
992 if(temporary_file)*svgfile << std::endl;
993 else *svgfile <<"\" />" <<std::endl;
994 
995 }
996 void TrackerMap::drawPsu(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
997 {
998  double xp[4],yp[4];
999  int color;
1000  int green = 0;
1001  int red = 0;
1002  int blue = 0;
1003  double xd[4],yd[4];
1004  int np = 4;
1005  double boxinitx=35, boxinity=12;
1006  double dx=3,dy=1.3;
1007 
1008  boxinitx= boxinitx+(5 - numcrate_inrack)*5;
1009  boxinity= boxinity+(18 - psu->getPsuBoard())*1.75;
1010 
1011  xp[0]=boxinitx;yp[0]=boxinity;
1012  xp[1]=boxinitx+dx;yp[1]=boxinity;
1013  xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
1014  xp[3]=boxinitx;yp[3]=boxinity + dy;
1015 
1016 
1017  for(int j=0;j<4;j++){
1018  xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
1019  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1020  }
1021 
1022  char buffer [20];
1023  sprintf(buffer,"%X",psu->idex);
1024  std::string s = psu->text;
1025  s.erase(s.begin()+s.find("connected"),s.end());
1026 
1027  if(psu->red < 0){ //use count to compute color
1028  if(psu->value > 0){
1029  color = getcolor(psu->value,palette);
1030  red=(color>>16)&0xFF;
1031  green=(color>>8)&0xFF;
1032  blue=(color)&0xFF;
1033  if(!print_total)psu->value=psu->value*psu->count;//restore mod->value
1034  if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
1035  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=\"";
1036  }
1037  else{
1038 
1039  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
1040  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=\"";
1041  }
1042  }
1043 
1044  else {//color defined with fillc
1045  if(psu->red>255)psu->red=255;
1046  if(psu->green>255)psu->green=255;
1047  if(psu->blue>255)psu->blue=255;
1048  if(temporary_file)*svgfile << psu->red << " " << psu->green << " " << psu->blue << " ";
1049  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=\"";
1050  }
1051 
1052 if(temporary_file)*svgfile << np << " ";
1053 for(int k=0;k<np;k++){
1054  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
1055  else *svgfile << xd[k] << "," << yd[k] << " " ;
1056 }
1057 if(temporary_file)*svgfile << std::endl;
1058 else *svgfile <<"\" />" <<std::endl;
1059 
1060 }
1061 
1062 void TrackerMap::drawHV2(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
1063 {
1064  double xp[4],yp[4];
1065  int color;
1066  int greenHV2 = 0;
1067  int redHV2 = 0;
1068  int blueHV2 = 0;
1069  double xd[4],yd[4];
1070  int np = 4;
1071  double boxinitx=35, boxinity=12;
1072  double dx=1.1,dy=1.3;
1073 
1074  boxinitx= boxinitx+(5 - numcrate_inrack)*5;
1075  boxinity= boxinity+(18 - psu->getPsuBoard())*1.75;
1076 
1077  xp[0]=boxinitx;yp[0]=boxinity;
1078  xp[1]=boxinitx+dx;yp[1]=boxinity;
1079  xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
1080  xp[3]=boxinitx;yp[3]=boxinity + dy;
1081 
1082 
1083  for(int j=0;j<4;j++){
1084  xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
1085  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1086  }
1087 
1088  char buffer [20];
1089  sprintf(buffer,"%X",psu->idex);
1090  std::string s = psu->textHV2;
1091  s.erase(s.begin()+s.find("connected"),s.end());
1092 
1093  if(psu->redHV2 < 0){ //use count to compute color
1094 
1095  if(psu->valueHV2 > 0){
1096  color = getcolor(psu->valueHV2,palette);
1097  redHV2=(color>>16)&0xFF;
1098  greenHV2=(color>>8)&0xFF;
1099  blueHV2=(color)&0xFF;
1100  if(!print_total)psu->valueHV2=psu->valueHV2*psu->countHV2;//restore mod->value
1101  if(temporary_file)*svgfile << redHV2 << " " << greenHV2 << " " << blueHV2 << " ";
1102  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=\"";
1103  }
1104  else{
1105  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
1106  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=\"";
1107  }
1108  }
1109 
1110  else {//color defined with fillc
1111  if(psu->redHV2>255)psu->redHV2=255;
1112  if(psu->greenHV2>255)psu->greenHV2=255;
1113  if(psu->blueHV2>255)psu->blueHV2=255;
1114  if(temporary_file)*svgfile << psu->redHV2 << " " << psu->greenHV2 << " " << psu->blueHV2 << " ";
1115  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=\"";
1116  }
1117 
1118 if(temporary_file)*svgfile << np << " ";
1119 for(int k=0;k<np;k++){
1120  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
1121  else *svgfile << xd[k] << "," << yd[k] << " " ;
1122 }
1123 if(temporary_file)*svgfile << std::endl;
1124 else *svgfile <<"\" />" <<std::endl;
1125 
1126 }
1127 
1128 
1129 void TrackerMap::drawHV3(int rack,int numcrate_inrack , bool print_total, TmPsu* psu,std::ofstream * svgfile,bool usePsuValue)
1130 {
1131  double xp[4],yp[4];
1132  int color;
1133  int greenHV3 = 0;
1134  int redHV3 = 0;
1135  int blueHV3 = 0;
1136  double xd[4],yd[4];
1137  int np = 4;
1138  double boxinitx=36.5, boxinity=12;
1139  double dx=1.1,dy=1.3;
1140 
1141  boxinitx= boxinitx+(5 - numcrate_inrack)*5;
1142  boxinity= boxinity+(18 - psu->getPsuBoard())*1.75;
1143 
1144  xp[0]=boxinitx;yp[0]=boxinity;
1145  xp[1]=boxinitx+dx;yp[1]=boxinity;
1146  xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
1147  xp[3]=boxinitx;yp[3]=boxinity + dy;
1148 
1149 
1150  for(int j=0;j<4;j++){
1151  xd[j]=xdpixelpsu(xp[j]);yd[j]=ydpixelpsu(yp[j]);
1152  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1153  }
1154 
1155  char buffer [20];
1156  sprintf(buffer,"%X",psu->idex);
1157  std::string s = psu->textHV3;
1158  s.erase(s.begin()+s.find("connected"),s.end());
1159 
1160  if(psu->redHV3 < 0){ //use count to compute color
1161  if(psu->valueHV3 > 0){
1162  color = getcolor(psu->valueHV3,palette);
1163  redHV3=(color>>16)&0xFF;
1164  greenHV3=(color>>8)&0xFF;
1165  blueHV3=(color)&0xFF;
1166  if(!print_total)psu->valueHV3=psu->valueHV3*psu->countHV3;//restore mod->value
1167  if(temporary_file)*svgfile << redHV3 << " " << greenHV3 << " " << blueHV3 << " ";
1168  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=\"";
1169  }
1170  else{
1171  if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
1172  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=\"";
1173  }
1174  }
1175 
1176  else {//color defined with fillc
1177  if(psu->redHV3>255)psu->redHV3=255;
1178  if(psu->greenHV3>255)psu->greenHV3=255;
1179  if(psu->blueHV3>255)psu->blueHV3=255;
1180  if(temporary_file)*svgfile << psu->redHV3 << " " << psu->greenHV3 << " " << psu->blueHV3 << " ";
1181  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=\"";
1182  }
1183 
1184 if(temporary_file)*svgfile << np << " ";
1185 for(int k=0;k<np;k++){
1186  if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
1187  else *svgfile << xd[k] << "," << yd[k] << " " ;
1188 }
1189 if(temporary_file)*svgfile << std::endl;
1190 else *svgfile <<"\" />" <<std::endl;
1191 
1192 }
1193 
1194 void TrackerMap::save_as_fectrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
1195  if(enableFecProcessing){
1196  std::string filetype=s,outputfilename=s;
1197  std::vector<TPolyLine*> vp;
1198  size_t found=filetype.find_last_of(".");
1199  filetype=filetype.substr(found+1);
1200  found=outputfilename.find_last_of(".");
1201  outputfilename=outputfilename.substr(0,found);
1202  temporary_file=true;
1203  if(filetype=="xml"||filetype=="svg")temporary_file=false;
1204  std::ostringstream outs;
1205  minvalue=minval; maxvalue=maxval;
1206  outs << outputfilename << ".coor";
1207  if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1208  std::map<int , TmCcu *>::iterator i_ccu;
1209  std::multimap<TmCcu*, TmModule*>::iterator it;
1210  std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
1211  //Decide if we must use Module or Ccu value
1212  bool useCcuValue=false;
1213 
1214 
1215  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1216  TmCcu * ccu= i_ccu->second;
1217  if(ccu!=0) {
1218  if(ccu->count > 0 || ccu->red!=-1) { useCcuValue=true; break;}
1219  }
1220  }
1221 
1222 
1223  if(!useCcuValue)//store mean of connected modules value{
1224  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1225  TmCcu * ccu= i_ccu->second;
1226  if(ccu!=0) {
1227  ret = fecModuleMap.equal_range(ccu);
1228  for (it = ret.first; it != ret.second; ++it)
1229  {
1230  if( (*it).second->count>0){ccu->value=ccu->value+(*it).second->value;ccu->count++;}
1231  }
1232  if(ccu->count>0)ccu->value=ccu->value/ccu->count;
1233  if(ccu->nmod==0) { ccu->red=0;ccu->green=0;ccu->blue=0;}
1234  }
1235  }
1236 
1237 
1238  if(title==" Tracker Map from QTestAlarm"){
1239  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1240  TmCcu * ccu= i_ccu->second;
1241  if(ccu!=0) {
1242  ret = fecModuleMap.equal_range(ccu);
1243  ccu->red=0;ccu->green=255;ccu->blue=0;
1244  for (it = ret.first; it != ret.second; ++it) {
1245  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 ) ){
1246  ccu->red=255;ccu->green=0;ccu->blue=0;
1247  }
1248  }
1249  }
1250  }
1251  }
1252 
1253 
1254 
1255  if(!print_total){
1256  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1257  TmCcu * ccu= i_ccu->second;
1258  if(ccu!=0) {
1259  if(useCcuValue) ccu->value = ccu->value / ccu->count;
1260 
1261  }
1262  }
1263  }
1264 
1265  if(minvalue>=maxvalue){
1266 
1267  minvalue=9999999.;
1268  maxvalue=-9999999.;
1269  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1270  TmCcu * ccu= i_ccu->second;
1271  if(ccu!=0) {
1272  if (minvalue > ccu->value)minvalue=ccu->value;
1273  if (maxvalue < ccu->value)maxvalue=ccu->value;
1274  }
1275  }
1276  }
1277 
1278 
1279 
1280  if(filetype=="svg"){
1281  saveAsSingleLayer=false;
1282  std::ostringstream outs;
1283  outs << outputfilename<<".svg";
1284  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1285  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<std::endl;
1286  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1287  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" "<<std::endl;
1288  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">"<<std::endl;
1289  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
1290  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl;
1291  *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
1292  }
1293  for (int crate=1; crate < (nfeccrates+1); crate++){
1294  if(filetype=="xml"){
1295  saveAsSingleLayer=true;
1296  std::ostringstream outs;
1297  outs << outputfilename<<"feccrate" <<crate<< ".xml";
1298  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1299  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
1300  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1301  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\""<<std::endl;
1302  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >"<<std::endl;
1303  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"feccrate.js\" />"<<std::endl;
1304  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
1305  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
1306  *savefile << "<g id=\"crate\" transform=\" translate(280,580) rotate(270) scale(.7,.8)\" > "<<std::endl;
1307  }
1308  ncrate=crate;
1310 
1311  for ( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1312  TmCcu * ccu= i_ccu->second;
1313  if(ccu!=0){
1314  if(ccu->getCcuCrate() == crate){
1315 
1316  drawCcu(crate,ccu->getCcuSlot()-2,print_total,ccu,savefile,useCcuValue);
1317  }
1318  }
1319  }
1320 
1321  if(!temporary_file){
1322  if(filetype=="xml"){
1323  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
1324  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
1325  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
1326  *savefile << " </text> </svg>" << std::endl;
1327  savefile->close();
1328  saveAsSingleLayer=false;
1329  }
1330  }
1331  }
1332  if(filetype=="svg"){
1333  *savefile << "</g> </svg> </svg> " << std::endl;
1334  savefile->close();
1335  }
1336  if(!print_total && !useCcuValue){
1337 //Restore ccu value
1338  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
1339  TmCcu * ccu= i_ccu->second;
1340  if(ccu!=0) {
1341  ccu->value = ccu->value * ccu->count;
1342  }
1343 }
1344 }
1345  if(temporary_file){
1346  // if(printflag)drawPalette(savefile);
1347  savefile->close();
1348 
1349  const char * command1;
1350  std::string tempfilename = outputfilename + ".coor";
1351  int red,green,blue,npoints,colindex,ncolor;
1352  double x[4],y[4];
1353  ifstream tempfile(tempfilename.c_str(),std::ios::in);
1354  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
1355  gPad->SetFillColor(38);
1356 
1357  gPad->Range(0,0,3700,1600);
1358 
1359  //First build palette
1360  ncolor=0;
1361  typedef std::map<int,int> ColorList;
1362  ColorList colorList;
1363  ColorList::iterator pos;
1364  TColor *col,*c;
1365  while(!tempfile.eof()) {
1366  tempfile >> red >> green >> blue >> npoints;
1367  colindex=red+green*1000+blue*1000000;
1368  pos=colorList.find(colindex);
1369  if(pos == colorList.end()){
1370  colorList[colindex]=ncolor+100;
1371  col =gROOT->GetColor(ncolor+100);
1372  if(col)
1373  col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1374  else
1375  c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1376  vc.push_back(c);
1377  ncolor++;
1378  }
1379  for (int i=0;i<npoints;i++){
1380  tempfile >> x[i] >> y[i];
1381  }
1382  }
1383  if(ncolor>0 && ncolor<10000){
1384  Int_t colors[10000];
1385  for(int i=0;i<ncolor;i++){colors[i]=i+100;}
1386  gStyle->SetPalette(ncolor,colors);
1387  }
1388  tempfile.clear();
1389  tempfile.seekg(0,std::ios::beg);
1390  std::cout << "created palette with " << ncolor << " colors" << std::endl;
1391  while(!tempfile.eof()) {//create polylines
1392  tempfile >> red >> green >> blue >> npoints;
1393  for (int i=0;i<npoints;i++){
1394  tempfile >> x[i] >> y[i];
1395  }
1396  colindex=red+green*1000+blue*1000000;
1397  pos=colorList.find(colindex);
1398  if(pos != colorList.end()){
1399  TPolyLine* pline = new TPolyLine(npoints,y,x);
1400  vp.push_back(pline);
1401  pline->SetFillColor(colorList[colindex]);
1402  pline->SetLineWidth(0);
1403  pline->Draw("f");
1404  }
1405  }
1406  MyC->Update();
1407  std::cout << "Filetype " << filetype << std::endl;
1408  if(filetype=="png"){
1409  std::string filename = outputfilename + ".png";
1410  MyC->Print(filename.c_str());
1411  }
1412  if(filetype=="jpg"){
1413  std::string filename = outputfilename + ".jpg";
1414  MyC->Print(filename.c_str());
1415  }
1416  if(filetype=="pdf"){
1417  std::string filename = outputfilename + ".pdf";
1418  MyC->Print(filename.c_str());
1419  }
1420  std::string command = "rm "+tempfilename ;
1421  command1=command.c_str();
1422  std::cout << "Executing " << command1 << std::endl;
1423  system(command1);
1424  MyC->Clear();
1425  delete MyC;
1426  for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
1427  delete (*pos1);}
1428 
1429 
1430 
1431 
1432 }//if(temporary_file)
1433 }//if(enabledFecProcessing)
1434 }
1435 void TrackerMap::save_as_HVtrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
1436 
1437  if(enableHVProcessing){
1438  std::string filetype=s,outputfilename=s;
1439  std::vector<TPolyLine*> vp;
1440 
1441  size_t found=filetype.find_last_of(".");
1442  filetype=filetype.substr(found+1);
1443  found=outputfilename.find_last_of(".");
1444  outputfilename=outputfilename.substr(0,found);
1445 
1446  temporary_file=true;
1447 
1448 
1449  if(filetype=="xml"||filetype=="svg")temporary_file=false;
1450 
1451  std::ostringstream outs;
1452  minvalue=minval; maxvalue=maxval;
1453  outs << outputfilename << ".coor";
1454  if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1455 
1456  std::map<int , TmPsu *>::iterator ipsu;
1457  std::multimap<TmPsu*, TmModule*>::iterator it;
1458  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
1459 
1460 
1461  bool usePsuValue=false;
1462 
1463  for( ipsu=psuMap.begin();ipsu!=psuMap.end(); ipsu++){
1464  TmPsu* psu= ipsu->second;
1465  if(psu!=0) {
1466  if(psu->countHV2 > 0 || psu->redHV2!=-1 || psu->countHV3 > 0 || psu->redHV3!=-1) { usePsuValue=true; break;}
1467  }
1468  }
1469 
1470  if(!usePsuValue){//store mean of connected modules value{
1471 
1472  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1473  TmPsu * psu= ipsu->second;
1474  if(psu!=0) {
1475  ret = psuModuleMap.equal_range(psu);
1476  for(it = ret.first; it != ret.second; ++it){
1477  if((*it).second->HVchannel==2){ psu->valueHV2=psu->valueHV2+(*it).second->value;}
1478  if((*it).second->HVchannel==3){ psu->valueHV3=psu->valueHV3+(*it).second->value;}
1479  }
1480  if(psu->nmodHV2!=0){psu->valueHV2=psu->valueHV2/psu->nmodHV2;}
1481  if(psu->nmodHV3!=0){psu->valueHV3=psu->valueHV3/psu->nmodHV3;}
1482  psu->countHV2=1;
1483  psu->countHV3=1;
1484 
1485  }
1486 
1487  }
1488  }
1489 
1490  if(title==" Tracker Map from QTestAlarm"){
1491  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1492  TmPsu * psu= ipsu->second;
1493  if(psu!=0) {
1494  ret = psuModuleMap.equal_range(psu);
1495  psu->redHV2=0;psu->greenHV2=255;psu->blueHV2=0;
1496  psu->redHV3=0;psu->greenHV3=255;psu->blueHV3=0;
1497  for (it = ret.first; it != ret.second; ++it) {
1498  if((*it).second->HVchannel==2){
1499  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 ) ){
1500  psu->redHV2=255;psu->greenHV2=0;psu->blueHV2=0;
1501  }
1502  }
1503  if((*it).second->HVchannel==3){
1504  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 ) ){
1505  psu->redHV3=255;psu->greenHV3=0;psu->blueHV3=0;
1506  }
1507  }
1508  }
1509  }
1510  }
1511  }
1512 
1513  if(!print_total){
1514  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1515  TmPsu * psu= ipsu->second;
1516  if(psu!=0) {
1517  if(usePsuValue){
1518  psu->valueHV2 = psu->valueHV2 / psu->countHV2;
1519  psu->valueHV3 = psu->valueHV3 / psu->countHV3;
1520  }
1521  }
1522  }
1523  }
1524 
1525  if(minvalue>=maxvalue){
1526 
1527  minvalue=9999999.;
1528  maxvalue=-9999999.;
1529 
1530  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1531  TmPsu * psu= ipsu->second;
1532  if(psu!=0) {
1533  if (minvalue > psu->valueHV2 || minvalue > psu->valueHV3)minvalue=std::min(psu->valueHV2,psu->valueHV3);
1534  if (maxvalue < psu->valueHV2 || maxvalue < psu->valueHV3)maxvalue=std::max(psu->valueHV2,psu->valueHV3);
1535 
1536 
1537  }
1538  }
1539  }
1540 
1541  if(filetype=="svg"){
1542  saveAsSingleLayer=false;
1543  std::ostringstream outs;
1544  outs << outputfilename<<".svg";
1545  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1546  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<std::endl;
1547  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1548  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" "<<std::endl;
1549  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">"<<std::endl;
1550  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
1551  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl;
1552  *savefile << "<svg:g id=\"HVtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
1553  }
1554 
1555  for (int irack=1; irack < (npsuracks+1); irack++){
1556  if(filetype=="xml"){
1557  saveAsSingleLayer=true;
1558  std::ostringstream outs;
1559  outs << outputfilename<<"HVrack" <<irack<< ".xml";
1560  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1561  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
1562  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1563  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\""<<std::endl;
1564  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >"<<std::endl;
1565  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rackhv.js\" />"<<std::endl;
1566  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerRackhv.init()\">"<<std::endl;
1567  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
1568  *savefile << "<g id=\"rackhv\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > "<<std::endl;
1569  }
1570 
1571  nrack=irack;
1573  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1574  TmPsu * psu= ipsu->second;
1575  if(psu->getPsuRack() == irack){
1576  drawHV2(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
1577  drawHV3(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
1578  }
1579  }
1580 
1581 
1582  if(!temporary_file){
1583  if(filetype=="xml"){
1584  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
1585  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
1586  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
1587  *savefile << " </text> </svg>" << std::endl;
1588  savefile->close();
1589  saveAsSingleLayer=false;
1590  }
1591  }
1592  }
1593  if(filetype=="svg"){
1594  *savefile << "</g> </svg> </svg> " << std::endl;
1595  savefile->close();
1596  }
1597 
1598  //Restore psu value
1599  if(!print_total && !usePsuValue){
1600  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1601  TmPsu *psu = ipsu->second;
1602  if(psu!=0) {
1603  psu->valueHV2 = psu->valueHV2 * psu->countHV2;
1604  psu->valueHV3 = psu->valueHV3 * psu->countHV3;
1605  }
1606  }
1607  }
1608 
1609 
1610  if(temporary_file){
1611  // if(printflag)drawPalette(savefile);
1612  savefile->close();
1613 
1614  const char * command1;
1615  std::string tempfilename = outputfilename + ".coor";
1616  int red,green,blue,npoints,colindex,ncolor;
1617  double x[4],y[4];
1618  ifstream tempfile(tempfilename.c_str(),std::ios::in);
1619  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
1620  gPad->SetFillColor(38);
1621 
1622  gPad->Range(0,0,3700,1600);
1623 
1624  //First build palette
1625  ncolor=0;
1626  typedef std::map<int,int> ColorList;
1627  ColorList colorList;
1628  ColorList::iterator pos;
1629  TColor *col,*c;
1630  while(!tempfile.eof()) {
1631  tempfile >> red >> green >> blue >> npoints;
1632  colindex=red+green*1000+blue*1000000;
1633  pos=colorList.find(colindex);
1634  if(pos == colorList.end()){
1635  colorList[colindex]=ncolor+100;
1636  col =gROOT->GetColor(ncolor+100);
1637  if(col)
1638  col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1639  else
1640  c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1641  vc.push_back(c);
1642  ncolor++;
1643  }
1644  for (int i=0;i<npoints;i++){
1645  tempfile >> x[i] >> y[i];
1646  }
1647  }
1648  if(ncolor>0 && ncolor<10000){
1649  Int_t colors[10000];
1650  for(int i=0;i<ncolor;i++){colors[i]=i+100;}
1651  gStyle->SetPalette(ncolor,colors);
1652  }
1653  tempfile.clear();
1654  tempfile.seekg(0,std::ios::beg);
1655  std::cout << "created palette with " << ncolor << " colors" << std::endl;
1656  while(!tempfile.eof()) {//create polylines
1657  tempfile >> red >> green >> blue >> npoints;
1658  for (int i=0;i<npoints;i++){
1659  tempfile >> x[i] >> y[i];
1660  }
1661  colindex=red+green*1000+blue*1000000;
1662  pos=colorList.find(colindex);
1663  if(pos != colorList.end()){
1664  TPolyLine* pline = new TPolyLine(npoints,y,x);
1665  vp.push_back(pline);
1666  pline->SetFillColor(colorList[colindex]);
1667  pline->SetLineWidth(0);
1668  pline->Draw("f");
1669  }
1670  }
1671  MyC->Update();
1672  std::cout << "Filetype " << filetype << std::endl;
1673  if(filetype=="png"){
1674  std::string filename = outputfilename + ".png";
1675  MyC->Print(filename.c_str());
1676  }
1677  if(filetype=="jpg"){
1678  std::string filename = outputfilename + ".jpg";
1679  MyC->Print(filename.c_str());
1680  }
1681  if(filetype=="pdf"){
1682  std::string filename = outputfilename + ".pdf";
1683  MyC->Print(filename.c_str());
1684  }
1685  std::string command = "rm "+tempfilename ;
1686  command1=command.c_str();
1687  std::cout << "Executing " << command1 << std::endl;
1688  system(command1);
1689  MyC->Clear();
1690  delete MyC;
1691  for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
1692  delete (*pos1);}
1693 
1694 
1695  }//if(temporary_file)
1696 }//if(enabledHVProcessing)
1697 }
1698 
1699 
1700 void TrackerMap::save_as_psutrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
1701 
1702  if(enableLVProcessing){
1703 
1704  std::string filetype=s,outputfilename=s;
1705  std::vector<TPolyLine*> vp;
1706 
1707  size_t found=filetype.find_last_of(".");
1708  filetype=filetype.substr(found+1);
1709  found=outputfilename.find_last_of(".");
1710  outputfilename=outputfilename.substr(0,found);
1711 
1712  temporary_file=true;
1713 
1714 
1715 
1716  if(filetype=="xml"||filetype=="svg")temporary_file=false;
1717 
1718  std::ostringstream outs;
1719  minvalue=minval; maxvalue=maxval;
1720  outs << outputfilename << ".coor";
1721  if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1722 
1723  std::map<int , TmPsu *>::iterator ipsu;
1724  std::multimap<TmPsu*, TmModule*>::iterator it;
1725  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
1726 
1727  //Decide if we must use Module or Power Psupply value
1728  bool usePsuValue=false;
1729 
1730  for( ipsu=psuMap.begin();ipsu!=psuMap.end(); ipsu++){
1731  TmPsu* psu= ipsu->second;
1732  if(psu!=0) {
1733  if(psu->count > 0 || psu->red!=-1) { usePsuValue=true; break;}
1734  }
1735  }
1736 
1737  if(!usePsuValue){//store mean of connected modules value{
1738  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1739  TmPsu * psu= ipsu->second;
1740  if(psu!=0) {
1741  ret = psuModuleMap.equal_range(psu);
1742  for(it = ret.first; it != ret.second; ++it){
1743  psu->value=psu->value+(*it).second->value;
1744 
1745  }
1746  psu->value=psu->value/psu->nmod;
1747  psu->count=1;
1748 
1749  }
1750  }
1751  }
1752 
1753  if(title==" Tracker Map from QTestAlarm"){
1754  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1755  TmPsu * psu= ipsu->second;
1756  if(psu!=0) {
1757  ret = psuModuleMap.equal_range(psu);
1758  psu->red=0;psu->green=255;psu->blue=0;
1759  for (it = ret.first; it != ret.second; ++it) {
1760  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 ) ){
1761  psu->red=255;psu->green=0;psu->blue=0;
1762  }
1763  }
1764  }
1765  }
1766  }
1767 
1768 
1769 
1770  if(!print_total){
1771  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1772  TmPsu * psu= ipsu->second;
1773  if(psu!=0) {
1774  if(usePsuValue) psu->value = psu->value / psu->count;
1775 
1776  }
1777  }
1778  }
1779 
1780  if(minvalue>=maxvalue){
1781 
1782  minvalue=9999999.;
1783  maxvalue=-9999999.;
1784  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1785  TmPsu * psu= ipsu->second;
1786  if(psu!=0) {
1787  if (minvalue > psu->value)minvalue=psu->value;
1788  if (maxvalue < psu->value)maxvalue=psu->value;
1789  }
1790  }
1791  }
1792 
1793  if(filetype=="svg"){
1794  saveAsSingleLayer=false;
1795  std::ostringstream outs;
1796  outs << outputfilename<<".svg";
1797  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1798  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<std::endl;
1799  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1800  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" "<<std::endl;
1801  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">"<<std::endl;
1802  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
1803  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl;
1804  *savefile << "<svg:g id=\"psutrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
1805  }
1806 
1807  for (int irack=1; irack < (npsuracks+1); irack++){
1808  if(filetype=="xml"){
1809  saveAsSingleLayer=true;
1810  std::ostringstream outs;
1811  outs << outputfilename<<"psurack" <<irack<< ".xml";
1812  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1813  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
1814  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
1815  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\""<<std::endl;
1816  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >"<<std::endl;
1817  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rack.js\" />"<<std::endl;
1818  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
1819  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
1820  *savefile << "<g id=\"rack\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > "<<std::endl;
1821  }
1822 
1823 
1824  nrack=irack;
1826  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1827  TmPsu * psu= ipsu->second;
1828  if(psu->getPsuRack() == irack){
1829 
1830  drawPsu(irack,psu->getPsuCrate(),print_total,psu,savefile,usePsuValue);
1831  }
1832  }
1833 
1834 
1835  if(!temporary_file){
1836  if(filetype=="xml"){
1837  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
1838  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
1839  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
1840  *savefile << " </text> </svg>" << std::endl;
1841  savefile->close();
1842  saveAsSingleLayer=false;
1843  }
1844  }
1845  }
1846  if(filetype=="svg"){
1847  *savefile << "</g> </svg> </svg> " << std::endl;
1848  savefile->close();
1849  }
1850 
1851  //Restore psu value
1852  if(!print_total && !usePsuValue){
1853  for( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
1854  TmPsu *psu = ipsu->second;
1855  if(psu!=0) {
1856  psu->value = psu->value * psu->count;
1857  }
1858  }
1859  }
1860 
1861 
1862  if(temporary_file){
1863  // if(printflag)drawPalette(savefile);
1864  savefile->close();
1865 
1866  const char * command1;
1867  std::string tempfilename = outputfilename + ".coor";
1868  int red,green,blue,npoints,colindex,ncolor;
1869  double x[4],y[4];
1870  ifstream tempfile(tempfilename.c_str(),std::ios::in);
1871  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
1872  gPad->SetFillColor(38);
1873 
1874  gPad->Range(0,0,3700,1600);
1875 
1876  //First build palette
1877  ncolor=0;
1878  typedef std::map<int,int> ColorList;
1879  ColorList colorList;
1880  ColorList::iterator pos;
1881  TColor *col,*c;
1882  while(!tempfile.eof()) {
1883  tempfile >> red >> green >> blue >> npoints;
1884  colindex=red+green*1000+blue*1000000;
1885  pos=colorList.find(colindex);
1886  if(pos == colorList.end()){
1887  colorList[colindex]=ncolor+100;
1888  col =gROOT->GetColor(ncolor+100);
1889  if(col)
1890  col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1891  else
1892  c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
1893  vc.push_back(c);
1894  ncolor++;
1895  }
1896  for (int i=0;i<npoints;i++){
1897  tempfile >> x[i] >> y[i];
1898  }
1899  }
1900  if(ncolor>0 && ncolor<10000){
1901  Int_t colors[10000];
1902  for(int i=0;i<ncolor;i++){colors[i]=i+100;}
1903  gStyle->SetPalette(ncolor,colors);
1904  }
1905  tempfile.clear();
1906  tempfile.seekg(0,std::ios::beg);
1907  std::cout << "created palette with " << ncolor << " colors" << std::endl;
1908  while(!tempfile.eof()) {//create polylines
1909  tempfile >> red >> green >> blue >> npoints;
1910  for (int i=0;i<npoints;i++){
1911  tempfile >> x[i] >> y[i];
1912  }
1913  colindex=red+green*1000+blue*1000000;
1914  pos=colorList.find(colindex);
1915  if(pos != colorList.end()){
1916  TPolyLine* pline = new TPolyLine(npoints,y,x);
1917  vp.push_back(pline);
1918  pline->SetFillColor(colorList[colindex]);
1919  pline->SetLineWidth(0);
1920  pline->Draw("f");
1921  }
1922  }
1923  MyC->Update();
1924  std::cout << "Filetype " << filetype << std::endl;
1925  if(filetype=="png"){
1926  std::string filename = outputfilename + ".png";
1927  MyC->Print(filename.c_str());
1928  }
1929  if(filetype=="jpg"){
1930  std::string filename = outputfilename + ".jpg";
1931  MyC->Print(filename.c_str());
1932  }
1933  if(filetype=="pdf"){
1934  std::string filename = outputfilename + ".pdf";
1935  MyC->Print(filename.c_str());
1936  }
1937  std::string command = "rm "+tempfilename ;
1938  command1=command.c_str();
1939  std::cout << "Executing " << command1 << std::endl;
1940  system(command1);
1941  MyC->Clear();
1942  delete MyC;
1943  for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
1944  delete (*pos1);}
1945 
1946 }//if(temporary_file)
1947 }//if(enabledFedProcessing)
1948 }
1949 
1950 void TrackerMap::save_as_fedtrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
1951  if(enableFedProcessing){
1952  std::string filetype=s,outputfilename=s;
1953  std::vector<TPolyLine*> vp;
1954 
1955  size_t found=filetype.find_last_of(".");
1956  filetype=filetype.substr(found+1);
1957  found=outputfilename.find_last_of(".");
1958  outputfilename=outputfilename.substr(0,found);
1959 
1960  temporary_file=true;
1961  if(filetype=="xml"||filetype=="svg")temporary_file=false;
1962  std::ostringstream outs;
1963  minvalue=minval; maxvalue=maxval;
1964  outs << outputfilename << ".coor";
1965  if(temporary_file)savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
1966  std::map<int , TmApvPair *>::iterator i_apv;
1967  std::map<int , int>::iterator i_fed;
1968  //Decide if we must use Module or ApvPair value
1969  bool useApvPairValue=false;
1970  for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
1971  TmApvPair * apvPair= i_apv->second;
1972  if(apvPair!=0) {
1973  TmModule * apv_mod = apvPair->mod;
1974  if(apv_mod !=0 && !apv_mod->notInUse()){
1975  if(apvPair->count > 0 || apvPair->red!=-1) { useApvPairValue=true; break;}
1976  }
1977  }
1978  }
1979  if(!print_total){
1980  for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
1981  TmApvPair * apvPair= i_apv->second;
1982  if(apvPair!=0) {
1983  TmModule * apv_mod = apvPair->mod;
1984  if(apv_mod !=0 && !apv_mod->notInUse()){
1985  if(useApvPairValue) apvPair->value = apvPair->value / apvPair->count;
1986  else if(apvPair->mpos==0)apv_mod->value = apv_mod->value / apv_mod->count;
1987  }
1988  }
1989  }
1990  }
1991  if(minvalue>=maxvalue){
1992 
1993  minvalue=9999999.;
1994  maxvalue=-9999999.;
1995  for(i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
1996  TmApvPair * apvPair= i_apv->second;
1997  if(apvPair!=0) {
1998  TmModule * apv_mod = apvPair->mod;
1999  if( apv_mod !=0 && !apv_mod->notInUse()){
2000  if(useApvPairValue){
2001  if (minvalue > apvPair->value)minvalue=apvPair->value;
2002  if (maxvalue < apvPair->value)maxvalue=apvPair->value;
2003  } else {
2004  if (minvalue > apv_mod->value)minvalue=apv_mod->value;
2005  if (maxvalue < apv_mod->value)maxvalue=apv_mod->value;
2006  }
2007  }
2008  }
2009  }
2010  }
2011  if(filetype=="svg"){
2012  saveAsSingleLayer=false;
2013  std::ostringstream outs;
2014  outs << outputfilename<<".svg";
2015  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
2016  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<std::endl;
2017  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
2018  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" "<<std::endl;
2019  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">"<<std::endl;
2020  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<std::endl;
2021  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<std::endl;
2022  *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<std::endl;
2023  }
2024  for (int crate=1; crate < (ncrates+1); crate++){
2025  if(filetype=="xml"){
2026  saveAsSingleLayer=true;
2027  std::ostringstream outs;
2028  outs << outputfilename<<"crate" <<crate<< ".xml";
2029  savefile = new std::ofstream(outs.str().c_str(),std::ios::out);
2030  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
2031  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
2032  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\""<<std::endl;
2033  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >"<<std::endl;
2034  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"crate.js\" />"<<std::endl;
2035  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<std::endl;
2036  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
2037  *savefile << "<g id=\"crate\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > "<<std::endl;
2038  }
2039  ncrate=crate;
2040  defcwindow(ncrate);
2041  int numfed_incrate=0;
2042  for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
2043  if(i_fed->second == crate){
2044  int fedId = i_fed->first;
2045  numfed_incrate++;
2046  for (int nconn=0;nconn<96;nconn++){
2047  int key = fedId*1000+nconn;
2048  TmApvPair * apvPair= apvMap[key];
2049  if(apvPair !=0){
2050  TmModule * apv_mod = apvPair->mod;
2051  if(apv_mod !=0 && !apv_mod->notInUse()){
2052  drawApvPair(crate,numfed_incrate,print_total,apvPair,savefile,useApvPairValue);
2053  }
2054  }
2055  }
2056  }
2057  }
2058  if(!temporary_file){
2059  if(filetype=="xml"){
2060  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2061  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2062  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2063  *savefile << " </text> </svg>" << std::endl;
2064  savefile->close();delete savefile;
2065  saveAsSingleLayer=false;
2066  }
2067  }
2068  }
2069  if(filetype=="svg"){
2070  *savefile << "</g> </svg> </svg> " << std::endl;
2071  savefile->close();delete savefile;
2072  }
2073  if(!print_total && !useApvPairValue){
2074 //Restore module value
2075  for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
2076  TmApvPair * apvPair= i_apv->second;
2077  if(apvPair!=0) {
2078  TmModule * apv_mod = apvPair->mod;
2079  if(apv_mod !=0 && apvPair->mpos==0 && !apv_mod->notInUse()){
2080  apv_mod->value = apv_mod->value * apv_mod->count;
2081  }
2082  }
2083  }
2084 }
2085 
2086  if(temporary_file){
2087  //if(printflag)drawPalette(savefile);
2088  savefile->close(); delete savefile;
2089 
2090  const char * command1;
2091  std::string tempfilename = outputfilename + ".coor";
2092  int red,green,blue,npoints,colindex,ncolor;
2093  double x[4],y[4];
2094  ifstream tempfile(tempfilename.c_str(),std::ios::in);
2095  TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
2096  gPad->SetFillColor(38);
2097 
2098  gPad->Range(0,0,3750,1600);
2099 
2100  //First build palette
2101  ncolor=0;
2102  typedef std::map<int,int> ColorList;
2103  ColorList colorList;
2104  ColorList::iterator pos;
2105  TColor *col,*c;
2106  while(!tempfile.eof()) {
2107  tempfile >> red >> green >> blue >> npoints;
2108  colindex=red+green*1000+blue*1000000;
2109  pos=colorList.find(colindex);
2110  if(pos == colorList.end()){
2111  colorList[colindex]=ncolor+100;
2112  col =gROOT->GetColor(ncolor+100);
2113  if(col)
2114  col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
2115  else
2116  c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
2117  vc.push_back(c);
2118  ncolor++;
2119  }
2120  for (int i=0;i<npoints;i++){
2121  tempfile >> x[i] >> y[i];
2122  }
2123  }
2124  if(ncolor>0 && ncolor<10000){
2125  Int_t colors[10000];
2126  for(int i=0;i<ncolor;i++){colors[i]=i+100;}
2127  gStyle->SetPalette(ncolor,colors);
2128  }
2129  tempfile.clear();
2130  tempfile.seekg(0,std::ios::beg);
2131  std::cout << "created palette with " << ncolor << " colors" << std::endl;
2132  while(!tempfile.eof()) {//create polylines
2133  tempfile >> red >> green >> blue >> npoints;
2134  for (int i=0;i<npoints;i++){
2135  tempfile >> x[i] >> y[i];
2136  }
2137  colindex=red+green*1000+blue*1000000;
2138  pos=colorList.find(colindex);
2139  if(pos != colorList.end()){
2140  TPolyLine* pline = new TPolyLine(npoints,y,x);
2141  vp.push_back(pline);
2142  pline->SetFillColor(colorList[colindex]);
2143  pline->SetLineWidth(0);
2144  pline->Draw("f");
2145  }
2146  }
2147  MyC->Update();
2148  std::cout << "Filetype " << filetype << std::endl;
2149  if(filetype=="png"){
2150  std::string filename = outputfilename + ".png";
2151  MyC->Print(filename.c_str());
2152  }
2153  if(filetype=="jpg"){
2154  std::string filename = outputfilename + ".jpg";
2155  MyC->Print(filename.c_str());
2156  }
2157  if(filetype=="pdf"){
2158  std::string filename = outputfilename + ".pdf";
2159  MyC->Print(filename.c_str());
2160  }
2161  std::string command = "rm "+tempfilename ;
2162  command1=command.c_str();
2163  std::cout << "Executing " << command1 << std::endl;
2164  system(command1);
2165  MyC->Clear();
2166  delete MyC;
2167  for(std::vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
2168  delete (*pos1);}
2169 
2170 
2171 }//if(temporary_file)
2172 }//if(enabledFedProcessing)
2173 }
2174 
2175 void TrackerMap::load(std::string inputfilename){
2176  inputfile = new ifstream(inputfilename.c_str(),std::ios::in);
2177  std::string line,value;
2178  int ipos,ipos1,ipos2,id=0,val=0;
2179  int nline=0;
2180  while (getline( *inputfile, line ))
2181  {
2182  ipos1 = line.find("value=\"");
2183  if(ipos1 > 0) {
2184  value = line.substr(ipos1+7,10);
2185  ipos = value.find("\"");
2186  value = value.substr(0,ipos);
2187  val=atoi(value.c_str());
2188  }
2189  ipos2 = line.find("detid=\"");
2190  if(ipos2 > 0) {
2191  value = line.substr(ipos2+7,10);
2192  ipos = value.find("\"");
2193  value = value.substr(0,ipos);
2194  id = atoi(value.c_str());
2195  }
2196  if(ipos1>0 && ipos2>0 && val>0)this->fill(id,val);
2197  if(ipos1>0 && ipos2>0)nline++;
2198  //if(ipos1>0 && ipos2>0)std::cout << nline << " " << id << " " << val << std::endl;
2199 
2200  }
2201  std::cout << nline << " modules found in this svg file " << std::endl;
2202  inputfile->close();delete inputfile;
2203  }
2204 
2205 
2206 
2207 //print in svg format tracker map
2208 //print_total = true represent in color the total stored in the module
2209 //print_total = false represent in color the average
2210 void TrackerMap::print(bool print_total, float minval, float maxval, std::string outputfilename){
2211  temporary_file=false;
2212  std::ostringstream outs;
2213  minvalue=minval; maxvalue=maxval;
2214  outs << outputfilename << ".xml";
2215  svgfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2216  jsfile = new ifstream(edm::FileInPath(jsfilename).fullPath().c_str(),std::ios::in);
2217 
2218  //copy javascript interface from trackermap.txt file
2219  std::string line;
2220  while (getline( *jsfile, line ))
2221  {
2222  *svgfile << line << std::endl;
2223  }
2224  jsfile->close();delete jsfile;
2225  //
2226  if(!print_total){
2227  for (int layer=1; layer < 44; layer++){
2228  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
2229  for (int module=1;module<200;module++) {
2230  int key=layer*100000+ring*1000+module;
2231  TmModule * mod = smoduleMap[key];
2232  if(mod !=0 && !mod->notInUse()){
2233  mod->value = mod->value / mod->count;
2234  }
2235  }
2236  }
2237  }
2238  }
2239  if(minvalue>=maxvalue){
2240  minvalue=9999999.;
2241  maxvalue=-9999999.;
2242  for (int layer=1; layer < 44; layer++){
2243  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
2244  for (int module=1;module<200;module++) {
2245  int key=layer*100000+ring*1000+module;
2246  TmModule * mod = smoduleMap[key];
2247  if(mod !=0 && !mod->notInUse()){
2248  if (minvalue > mod->value)minvalue=mod->value;
2249  if (maxvalue < mod->value)maxvalue=mod->value;
2250  }
2251  }
2252  }
2253  }
2254 }
2255  for (int layer=1; layer < 44; layer++){
2256  nlay=layer;
2257  defwindow(nlay);
2258  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
2259  for (int module=1;module<200;module++) {
2260  int key=layer*100000+ring*1000+module;
2261  TmModule * mod = smoduleMap[key];
2262  if(mod !=0 && !mod->notInUse()){
2263  drawModule(mod,key,layer,print_total,svgfile);
2264  }
2265  }
2266  }
2267  }
2268  *svgfile << "</svg:g></svg:svg>"<<std::endl;
2269  *svgfile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<std::endl;
2271  *svgfile << "</svg:svg>"<<std::endl;
2272  *svgfile << "</body></html>"<<std::endl;
2273  svgfile->close();delete svgfile;
2274 
2275 }
2276 
2277 void TrackerMap::drawPalette(std::ofstream * svgfile){
2278  int color,red, green, blue;
2279  float val=minvalue;
2280  int paletteLength = 250;
2281  float dval = (maxvalue-minvalue)/(float)paletteLength;
2282  for(int i=0;i<paletteLength;i++){
2283  color = getcolor(val,palette);
2284  red=(color>>16)&0xFF;
2285  green=(color>>8)&0xFF;
2286  blue=(color)&0xFF;
2287  // if(!temporary_file)*svgfile <<"<svg:rect x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"6\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n";
2288  // else *svgfile << red << " " << green << " " << blue << " 4 " << (6*i)+40 << " 3010. " <<//
2289  // (6*i)+40 << " 3060. " <<//
2290  // (6*(i-1))+40 << " 3060. " <<//
2291  // (6*(i-1))+40 <<" 3010. " << std::endl; //
2292 
2293  // if(i%50 == 0){
2294  // if(!temporary_file)*svgfile <<"<svg:rect x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"1\" fill=\"black\" />\n";
2295  // if(i%50==0&&!temporary_file)*svgfile << " <svg:text class=\"normalText\" x=\"3060\" y=\""<<(1560-6*i)<<"\">" <<val<<"</svg:text>"<<std::endl;
2296 
2297  if(!temporary_file)*svgfile <<"<svg:rect x=\"3610\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"6\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n";
2298  else *svgfile << red << " " << green << " " << blue << " 4 " << (6*i)+40 << " 3610. " <<//
2299  (6*i)+40 << " 3660. " <<//
2300  (6*(i-1))+40 << " 3660. " <<//
2301  (6*(i-1))+40 <<" 3610. " << std::endl; //
2302 
2303  if(i%50 == 0){
2304  if(!temporary_file)*svgfile <<"<svg:rect x=\"3610\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"1\" fill=\"black\" />\n";
2305  if(i%50==0&&!temporary_file)*svgfile << " <svg:text class=\"normalText\" x=\"3660\" y=\""<<(1560-6*i)<<"\">" <<val<<"</svg:text>"<<std::endl;
2306  }
2307  val = val + dval;
2308  }
2309 }
2310 void TrackerMap::fillc_fed_channel(int fedId,int fedCh, int red, int green, int blue )
2311 {
2312  int key = fedId*1000+fedCh;
2313  TmApvPair* apvpair = apvMap[key];
2314 
2315  if(apvpair!=0){
2316  apvpair->red=red; apvpair->green=green; apvpair->blue=blue;
2317  return;
2318  }
2319  std::cout << "*** error in FedTrackerMap fillc method ***";
2320 }
2321 
2322 void TrackerMap::fill_fed_channel(int idmod, float qty )
2323 {
2324  std::multimap<const int, TmApvPair*>::iterator pos;
2325  for (pos = apvModuleMap.lower_bound(idmod);
2326  pos != apvModuleMap.upper_bound(idmod); ++pos) {
2327  TmApvPair* apvpair = pos->second;
2328  if(apvpair!=0){
2329  apvpair->value=apvpair->value+qty;
2330  apvpair->count++;
2331  }
2332  }
2333  return;
2334  std::cout << "*** error in FedTrackerMap fill by module method ***";
2335  }
2336 
2337 void TrackerMap::fill_current_val_fed_channel(int fedId, int fedCh, float current_val )
2338 {
2339  int key = fedId*1000+fedCh;
2340  TmApvPair* apvpair = apvMap[key];
2341 
2342  if(apvpair!=0) {apvpair->value=current_val; apvpair->count=1; apvpair->red=-1;}
2343  else
2344  std::cout << "*** error in FedTrackerMap fill_current_val method ***";
2345 }
2346 
2347 
2348 void TrackerMap::fillc_fec_channel(int crate,int slot, int ring, int addr, int red, int green, int blue )
2349  {
2350  int key =crate*10000000+slot*100000+ring*1000+addr;
2351 
2352  TmCcu *ccu = ccuMap[key];
2353 
2354  if(ccu!=0){
2355  ccu->red=red; ccu->green=green; ccu->blue=blue;
2356  return;
2357  }
2358  std::cout << "*** error in FecTrackerMap fillc method ***";
2359 }
2360 
2361 void TrackerMap::fill_fec_channel(int crate,int slot, int ring, int addr, float qty )
2362 {
2363  int key =crate*10000000+slot*100000+ring*1000+addr;
2364  TmCcu *ccu = ccuMap[key];
2365  if(ccu!=0){
2366  ccu->count++; ccu->value=ccu->value+qty;
2367  return;
2368 
2369  }
2370 
2371  std::cout << "*** error in FecTrackerMap fill by module method ***";
2372  }
2373 
2374 
2375 
2376 void TrackerMap::fillc_lv_channel(int rack,int crate, int board, int red, int green, int blue )
2377 {
2378 
2379  int key = rack*1000+crate*100+board;
2380 
2381  TmPsu *psu = psuMap[key];
2382 
2383  if(psu!=0){
2384  psu->red=red; psu->green=green; psu->blue=blue;
2385  return;
2386  }
2387  std::cout << "*** error in LVTrackerMap fillc method ***";
2388 }
2389 
2390 void TrackerMap::fill_lv_channel(int rack,int crate, int board, float qty )
2391 {
2392  int key = rack*1000+crate*100+board;
2393  TmPsu *psu = psuMap[key];
2394  if(psu!=0){
2395  psu->count++; psu->value=psu->value+qty;
2396  return;
2397 
2398  }
2399 
2400  std::cout << "*** error in LVTrackerMap fill by module method ***";
2401  }
2402 
2403 void TrackerMap::fillc_hv_channel2(int rack,int crate, int board, int red, int green, int blue )
2404 {
2405 
2406  int key = rack*1000+crate*100+board;
2407 
2408  TmPsu *psu = psuMap[key];
2409 
2410  if(psu!=0){
2411  psu->redHV2=red; psu->greenHV2=green; psu->blueHV2=blue;
2412  return;
2413  }
2414  std::cout << "*** error in HVTrackerMap (channel 2) fillc method ***";
2415 }
2416 void TrackerMap::fillc_hv_channel3(int rack,int crate, int board, int red, int green, int blue )
2417 {
2418 
2419  int key = rack*1000+crate*100+board;
2420 
2421  TmPsu *psu = psuMap[key];
2422 
2423  if(psu!=0){
2424  psu->redHV3=red; psu->greenHV3=green; psu->blueHV3=blue;
2425  return;
2426  }
2427  std::cout << "*** error in HVTrackerMap (channel 3) fillc method ***";
2428 }
2429 
2430 
2431 void TrackerMap::fill_hv_channel2(int rack,int crate, int board, float qty )
2432 {
2433  int key = rack*1000+crate*100+board;
2434  TmPsu *psu = psuMap[key];
2435  if(psu!=0){
2436  psu->countHV2++; psu->valueHV2=psu->valueHV2+qty;
2437  return;
2438 
2439  }
2440 
2441  std::cout << "*** error in HVTrackerMap fill by module method ***";
2442  }
2443 void TrackerMap::fill_hv_channel3(int rack,int crate, int board, float qty )
2444 {
2445  int key = rack*1000+crate*100+board;
2446  TmPsu *psu = psuMap[key];
2447  if(psu!=0){
2448  psu->countHV3++; psu->valueHV3=psu->valueHV3+qty;
2449  return;
2450 
2451  }
2452 
2453  std::cout << "*** error in HVTrackerMap fill by module method ***";
2454  }
2455 
2456 
2457 
2458 
2459 
2460 int TrackerMap::module(int fedId, int fedCh)
2461 {
2462  int key = fedId*1000+fedCh;
2463  TmApvPair* apvpair = apvMap[key];
2464  if(apvpair!=0){
2465  return(apvpair->mod->idex);
2466  }
2467  return(0);
2468  std::cout << "*** error in FedTrackerMap module method ***";
2469 }
2470 void TrackerMap::fill_fed_channel(int fedId, int fedCh, float qty )
2471 {
2472  int key = fedId*1000+fedCh;
2473  TmApvPair* apvpair = apvMap[key];
2474  if(apvpair!=0){
2475  apvpair->value=apvpair->value+qty;
2476  apvpair->count++;
2477  return;
2478  }
2479  std::cout << "*** error inFedTrackerMap fill method ***";
2480 }
2481 
2482 
2483 void TrackerMap::fillc(int idmod, int red, int green, int blue ){
2484 
2485  TmModule * mod = imoduleMap[idmod];
2486  if(mod!=0){
2487  mod->red=red; mod->green=green; mod->blue=blue;
2488  return;
2489  }
2490  std::cout << "**************************error in fill method **************module "<<idmod<<std::endl;
2491 }
2492 void TrackerMap::fillc(int layer, int ring, int nmod, int red, int green, int blue ){
2493 
2494  int key = layer*10000+ring*1000+nmod;
2495  TmModule * mod = smoduleMap[key];
2496 
2497  if(mod!=0){
2498  mod->red=red; mod->green=green; mod->blue=blue;
2499  return;
2500  }
2501  std::cout << "**************************error in fill method **************"<< std::endl;
2502 }
2503 
2505 
2506  std::map<const int , TmModule *>::iterator imod;
2507  for( imod=imoduleMap.begin();imod !=imoduleMap.end(); imod++){
2508  fillc(imod->first,255,255,255);
2509  }
2510 }
2511 
2513 
2514  std::map<const int , TmModule *>::iterator imod;
2515  for( imod=imoduleMap.begin();imod !=imoduleMap.end(); imod++){
2516  fill_current_val(imod->first,0);
2517  }
2518 }
2519 
2520 
2521 
2522 void TrackerMap::fill_current_val(int idmod, float current_val ){
2523 
2524  TmModule * mod = imoduleMap[idmod];
2525  if(mod!=0) {mod->value=current_val; mod->count=1; mod->red=-1;}
2526  else std::cout << "**error in fill_current_val method ***module "<<idmod<<std::endl;
2527 }
2528 
2529 void TrackerMap::fill(int idmod, float qty ){
2530 
2531  TmModule * mod = imoduleMap[idmod];
2532  if(mod!=0){
2533  mod->value=mod->value+qty;
2534  mod->count++;
2535  return;
2536  }else{
2537  TmModule * mod1 = imoduleMap[idmod+1];
2538  TmModule * mod2 = imoduleMap[idmod+2];
2539  if(mod1!=0 && mod2!=0){
2540  mod1->value=mod1->value+qty;
2541  mod1->count++;
2542  mod2->value=mod2->value+qty;
2543  mod2->count++;
2544  return;
2545  }}
2546  std::cout << "**************************error in fill method **************module "<<idmod<<std::endl;
2547 }
2548 
2549 void TrackerMap::fill(int layer, int ring, int nmod, float qty){
2550 
2551  int key = layer*100000+ring*1000+nmod;
2552  TmModule * mod = smoduleMap[key];
2553  if(mod!=0){
2554  mod->value=mod->value+qty;
2555  mod->count++;
2556  }
2557  else std::cout << "**************************error in SvgModuleMap **************";
2558 }
2559 
2560 void TrackerMap::setText(int idmod, std::string s){
2561 
2562  TmModule * mod = imoduleMap[idmod];
2563  if(mod!=0){
2564  mod->text=s;
2565  }
2566  else std::cout << "**************************error in IdModuleMap **************";
2567 }
2568 
2569 
2570 void TrackerMap::setText(int layer, int ring, int nmod, std::string s){
2571 
2572  int key = layer*100000+ring*1000+nmod;
2573  TmModule * mod = smoduleMap[key];
2574  if(mod!=0){
2575  mod->text=s;
2576  }
2577  else std::cout << "**************************error in SvgModuleMap **************";
2578 }
2579 
2581  // ifstream* infile;
2582 
2583  int nmods, pix_sil, fow_bar, ring, nmod, layer;
2584  unsigned int idex;
2585  float posx, posy, posz, length, width, thickness, widthAtHalfLength;
2586  int iModule=0,old_layer=0, ntotMod =0;
2587  std::string name,dummys;
2588  ifstream infile(edm::FileInPath(infilename).fullPath().c_str(),std::ios::in);
2589  while(!infile.eof()) {
2590  infile >> nmods >> pix_sil >> fow_bar >> layer >> ring >> nmod >> posx >> posy
2591  >> posz>> length >> width >> thickness
2592  >> widthAtHalfLength >> idex ;
2593  getline(infile,dummys); //necessary to reach end of record
2594  getline(infile,name);
2595  if(old_layer!=layer){old_layer=layer;iModule=0;}
2596  iModule++;
2597  ntotMod++;
2598  int key=layer*100000+ring*1000+nmod;
2599  TmModule * mod = smoduleMap[key];
2600 
2601  imoduleMap[idex]=mod;
2602 
2603  if(mod==0) std::cout << "error in module "<<key <<std::endl;
2604  else
2605  {
2606  mod->posx = posx;
2607  mod->posy = posy;
2608  mod->setUsed();
2609  mod->value=0;
2610  mod->count=0;
2611  mod->posz = posz;
2612  mod->length = length;
2613  mod->width = width;
2614  mod->thickness = thickness;
2615  mod->widthAtHalfLength = widthAtHalfLength;
2616  mod->idex = idex;
2617  mod->name = name;
2618  }
2619  }
2620  infile.close();
2621  number_modules = ntotMod-1;
2622 }
2623 int TrackerMap::getcolor(float value,int palette){
2624  int red,green,blue;
2625  red=0;green=0;blue=0;
2626  if(palette==1){//palette1 1 - raibow
2627  float delta=(maxvalue-minvalue);
2628  float x =(value-minvalue);
2629  if(value<minvalue){red=0;green=0;blue=255;}
2630  if(value>maxvalue){red=255;green=0;blue=0;}
2631  if(value>=minvalue&&value<=maxvalue){
2632  red = (int) ( x<(delta/2) ? 0 : ( x > ((3./4.)*delta) ? 255 : 255/(delta/4) * (x-(2./4.)*delta) ) );
2633  green= (int) ( x<delta/4 ? (x*255/(delta/4)) : ( x > ((3./4.)*delta) ? 255-255/(delta/4) *(x-(3./4.)*delta) : 255 ) );
2634  blue = (int) ( x<delta/4 ? 255 : ( x > ((1./2.)*delta) ? 0 : 255-255/(delta/4) * (x-(1./4.)*delta) ) );
2635  }
2636  }
2637  if (palette==2){//palette 2 yellow-green
2638  green = (int)((value-minvalue)/(maxvalue-minvalue)*256.);
2639  if (green > 255) green=255;
2640  red = 255; blue=0;green=255-green;
2641  }
2642  return(blue|(green<<8)|(red<<16));
2643 }
2645 //Copy interface
2646  std::ofstream * ofilename;
2647  std::ifstream * ifilename;
2648  std::ostringstream ofname;
2649  std::string ifname;
2650  std::string command;
2651  std::string line;
2652  std::string outputfilename="dqmtmap";
2653  ifilename=findfile("viewerHeader.xhtml");
2654  ofname << outputfilename << "viewer.html";
2655  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2656  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2657 *ofilename <<" var tmapname=\"" <<outputfilename << "\""<<std::endl;
2658 *ofilename <<" var tmaptitle=\"" <<title << "\""<<std::endl;
2659 *ofilename <<" var ncrates=" <<ncrates << ";"<<std::endl;
2660 *ofilename <<" var nfeccrates=" <<nfeccrates << ";"<<std::endl;
2661  *ofilename <<" var npsuracks=" <<npsuracks << ";"<<std::endl;
2662 
2663  ifilename->close();delete ifilename;
2664 
2665  ifilename=findfile("viewerTrailer.xhtml");
2666  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2667  ofilename->close();delete ofilename;
2668  command = "sed -i \"s/XtmapnameX/"+outputfilename+"/g\" "+ ofname.str();
2669  std::cout << "Executing " << command << std::endl;
2670  system(command.c_str());
2671  command = "sed -i \"s/XtmaptitleX/"+title+"/g\" "+ ofname.str();
2672  std::cout << "Executing " << command << std::endl;
2673  system(command.c_str());
2674  ofname.str("");
2675  ifilename->close();delete ifilename;
2676 
2677  ifilename=findfile("jqviewer.js");
2678  ofname << "jqviewer.js";
2679  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2680  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2681  ofname.str("");
2682  ofilename->close();delete ofilename;
2683  ifilename->close();delete ifilename;
2684 
2685  ifilename=findfile("crate.js");
2686  ofname << "crate.js";
2687  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2688  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2689  ofname.str("");
2690  ofilename->close();delete ofilename;
2691  ifilename->close();delete ifilename;
2692 
2693  ifilename=findfile("feccrate.js");
2694  ofname << "feccrate.js";
2695  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2696  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2697  ofname.str("");
2698  ofilename->close();delete ofilename;
2699  ifilename->close();delete ifilename;
2700 
2701  ifilename=findfile("layer.js");
2702  ofname << "layer.js";
2703  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2704  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2705  ofname.str("");
2706  ofilename->close();delete ofilename;
2707  ifilename->close();delete ifilename;
2708 
2709  ifilename=findfile("rack.js");
2710  ofname << "rack.js";
2711  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2712  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2713  ofname.str("");
2714  ofilename->close();delete ofilename;
2715  ifilename->close();delete ifilename;
2716  ofname.str("");
2717 
2718  ifilename=findfile("rackhv.js");
2719  ofname << "rackhv.js";
2720  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2721  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2722  ofname.str("");
2723  ofilename->close();delete ofilename;
2724  ifilename->close();delete ifilename;
2725 
2726 
2727 
2728 
2729  std::ostringstream outs,outs1,outs2;
2730  outs << outputfilename<<".png";
2731 save(true,gminvalue,gmaxvalue,outs.str(),3000,1600);
2732 temporary_file=false;
2733 printlayers(true,gminvalue,gmaxvalue,outputfilename);
2734 
2735 //Now print a text file for each layer
2736  std::ofstream * txtfile;
2737 for (int layer=1; layer < 44; layer++){
2738  std::ostringstream outs;
2739  outs << outputfilename <<"layer"<<layer<< ".html";
2740  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2741  *txtfile << "<html><head></head> <body>" << std::endl;
2742  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
2743  for (int module=1;module<200;module++) {
2744  int key=layer*100000+ring*1000+module;
2745  TmModule * mod = smoduleMap[key];
2746  if(mod !=0 && !mod->notInUse()){
2747  int idmod=mod->idex;
2748  int nchan=0;
2749  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
2750  std::multimap<const int, TmApvPair*>::iterator pos;
2751  for (pos = apvModuleMap.lower_bound(idmod);
2752  pos != apvModuleMap.upper_bound(idmod); ++pos) {
2753  TmApvPair* apvpair = pos->second;
2754  if(apvpair!=0){
2755  nchan++;
2756  *txtfile << apvpair->text << std::endl;
2757  }
2758 
2759  }
2760  *txtfile << "</pre><h3>"<< mod->name<<"</h3>"<<std::endl;
2761  }
2762  }
2763  }
2764  *txtfile << "</body></html>" << std::endl;
2765  txtfile->close();delete txtfile;
2766  }
2768  outs1 << outputfilename<<"fed.png";
2769 save_as_fedtrackermap(true,gminvalue,gmaxvalue,outs1.str(),6000,3200);
2770  outs2 << outputfilename<<".xml";
2771 save_as_fedtrackermap(true,gminvalue,gmaxvalue,outs2.str(),3000,1600);
2772 //And a text file for each crate
2773  std::map<int , int>::iterator i_fed;
2774  std::ofstream * txtfile;
2775  for (int crate=1; crate < (ncrates+1); crate++){
2776  std::ostringstream outs;
2777  outs << outputfilename <<"crate"<<crate<< ".html";
2778  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2779  *txtfile << "<html><head></head> <body>" << std::endl;
2780  for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
2781  if(i_fed->second == crate){
2782  int fedId = i_fed->first;
2783  for (int nconn=0;nconn<96;nconn++){
2784  int key = fedId*1000+nconn;
2785  TmApvPair * apvPair= apvMap[key];
2786  if(apvPair !=0){
2787  int idmod=apvPair->idex;
2788  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
2789  *txtfile << apvPair->text << std::endl;
2790  std::ostringstream outs;
2791  outs << "fedchannel " <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module " << apvPair->mod->idex ;
2792  *txtfile << "</pre><h3>"<< outs.str()<<"</h3>"<<std::endl;
2793  }
2794  }
2795  }
2796  }
2797  *txtfile << "</body></html>" << std::endl;
2798  txtfile->close();delete txtfile;
2799  }
2800  }
2802  std::ostringstream outs1,outs2;
2803  outs1 << outputfilename<<"fec.png";
2804 save_as_fectrackermap(true,gminvalue,gmaxvalue,outs1.str(),6000,3200);
2805  outs2 << outputfilename<<".xml";
2806 save_as_fectrackermap(true,gminvalue,gmaxvalue,outs2.str(),3000,1600);
2807 //And a text file for each crate
2808  std::ofstream * txtfile;
2809  std::map<int , TmCcu *>::iterator i_ccu;
2810  std::multimap<TmCcu*, TmModule*>::iterator it;
2811  std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
2812  for (int crate=1; crate < (nfeccrates+1); crate++){
2813  std::ostringstream outs;
2814  outs << outputfilename <<"feccrate"<<crate<< ".html";
2815  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2816  *txtfile << "<html><head></head> <body>" << std::endl;
2817  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
2818  TmCcu * ccu= i_ccu->second;
2819  if(ccu!=0&&ccu->getCcuCrate() == crate){
2820  int idmod=ccu->idex;
2821  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
2822  *txtfile << ccu->text << std::endl;
2823  std::ostringstream outs;
2824  if(ccu->nmod==0)outs << "ccu is in position" << ccu->mpos<<"in ring but doesn't seem to have any module connected"; else
2825  {
2826  outs << "ccu is in position " << ccu->mpos<<" in ring and connects " <<ccu->nmod<< " modules" << std::endl;
2827  ret = fecModuleMap.equal_range(ccu);
2828  for (it = ret.first; it != ret.second; ++it)
2829  {
2830  outs << (*it).second->idex<<" " << (*it).second->name <<" value= "<< (*it).second->value<<"\n\n";
2831  }
2832 
2833  *txtfile << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
2834  }//ifccu->nmod==0
2835  }//if ccu!=0
2836  }//for i_ccu
2837  *txtfile << "</body></html>" << std::endl;
2838  txtfile->close();delete txtfile;
2839  }//for int crate
2840  }
2841 if(enableLVProcessing){
2842  std::ostringstream outs3,outs4;
2843  outs3 << outputfilename<<"psu.png";
2844 save_as_psutrackermap(true,gminvalue,gmaxvalue,outs3.str(),6000,3200);
2845 
2846  outs4 << outputfilename<<".xml";
2847 save_as_psutrackermap(true,gminvalue,gmaxvalue,outs4.str(),3000,1600);
2848 //And a text file for each rack
2849 
2850  std::ofstream * txtfile;
2851  std::map<int , TmPsu *>::iterator ipsu;
2852  std::multimap<TmPsu*, TmModule*>::iterator it;
2853  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
2854  for (int rack=1; rack < (npsuracks+1); rack++){
2855  std::ostringstream outs;
2856 
2857  outs << outputfilename <<"psurack"<<rack<< ".html";
2858  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2859  *txtfile << "<html><head></head> <body>" << std::endl;
2860  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
2861  TmPsu * psu= ipsu->second;
2862  if(psu!=0 && psu->getPsuRack() == rack){
2863  *txtfile << "<a name="<<psu->idex<<"><pre>"<<std::endl;
2864  *txtfile << psu->text << std::endl;
2865  std::ostringstream outs;
2866  if(psu->nmod==0)outs << "Ps is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
2867  {
2868  outs<< "PS is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmod<<" modules. "<<std::endl;
2869 
2870  ret = psuModuleMap.equal_range(psu);
2871  for (it = ret.first; it != ret.second; ++it)
2872  {
2873  outs <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;
2874 
2875  }
2876  *txtfile << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
2877  }
2878  }
2879  }
2880  *txtfile << "</body></html>" << std::endl;
2881  txtfile->close();delete txtfile;
2882  }
2883  }
2884 
2885 
2886 if(enableHVProcessing){
2887  std::ostringstream outs5,outs6;
2888  outs5 << outputfilename<<"hv.png";
2889 save_as_HVtrackermap(true,gminvalue,gmaxvalue,outs5.str(),6000,3200);
2890 
2891  outs6 << outputfilename<<".xml";
2892 save_as_HVtrackermap(true,gminvalue,gmaxvalue,outs6.str(),3000,1600);
2893 //And a text file for each rack
2894 
2895  std::ofstream * txtfile;
2896  std::map<int , TmPsu *>::iterator ipsu;
2897  std::multimap<TmPsu*, TmModule*>::iterator it;
2898  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
2899  for (int rack=1; rack < (npsuracks+1); rack++){
2900  std::ostringstream outs;
2901 
2902  outs << outputfilename <<"HVrack"<<rack<< ".html";
2903  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
2904  *txtfile << "<html><head></head> <body>" << std::endl;
2905  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
2906  TmPsu * psu= ipsu->second;
2907  if(psu!=0 && psu->getPsuRack() == rack){
2908  *txtfile << "<a name="<<psu->idex<<"><pre>"<<std::endl;
2909  *txtfile << psu->textHV2 << std::endl;
2910  std::ostringstream outsHV2;
2911  if(psu->nmodHV2==0)outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
2912  {
2913  outsHV2<< "HV Channel002 is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV2<<" modules. "<<" <br>"<<std::endl;
2914 
2915  ret = psuModuleMap.equal_range(psu);
2916  for (it = ret.first; it != ret.second; ++it)
2917  {
2918  if((*it).second->HVchannel==2){outsHV2 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
2919  }
2920  *txtfile << "</pre><h4>"<< outsHV2.str()<<"</h4>"<<std::endl;
2921  }
2922 
2923  *txtfile << psu->textHV3 << std::endl;
2924  std::ostringstream outsHV3;
2925  if(psu->nmodHV3==0)outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
2926  {
2927  outsHV3<< "HV Channel003 is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV3<<" modules. "<<" <br>"<<std::endl;
2928 
2929  ret = psuModuleMap.equal_range(psu);
2930  for (it = ret.first; it != ret.second; ++it)
2931  {
2932  if((*it).second->HVchannel==3){outsHV3 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
2933  }
2934  *txtfile << "</pre><h4>"<< outsHV3.str()<<"</h4>"<<std::endl;
2935  }
2936 
2937  }
2938  }
2939  *txtfile << "</body></html>" << std::endl;
2940  txtfile->close();delete txtfile;
2941  }
2942  }
2943 
2944 }
2945 void TrackerMap::printall(bool print_total, float minval, float maxval, std::string outputfilename){
2946 //Copy interface
2947  std::ofstream * ofilename;
2948  std::ifstream * ifilename;
2949  std::ostringstream ofname;
2950  std::string ifname;
2951  std::string line;
2952  std::string command;
2953 
2954  ifilename=findfile("viewerHeader.xhtml");
2955  ofname << outputfilename << "viewer.html";
2956  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2957  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2958 *ofilename <<" var tmapname=\"" <<outputfilename << "\""<<std::endl;
2959 *ofilename <<" var tmaptitle=\"" <<title << "\""<<std::endl;
2960 *ofilename <<" var ncrates=" <<ncrates << ";"<<std::endl;
2961 *ofilename <<" var nfeccrates=" <<nfeccrates << ";"<<std::endl;
2962 *ofilename <<" var npsuracks=" <<npsuracks << ";"<<std::endl;
2963  ifilename->close();delete ifilename;
2964  ifilename=findfile("viewerTrailer.xhtml");
2965  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2966  ofilename->close();delete ofilename;
2967  ifilename->close();delete ifilename;
2968  command = "sed -i \"s/XtmapnameX/"+outputfilename+"/g\" "+ ofname.str();
2969  std::cout << "Executing " << command << std::endl;
2970  system(command.c_str());
2971  command = "sed -i \"s/XtmaptitleX/"+title+"/g\" "+ ofname.str();
2972  std::cout << "Executing " << command << std::endl;
2973  system(command.c_str());
2974  ofname.str("");
2975 
2976 ifilename=findfile("jqviewer.js");
2977  ofname << "jqviewer.js";
2978  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2979  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2980  ofilename->close();delete ofilename;
2981  ifilename->close();delete ifilename;
2982 
2983  ofname.str("");
2984  ifilename=findfile("crate.js");
2985  ofname << "crate.js";
2986  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2987  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2988  ofilename->close();delete ofilename;
2989  ifilename->close();delete ifilename;
2990 
2991  ofname.str("");
2992  ifilename=findfile("feccrate.js");
2993  ofname << "feccrate.js";
2994  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
2995  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
2996  ofilename->close();delete ofilename;
2997  ifilename->close();delete ifilename;
2998 
2999  ofname.str("");
3000  ifilename=findfile("rack.js");
3001  ofname << "rack.js";
3002  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
3003  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
3004  ofilename->close();delete ofilename;
3005  ifilename->close();delete ifilename;
3006 
3007  ofname.str("");
3008  ifilename=findfile("rackhv.js");
3009  ofname << "rackhv.js";
3010  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
3011  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
3012  ofilename->close();delete ofilename;
3013  ifilename->close();delete ifilename;
3014 
3015  ofname.str("");
3016  ifilename=findfile("layer.js");
3017  ofname << "layer.js";
3018  ofilename = new std::ofstream(ofname.str().c_str(),std::ios::out);
3019  while (getline( *ifilename, line )) { *ofilename << line << std::endl; }
3020  ofilename->close();delete ofilename;
3021  ifilename->close();delete ifilename;
3022 
3023  command = "scp -r ../../DQM/TrackerCommon/test/jquery/ .";
3024  std::cout << "Executing " << command << std::endl;
3025  system(command.c_str());
3026  command = "scp -r ../../CommonTools/TrackerMap/data/images/ .";
3027  std::cout << "Executing " << command << std::endl;
3028  system(command.c_str());
3029 
3030 
3031  std::ostringstream outs;
3032  outs << outputfilename<<".png";
3033 save(true,minval,maxval,outs.str(),3000,1600);
3034 temporary_file=false;
3035 printlayers(true,minval,maxval,outputfilename);
3036 
3037 //Now print a text file for each layer
3038  std::ofstream * txtfile;
3039 for (int layer=1; layer < 44; layer++){
3040  std::ostringstream outs;
3041  outs << outputfilename <<"layer"<<layer<< ".html";
3042  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3043  *txtfile << "<html><head></head> <body>" << std::endl;
3044  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
3045  for (int module=1;module<200;module++) {
3046  int key=layer*100000+ring*1000+module;
3047  TmModule * mod = smoduleMap[key];
3048  if(mod !=0 && !mod->notInUse()){
3049  int idmod=mod->idex;
3050  int nchan=0;
3051  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
3052  std::multimap<const int, TmApvPair*>::iterator pos;
3053  for (pos = apvModuleMap.lower_bound(idmod);
3054  pos != apvModuleMap.upper_bound(idmod); ++pos) {
3055  TmApvPair* apvpair = pos->second;
3056  if(apvpair!=0){
3057  nchan++;
3058  *txtfile << apvpair->text << std::endl;
3059  }
3060 
3061  }
3062  *txtfile << "</pre><h3>"<< mod->name<<"</h3>"<<std::endl;
3063  }
3064  }
3065  }
3066  *txtfile << "</body></html>" << std::endl;
3067  txtfile->close();delete txtfile;
3068  }
3070  std::ostringstream outs1,outs2;
3071  outs1 << outputfilename<<"fed.png";
3072 save_as_fedtrackermap(true,0.,0.,outs1.str(),6000,3200);
3073  outs2 << outputfilename<<".xml";
3074 save_as_fedtrackermap(true,0.,0.,outs2.str(),3000,1600);
3075 //And a text file for each crate
3076  std::map<int , int>::iterator i_fed;
3077  std::ofstream * txtfile;
3078  for (int crate=1; crate < (ncrates+1); crate++){
3079  std::ostringstream outs;
3080  outs << outputfilename <<"crate"<<crate<< ".html";
3081  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3082  *txtfile << "<html><head></head> <body>" << std::endl;
3083  for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
3084  if(i_fed->second == crate){
3085  int fedId = i_fed->first;
3086  for (int nconn=0;nconn<96;nconn++){
3087  int key = fedId*1000+nconn;
3088  TmApvPair * apvPair= apvMap[key];
3089  if(apvPair !=0){
3090  int idmod=apvPair->idex;
3091  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
3092  *txtfile << apvPair->text << std::endl;
3093  std::ostringstream outs;
3094  outs << "fedchannel " <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module " << apvPair->mod->idex ;
3095  *txtfile << "</pre><h3>"<< outs.str()<<"</h3>"<<std::endl;
3096  }
3097  }
3098  }
3099  }
3100  *txtfile << "</body></html>" << std::endl;
3101  txtfile->close();delete txtfile;
3102  }
3103  }
3105  std::ostringstream outs1,outs2;
3106  outs1 << outputfilename<<"fec.png";
3107 save_as_fectrackermap(true,0.,0.,outs1.str(),6000,3200);
3108  outs2 << outputfilename<<".xml";
3109 save_as_fectrackermap(true,0.,0.,outs2.str(),3000,1600);
3110 //And a text file for each crate
3111  std::ofstream * txtfile;
3112  std::map<int , TmCcu *>::iterator i_ccu;
3113  std::multimap<TmCcu*, TmModule*>::iterator it;
3114  std::pair<std::multimap<TmCcu*, TmModule*>::iterator,std::multimap<TmCcu*, TmModule*>::iterator> ret;
3115  for (int crate=1; crate < (nfeccrates+1); crate++){
3116  std::ostringstream outs;
3117  outs << outputfilename <<"feccrate"<<crate<< ".html";
3118  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3119  *txtfile << "<html><head></head> <body>" << std::endl;
3120  for( i_ccu=ccuMap.begin();i_ccu !=ccuMap.end(); i_ccu++){
3121  TmCcu * ccu= i_ccu->second;
3122  if(ccu!=0&&ccu->getCcuCrate() == crate){
3123  int idmod=ccu->idex;
3124  *txtfile << "<a name="<<idmod<<"><pre>"<<std::endl;
3125  *txtfile << ccu->text << std::endl;
3126  std::ostringstream outs;
3127  if(ccu->nmod==0)outs << "ccu is in position" << ccu->mpos<<"in ring but doesn't seem to have any module connected"; else
3128  {
3129  outs << "ccu is in position " << ccu->mpos<<" in ring and connects " <<ccu->nmod<< " modules" << std::endl;
3130  ret = fecModuleMap.equal_range(ccu);
3131  for (it = ret.first; it != ret.second; ++it)
3132  {
3133  outs << (*it).second->idex<<" " << (*it).second->name <<" value= "<< (*it).second->value<<"\n\n";
3134  }
3135 
3136  *txtfile << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
3137  }//ifccu->nmod==0
3138  }//if ccu!=0
3139  }//for i_ccu
3140  *txtfile << "</body></html>" << std::endl;
3141  txtfile->close();
3142  }//for int crate
3143  }
3144 if(enableLVProcessing){
3145  std::ostringstream outs3,outs4;
3146  outs3 << outputfilename<<"psu.png";
3147 save_as_psutrackermap(true,0.,0.,outs3.str(),6000,3200);
3148 
3149  outs4 << outputfilename<<".xml";
3150 save_as_psutrackermap(true,0.,0.,outs4.str(),3000,1600);
3151 //And a text file for each rack
3152 
3153  std::ofstream * txtfile;
3154  std::map<int , TmPsu *>::iterator ipsu;
3155  std::multimap<TmPsu*, TmModule*>::iterator it;
3156  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
3157  for (int rack=1; rack < (npsuracks+1); rack++){
3158  std::ostringstream outs;
3159 
3160  outs << outputfilename <<"psurack"<<rack<< ".html";
3161  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3162  *txtfile << "<html><head></head> <body>" << std::endl;
3163  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
3164  TmPsu * psu= ipsu->second;
3165  if(psu!=0 && psu->getPsuRack() == rack){
3166  *txtfile << "<a name="<<psu->idex<<"><pre>"<<std::endl;
3167  *txtfile << psu->text << std::endl;
3168  std::ostringstream outs;
3169  if(psu->nmod==0)outs << "Ps is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
3170  {
3171  outs<< "PS is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmod<<" modules. "<<std::endl;
3172 
3173  ret = psuModuleMap.equal_range(psu);
3174  for (it = ret.first; it != ret.second; ++it)
3175  {
3176  outs <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;
3177 
3178  }
3179  *txtfile << "</pre><h4>"<< outs.str()<<"</h4>"<<std::endl;
3180  }
3181  }
3182  }
3183  *txtfile << "</body></html>" << std::endl;
3184  txtfile->close();
3185  }
3186  }
3187 
3188 
3189 if(enableHVProcessing){
3190  std::ostringstream outs5,outs6;
3191  outs5 << outputfilename<<"hv.png";
3192 save_as_HVtrackermap(true,0.,0.,outs5.str(),6000,3200);
3193 
3194  outs6 << outputfilename<<".xml";
3195 save_as_HVtrackermap(true,0.,0.,outs6.str(),3000,1600);
3196 //And a text file for each rack
3197 
3198  std::ofstream * txtfile;
3199  std::map<int , TmPsu *>::iterator ipsu;
3200  std::multimap<TmPsu*, TmModule*>::iterator it;
3201  std::pair<std::multimap<TmPsu*, TmModule*>::iterator,std::multimap<TmPsu*, TmModule*>::iterator> ret;
3202  for (int rack=1; rack < (npsuracks+1); rack++){
3203  std::ostringstream outs;
3204 
3205  outs << outputfilename <<"HVrack"<<rack<< ".html";
3206  txtfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3207  *txtfile << "<html><head></head> <body>" << std::endl;
3208  for ( ipsu=psuMap.begin();ipsu !=psuMap.end(); ipsu++){
3209  TmPsu * psu= ipsu->second;
3210  if(psu!=0 && psu->getPsuRack() == rack){
3211  *txtfile << "<a name="<<psu->idex<<"><pre>"<<std::endl;
3212  *txtfile << psu->textHV2 << std::endl;
3213  std::ostringstream outsHV2;
3214  if(psu->nmodHV2==0)outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
3215  {
3216  outsHV2<< "HV Channel002 is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV2<<" modules. "<<" <br>"<<std::endl;
3217 
3218  ret = psuModuleMap.equal_range(psu);
3219  for (it = ret.first; it != ret.second; ++it)
3220  {
3221  if((*it).second->HVchannel==2){outsHV2 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
3222  }
3223  *txtfile << "</pre><h4>"<< outsHV2.str()<<"</h4>"<<std::endl;
3224  }
3225 
3226  *txtfile << psu->textHV3 << std::endl;
3227  std::ostringstream outsHV3;
3228  if(psu->nmodHV3==0)outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()<<"in crate but doesn't seem to have any module connected"; else
3229  {
3230  outsHV3<< "HV Channel003 is in position " <<psu->getPsuBoard()<< " in crate and connects to "<<psu->nmodHV3<<" modules. "<<" <br>"<<std::endl;
3231 
3232  ret = psuModuleMap.equal_range(psu);
3233  for (it = ret.first; it != ret.second; ++it)
3234  {
3235  if((*it).second->HVchannel==3){outsHV3 <<(*it).second->idex << " "<< (*it).second->name<<" value= "<<(*it).second->value<<" <br>"<<std::endl;}
3236  }
3237  *txtfile << "</pre><h4>"<< outsHV3.str()<<"</h4>"<<std::endl;
3238  }
3239 
3240  }
3241  }
3242  *txtfile << "</body></html>" << std::endl;
3243  txtfile->close();
3244  }
3245  }
3246 
3247 
3248 }
3249 
3250 
3251 std::ifstream * TrackerMap::findfile(std::string filename) {
3252  std::ifstream * ifilename;
3253  std::string ifname;
3254  if(jsPath!=""){
3255  ifname=jsPath+filename;
3256  ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
3257  if(!ifilename){
3258  ifname="CommonTools/TrackerMap/data/"+filename;
3259  ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
3260  }
3261  }else {
3262  ifname="CommonTools/TrackerMap/data/"+filename;
3263  ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),std::ios::in);
3264  }
3265  if(!ifilename)std::cout << "File " << filename << " missing" << std::endl;
3266  return ifilename;
3267  }
3268 void TrackerMap::printlayers(bool print_total, float minval, float maxval, std::string outputfilename){
3269  std::ofstream * xmlfile;
3270 saveAsSingleLayer=true;
3271 if(!print_total){
3272  for (int layer=1; layer < 44; layer++){
3273  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
3274  for (int module=1;module<200;module++) {
3275  int key=layer*100000+ring*1000+module;
3276  TmModule * mod = smoduleMap[key];
3277  if(mod !=0 && !mod->notInUse()){
3278  mod->value = mod->value / mod->count;
3279  }
3280  }
3281  }
3282  }
3283  }
3284  if(minvalue>=maxvalue){
3285  minvalue=9999999.;
3286  maxvalue=-9999999.;
3287  for (int layer=1; layer < 44; layer++){
3288  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
3289  for (int module=1;module<200;module++) {
3290  int key=layer*100000+ring*1000+module;
3291  TmModule * mod = smoduleMap[key];
3292  if(mod !=0 && !mod->notInUse()){
3293  if (minvalue > mod->value)minvalue=mod->value;
3294  if (maxvalue < mod->value)maxvalue=mod->value;
3295  }
3296  }
3297  }
3298  }
3299  }
3300 for (int layer=1; layer < 44; layer++){
3301  std::ostringstream outs;
3302  outs << outputfilename <<"layer"<<layer<< ".xml";
3303  xmlfile = new std::ofstream(outs.str().c_str(),std::ios::out);
3304  *xmlfile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<std::endl;
3305  *xmlfile << "<svg xmlns=\"http://www.w3.org/2000/svg\""<<std::endl;
3306  *xmlfile << "xmlns:svg=\"http://www.w3.org/2000/svg\""<<std::endl;
3307  *xmlfile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >"<<std::endl;
3308  *xmlfile << "<script type=\"text/ecmascript\" xlink:href=\"layer.js\" />"<<std::endl;
3309  *xmlfile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerLayer.init()\">"<<std::endl;
3310  if(layer<31)*xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,1.)\" > "<<std::endl;
3311  else *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,0.8)\" > "<<std::endl;
3312  *xmlfile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<std::endl;
3313  *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;
3314  *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;
3315  *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;
3316  *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;
3317  *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;
3318 
3319  nlay=layer;
3320  defwindow(nlay);
3321  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
3322  for (int module=1;module<200;module++) {
3323  int key=layer*100000+ring*1000+module;
3324  TmModule * mod = smoduleMap[key];
3325  if(mod !=0 && !mod->notInUse()){
3326  drawModule(mod,key,layer,print_total,xmlfile);
3327  }
3328  }
3329  }
3330  *xmlfile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\">" << std::endl;
3331  *xmlfile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
3332  *xmlfile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
3333  *xmlfile << "<tspan id=\"line3\" x=\"40\" y=\"90\"> </tspan> " << std::endl;
3334  *xmlfile << "<tspan id=\"line4\" x=\"40\" y=\"120\"> </tspan> " << std::endl;
3335  if(layer > 33){
3336  *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;
3337  *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;
3338  *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;
3339  *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;
3340  *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;
3341  }
3342  else{
3343  *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;
3344  *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;
3345  *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;
3346  *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;
3347  *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;
3348  }
3349  *xmlfile << " </text> </svg>" << std::endl;
3350  xmlfile->close();delete xmlfile;
3351  }
3352 saveAsSingleLayer=false;
3353 }
TmModule * mod
Definition: TmApvPair.h:16
void drawHV3(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:1129
void reset()
Definition: TrackerMap.cc:390
dbl * delta
Definition: mlp_gen.cc:36
void fill_hv_channel2(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:2431
std::string text
Definition: TmApvPair.h:12
T getUntrackedParameter(std::string const &, T const &) const
int getPsuBranch()
Definition: TmPsu.h:14
int i
Definition: DBlmapReader.cc:9
void build()
Definition: TrackerMap.cc:2580
float minvalue
Definition: TrackerMap.h:442
TrackerMap(std::string s=" ", int xsize1=340, int ysize1=200)
Definition: TrackerMap.cc:379
ModApvPair apvModuleMap
Definition: TrackerMap.h:89
double ydpixelc(double y)
Definition: TrackerMap.h:200
std::ifstream * findfile(std::string filename)
Definition: TrackerMap.cc:3251
int nfeccrates
Definition: TrackerMap.h:430
int redHV2
Definition: TmPsu.h:21
void fillc_all_blank()
Definition: TrackerMap.cc:2504
double ydpixelfec(double y)
Definition: TrackerMap.h:214
int getmoduleCount(int subdet, int partdet, int layer, int ring)
Definition: TrackerMap.h:349
float value
Definition: TmModule.h:12
MapCcu ccuMap
Definition: TrackerMap.h:93
int green
Definition: TmApvPair.h:10
int mpos
Definition: TmApvPair.h:17
std::string cmodid_HV2
Definition: TmPsu.h:33
void save_as_psutrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="psu_svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:1700
int nmodHV3
Definition: TmPsu.h:31
void fillc_hv_channel2(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:2403
SmoduleMap smoduleMap
Definition: TrackerMap.h:83
std::ifstream * inputfile
Definition: TrackerMap.h:439
std::ofstream * savefile
Definition: TrackerMap.h:437
void setUsed()
Definition: TmModule.h:25
bool psetAvailable
Definition: TrackerMap.h:111
int count
Definition: TmPsu.h:26
int idex
Definition: TmPsu.h:11
~TrackerMap()
default destructor
Definition: TrackerMap.cc:448
std::string cmodid
Definition: TmCcu.h:16
static const uint32_t invalid32_
Definition: Constants.h:16
int countHV2
Definition: TmPsu.h:27
void drawPsu(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:996
int module(int fedId, int fedCh)
Definition: TrackerMap.cc:2460
bool enableFecProcessing
Definition: TrackerMap.h:103
int layer
Definition: TmCcu.h:17
void defwindow(int num_lay)
Definition: TrackerMap.h:273
int idModule
Definition: TmModule.h:26
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void save_as_HVtrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="psu_svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:1435
float posz
Definition: TmModule.h:9
int getCcuRing()
Definition: TmCcu.h:21
double xdpixelc(double x)
Definition: TrackerMap.h:194
void defpsuwindow(int num_rack)
Definition: TrackerMap.h:256
bool addPixelFlag
Definition: TrackerMap.h:450
int number_modules
Definition: TrackerMap.h:443
std::string infilename
Definition: TrackerMap.h:109
int getlayerCount(int subdet, int partdet)
Definition: TrackerMap.h:152
bool exists(std::string const &parameterName) const
checks if a parameter exists
int npsuracks
Definition: TrackerMap.h:431
void fill_current_val_fed_channel(int fedId, int fedCh, float current_val)
Definition: TrackerMap.cc:2337
const std::vector< SiStripFecCrate > & crates() const
float value
Definition: TmPsu.h:23
tuple txtfile
Delete all three files at once to make sure the user never sees stale data (e.g.
int getPsuBoard()
Definition: TmPsu.h:17
int red
Definition: TmPsu.h:20
int greenHV3
Definition: TmPsu.h:22
bool enableFedProcessing
Definition: TrackerMap.h:102
#define min(a, b)
Definition: mlp_lapack.h:161
int layer
Definition: TmModule.h:28
ImoduleMap imoduleMap
Definition: TrackerMap.h:85
int count
Definition: TmCcu.h:12
int firstRing[43]
Definition: TrackerMap.h:423
float gminvalue
Definition: TrackerMap.h:441
int nmod
Definition: TmCcu.h:15
void fillc_fec_channel(int crate, int slot, int ring, int addr, int red, int green, int blue)
Definition: TrackerMap.cc:2348
tuple xmlfile
Make an XML representation of the misalignment.
float posx
Definition: TmModule.h:9
std::string jsPath
Definition: TrackerMap.h:110
bool enableHVProcessing
Definition: TrackerMap.h:105
double xdpixelfec(double x)
Definition: TrackerMap.h:208
bool posrel
Definition: TrackerMap.h:434
int getFedId()
Definition: TmApvPair.h:19
int getPsuDcs()
Definition: TmPsu.h:13
int getCcuSlot()
Definition: TmCcu.h:20
int red
Definition: TmApvPair.h:10
double phival(double x, double y)
Definition: TrackerMap.h:112
void fill_all_blank()
Definition: TrackerMap.cc:2512
void fillc_lv_channel(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:2376
unsigned int idex
Definition: TmModule.h:29
vector< Color_t > colors
int getringCount(int subdet, int partdet, int layer)
Definition: TrackerMap.h:316
int np
Definition: AMPTWrapper.h:33
double xdpixelpsu(double x)
Definition: TrackerMap.h:222
int nmod
Definition: TmPsu.h:29
const T & max(const T &a, const T &b)
int nchan
Definition: TauolaWrapper.h:80
std::string text
Definition: TmModule.h:14
float posy
Definition: TmModule.h:9
std::string PsuId
Definition: TmModule.h:18
T sqrt(T t)
Definition: SSEVec.h:46
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:632
void drawHV2(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:1062
bool saveAsSingleLayer
Definition: TrackerMap.h:449
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int blueHV3
Definition: TmPsu.h:22
void deffecwindow(int num_crate)
Definition: TrackerMap.h:247
int j
Definition: DBlmapReader.cc:9
bool temporary_file
Definition: TrackerMap.h:444
void drawPalette(std::ofstream *file)
Definition: TrackerMap.cc:2277
std::ofstream * svgfile
Definition: TrackerMap.h:436
void load(std::string s="tmap.svg")
Definition: TrackerMap.cc:2175
int greenHV2
Definition: TmPsu.h:21
list mod
Load physics model.
int getCcuCrate()
Definition: TmCcu.h:19
int green
Definition: TmCcu.h:9
int getPsuRack()
Definition: TmPsu.h:15
int nmodHV2
Definition: TmPsu.h:30
double ydpixel(double y)
Definition: TrackerMap.h:180
void drawModule(TmModule *mod, int key, int layer, bool total, std::ofstream *file)
Definition: TrackerMap.cc:495
int green
Definition: TmPsu.h:20
int blue
Definition: TmApvPair.h:10
void drawApvPair(int crate, int numfed_incrate, bool total, TmApvPair *apvPair, std::ofstream *file, bool useApvPairValue)
Definition: TrackerMap.cc:847
void init()
Definition: TrackerMap.cc:398
void fillc_fed_channel(int fedId, int fedCh, int red, int green, int blue)
Definition: TrackerMap.cc:2310
int getcolor(float value, int palette)
Definition: TrackerMap.cc:2623
int count
Definition: TmModule.h:13
float width
Definition: TmModule.h:10
std::string psId
Definition: TmPsu.h:12
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:48
void printlayers(bool print_total=true, float minval=0., float maxval=0., std::string s="layer")
Definition: TrackerMap.cc:3268
int psuIdex
Definition: TmModule.h:19
int k[5][pyjets_maxn]
tuple out
Definition: dbtoconf.py:99
int mpos
Definition: TmCcu.h:18
int redHV3
Definition: TmPsu.h:22
std::string capvids
Definition: TmModule.h:16
void drawCcu(int crate, int numfed_incrate, bool total, TmCcu *ccu, std::ofstream *file, bool useCcuValue)
Definition: TrackerMap.cc:931
short int HVchannel
Definition: TmModule.h:20
float widthAtHalfLength
Definition: TmModule.h:10
int getKey()
Definition: TmModule.h:23
#define M_PI
Definition: BFit3D.cc:3
int green
Definition: TmModule.h:11
int CcuId
Definition: TmModule.h:17
int count
Definition: TmApvPair.h:13
SvgFed fedMap
Definition: TrackerMap.h:91
PsuModule psuModuleMap
Definition: TrackerMap.h:99
float value
Definition: TmCcu.h:10
std::string cmodid_HV3
Definition: TmPsu.h:34
void fill_hv_channel3(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:2443
float thickness
Definition: TmModule.h:10
float valueHV2
Definition: TmPsu.h:25
tuple branchinfo
Definition: dataDML.py:2346
bool printflag
Definition: TrackerMap.h:101
static const uint16_t invalid_
Definition: Constants.h:17
int crate
Definition: TmApvPair.h:15
FecModule fecModuleMap
Definition: TrackerMap.h:95
bool notInUse()
Definition: TmModule.h:24
int red
Definition: TmModule.h:11
int blue
Definition: TmModule.h:11
std::string title
Definition: TrackerMap.h:108
double xdpixel(double x)
Definition: TrackerMap.h:174
int idex
Definition: TmCcu.h:13
void printonline()
Definition: TrackerMap.cc:2644
int nlayer(int det, int part, int lay)
Definition: TrackerMap.h:393
list key
Definition: combine.py:13
std::string textHV3
Definition: TmPsu.h:37
int red
Definition: TmCcu.h:9
list infile
Definition: EdgesToViz.py:90
SvgApvPair apvMap
Definition: TrackerMap.h:87
void print(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2210
tuple filename
Definition: lut2db_cfg.py:20
std::string text
Definition: TmPsu.h:35
void save_as_fedtrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="fed_svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:1950
int countHV3
Definition: TmPsu.h:28
void fill_fec_channel(int crate, int slot, int ring, int addr, float qty)
Definition: TrackerMap.cc:2361
float gmaxvalue
Definition: TrackerMap.h:441
int idex
Definition: TmApvPair.h:14
void fill_current_val(int idmod, float current_val)
Definition: TrackerMap.cc:2522
float maxvalue
Definition: TrackerMap.h:442
tuple cout
Definition: gather_cfg.py:121
std::string cmodid_LV
Definition: TmPsu.h:32
float valueHV3
Definition: TmPsu.h:24
void setText(int idmod, std::string s)
Definition: TrackerMap.cc:2560
int blue
Definition: TmCcu.h:9
bool enableLVProcessing
Definition: TrackerMap.h:104
bool firstcall
Definition: TrackerMap.h:435
std::string textHV2
Definition: TmPsu.h:36
int blue
Definition: TmPsu.h:20
x
Definition: VDTMath.h:216
MapPsu psuMap
Definition: TrackerMap.h:97
static bool isRingStereo(int key)
Definition: TrackerMap.h:384
Definition: TmCcu.h:5
int blueHV2
Definition: TmPsu.h:21
void defcwindow(int num_crate)
Definition: TrackerMap.h:237
std::ifstream * jsfile
Definition: TrackerMap.h:438
int ring
Definition: TmModule.h:27
std::string text
Definition: TmCcu.h:11
Definition: TmPsu.h:6
float length
Definition: TmModule.h:10
Definition: vlib.h:209
void fill_lv_channel(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:2390
std::vector< TColor * > vc
Definition: TrackerMap.h:80
float value
Definition: TmApvPair.h:11
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2549
double ydpixelpsu(double y)
Definition: TrackerMap.h:228
void save_as_fectrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="fec_svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:1194
std::string name
Definition: TmModule.h:15
void printall(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2945
void fill_fed_channel(int fedId, int fedCh, float qty)
Definition: TrackerMap.cc:2470
int getFedCh()
Definition: TmApvPair.h:18
void fillc_hv_channel3(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:2416
int ntotRing[43]
Definition: TrackerMap.h:422
int getPsuCrate()
Definition: TmPsu.h:16
Definition: DDAxes.h:10
std::string jsfilename
Definition: TrackerMap.h:109