CMS 3D CMS Logo

TrackerMap.cc
Go to the documentation of this file.
12 #include <fstream>
13 #include <vector>
14 #include <iostream>
15 #include <sstream>
16 #include "TCanvas.h"
17 #include "TPolyLine.h"
18 #include "TStyle.h"
19 #include "TColor.h"
20 #include "TROOT.h"
21 #include "TGaxis.h"
22 #include "TLatex.h"
23 #include "TArrow.h"
24 #include "TLegend.h"
25 #include "TH1F.h"
26 
27 /**********************************************************
28 Allocate all the modules in a map of TmModule
29 The filling of the values for each module is done later
30 when the user starts to fill it.
31 **********************************************************/
32 
34  const SiStripFedCabling *tkFed,
35  const TrackerTopology *const topology) {
36  psetAvailable = true;
37  xsize = 340;
38  ysize = 200;
39 
40  title = " ";
41  jsPath = "";
42  jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
43  infilename = "CommonTools/TrackerMap/data/tracker.dat";
44  saveAsSingleLayer = false;
45  tkMapLog = false;
46  // if(tkmapPset.exists("trackermaptxtPath")){
47  jsPath = tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath", "CommonTools/TrackerMap/data/");
48  jsfilename = jsPath + "trackermap.txt";
49  std::cout << jsfilename << std::endl;
50  infilename =
51  tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "tracker.dat";
52  std::cout << infilename << std::endl;
53  saveWebInterface = tkmapPset.getUntrackedParameter<bool>("saveWebInterface", false);
54  saveGeoTrackerMap = tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap", true);
55  ncrates = 0;
56  firstcrate = 0;
57  enableFedProcessing = tkmapPset.getUntrackedParameter<bool>("loadFedCabling", false);
58  if (tkFed == nullptr && enableFedProcessing) {
59  enableFedProcessing = false;
60  std::cout << "ERROR:fed trackermap requested but no valid fedCabling is available!!!" << std::endl;
61  }
62  nfeccrates = 0;
63  enableFecProcessing = tkmapPset.getUntrackedParameter<bool>("loadFecCabling", false);
64  if (tkFed == nullptr && enableFecProcessing) {
65  enableFecProcessing = false;
66  std::cout << "ERROR:fec trackermap requested but no valid fedCabling is available!!!" << std::endl;
67  }
68  // std::cout << "loadFecCabling " << enableFecProcessing << std::endl;
69  npsuracks = 0;
70  enableLVProcessing = tkmapPset.getUntrackedParameter<bool>("loadLVCabling", false);
71  // std::cout << "loadLVCabling " << enableLVProcessing << std::endl;
72  enableHVProcessing = tkmapPset.getUntrackedParameter<bool>("loadHVCabling", false);
73  // std::cout << "loadHVCabling " << enableHVProcessing << std::endl;
74  tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale", false);
75  // } else std::cout << "no parameters found" << std::endl;
76 
77  init();
78  // Now load fed cabling information
79  if (enableFedProcessing) {
80  auto feds = tkFed->fedIds();
81  std::cout << "SiStripFedCabling has " << feds.size() << " active FEDS" << std::endl;
82  // int num_board=0;
83  // int num_crate=0;
84  for (std::vector<unsigned short>::const_iterator ifed = feds.begin(); ifed < feds.end(); ifed++) {
85  auto theconn = tkFed->fedConnections(*ifed);
86  int num_conn = 0;
87  for (auto iconn = theconn.begin(); iconn < theconn.end(); iconn++) {
88  if (iconn->fedId() == sistrip::invalid_ || iconn->detId() == sistrip::invalid_ ||
89  iconn->detId() == sistrip::invalid32_ || iconn->apvPairNumber() == sistrip::invalid_ ||
90  iconn->nApvPairs() == sistrip::invalid_) {
91  continue;
92  }
93 
94  TmModule *imod = imoduleMap[iconn->detId()];
95  int key = iconn->fedId() * 1000 + iconn->fedCh();
96  TmApvPair *apvpair = apvMap[key];
97  if (apvpair != nullptr)
98  std::cout << "Fed " << iconn->fedId() << " channel " << iconn->fedCh() << " seem to be already loaded!"
99  << std::endl;
100  else {
101  num_conn++;
102  if (num_conn == 1) {
103  // if(fedMap[iconn->fedId()]==0){num_crate=num_board/18+1;fedMap[iconn->fedId()]=num_crate;num_board++;}
104  if (fedMap[iconn->fedId()] == 0) {
105  fedMap[iconn->fedId()] = iconn->fedCrate();
106  }
107  if (slotMap[iconn->fedId()] == 0) {
108  slotMap[iconn->fedId()] = iconn->fedSlot();
109  }
110  if (ncrates == 0 || ncrates < iconn->fedCrate())
111  ncrates = iconn->fedCrate();
112  if (firstcrate == 0 || firstcrate > iconn->fedCrate())
113  firstcrate = iconn->fedCrate();
114  }
115 
116  // apvpair = new TmApvPair(key,num_crate);
117  apvpair = new TmApvPair(key, iconn->fedCrate());
118  apvpair->mod = imod;
119  apvpair->mpos = iconn->apvPairNumber();
120  apvMap[key] = apvpair;
121  apvModuleMap.insert(std::make_pair(iconn->detId(), apvpair));
122  std::stringstream s;
123  iconn->print(s);
124  apvpair->text = s.str();
125  }
126  }
127  }
128  // ncrates=num_crate;
129  std::cout << "from " << firstcrate << " to " << ncrates << " crates used " << std::endl;
130  //Now add APv information to module name
131  std::map<int, TmModule *>::iterator i_mod;
132  for (i_mod = imoduleMap.begin(); i_mod != imoduleMap.end(); i_mod++) {
133  TmModule *mod = i_mod->second;
134  if (mod != nullptr) {
135  std::ostringstream outs, outs1;
136  outs << " connected to ";
137  outs1 << "(";
138 
139  int idmod = mod->idex;
140  int nchan = 0;
141  std::multimap<const int, TmApvPair *>::iterator pos;
142  for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
143  TmApvPair *apvpair = pos->second;
144  if (apvpair != nullptr) {
145  outs << apvpair->mpos << " " << apvpair->getFedId() << "/" << apvpair->getFedCh() << " ";
146  outs1 << apvpair->idex + apvpair->crate * 1000000 << ",";
147  nchan++;
148  }
149  }
150  outs << "(" << nchan << ")";
151  mod->name = mod->name + outs.str();
152  std::string s = outs1.str();
153  s.erase(s.end() - 1, s.end());
154  mod->capvids = s + ")";
155  }
156  }
157  }
158  // Now load fec cabling information
159  if (enableFecProcessing) {
160  int nfec = 0;
161  int nccu;
162  int nmod;
163  int crate, slot, ring, addr, pos;
164  SiStripFecCabling *fecCabling_;
165  fecCabling_ = new SiStripFecCabling(*tkFed);
166  std::string Ccufilename = tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "") + "cculist.txt";
167  std::ifstream Ccufile(edm::FileInPath(Ccufilename).fullPath().c_str(), std::ios::in);
168  std::string dummys;
169  while (!Ccufile.eof()) {
170  Ccufile >> crate >> slot >> ring >> addr >> pos;
171  getline(Ccufile, dummys);
172  int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
173  TmCcu *ccu = ccuMap[key];
174  if (ccu == nullptr) {
175  ccu = new TmCcu(crate, slot, ring, addr);
176  ccu->mpos = pos, ccuMap[key] = ccu;
177  }
178  }
179 
180  for (std::vector<SiStripFecCrate>::const_iterator icrate = fecCabling_->crates().begin();
181  icrate != fecCabling_->crates().end();
182  icrate++) {
183  for (std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end();
184  ifec++) {
185  for (std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end();
186  iring++) {
187  nccu = 0;
188  nfec++;
189  for (std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end();
190  iccu++) {
191  nccu++;
192  nmod = 0;
193  int key =
194  icrate->fecCrate() * 10000000 + ifec->fecSlot() * 100000 + iring->fecRing() * 1000 + iccu->ccuAddr();
195  int layer = 0;
196  TmCcu *ccu = ccuMap[key];
197  for (std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin();
198  imod != iccu->modules().end();
199  imod++) {
200  nmod++;
201  TmModule *imod1 = imoduleMap[imod->detId()];
202  layer = imod1->layer;
203  fecModuleMap.insert(std::make_pair(ccu, imod1));
204  if (imod1 != nullptr)
205  imod1->CcuId = key; //imod1->ccuId=key+Crate*1000000
206  }
207  if (ccu == nullptr)
208  std::cout << key << " This ccu seems to have not been stored! " << std::endl;
209  else {
210  ccu->nmod = nmod;
211  ccu->layer = layer;
212  }
213  //std::cout <<nfec<<" "<< nccu << " " << nmod << std::endl;
214  }
215  }
216  }
217  }
218 
219  std::map<int, TmCcu *>::iterator i_ccu;
220  std::multimap<TmCcu *, TmModule *>::iterator it;
221  std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
222  nccu = 0;
223  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
224  TmCcu *ccu = i_ccu->second;
225  nccu++;
226  if (ccu != nullptr) {
227  std::ostringstream outs;
228  std::ostringstream outs1;
229  outs << "CCU " << ccu->idex << " connected to fec,ring " << ccu->getCcuSlot() << "," << ccu->getCcuRing()
230  << " in crate " << ccu->getCcuCrate() << " at position " << ccu->mpos << " with " << ccu->nmod
231  << " modules: ";
232  outs1 << "(";
233  ret = fecModuleMap.equal_range(ccu);
234  for (it = ret.first; it != ret.second; ++it) {
235  outs << (*it).second->idex << " ";
236  outs1 << (*it).second->getKey() << ",";
237  }
238  outs1 << ")";
239  ccu->text = outs.str();
240  ccu->cmodid = outs1.str();
241  //std::cout << ccu->text << std::endl;
242  }
243  }
244  nfeccrates = 4;
245  std::cout << nccu << " ccu stored in " << nfeccrates << " crates" << std::endl;
246 
247  delete fecCabling_;
248  }
249  //load Psu cabling info
250  //load Psu cabling info
252  SiStripDetCabling *detCabling = nullptr;
254  detCabling = new SiStripDetCabling(*tkFed, topology);
255 
256  int npsu = 0;
257  int nmod, nmodHV2, nmodHV3;
258  int modId1, dcuId; // ,modId2;
259  int dcs, branch, crate, board;
260  int rack = 0;
261  std::string channelstr1;
262  short int channel;
263  std::string psinfo;
264  std::string psIdinfo;
265  int rack_order[54] = {0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 6, 0, 7, 8, 0, 9, 10, 0,
266  11, 12, 0, 13, 14, 0, 15, 0, 0, 0, 0, 0, 0, 16, 0, 17, 18, 0,
267  19, 20, 0, 21, 0, 22, 0, 23, 0, 24, 25, 0, 26, 27, 0, 28, 0, 29};
268  // std::ifstream *LVfile;
269  // std::ifstream *HVfile;
270 
271  std::string LVfilename =
272  tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "psdcumap.dat";
273  //std::string HVfilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"hvmap.dat";
274 
275  std::ifstream LVfile(edm::FileInPath(LVfilename).fullPath().c_str(), std::ios::in);
276 
277  std::cout << LVfilename << std::endl;
278 
279  /*
280  if(enableHVProcessing){
281  std::ifstream HVfile(edm::FileInPath(HVfilename).fullPath().c_str(),std::ios::in);
282  while(!HVfile.eof()) {
283  HVfile >> modId2 >> channelstr1;
284  std::string channelstr2 = channelstr1.substr(9,1);
285  channel= atoi(channelstr2.c_str());
286  TmModule *imod = imoduleMap[modId2];
287  // if(modId1==modId2){
288  imod->HVchannel=channel;
289 
290  }
291 
292  }
293 */
294 
295  while (!LVfile.eof()) {
296  LVfile >> modId1 >> dcuId >> psIdinfo >> psinfo;
297 
298  if (detCabling && detCabling->getConnections(modId1).empty())
299  continue;
300 
301  // int length=psinfo.length();
302  std::string dcsinfo = psinfo.substr(39, 1);
303  std::string branchinfo = psinfo.substr(57, 2);
304  std::string crateinfo = psinfo.substr(69, 1);
305  std::string boardinfo = psinfo.substr(80, 2);
306  std::string channelinfo = psinfo.substr(90, 3);
307 
308  dcs = atoi(dcsinfo.c_str());
309  branch = atoi(branchinfo.c_str());
310  crate = atoi(crateinfo.c_str()) + 1;
311  board = atoi(boardinfo.c_str()) + 1;
312  rack = (branch + 1) + (dcs - 1) * 6;
313  rack = rack_order[rack];
314  channel = atoi(channelinfo.c_str());
315  // std::cout << dcs << " " << branch<< " " <<crate<< " " << board<<" " << rack << std::endl;
316  int key = rack * 1000 + crate * 100 + board;
317 
318  TmPsu *psu = psuMap[key];
319  TmModule *imod = imoduleMap[modId1];
320  if (psu == nullptr) {
321  psu = new TmPsu(dcs, branch, rack, crate, board);
322  psuMap[key] = psu;
323  psu->psId = psIdinfo;
324  }
325 
326  psuModuleMap.insert(std::make_pair(psu, imod));
327  if (imod != nullptr) {
328  imod->PsuId = psIdinfo;
329  imod->psuIdex = psu->idex;
330  imod->HVchannel = channel;
331  }
332  }
333 
334  // int nmax=0;
335  std::map<int, TmPsu *>::iterator ipsu;
336  std::multimap<TmPsu *, TmModule *>::iterator it;
337  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
338  npsu = 0;
339 
340  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
341  TmPsu *psu = ipsu->second;
342  npsu++;
343 
344  if (psu != nullptr) {
345  std::ostringstream outs;
346  std::ostringstream outs1;
347 
348  std::ostringstream outs3;
349  std::ostringstream outs4;
350 
351  std::ostringstream outs5;
352  std::ostringstream outs6;
353 
354  outs << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
355  << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "), crate " << psu->getPsuCrate()
356  << " in position " << psu->getPsuBoard() << " with modules: ";
357  outs1 << "(";
358 
359  if (enableHVProcessing) {
360  outs3 << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
361  << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "),crate " << psu->getPsuCrate()
362  << " in position " << psu->getPsuBoard() << " and HV channel 002 with modules: ";
363  outs4 << "(";
364 
365  outs5 << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
366  << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "), crate " << psu->getPsuCrate()
367  << " in position " << psu->getPsuBoard() << " and HV channel 002 with modules: ";
368  outs6 << "(";
369  }
370 
371  ret = psuModuleMap.equal_range(psu);
372  nmod = 0;
373  nmodHV2 = 0;
374  nmodHV3 = 0;
375  for (it = ret.first; it != ret.second; ++it) {
376  nmod++;
377  outs << (*it).second->idex << ", ";
378  outs1 << (*it).second->getKey() << ",";
379 
380  if (enableHVProcessing) {
381  if ((*it).second->HVchannel == 2) {
382  nmodHV2++;
383  outs3 << (*it).second->idex << ", ";
384  outs4 << (*it).second->getKey() << ",";
385  } else if ((*it).second->HVchannel == 3) {
386  nmodHV3++;
387  outs5 << (*it).second->idex << ", ";
388  outs6 << (*it).second->getKey() << ",";
389  }
390  }
391  }
392 
393  outs1 << ")";
394  psu->nmod = nmod;
395  outs << "(" << psu->nmod << ")";
396  psu->text = outs.str();
397  psu->cmodid_LV = outs1.str();
398  if (enableHVProcessing) {
399  outs4 << ")";
400  outs6 << ")";
401  psu->nmodHV2 = nmodHV2;
402  psu->nmodHV3 = nmodHV3;
403  outs3 << "(" << psu->nmodHV2 << ")";
404  outs5 << "(" << psu->nmodHV3 << ")";
405  psu->textHV2 = outs3.str();
406  psu->textHV3 = outs5.str();
407  psu->cmodid_HV2 = outs4.str();
408  psu->cmodid_HV3 = outs6.str();
409  }
410  }
411  }
412 
413  npsuracks = 29;
414  std::cout << npsu << " psu stored in " << npsuracks << " racks" << std::endl;
415  }
416 }
417 
419  psetAvailable = true;
420  xsize = 340;
421  ysize = 200;
422  title = " ";
423  jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
424  infilename = "CommonTools/TrackerMap/data/tracker.dat";
425  enableFedProcessing = true;
426  ncrates = 0;
427  firstcrate = 0;
428  saveAsSingleLayer = false;
429  tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale", false);
430  saveWebInterface = tkmapPset.getUntrackedParameter<bool>("saveWebInterface", false);
431  saveGeoTrackerMap = tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap", true);
432  // if(tkmapPset.exists("trackermaptxtPath")){
433  jsfilename = tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath", "CommonTools/TrackerMap/data/") +
434  "trackermap.txt";
435  std::cout << jsfilename << std::endl;
436  infilename =
437  tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "tracker.dat";
438  std::cout << infilename << std::endl;
439  // } else std::cout << "no parameters found" << std::endl;
440  init();
441 }
442 
443 TrackerMap::TrackerMap(std::string s, int xsize1, int ysize1) {
444  psetAvailable = false;
445  xsize = xsize1;
446  ysize = ysize1;
447  title = s;
448  jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
449  infilename = "CommonTools/TrackerMap/data/tracker.dat";
450  saveWebInterface = false;
451  saveGeoTrackerMap = true;
452  tkMapLog = false;
453  jsPath = "CommonTools/TrackerMap/data/";
454  enableFedProcessing = false;
455  enableFecProcessing = false;
456  enableLVProcessing = false;
457  enableHVProcessing = false;
458  saveAsSingleLayer = false;
459  init();
460 }
461 
463  std::map<int, TmModule *>::iterator i_mod;
464  for (i_mod = imoduleMap.begin(); i_mod != imoduleMap.end(); i_mod++) {
465  TmModule *mod = i_mod->second;
466  mod->count = 0;
467  mod->value = 0;
468  mod->red = -1;
469  }
470 }
471 
473  int ntotmod = 0;
474  ix = 0;
475  iy = 0; //used to compute the place of each layer in the tracker map
476  firstcall = true;
477  minvalue = 0.;
478  maxvalue = minvalue;
479  posrel = true;
480  palette = 1;
481  printflag = true;
482  addPixelFlag = false;
483  onlyPixelFlag = false;
484  temporary_file = false;
485  gminvalue = 0.;
486  gmaxvalue = 0.; //default global range for online rendering
487 
488  ndet = 3; // number of detectors: pixel, inner silicon, outer silicon
489  npart = 3; // number of detector parts: endcap -z, barrel, endcap +z
490 
491  //allocate module map
492  for (int subdet = 1; subdet < ndet + 1; subdet++) { //loop on subdetectors
493  for (int detpart = 1; detpart < npart + 1; detpart++) { //loop on subdetectors parts
494  int nlayers = getlayerCount(subdet, detpart); // compute number of layers
495  for (int layer = 1; layer < nlayers + 1; layer++) { //loop on layers
496  int nrings = getringCount(subdet, detpart, layer); // compute number of rings
497  //fill arrays used to do the loop on the rings
498  int layer_g = nlayer(subdet, detpart, layer);
499  ntotRing[layer_g - 1] = nrings;
500  firstRing[layer_g - 1] = 1;
501  if (subdet == 3 && detpart != 2)
502  firstRing[layer_g - 1] = 8 - nrings; //special numbering for TEC
503  for (int ring = firstRing[layer_g - 1]; ring < ntotRing[layer_g - 1] + firstRing[layer_g - 1];
504  ring++) { //loop on rings
505  int nmodules = getmoduleCount(subdet, detpart, layer, ring); // compute number of modules
506  int key = 0;
507  TmModule *smodule;
508  for (int module = 1; module < nmodules + 1; module++) { //loop on modules
509  smodule = new TmModule(module, ring, layer_g);
510  key = layer_g * 100000 + ring * 1000 + module; //key identifying module
511  smoduleMap[key] = smodule;
512  ntotmod++;
513  }
514  if (isRingStereo(key))
515  for (int module = 1; module < nmodules + 1; module++) { //loop on stereo modules
516  smodule = new TmModule(module + 100, ring, layer_g);
517  int key = layer_g * 100000 + ring * 1000 + module + 100;
518  smoduleMap[key] = smodule;
519  ntotmod++;
520  }
521  }
522  }
523  }
524  }
525  build();
526 }
527 
529  for (int layer = 1; layer < 44; layer++) {
530  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
531  for (int module = 1; module < 200; module++) {
532  int key = layer * 100000 + ring * 1000 + module;
534  if (mod != nullptr)
535  delete mod;
536  }
537  }
538  }
539 
540  //std::map<int , TmModule *>::iterator i_mod;
541  // for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
542  // TmModule * mod= i_mod->second;
543  // delete mod;
544  // }
545  std::map<int, TmApvPair *>::iterator i_apv;
546  for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
547  TmApvPair *apvPair = i_apv->second;
548  delete apvPair;
549  }
550 
551  std::map<int, TmCcu *>::iterator i_ccu;
552  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
553  TmCcu *ccu = i_ccu->second;
554  delete ccu;
555  }
556 
557  std::map<int, TmPsu *>::iterator ipsu;
558  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
559  TmPsu *psu = ipsu->second;
560  delete psu;
561  }
562 
563  gROOT->Reset();
564 
565  //for(std::vector<TColor*>::iterator col1=vc.begin();col1!=vc.end();col1++){
566  // std::cout<<(*col1)<<std::endl;}
567 }
568 
569 void TrackerMap::drawModule(TmModule *mod, int key, int mlay, bool print_total, std::ofstream *svgfile) {
570  //int x,y;
571  nlay = mlay;
572  double phi, r, dx, dy, dy1;
573  double xp[4], yp[4], xp1, yp1;
574  double vhbot, vhtop, vhapo;
575  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};
576  double xt1, yt1, xs1 = 0., ys1 = 0., xt2, yt2, xs2, ys2, pv1, pv2;
577  int green = 0;
578  int red = 0;
579  int blue = 0;
580  double xd[4], yd[4];
581  int np = 4;
582  //int numrec=0;
583  int numod = 0;
584  phi = phival(mod->posx, mod->posy);
585  r = sqrt(mod->posx * mod->posx + mod->posy * mod->posy);
586  vhtop = mod->width;
587  vhapo = mod->length;
588  if (mlay < 31) { //endcap
589  vhbot = mod->widthAtHalfLength / 2. - (mod->width / 2. - mod->widthAtHalfLength / 2.);
590  vhtop = mod->width / 2.;
591  vhapo = mod->length / 2.;
592  if (mlay > 12 && mlay < 19) {
593  if (posrel)
594  r = r + r;
595  xp[0] = r - vhtop;
596  yp[0] = -vhapo;
597  xp[1] = r + vhtop;
598  yp[1] = -vhapo;
599  xp[2] = r + vhtop;
600  yp[2] = vhapo;
601  xp[3] = r - vhtop;
602  yp[3] = vhapo;
603  } else {
604  if (posrel)
605  r = r + r / 3.;
606  xp[0] = r - vhapo;
607  yp[0] = -vhbot;
608  xp[1] = r + vhapo;
609  yp[1] = -vhtop;
610  xp[2] = r + vhapo;
611  yp[2] = vhtop;
612  xp[3] = r - vhapo;
613  yp[3] = vhbot;
614  }
615  for (int j = 0; j < 4; j++) {
616  xp1 = xp[j] * cos(phi) - yp[j] * sin(phi);
617  yp1 = xp[j] * sin(phi) + yp[j] * cos(phi);
618  xp[j] = xp1;
619  yp[j] = yp1;
620  }
621  } else { //barrel
622  numod = mod->idModule;
623  if (numod > 100)
624  numod = numod - 100;
625  int vane = mod->ring;
626  if (posrel) {
627  dx = vhapo;
628  phi = M_PI;
629  xt1 = rmedio[mlay - 31];
630  yt1 = -vhtop / 2.;
631  xs1 = xt1 * cos(phi) - yt1 * sin(phi);
632  ys1 = xt1 * sin(phi) + yt1 * cos(phi);
633  xt2 = rmedio[mlay - 31];
634  yt2 = vhtop / 2.;
635  xs2 = xt2 * cos(phi) - yt2 * sin(phi);
636  ys2 = xt2 * sin(phi) + yt2 * cos(phi);
637  dy = phival(xs2, ys2) - phival(xs1, ys1);
638  dy1 = dy;
639  if (mlay == 31)
640  dy1 = 0.39;
641  if (mlay == 32)
642  dy1 = 0.23;
643  if (mlay == 33)
644  dy1 = 0.16;
645  xp[0] = vane * (dx + dx / 8.);
646  yp[0] = numod * (dy1);
647  xp[1] = vane * (dx + dx / 8.) + dx;
648  yp[1] = numod * (dy1);
649  xp[2] = vane * (dx + dx / 8.) + dx;
650  yp[2] = numod * (dy1) + dy;
651  xp[3] = vane * (dx + dx / 8.);
652  yp[3] = numod * (dy1) + dy;
653  } else {
654  xt1 = r;
655  yt1 = -vhtop / 2.;
656  xs1 = xt1 * cos(phi) - yt1 * sin(phi);
657  ys1 = xt1 * sin(phi) + yt1 * cos(phi);
658  xt2 = r;
659  yt2 = vhtop / 2.;
660  xs2 = xt2 * cos(phi) - yt2 * sin(phi);
661  ys2 = xt2 * sin(phi) + yt2 * cos(phi);
662  pv1 = phival(xs1, ys1);
663  pv2 = phival(xs2, ys2);
664  if (fabs(pv1 - pv2) > M_PI && numod == 1)
665  pv1 = pv1 - 2. * M_PI;
666  if (fabs(pv1 - pv2) > M_PI && numod != 1)
667  pv2 = pv2 + 2. * M_PI;
668  xp[0] = mod->posz - vhapo / 2.;
669  yp[0] = 4.2 * pv1;
670  xp[1] = mod->posz + vhapo / 2.;
671  yp[1] = 4.2 * pv1;
672  xp[2] = mod->posz + vhapo / 2.;
673  yp[2] = 4.2 * pv2;
674  xp[3] = mod->posz - vhapo / 2.;
675  yp[3] = 4.2 * pv2;
676  }
677  }
678  if (isRingStereo(key)) {
679  np = 3;
680  if (mod->idModule > 100) {
681  for (int j = 0; j < 3; j++) {
682  xd[j] = xdpixel(xp[j]);
683  yd[j] = ydpixel(yp[j]);
684  }
685  } else {
686  xd[0] = xdpixel(xp[2]);
687  yd[0] = ydpixel(yp[2]);
688  xd[1] = xdpixel(xp[3]);
689  yd[1] = ydpixel(yp[3]);
690  xd[2] = xdpixel(xp[0]);
691  yd[2] = ydpixel(yp[0]);
692  }
693  } else {
694  for (int j = 0; j < 4; j++) {
695  xd[j] = xdpixel(xp[j]);
696  yd[j] = ydpixel(yp[j]);
697  }
698  }
699  char buffer[20];
700  sprintf(buffer, "%X", mod->idex);
701 
702  if (mod->red < 0) { //use count to compute color
703  int color = getcolor(mod->value, palette);
704  red = (color >> 16) & 0xFF;
705  green = (color >> 8) & 0xFF;
706  blue = (color)&0xFF;
707 
708  if (!print_total)
709  mod->value = mod->value * mod->count; //restore mod->value
710 
711  if (mod->count > 0)
712  if (temporary_file)
713  *svgfile << red << " " << green << " " << blue << " ";
714  else
715  *svgfile
716  << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
717  << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
718  << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
719  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
720  << mod->text << "\" POS=\"" << mod->name << " \" fill=\"rgb(" << red << "," << green << "," << blue
721  << ")\" points=\"";
722  else if (temporary_file)
723  *svgfile << 255 << " " << 255 << " " << 255 << " ";
724  else
725  *svgfile
726  << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
727  << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
728  << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
729  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
730  << mod->text << "\" POS=\"" << mod->name << " \" fill=\"white\" points=\"";
731  if (temporary_file)
732  *svgfile << np << " ";
733  for (int k = 0; k < np; k++) {
734  if (temporary_file)
735  *svgfile << xd[k] << " " << yd[k] << " ";
736  else
737  *svgfile << xd[k] << "," << yd[k] << " ";
738  }
739  if (temporary_file)
740  *svgfile << std::endl;
741  else
742  *svgfile << "\" />" << std::endl;
743  } else { //color defined with fillc
744  if (mod->red > 255)
745  mod->red = 255;
746  if (mod->green > 255)
747  mod->green = 255;
748  if (mod->blue > 255)
749  mod->blue = 255;
750  if (temporary_file)
751  *svgfile << mod->red << " " << mod->green << " " << mod->blue << " ";
752  else
753  *svgfile
754  << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
755  << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
756  << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
757  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
758  << mod->text << "\" POS=\"" << mod->name << " \" fill=\"rgb(" << mod->red << "," << mod->green << ","
759  << mod->blue << ")\" points=\"";
760  if (temporary_file)
761  *svgfile << np << " ";
762  for (int k = 0; k < np; k++) {
763  if (temporary_file)
764  *svgfile << xd[k] << " " << yd[k] << " ";
765  else
766  *svgfile << xd[k] << "," << yd[k] << " ";
767  }
768  if (temporary_file)
769  *svgfile << std::endl;
770  else
771  *svgfile << "\" />" << std::endl;
772  }
773 }
774 void TrackerMap::setRange(float min, float max) {
775  gminvalue = min;
776  gmaxvalue = max;
777  if (tkMapLog) {
778  gminvalue = pow(10., min);
779  gmaxvalue = pow(10., max);
780  }
781 }
782 
783 std::pair<float, float> TrackerMap::getAutomaticRange() {
784  float minval, maxval;
785  minval = 9999999.;
786  maxval = -9999999.;
787  for (int layer = 1; layer < 44; layer++) {
788  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
789  for (int module = 1; module < 200; module++) {
790  int key = layer * 100000 + ring * 1000 + module;
792  if (mod != nullptr && !mod->notInUse() && mod->count > 0) {
793  if (minval > mod->value)
794  minval = mod->value;
795  if (maxval < mod->value)
796  maxval = mod->value;
797  }
798  }
799  }
800  }
801  if (tkMapLog) {
802  minval = log(minval) / log(10);
803  maxval = log(maxval) / log(10);
804  }
805  return std::make_pair(minval, maxval);
806 }
807 
808 //export tracker map
809 //print_total = true represent in color the total stored in the module
810 //print_total = false represent in color the average
811 void TrackerMap::save(bool print_total, float minval, float maxval, std::string s, int width, int height) {
812  printflag = true;
813  bool rangefound = true;
814  if (saveGeoTrackerMap) {
816  std::vector<TPolyLine *> vp;
817  TGaxis *axis = nullptr;
818  size_t found = filetype.find_last_of('.');
819  filetype = filetype.substr(found + 1);
820  found = outputfilename.find_last_of('.');
821  outputfilename = outputfilename.substr(0, found);
822  //outputfilename.erase(outputfilename.begin()+outputfilename.find("."),outputfilename.end());
823  temporary_file = true;
824  if (filetype == "svg")
825  temporary_file = false;
826  std::ostringstream outs;
827  minvalue = minval;
828  maxvalue = maxval;
829  outs << outputfilename << ".coor";
830  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
831  if (!print_total) {
832  for (int layer = 1; layer < 44; layer++) {
833  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
834  for (int module = 1; module < 200; module++) {
835  int key = layer * 100000 + ring * 1000 + module;
837  if (mod != nullptr && !mod->notInUse()) {
838  mod->value = mod->value / mod->count;
839  }
840  }
841  }
842  }
843  }
844 
845  if (minvalue >= maxvalue) {
846  minvalue = 9999999.;
847  maxvalue = -9999999.;
848  rangefound = false;
849  for (int layer = 1; layer < 44; layer++) {
850  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
851  for (int module = 1; module < 200; module++) {
852  int key = layer * 100000 + ring * 1000 + module;
854  if (mod != nullptr && !mod->notInUse() && mod->count > 0) {
855  rangefound = true;
856  if (minvalue > mod->value)
857  minvalue = mod->value;
858  if (maxvalue < mod->value)
859  maxvalue = mod->value;
860  }
861  }
862  }
863  }
864  }
865  if ((title.find("QTestAlarm") != std::string::npos) || (maxvalue == minvalue) || !rangefound)
866  printflag = false;
867  if (!temporary_file) {
868  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
869  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
870  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
871  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
872  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3100 1600"
873  << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
874  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3100\" height=\"1600\" /> "
875  << std::endl;
876  *savefile << "<svg:g id=\"tracker\" transform=\"translate(10,1500) rotate(270)\" "
877  "style=\"fill:none;stroke:black;stroke-width:0;\"> "
878  << std::endl;
879  }
880  for (int layer = 1; layer < 44; layer++) {
881  // nlay=layer;
882  defwindow(layer);
883  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
884  for (int module = 1; module < 200; module++) {
885  int key = layer * 100000 + ring * 1000 + module;
887  if (mod != nullptr && !mod->notInUse()) {
888  drawModule(mod, key, layer, print_total, savefile);
889  }
890  }
891  }
892  }
893 
894  if (!temporary_file) {
895  *savefile << "</svg:g>" << std::endl;
896  *savefile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">" << title << "</svg:text>"
897  << std::endl;
898  }
899 
900  if (printflag) {
901  if (onlyPixelFlag) {
902  drawPalette(savefile, -30);
903  } else {
905  }
906  }
907  if (!temporary_file) {
908  *savefile << "</svg:svg>" << std::endl;
909  *savefile << "</svg>" << std::endl;
910  }
911  savefile->close();
912  delete savefile;
913 
914  const char *command1;
915  std::string tempfilename = outputfilename + ".coor";
916  if (filetype == "svg") {
917  std::string command = "mv " + tempfilename + " " + outputfilename + ".svg";
918  command1 = command.c_str();
919  std::cout << "Executing " << command1 << std::endl;
920  system(command1);
921  }
922 
923  if (temporary_file) { // create root trackermap image
924  int red, green, blue, npoints, colindex, ncolor;
925  double x[4], y[4];
926  std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
927  TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
928  gPad->SetFillColor(38);
929 
930  if (addPixelFlag) {
931  gPad->Range(0, 0, 3800, 1600);
932  } else if (onlyPixelFlag) {
933  gPad->Range(-100, 0, 800, 1600);
934  } else {
935  gPad->Range(800, 0, 3800, 1600);
936  }
937 
938  //First build palette
939  ncolor = 0;
940  typedef std::map<int, int> ColorList;
941  ColorList colorList;
942  ColorList::iterator pos;
943  TColor *col, *c;
944  std::cout << "tempfilename " << tempfilename << std::endl;
945  while (!tempfile.eof()) {
946  tempfile >> red >> green >> blue >> npoints;
947  colindex = red + green * 1000 + blue * 1000000;
948  pos = colorList.find(colindex);
949  if (pos == colorList.end()) {
950  colorList[colindex] = ncolor + 100;
951  col = gROOT->GetColor(ncolor + 100);
952  if (col)
953  col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
954  else
955  c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
956  vc.push_back(c);
957  ncolor++;
958  }
959  for (int i = 0; i < npoints; i++) {
960  tempfile >> x[i] >> y[i];
961  }
962  }
963 
964  if (ncolor > 0 && ncolor < 10000) {
965  Int_t colors[10000];
966  for (int i = 0; i < ncolor; i++) {
967  colors[i] = i + 100;
968  }
969  gStyle->SetPalette(ncolor, colors);
970  }
971 
972  tempfile.clear();
973  tempfile.seekg(0, std::ios::beg);
974  std::cout << "created palette with " << ncolor << " colors" << std::endl;
975 
976  while (!tempfile.eof()) { //create polylines
977  tempfile >> red >> green >> blue >> npoints;
978  for (int i = 0; i < npoints; i++) {
979  tempfile >> x[i] >> y[i];
980  }
981  colindex = red + green * 1000 + blue * 1000000;
982  pos = colorList.find(colindex);
983  if (pos != colorList.end()) {
984  TPolyLine *pline = new TPolyLine(npoints, y, x);
985  vp.push_back(pline);
986  pline->SetFillColor(colorList[colindex]);
987  pline->SetLineWidth(0);
988  pline->Draw("f");
989  }
990  }
991  if (printflag) {
992  float lminvalue = minvalue;
993  float lmaxvalue = maxvalue;
994  if (tkMapLog) {
995  lminvalue = log(minvalue) / log(10);
996  lmaxvalue = log(maxvalue) / log(10);
997  }
998  if (onlyPixelFlag) {
999  axis = new TGaxis(-30, 36, -30, 1530, lminvalue, lmaxvalue, 510, "+L");
1000  } else {
1001  axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
1002  }
1003  axis->SetLabelSize(0.02);
1004  axis->Draw();
1005  }
1006  TLatex l;
1007  l.SetTextSize(0.03);
1008  l.DrawLatex(950, 1330, "TID");
1009  l.DrawLatex(2300, 1330, "TEC");
1010  l.DrawLatex(300, 1330, "FPIX");
1011  l.DrawLatex(20, 560, "BPIX L1");
1012  l.DrawLatex(500, 385, "BPIX L2");
1013  l.DrawLatex(500, 945, "BPIX L3");
1014  l.SetTextSize(0.04);
1015  std::string fulltitle = title;
1016  if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
1017  fulltitle += ": Log10 scale";
1018  if (onlyPixelFlag) {
1019  l.DrawLatex(30, 1500, fulltitle.c_str());
1020  } else {
1021  l.DrawLatex(850, 1500, fulltitle.c_str());
1022  }
1023  if (onlyPixelFlag) {
1024  l.DrawLatex(380, 40, "-z");
1025  } else {
1026  l.DrawLatex(1730, 40, "-z");
1027  }
1028  if (onlyPixelFlag) {
1029  l.DrawLatex(380, 1330, "+z");
1030  } else {
1031  l.DrawLatex(1730, 1360, "+z");
1032  }
1033  l.DrawLatex(1085, 330, "TIB L1");
1034  l.DrawLatex(1085, 1000, "TIB L2");
1035  l.DrawLatex(1585, 330, "TIB L3");
1036  l.DrawLatex(1585, 1000, "TIB L4");
1037  l.DrawLatex(2085, 330, "TOB L1");
1038  l.DrawLatex(2085, 1000, "TOB L2");
1039  l.DrawLatex(2585, 330, "TOB L3");
1040  l.DrawLatex(2585, 1000, "TOB L4");
1041  l.DrawLatex(3085, 330, "TOB L5");
1042  l.DrawLatex(3085, 1000, "TOB L6");
1043  TArrow arx(3448, 1190, 3448, 1350, 0.01, "|>");
1044  l.DrawLatex(3460, 1350, "x");
1045  TArrow ary(3448, 1190, 3312, 1190, 0.01, "|>");
1046  l.DrawLatex(3312, 1210, "y");
1047  TArrow arz(3485, 373, 3485, 676, 0.01, "|>");
1048  l.DrawLatex(3510, 667, "z");
1049  TArrow arphi(3485, 511, 3037, 511, 0.01, "|>");
1050  l.DrawLatex(3023, 520, "#Phi");
1051  arx.SetLineWidth(3);
1052  ary.SetLineWidth(3);
1053  arz.SetLineWidth(3);
1054  arphi.SetLineWidth(3);
1055  if (onlyPixelFlag) {
1056  arx.SetX1(570);
1057  arx.SetX2(570);
1058  arx.SetY1(1190);
1059  arx.SetY2(1350);
1060  l.DrawLatex(570 + 12, 1190 + 160, "x");
1061  ary.SetX1(570);
1062  ary.SetX2(570 - 160);
1063  ary.SetY1(1190);
1064  ary.SetY2(1190);
1065  l.DrawLatex(570 - 160, 1190 + 30, "y");
1066  arz.SetX1(380);
1067  arz.SetX2(380);
1068  arz.SetY1(683 - 100);
1069  arz.SetY2(683 + 100);
1070  l.DrawLatex(380 + 15, 683 + 100 - 9, "z");
1071  arphi.SetX1(380);
1072  arphi.SetX2(380 - 390);
1073  arphi.SetY1(683);
1074  arphi.SetY2(683);
1075  l.DrawLatex(380 - 390 - 14, 683 + 9, "#Phi");
1076  }
1077  arx.Draw();
1078  ary.Draw();
1079  arz.Draw();
1080  arphi.Draw();
1081  TLegend *MyL = buildLegend();
1082 
1083  if (title.find("QTestAlarm") != std::string::npos) {
1084  MyL->Draw();
1085  }
1086  MyC->Update();
1087  if (filetype == "png") {
1088  std::string filename = outputfilename + ".png";
1089  std::cout << "printing " << filename << std::endl;
1090  MyC->Print(filename.c_str());
1091  }
1092  if (filetype == "jpg") {
1093  std::string filename = outputfilename + ".jpg";
1094  MyC->Print(filename.c_str());
1095  }
1096  if (filetype == "pdf") {
1097  std::string filename = outputfilename + ".pdf";
1098  MyC->Print(filename.c_str());
1099  }
1100  std::string command = "rm " + tempfilename;
1101  command1 = command.c_str();
1102  std::cout << "Executing " << command1 << std::endl;
1103  system(command1);
1104  MyC->Clear();
1105  delete MyC;
1106  delete MyL;
1107  if (printflag)
1108  delete axis;
1109  for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
1110  delete (*pos1);
1111  }
1112  }
1113  }
1114  return;
1115 }
1117  int crate, int numfed_incrate, bool print_total, TmApvPair *apvPair, std::ofstream *svgfile, bool useApvPairValue) {
1118  double xp[4], yp[4];
1119  int color;
1120  int green = 0;
1121  int red = 0;
1122  int blue = 0;
1123  double xd[4], yd[4];
1124  int np = 4;
1125  double boxinitx = 0., boxinity = 0.;
1126  double dx = .9, dy = .9;
1127  /*
1128  int numfedch_incolumn = 12;
1129  int numfedch_inrow = 8;
1130  int numfed_incolumn = 6;
1131  int numfed_inrow = 4;
1132  */
1133  boxinitx = boxinitx + (NUMFED_INCOLUMN - 1 - (numfed_incrate - 1) / NUMFED_INROW) * (NUMFEDCH_INCOLUMN + 2);
1134  boxinity = boxinity + (NUMFED_INROW - 1 - (numfed_incrate - 1) % NUMFED_INROW) * (NUMFEDCH_INROW + 1);
1135  boxinity = boxinity + NUMFEDCH_INROW - (apvPair->getFedCh() / NUMFEDCH_INCOLUMN);
1136  boxinitx = boxinitx + NUMFEDCH_INCOLUMN - (int)(apvPair->getFedCh() % NUMFEDCH_INCOLUMN);
1137  // std::cout << crate << " " << numfed_incrate << " " << apvPair->getFedCh()<<" "<<boxinitx<< " " << boxinity << std::endl; ;
1138  xp[0] = boxinitx;
1139  yp[0] = boxinity;
1140  xp[1] = boxinitx + dx;
1141  yp[1] = boxinity;
1142  xp[2] = boxinitx + dx;
1143  yp[2] = boxinity + dy;
1144  xp[3] = boxinitx;
1145  yp[3] = boxinity + dy;
1146  for (int j = 0; j < 4; j++) {
1147  xd[j] = xdpixelc(xp[j]);
1148  yd[j] = ydpixelc(yp[j]);
1149  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1150  }
1151 
1152  char buffer[20];
1153  sprintf(buffer, "%X", apvPair->mod->idex);
1154  std::string s = apvPair->mod->name;
1155  s.erase(s.begin() + s.find("connected"), s.end());
1156 
1157  if (useApvPairValue) {
1158  if (apvPair->red < 0) { //use count to compute color
1159  if (apvPair->count > 0) {
1160  color = getcolor(apvPair->value, palette);
1161  red = (color >> 16) & 0xFF;
1162  green = (color >> 8) & 0xFF;
1163  blue = (color)&0xFF;
1164  if (!print_total)
1165  apvPair->value = apvPair->value * apvPair->count; //restore mod->value
1166  if (temporary_file)
1167  *svgfile << red << " " << green << " " << blue << " ";
1168  else
1169  *svgfile
1170  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1171  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1172  << apvPair->mod->getKey()
1173  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1174  "\" POS=\"Fed/Ch "
1175  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1176  << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1177  } else {
1178  if (temporary_file)
1179  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1180  else
1181  *svgfile
1182  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1183  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1184  << apvPair->mod->getKey()
1185  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1186  "\" POS=\"Fed/Ch "
1187  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1188  << " \" fill=\"white\" points=\"";
1189  }
1190  } else { //color defined with fillc
1191  if (apvPair->red > 255)
1192  apvPair->red = 255;
1193  if (apvPair->green > 255)
1194  apvPair->green = 255;
1195  if (apvPair->blue > 255)
1196  apvPair->blue = 255;
1197  if (temporary_file)
1198  *svgfile << apvPair->red << " " << apvPair->green << " " << apvPair->blue << " ";
1199  else
1200  *svgfile
1201  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1202  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1203  << apvPair->mod->getKey()
1204  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1205  "\" POS=\"Fed/Ch "
1206  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1207  << " \" fill=\"rgb(" << apvPair->red << "," << apvPair->green << "," << apvPair->blue << ")\" points=\"";
1208  }
1209  } else {
1210  if (apvPair->mod->red < 0) { //use count to compute color
1211  if (apvPair->mod->count > 0) {
1212  color = getcolor(apvPair->mod->value, palette);
1213  red = (color >> 16) & 0xFF;
1214  green = (color >> 8) & 0xFF;
1215  blue = (color)&0xFF;
1216  if (temporary_file)
1217  *svgfile << red << " " << green << " " << blue << " ";
1218  else
1219  *svgfile
1220  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1221  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1222  << apvPair->mod->getKey()
1223  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1224  "\" POS=\"Fed/Ch "
1225  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1226  << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1227  } else {
1228  if (temporary_file)
1229  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1230  else
1231  *svgfile
1232  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1233  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1234  << apvPair->mod->getKey()
1235  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1236  "\" POS=\"Fed/Ch "
1237  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1238  << " \" fill=\"white\" points=\"";
1239  }
1240  } else { //color defined with fillc
1241  if (apvPair->mod->red > 255)
1242  apvPair->mod->red = 255;
1243  if (apvPair->mod->green > 255)
1244  apvPair->mod->green = 255;
1245  if (apvPair->mod->blue > 255)
1246  apvPair->mod->blue = 255;
1247  if (temporary_file)
1248  *svgfile << apvPair->mod->red << " " << apvPair->mod->green << " " << apvPair->mod->blue << " ";
1249  else
1250  *svgfile
1251  << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1252  << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1253  << apvPair->mod->getKey()
1254  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1255  "\" POS=\"Fed/Ch "
1256  << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1257  << " \" fill=\"rgb(" << apvPair->mod->red << "," << apvPair->mod->green << "," << apvPair->mod->blue
1258  << ")\" points=\"";
1259  }
1260  }
1261  if (temporary_file)
1262  *svgfile << np << " ";
1263  for (int k = 0; k < np; k++) {
1264  if (temporary_file)
1265  *svgfile << xd[k] << " " << yd[k] << " ";
1266  else
1267  *svgfile << xd[k] << "," << yd[k] << " ";
1268  }
1269  if (temporary_file)
1270  *svgfile << std::endl;
1271  else
1272  *svgfile << "\" />" << std::endl;
1273 }
1275  int crate, int numfec_incrate, bool print_total, TmCcu *ccu, std::ofstream *svgfile, bool useCcuValue) {
1276  double xp[4], yp[4];
1277  int color;
1278  int green = 0;
1279  int red = 0;
1280  int blue = 0;
1281  double xd[4], yd[4];
1282  int np = 4;
1283  double boxinitx = 0., boxinity = 0.;
1284  double dx = .9, dy = .9;
1285  int numccu_incolumn = 8;
1286  int numccu_inrow = 15;
1287  int numfec_incolumn = 5;
1288  int numfec_inrow = 4;
1289  boxinitx = boxinitx + (numfec_incolumn - (numfec_incrate - 1) / numfec_inrow) * 14.;
1290  boxinity = boxinity + (numfec_inrow - (numfec_incrate - 1) % numfec_inrow) * 16.;
1291  boxinity = boxinity + numccu_inrow - ccu->mpos;
1292  boxinitx = boxinitx + numccu_incolumn - (int)(ccu->getCcuRing() % numccu_incolumn);
1293  //std::cout << crate << " " << numfec_incrate << " " << ccu->getCcuRing()<<" "<<ccu->mpos<<" "<<boxinitx<< " " << boxinity << std::endl; ;
1294  xp[0] = boxinitx;
1295  yp[0] = boxinity;
1296  xp[1] = boxinitx + dx;
1297  yp[1] = boxinity;
1298  xp[2] = boxinitx + dx;
1299  yp[2] = boxinity + dy;
1300  xp[3] = boxinitx;
1301  yp[3] = boxinity + dy;
1302  for (int j = 0; j < 4; j++) {
1303  xd[j] = xdpixelfec(xp[j]);
1304  yd[j] = ydpixelfec(yp[j]);
1305  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1306  }
1307 
1308  char buffer[20];
1309  sprintf(buffer, "%X", ccu->idex);
1310  //sprintf(buffer,"%X",ccu->mod->idex);
1311  //std::string s = ccu->mod->name;
1312  std::string s = ccu->text;
1313  s.erase(s.begin() + s.find("connected"), s.end());
1314 
1315  if (ccu->red < 0) { //use count to compute color
1316  if (ccu->count > 0) {
1317  color = getcolor(ccu->value, palette);
1318  red = (color >> 16) & 0xFF;
1319  green = (color >> 8) & 0xFF;
1320  blue = (color)&0xFF;
1321  if (!print_total)
1322  ccu->value = ccu->value * ccu->count; //restore mod->value
1323  if (temporary_file)
1324  *svgfile << red << " " << green << " " << blue << " ";
1325  else
1326  *svgfile
1327  << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1328  << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\"" << ccu->layer
1329  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1330  "\" POS=\"Slot/Ring"
1331  << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1332  << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1333  } else {
1334  if (temporary_file)
1335  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1336  else
1337  *svgfile
1338  << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1339  << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\""
1340  << ccu->layer
1341  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1342  "\" POS=\"Slot/Ring "
1343  << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1344  << " \" fill=\"white\" points=\"";
1345  }
1346  } else { //color defined with fillc
1347  if (ccu->red > 255)
1348  ccu->red = 255;
1349  if (ccu->green > 255)
1350  ccu->green = 255;
1351  if (ccu->blue > 255)
1352  ccu->blue = 255;
1353  if (temporary_file)
1354  *svgfile << ccu->red << " " << ccu->green << " " << ccu->blue << " ";
1355  else
1356  *svgfile
1357  << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1358  << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\"" << ccu->layer
1359  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1360  "\" POS=\"Slot/Ring "
1361  << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1362  << " \" fill=\"rgb(" << ccu->red << "," << ccu->green << "," << ccu->blue << ")\" points=\"";
1363  }
1364  if (temporary_file)
1365  *svgfile << np << " ";
1366  for (int k = 0; k < np; k++) {
1367  if (temporary_file)
1368  *svgfile << xd[k] << " " << yd[k] << " ";
1369  else
1370  *svgfile << xd[k] << "," << yd[k] << " ";
1371  }
1372  if (temporary_file)
1373  *svgfile << std::endl;
1374  else
1375  *svgfile << "\" />" << std::endl;
1376 }
1378  int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1379  double xp[4], yp[4];
1380  int color;
1381  int green = 0;
1382  int red = 0;
1383  int blue = 0;
1384  double xd[4], yd[4];
1385  int np = 4;
1386  double boxinitx = 0., boxinity = 0.;
1387  double dx = .9, dy = .9;
1388 
1389  boxinitx = boxinitx + (NUMPSUCRATE_INCOLUMN - psu->getPsuCrate()) * 1.5;
1390  boxinity = boxinity + (NUMPSUCH_INROW - psu->getPsuBoard());
1391 
1392  xp[0] = boxinitx;
1393  yp[0] = boxinity;
1394  xp[1] = boxinitx + dx;
1395  yp[1] = boxinity;
1396  xp[2] = boxinitx + dx;
1397  yp[2] = boxinity + dy;
1398  xp[3] = boxinitx;
1399  yp[3] = boxinity + dy;
1400 
1401  for (int j = 0; j < 4; j++) {
1402  xd[j] = xdpixelpsu(xp[j]);
1403  yd[j] = ydpixelpsu(yp[j]);
1404  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1405  }
1406 
1407  // lines needed to prepare the clickable maps: understand why I get twice the full list of channels (HV1 and HV0?)
1408  /*
1409  double scalex=2695./2700.;
1410  double scaley=1520./1550.;
1411  std::cout << "<area shape=\"rect\" coords=\" "
1412  << int(scalex*yd[2]) << "," << int(1520-scaley*xd[2])
1413  << "," << int(scalex*yd[0]) << "," << int(1520-scaley*xd[0])
1414  << "\" title=\" " << psu->psId << "\" /> " << std::endl;
1415  */
1416  //
1417 
1418  char buffer[20];
1419  sprintf(buffer, "%X", psu->idex);
1420  std::string s = psu->text;
1421  s.erase(s.begin() + s.find("connected"), s.end());
1422 
1423  if (psu->red < 0) { //use count to compute color
1424  if (psu->count > 0) {
1425  color = getcolor(psu->value, palette);
1426  red = (color >> 16) & 0xFF;
1427  green = (color >> 8) & 0xFF;
1428  blue = (color)&0xFF;
1429  if (!print_total)
1430  psu->value = psu->value * psu->count; //restore mod->value
1431  if (temporary_file)
1432  *svgfile << red << " " << green << " " << blue << " ";
1433  else
1434  *svgfile
1435  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1436  << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1437  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1438  "\" POS=\"easyCrate/easyBoard "
1439  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << red
1440  << "," << green << "," << blue << ")\" points=\"";
1441  } else {
1442  if (temporary_file)
1443  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1444  else
1445  *svgfile
1446  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1447  << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1448  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1449  "\" POS=\"easyCrate/easyBoard "
1450  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1451  << " \" fill=\"white\" points=\"";
1452  }
1453  }
1454 
1455  else { //color defined with fillc
1456  if (psu->red > 255)
1457  psu->red = 255;
1458  if (psu->green > 255)
1459  psu->green = 255;
1460  if (psu->blue > 255)
1461  psu->blue = 255;
1462  if (temporary_file)
1463  *svgfile << psu->red << " " << psu->green << " " << psu->blue << " ";
1464  else
1465  *svgfile
1466  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1467  << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1468  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1469  "\" POS=\"easyCrate/easyBoard "
1470  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << psu->red
1471  << "," << psu->green << "," << psu->blue << ")\" points=\"";
1472  }
1473 
1474  if (temporary_file)
1475  *svgfile << np << " ";
1476  for (int k = 0; k < np; k++) {
1477  if (temporary_file)
1478  *svgfile << xd[k] << " " << yd[k] << " ";
1479  else
1480  *svgfile << xd[k] << "," << yd[k] << " ";
1481  }
1482  if (temporary_file)
1483  *svgfile << std::endl;
1484  else
1485  *svgfile << "\" />" << std::endl;
1486 }
1487 
1489  int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1490  double xp[4], yp[4];
1491  int color;
1492  int greenHV2 = 0;
1493  int redHV2 = 0;
1494  int blueHV2 = 0;
1495  double xd[4], yd[4];
1496  int np = 4;
1497  double boxinitx = 35, boxinity = 12;
1498  double dx = 1.1, dy = 1.3;
1499 
1500  boxinitx = boxinitx + (5 - psu->getPsuCrate()) * 5;
1501  boxinity = boxinity + (18 - psu->getPsuBoard()) * 1.75;
1502 
1503  xp[0] = boxinitx;
1504  yp[0] = boxinity;
1505  xp[1] = boxinitx + dx;
1506  yp[1] = boxinity;
1507  xp[2] = boxinitx + dx;
1508  yp[2] = boxinity + dy;
1509  xp[3] = boxinitx;
1510  yp[3] = boxinity + dy;
1511 
1512  for (int j = 0; j < 4; j++) {
1513  xd[j] = xdpixelpsu(xp[j]);
1514  yd[j] = ydpixelpsu(yp[j]);
1515  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1516  }
1517 
1518  char buffer[20];
1519  sprintf(buffer, "%X", psu->idex);
1520  std::string s = psu->textHV2;
1521  s.erase(s.begin() + s.find("connected"), s.end());
1522 
1523  if (psu->redHV2 < 0) { //use count to compute color
1524 
1525  if (psu->valueHV2 > 0) {
1526  color = getcolor(psu->valueHV2, palette);
1527  redHV2 = (color >> 16) & 0xFF;
1528  greenHV2 = (color >> 8) & 0xFF;
1529  blueHV2 = (color)&0xFF;
1530  if (!print_total)
1531  psu->valueHV2 = psu->valueHV2 * psu->countHV2; //restore mod->value
1532  if (temporary_file)
1533  *svgfile << redHV2 << " " << greenHV2 << " " << blueHV2 << " ";
1534  else
1535  *svgfile
1536  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1537  << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1538  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1539  "\" POS=\"easyCrate/easyBoard "
1540  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << redHV2
1541  << "," << greenHV2 << "," << blueHV2 << ")\" points=\"";
1542  } else {
1543  if (temporary_file)
1544  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1545  else
1546  *svgfile
1547  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1548  << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1549  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1550  "\" POS=\"easyCrate/easyBoard "
1551  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1552  << " \" fill=\"white\" points=\"";
1553  }
1554  }
1555 
1556  else { //color defined with fillc
1557  if (psu->redHV2 > 255)
1558  psu->redHV2 = 255;
1559  if (psu->greenHV2 > 255)
1560  psu->greenHV2 = 255;
1561  if (psu->blueHV2 > 255)
1562  psu->blueHV2 = 255;
1563  if (temporary_file)
1564  *svgfile << psu->redHV2 << " " << psu->greenHV2 << " " << psu->blueHV2 << " ";
1565  else
1566  *svgfile
1567  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1568  << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1569  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1570  "\" POS=\"easyCrate/easyBoard "
1571  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb("
1572  << psu->redHV2 << "," << psu->greenHV2 << "," << psu->blueHV2 << ")\" points=\"";
1573  }
1574 
1575  if (temporary_file)
1576  *svgfile << np << " ";
1577  for (int k = 0; k < np; k++) {
1578  if (temporary_file)
1579  *svgfile << xd[k] << " " << yd[k] << " ";
1580  else
1581  *svgfile << xd[k] << "," << yd[k] << " ";
1582  }
1583  if (temporary_file)
1584  *svgfile << std::endl;
1585  else
1586  *svgfile << "\" />" << std::endl;
1587 }
1588 
1590  int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1591  double xp[4], yp[4];
1592  int color;
1593  int greenHV3 = 0;
1594  int redHV3 = 0;
1595  int blueHV3 = 0;
1596  double xd[4], yd[4];
1597  int np = 4;
1598  double boxinitx = 36.5, boxinity = 12;
1599  double dx = 1.1, dy = 1.3;
1600 
1601  boxinitx = boxinitx + (5 - psu->getPsuCrate()) * 5;
1602  boxinity = boxinity + (18 - psu->getPsuBoard()) * 1.75;
1603 
1604  xp[0] = boxinitx;
1605  yp[0] = boxinity;
1606  xp[1] = boxinitx + dx;
1607  yp[1] = boxinity;
1608  xp[2] = boxinitx + dx;
1609  yp[2] = boxinity + dy;
1610  xp[3] = boxinitx;
1611  yp[3] = boxinity + dy;
1612 
1613  for (int j = 0; j < 4; j++) {
1614  xd[j] = xdpixelpsu(xp[j]);
1615  yd[j] = ydpixelpsu(yp[j]);
1616  //std::cout << boxinity << " "<< ymax << " "<< yp[j] << std::endl;
1617  }
1618 
1619  char buffer[20];
1620  sprintf(buffer, "%X", psu->idex);
1621  std::string s = psu->textHV3;
1622  s.erase(s.begin() + s.find("connected"), s.end());
1623 
1624  if (psu->redHV3 < 0) { //use count to compute color
1625  if (psu->valueHV3 > 0) {
1626  color = getcolor(psu->valueHV3, palette);
1627  redHV3 = (color >> 16) & 0xFF;
1628  greenHV3 = (color >> 8) & 0xFF;
1629  blueHV3 = (color)&0xFF;
1630  if (!print_total)
1631  psu->valueHV3 = psu->valueHV3 * psu->countHV3; //restore mod->value
1632  if (temporary_file)
1633  *svgfile << redHV3 << " " << greenHV3 << " " << blueHV3 << " ";
1634  else
1635  *svgfile
1636  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1637  << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1638  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1639  "\" POS=\"easyCrate/easyBoard"
1640  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << redHV3
1641  << "," << greenHV3 << "," << blueHV3 << ")\" points=\"";
1642  } else {
1643  if (temporary_file)
1644  *svgfile << 255 << " " << 255 << " " << 255 << " ";
1645  else
1646  *svgfile
1647  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1648  << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1649  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1650  "\" POS=\"easyCrate/easyBoard "
1651  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1652  << " \" fill=\"white\" points=\"";
1653  }
1654  }
1655 
1656  else { //color defined with fillc
1657  if (psu->redHV3 > 255)
1658  psu->redHV3 = 255;
1659  if (psu->greenHV3 > 255)
1660  psu->greenHV3 = 255;
1661  if (psu->blueHV3 > 255)
1662  psu->blueHV3 = 255;
1663  if (temporary_file)
1664  *svgfile << psu->redHV3 << " " << psu->greenHV3 << " " << psu->blueHV3 << " ";
1665  else
1666  *svgfile
1667  << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1668  << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1669  << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1670  "\" POS=\"easyCrate/easyBoard "
1671  << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb("
1672  << psu->redHV3 << "," << psu->greenHV3 << "," << psu->blueHV3 << ")\" points=\"";
1673  }
1674 
1675  if (temporary_file)
1676  *svgfile << np << " ";
1677  for (int k = 0; k < np; k++) {
1678  if (temporary_file)
1679  *svgfile << xd[k] << " " << yd[k] << " ";
1680  else
1681  *svgfile << xd[k] << "," << yd[k] << " ";
1682  }
1683  if (temporary_file)
1684  *svgfile << std::endl;
1685  else
1686  *svgfile << "\" />" << std::endl;
1687 }
1688 
1690  bool print_total, float minval, float maxval, std::string s, int width, int height) {
1691  if (enableFecProcessing) {
1693  std::vector<TPolyLine *> vp;
1694  TGaxis *axis = nullptr;
1695  size_t found = filetype.find_last_of('.');
1696  filetype = filetype.substr(found + 1);
1697  found = outputfilename.find_last_of('.');
1698  outputfilename = outputfilename.substr(0, found);
1699  temporary_file = true;
1700  if (filetype == "xml" || filetype == "svg")
1701  temporary_file = false;
1702  std::ostringstream outs;
1703  minvalue = minval;
1704  maxvalue = maxval;
1705  outs << outputfilename << ".coor";
1706  if (temporary_file)
1707  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1708  std::map<int, TmCcu *>::iterator i_ccu;
1709  std::multimap<TmCcu *, TmModule *>::iterator it;
1710  std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
1711  //Decide if we must use Module or Ccu value
1712  bool useCcuValue = false;
1713 
1714  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1715  TmCcu *ccu = i_ccu->second;
1716  if (ccu != nullptr) {
1717  if (ccu->count > 0 || ccu->red != -1) {
1718  useCcuValue = true;
1719  break;
1720  }
1721  }
1722  }
1723 
1724  if (!useCcuValue) //store mean of connected modules value{
1725  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1726  TmCcu *ccu = i_ccu->second;
1727  if (ccu != nullptr) {
1728  ret = fecModuleMap.equal_range(ccu);
1729  for (it = ret.first; it != ret.second; ++it) {
1730  if ((*it).second->count > 0) {
1731  ccu->value = ccu->value + (*it).second->value;
1732  ccu->count++;
1733  }
1734  }
1735  if (ccu->count > 0)
1736  ccu->value = ccu->value / ccu->count;
1737  if (ccu->nmod == 0) {
1738  ccu->red = 0;
1739  ccu->green = 0;
1740  ccu->blue = 0;
1741  }
1742  }
1743  }
1744 
1745  if (title.find("QTestAlarm") != std::string::npos) {
1746  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1747  TmCcu *ccu = i_ccu->second;
1748  if (ccu != nullptr) {
1749  ret = fecModuleMap.equal_range(ccu);
1750  ccu->red = 0;
1751  ccu->green = 255;
1752  ccu->blue = 0;
1753  for (it = ret.first; it != ret.second; ++it) {
1754  if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
1755  !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
1756  ccu->red = 255;
1757  ccu->green = 0;
1758  ccu->blue = 0;
1759  }
1760  }
1761  }
1762  }
1763  }
1764 
1765  if (!print_total) {
1766  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1767  TmCcu *ccu = i_ccu->second;
1768  if (ccu != nullptr) {
1769  if (useCcuValue)
1770  ccu->value = ccu->value / ccu->count;
1771  }
1772  }
1773  }
1774 
1775  if (minvalue >= maxvalue) {
1776  minvalue = 9999999.;
1777  maxvalue = -9999999.;
1778  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1779  TmCcu *ccu = i_ccu->second;
1780  if (ccu != nullptr && ccu->count > 0) {
1781  if (minvalue > ccu->value)
1782  minvalue = ccu->value;
1783  if (maxvalue < ccu->value)
1784  maxvalue = ccu->value;
1785  }
1786  }
1787  }
1788 
1789  if (filetype == "svg") {
1790  saveAsSingleLayer = false;
1791  std::ostringstream outs;
1792  outs << outputfilename << ".svg";
1793  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1794  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
1795  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
1796  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
1797  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
1798  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
1799  << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
1800  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
1801  << std::endl;
1802  *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
1803  "style=\"fill:none;stroke:black;stroke-width:0;\"> "
1804  << std::endl;
1805  }
1806  for (int crate = 1; crate < (nfeccrates + 1); crate++) {
1807  if (filetype == "xml") {
1808  saveAsSingleLayer = true;
1809  std::ostringstream outs;
1810  outs << outputfilename << "feccrate" << crate << ".xml";
1811  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1812  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
1813  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
1814  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
1815  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
1816  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"feccrate.js\" />" << std::endl;
1817  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
1818  "onload=\"TrackerCrate.init()\">"
1819  << std::endl;
1820  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
1821  << std::endl;
1822  *savefile << "<g id=\"crate\" transform=\" translate(280,580) rotate(270) scale(.7,.8)\" > " << std::endl;
1823  }
1824  // ncrate=crate;
1825  deffecwindow(crate);
1826 
1827  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1828  TmCcu *ccu = i_ccu->second;
1829  if (ccu != nullptr) {
1830  if (ccu->getCcuCrate() == crate) {
1831  drawCcu(crate, ccu->getCcuSlot() - 2, print_total, ccu, savefile, useCcuValue);
1832  }
1833  }
1834  }
1835 
1836  if (!temporary_file) {
1837  if (filetype == "xml") {
1838  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
1839  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
1840  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
1841  *savefile << " </text> </svg>" << std::endl;
1842  savefile->close();
1843  saveAsSingleLayer = false;
1844  }
1845  }
1846  }
1847  if (filetype == "svg") {
1848  *savefile << "</g> </svg> </svg> " << std::endl;
1849  savefile->close();
1850  }
1851  if (!print_total && !useCcuValue) {
1852  //Restore ccu value
1853  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1854  TmCcu *ccu = i_ccu->second;
1855  if (ccu != nullptr) {
1856  ccu->value = ccu->value * ccu->count;
1857  }
1858  }
1859  }
1860  if (temporary_file) {
1861  if (printflag && !saveWebInterface)
1863  savefile->close();
1864 
1865  const char *command1;
1866  std::string tempfilename = outputfilename + ".coor";
1867  int red, green, blue, npoints, colindex, ncolor;
1868  double x[4], y[4];
1869  std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
1870  TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
1871  gPad->SetFillColor(38);
1872 
1873  if (saveWebInterface)
1874  gPad->Range(0, 0, 3700, 1600);
1875  else
1876  gPad->Range(0, 0, 3800, 1600);
1877 
1878  //First build palette
1879  ncolor = 0;
1880  typedef std::map<int, int> ColorList;
1881  ColorList colorList;
1882  ColorList::iterator pos;
1883  TColor *col, *c;
1884  while (!tempfile.eof()) {
1885  tempfile >> red >> green >> blue >> npoints;
1886  colindex = red + green * 1000 + blue * 1000000;
1887  pos = colorList.find(colindex);
1888  if (pos == colorList.end()) {
1889  colorList[colindex] = ncolor + 100;
1890  col = gROOT->GetColor(ncolor + 100);
1891  if (col)
1892  col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
1893  else {
1894  c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
1895  vc.push_back(c);
1896  }
1897  ncolor++;
1898  }
1899  for (int i = 0; i < npoints; i++) {
1900  tempfile >> x[i] >> y[i];
1901  }
1902  }
1903  if (ncolor > 0 && ncolor < 10000) {
1904  Int_t colors[10000];
1905  for (int i = 0; i < ncolor; i++) {
1906  colors[i] = i + 100;
1907  }
1908  gStyle->SetPalette(ncolor, colors);
1909  }
1910  tempfile.clear();
1911  tempfile.seekg(0, std::ios::beg);
1912  std::cout << "created palette with " << ncolor << " colors" << std::endl;
1913  while (!tempfile.eof()) { //create polylines
1914  tempfile >> red >> green >> blue >> npoints;
1915  for (int i = 0; i < npoints; i++) {
1916  tempfile >> x[i] >> y[i];
1917  }
1918  colindex = red + green * 1000 + blue * 1000000;
1919  pos = colorList.find(colindex);
1920  if (pos != colorList.end()) {
1921  TPolyLine *pline = new TPolyLine(npoints, y, x);
1922  vp.push_back(pline);
1923  pline->SetFillColor(colorList[colindex]);
1924  pline->SetLineWidth(0);
1925  pline->Draw("f");
1926  }
1927  }
1928  if (printflag && !saveWebInterface) {
1929  float lminvalue = minvalue;
1930  float lmaxvalue = maxvalue;
1931  if (tkMapLog) {
1932  lminvalue = log(minvalue) / log(10);
1933  lmaxvalue = log(maxvalue) / log(10);
1934  }
1935  axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
1936  axis->SetLabelSize(0.02);
1937  axis->Draw();
1938  }
1939 
1940  if (!saveWebInterface) {
1941  TLatex l;
1942  l.SetTextSize(0.05);
1943  std::string fulltitle = title;
1944  if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
1945  fulltitle += ": Log10 scale";
1946  l.DrawLatex(50, 1530, fulltitle.c_str());
1947  }
1948  MyC->Update();
1949  std::cout << "Filetype " << filetype << std::endl;
1950  if (filetype == "png") {
1951  std::string filename = outputfilename + ".png";
1952  MyC->Print(filename.c_str());
1953  }
1954  if (filetype == "jpg") {
1955  std::string filename = outputfilename + ".jpg";
1956  MyC->Print(filename.c_str());
1957  }
1958  if (filetype == "pdf") {
1959  std::string filename = outputfilename + ".pdf";
1960  MyC->Print(filename.c_str());
1961  }
1962  std::string command = "rm " + tempfilename;
1963  command1 = command.c_str();
1964  std::cout << "Executing " << command1 << std::endl;
1965  system(command1);
1966  MyC->Clear();
1967  delete MyC;
1968  if (printflag && !saveWebInterface)
1969  delete axis;
1970  for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
1971  delete (*pos1);
1972  }
1973 
1974  } //if(temporary_file)
1975  } //if(enabledFecProcessing)
1976 }
1978  bool print_total, float minval, float maxval, std::string s, int width, int height) {
1979  if (enableHVProcessing) {
1981  std::vector<TPolyLine *> vp;
1982  TGaxis *axis = nullptr;
1983  size_t found = filetype.find_last_of('.');
1984  filetype = filetype.substr(found + 1);
1985  found = outputfilename.find_last_of('.');
1986  outputfilename = outputfilename.substr(0, found);
1987 
1988  temporary_file = true;
1989 
1990  if (filetype == "xml" || filetype == "svg")
1991  temporary_file = false;
1992 
1993  std::ostringstream outs;
1994  minvalue = minval;
1995  maxvalue = maxval;
1996  outs << outputfilename << ".coor";
1997  if (temporary_file)
1998  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1999 
2000  std::map<int, TmPsu *>::iterator ipsu;
2001  std::multimap<TmPsu *, TmModule *>::iterator it;
2002  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
2003 
2004  bool usePsuValue = false;
2005 
2006  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2007  TmPsu *psu = ipsu->second;
2008  if (psu != nullptr) {
2009  if (psu->countHV2 > 0 || psu->redHV2 != -1 || psu->countHV3 > 0 || psu->redHV3 != -1) {
2010  usePsuValue = true;
2011  break;
2012  }
2013  }
2014  }
2015 
2016  if (!usePsuValue) { //store mean of connected modules value{
2017 
2018  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2019  TmPsu *psu = ipsu->second;
2020  if (psu != nullptr) {
2021  ret = psuModuleMap.equal_range(psu);
2022  int nconn1 = 0;
2023  int nconn2 = 0;
2024  for (it = ret.first; it != ret.second; ++it) {
2025  if ((*it).second->HVchannel == 2 && (*it).second->count > 0) {
2026  nconn1++;
2027  psu->valueHV2 = psu->valueHV2 + (*it).second->value;
2028  }
2029  if ((*it).second->HVchannel == 3 && (*it).second->count > 0) {
2030  nconn2++;
2031  psu->valueHV3 = psu->valueHV3 + (*it).second->value;
2032  }
2033  }
2034  if (psu->nmodHV2 != 0 && nconn1 > 0) {
2035  psu->valueHV2 = psu->valueHV2 / psu->nmodHV2;
2036  psu->countHV2 = 1;
2037  }
2038  if (psu->nmodHV3 != 0 && nconn2 > 0) {
2039  psu->valueHV3 = psu->valueHV3 / psu->nmodHV3;
2040  psu->countHV3 = 1;
2041  }
2042  }
2043  }
2044  }
2045 
2046  if (title.find("QTestAlarm") != std::string::npos) {
2047  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2048  TmPsu *psu = ipsu->second;
2049  if (psu != nullptr) {
2050  ret = psuModuleMap.equal_range(psu);
2051  psu->redHV2 = 0;
2052  psu->greenHV2 = 255;
2053  psu->blueHV2 = 0;
2054  psu->redHV3 = 0;
2055  psu->greenHV3 = 255;
2056  psu->blueHV3 = 0;
2057  for (it = ret.first; it != ret.second; ++it) {
2058  if ((*it).second->HVchannel == 2) {
2059  if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2060  !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2061  psu->redHV2 = 255;
2062  psu->greenHV2 = 0;
2063  psu->blueHV2 = 0;
2064  }
2065  }
2066  if ((*it).second->HVchannel == 3) {
2067  if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2068  !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2069  psu->redHV3 = 255;
2070  psu->greenHV3 = 0;
2071  psu->blueHV3 = 0;
2072  }
2073  }
2074  }
2075  }
2076  }
2077  }
2078 
2079  if (!print_total) {
2080  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2081  TmPsu *psu = ipsu->second;
2082  if (psu != nullptr) {
2083  if (usePsuValue) {
2084  psu->valueHV2 = psu->valueHV2 / psu->countHV2;
2085  psu->valueHV3 = psu->valueHV3 / psu->countHV3;
2086  }
2087  }
2088  }
2089  }
2090 
2091  if (minvalue >= maxvalue) {
2092  minvalue = 9999999.;
2093  maxvalue = -9999999.;
2094 
2095  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2096  TmPsu *psu = ipsu->second;
2097  if (psu != nullptr && psu->countHV2 > 0 && psu->countHV3 > 0) {
2098  if (minvalue > psu->valueHV2 || minvalue > psu->valueHV3)
2099  minvalue = std::min(psu->valueHV2, psu->valueHV3);
2100  if (maxvalue < psu->valueHV2 || maxvalue < psu->valueHV3)
2101  maxvalue = std::max(psu->valueHV2, psu->valueHV3);
2102  }
2103  }
2104  }
2105 
2106  if (filetype == "svg") {
2107  saveAsSingleLayer = false;
2108  std::ostringstream outs;
2109  outs << outputfilename << ".svg";
2110  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2111  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2112  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2113  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2114  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2115  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2116  << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2117  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2118  << std::endl;
2119  *savefile << "<svg:g id=\"HVtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2120  "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2121  << std::endl;
2122  }
2123 
2124  for (int irack = 1; irack < (npsuracks + 1); irack++) {
2125  if (filetype == "xml") {
2126  saveAsSingleLayer = true;
2127  std::ostringstream outs;
2128  outs << outputfilename << "HVrack" << irack << ".xml";
2129  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2130  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2131  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2132  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2133  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2134  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rackhv.js\" />" << std::endl;
2135  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2136  "onload=\"TrackerRackhv.init()\">"
2137  << std::endl;
2138  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2139  << std::endl;
2140  *savefile << "<g id=\"rackhv\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2141  }
2142 
2143  // nrack=irack;
2144  defpsuwindow(irack);
2145  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2146  TmPsu *psu = ipsu->second;
2147  if (psu->getPsuRack() == irack) {
2148  drawHV2(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2149  drawHV3(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2150  }
2151  }
2152 
2153  if (!temporary_file) {
2154  if (filetype == "xml") {
2155  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2156  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2157  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2158  *savefile << " </text> </svg>" << std::endl;
2159  savefile->close();
2160  saveAsSingleLayer = false;
2161  }
2162  }
2163  }
2164  if (filetype == "svg") {
2165  *savefile << "</g> </svg> </svg> " << std::endl;
2166  savefile->close();
2167  }
2168 
2169  //Restore psu value
2170  if (!print_total && !usePsuValue) {
2171  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2172  TmPsu *psu = ipsu->second;
2173  if (psu != nullptr) {
2174  psu->valueHV2 = psu->valueHV2 * psu->countHV2;
2175  psu->valueHV3 = psu->valueHV3 * psu->countHV3;
2176  }
2177  }
2178  }
2179 
2180  if (temporary_file) {
2181  if (printflag && !saveWebInterface)
2183  savefile->close();
2184 
2185  const char *command1;
2186  std::string tempfilename = outputfilename + ".coor";
2187  int red, green, blue, npoints, colindex, ncolor;
2188  double x[4], y[4];
2189  std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2190  TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2191  gPad->SetFillColor(38);
2192 
2193  if (saveWebInterface)
2194  gPad->Range(0, 0, 3700, 1600);
2195  else
2196  gPad->Range(0, 0, 3800, 1600);
2197 
2198  //First build palette
2199  ncolor = 0;
2200  typedef std::map<int, int> ColorList;
2201  ColorList colorList;
2202  ColorList::iterator pos;
2203  TColor *col, *c;
2204  while (!tempfile.eof()) {
2205  tempfile >> red >> green >> blue >> npoints;
2206  colindex = red + green * 1000 + blue * 1000000;
2207  pos = colorList.find(colindex);
2208  if (pos == colorList.end()) {
2209  colorList[colindex] = ncolor + 100;
2210  col = gROOT->GetColor(ncolor + 100);
2211  if (col)
2212  col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2213  else {
2214  c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2215  vc.push_back(c);
2216  }
2217  ncolor++;
2218  }
2219  for (int i = 0; i < npoints; i++) {
2220  tempfile >> x[i] >> y[i];
2221  }
2222  }
2223  if (ncolor > 0 && ncolor < 10000) {
2224  Int_t colors[10000];
2225  for (int i = 0; i < ncolor; i++) {
2226  colors[i] = i + 100;
2227  }
2228  gStyle->SetPalette(ncolor, colors);
2229  }
2230  tempfile.clear();
2231  tempfile.seekg(0, std::ios::beg);
2232  std::cout << "created palette with " << ncolor << " colors" << std::endl;
2233  while (!tempfile.eof()) { //create polylines
2234  tempfile >> red >> green >> blue >> npoints;
2235  for (int i = 0; i < npoints; i++) {
2236  tempfile >> x[i] >> y[i];
2237  }
2238  colindex = red + green * 1000 + blue * 1000000;
2239  pos = colorList.find(colindex);
2240  if (pos != colorList.end()) {
2241  TPolyLine *pline = new TPolyLine(npoints, y, x);
2242  vp.push_back(pline);
2243  pline->SetFillColor(colorList[colindex]);
2244  pline->SetLineWidth(0);
2245  pline->Draw("f");
2246  }
2247  }
2248  if (printflag && !saveWebInterface) {
2249  float lminvalue = minvalue;
2250  float lmaxvalue = maxvalue;
2251  if (tkMapLog) {
2252  lminvalue = log(minvalue) / log(10);
2253  lmaxvalue = log(maxvalue) / log(10);
2254  }
2255  axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
2256  axis->SetLabelSize(0.02);
2257  axis->Draw();
2258  }
2259 
2260  if (!saveWebInterface) {
2261  TLatex l;
2262  l.SetTextSize(0.05);
2263  std::string fulltitle = title;
2264  if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2265  fulltitle += ": Log10 scale";
2266  l.DrawLatex(50, 1530, fulltitle.c_str());
2267  }
2268  MyC->Update();
2269  std::cout << "Filetype " << filetype << std::endl;
2270  if (filetype == "png") {
2271  std::string filename = outputfilename + ".png";
2272  MyC->Print(filename.c_str());
2273  }
2274  if (filetype == "jpg") {
2275  std::string filename = outputfilename + ".jpg";
2276  MyC->Print(filename.c_str());
2277  }
2278  if (filetype == "pdf") {
2279  std::string filename = outputfilename + ".pdf";
2280  MyC->Print(filename.c_str());
2281  }
2282  std::string command = "rm " + tempfilename;
2283  command1 = command.c_str();
2284  std::cout << "Executing " << command1 << std::endl;
2285  system(command1);
2286  MyC->Clear();
2287  delete MyC;
2288  if (printflag && !saveWebInterface)
2289  delete axis;
2290  for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2291  delete (*pos1);
2292  }
2293 
2294  } //if(temporary_file)
2295  } //if(enabledHVProcessing)
2296 }
2297 
2299  bool print_total, float minval, float maxval, std::string s, int width, int height) {
2300  if (enableLVProcessing) {
2301  printflag = true;
2302  bool rangefound = true;
2304  std::vector<TPolyLine *> vp;
2305  TGaxis *axis = nullptr;
2306 
2307  size_t found = filetype.find_last_of('.');
2308  filetype = filetype.substr(found + 1);
2309  found = outputfilename.find_last_of('.');
2310  outputfilename = outputfilename.substr(0, found);
2311 
2312  temporary_file = true;
2313 
2314  if (filetype == "xml" || filetype == "svg")
2315  temporary_file = false;
2316 
2317  std::ostringstream outs;
2318  minvalue = minval;
2319  maxvalue = maxval;
2320  outs << outputfilename << ".coor";
2321  if (temporary_file)
2322  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2323 
2324  std::map<int, TmPsu *>::iterator ipsu;
2325  std::multimap<TmPsu *, TmModule *>::iterator it;
2326  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
2327 
2328  //Decide if we must use Module or Power Psupply value
2329  bool usePsuValue = false;
2330 
2331  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2332  TmPsu *psu = ipsu->second;
2333  if (psu != nullptr) {
2334  if (psu->count > 0 || psu->red != -1) {
2335  usePsuValue = true;
2336  break;
2337  }
2338  }
2339  }
2340 
2341  if (!usePsuValue) { //store mean of connected modules value{
2342  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2343  TmPsu *psu = ipsu->second;
2344  if (psu != nullptr) {
2345  ret = psuModuleMap.equal_range(psu);
2346  int nconn = 0;
2347  for (it = ret.first; it != ret.second; ++it) {
2348  if ((*it).second->count > 0) {
2349  nconn++;
2350  psu->value = psu->value + (*it).second->value;
2351  }
2352  }
2353  if (nconn > 0) {
2354  psu->value = psu->value / psu->nmod;
2355  psu->count = 1;
2356  }
2357  }
2358  }
2359  }
2360 
2361  if (title.find("QTestAlarm") != std::string::npos) {
2362  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2363  TmPsu *psu = ipsu->second;
2364  if (psu != nullptr) {
2365  ret = psuModuleMap.equal_range(psu);
2366  // psu->red=255;psu->green=255;psu->blue=255;
2367  psu->red = -1;
2368  int nconn = 0;
2369  for (it = ret.first; it != ret.second; ++it) {
2370  if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2371  !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2372  nconn++;
2373  psu->value++;
2374  }
2375  }
2376  if (nconn > 0) {
2377  psu->value = psu->value / psu->nmod;
2378  psu->count = 1;
2379  }
2380  }
2381  }
2382  }
2383 
2384  if (!print_total) {
2385  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2386  TmPsu *psu = ipsu->second;
2387  if (psu != nullptr) {
2388  if (usePsuValue)
2389  psu->value = psu->value / psu->count;
2390  }
2391  }
2392  }
2393 
2394  if (minvalue >= maxvalue) {
2395  minvalue = 9999999.;
2396  maxvalue = -9999999.;
2397  rangefound = false;
2398  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2399  TmPsu *psu = ipsu->second;
2400  if (psu != nullptr && psu->count > 0) {
2401  rangefound = true;
2402  if (minvalue > psu->value)
2403  minvalue = psu->value;
2404  if (maxvalue < psu->value)
2405  maxvalue = psu->value;
2406  }
2407  }
2408  }
2409  if ((maxvalue == minvalue) || !rangefound)
2410  printflag = false;
2411 
2412  if (filetype == "svg") {
2413  saveAsSingleLayer = false;
2414  std::ostringstream outs;
2415  outs << outputfilename << ".svg";
2416  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2417  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2418  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2419  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2420  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2421  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2422  << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2423  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2424  << std::endl;
2425  *savefile << "<svg:g id=\"psutrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2426  "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2427  << std::endl;
2428  }
2429 
2430  for (int irack = 1; irack < (npsuracks + 1); irack++) {
2431  if (filetype == "xml") {
2432  saveAsSingleLayer = true;
2433  std::ostringstream outs;
2434  outs << outputfilename << "psurack" << irack << ".xml";
2435  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2436  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2437  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2438  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2439  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2440  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rack.js\" />" << std::endl;
2441  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2442  "onload=\"TrackerCrate.init()\">"
2443  << std::endl;
2444  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2445  << std::endl;
2446  *savefile << "<g id=\"rack\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2447  }
2448 
2449  // nrack=irack;
2450  defpsuwindow(irack);
2451  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2452  TmPsu *psu = ipsu->second;
2453  if (psu->getPsuRack() == irack) {
2454  drawPsu(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2455  }
2456  }
2457 
2458  if (!temporary_file) {
2459  if (filetype == "xml") {
2460  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2461  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2462  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2463  *savefile << " </text> </svg>" << std::endl;
2464  savefile->close();
2465  saveAsSingleLayer = false;
2466  }
2467  }
2468  }
2469  if (filetype == "svg") {
2470  *savefile << "</g> </svg> </svg> " << std::endl;
2471  savefile->close();
2472  }
2473 
2474  //Restore psu value
2475  if (!print_total && !usePsuValue) {
2476  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2477  TmPsu *psu = ipsu->second;
2478  if (psu != nullptr) {
2479  psu->value = psu->value * psu->count;
2480  }
2481  }
2482  }
2483 
2484  int rangex = YPSUOFFSET + (YPSURSIZE + YPSUOFFSET) * NUMPSURACK_INROW + 300;
2485  int rangey = XPSUOFFSET + (XPSURSIZE + XPSUOFFSET) * NUMPSURACK_INCOLUMN + 300;
2486 
2487  if (temporary_file) {
2488  if (printflag && !saveWebInterface)
2489  drawPalette(savefile, rangex - 140, rangey - 100);
2490  savefile->close();
2491 
2492  const char *command1;
2493  std::string tempfilename = outputfilename + ".coor";
2494  int red, green, blue, npoints, colindex, ncolor;
2495  double x[4], y[4];
2496  std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2497  TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2498  gPad->SetFillColor(38);
2499 
2500  // if(saveWebInterface)gPad->Range(0,0,3700,1600); else gPad->Range(0,0,3800,1600);
2501  std::cout << " range x " << rangex << std::endl;
2502  std::cout << " range y " << rangey << std::endl;
2503  gPad->Range(0, 0, rangex, rangey);
2504 
2505  //First build palette
2506  ncolor = 0;
2507  typedef std::map<int, int> ColorList;
2508  ColorList colorList;
2509  ColorList::iterator pos;
2510  TColor *col, *c;
2511  while (!tempfile.eof()) {
2512  tempfile >> red >> green >> blue >> npoints;
2513  colindex = red + green * 1000 + blue * 1000000;
2514  pos = colorList.find(colindex);
2515  if (pos == colorList.end()) {
2516  colorList[colindex] = ncolor + 100;
2517  col = gROOT->GetColor(ncolor + 100);
2518  if (col)
2519  col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2520  else
2521  c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2522  vc.push_back(c);
2523  ncolor++;
2524  }
2525  for (int i = 0; i < npoints; i++) {
2526  tempfile >> x[i] >> y[i];
2527  }
2528  }
2529  if (ncolor > 0 && ncolor < 10000) {
2530  Int_t colors[10000];
2531  for (int i = 0; i < ncolor; i++) {
2532  colors[i] = i + 100;
2533  }
2534  gStyle->SetPalette(ncolor, colors);
2535  }
2536  tempfile.clear();
2537  tempfile.seekg(0, std::ios::beg);
2538  std::cout << "created palette with " << ncolor << " colors" << std::endl;
2539  while (!tempfile.eof()) { //create polylines
2540  tempfile >> red >> green >> blue >> npoints;
2541  for (int i = 0; i < npoints; i++) {
2542  tempfile >> x[i] >> y[i];
2543  }
2544  colindex = red + green * 1000 + blue * 1000000;
2545  pos = colorList.find(colindex);
2546  if (pos != colorList.end()) {
2547  TPolyLine *pline = new TPolyLine(npoints, y, x);
2548  vp.push_back(pline);
2549  pline->SetFillColor(colorList[colindex]);
2550  pline->SetLineWidth(0);
2551  pline->Draw("f");
2552  }
2553  }
2554  if (printflag && !saveWebInterface) {
2555  float lminvalue = minvalue;
2556  float lmaxvalue = maxvalue;
2557  if (tkMapLog) {
2558  lminvalue = log(minvalue) / log(10);
2559  lmaxvalue = log(maxvalue) / log(10);
2560  }
2561  axis = new TGaxis(rangex - 140, 34, rangex - 140, rangey - 106, lminvalue, lmaxvalue, 510, "+L");
2562  axis->SetLabelSize(0.02);
2563  axis->Draw();
2564  }
2565 
2566  if (!saveWebInterface) {
2567  TLatex l;
2568  l.SetTextSize(0.05);
2569  std::string fulltitle = title;
2570  if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2571  fulltitle += ": Log10 scale";
2572  l.DrawLatex(50, rangey - 200, fulltitle.c_str());
2573  }
2574  MyC->Update();
2575  std::cout << "Filetype " << filetype << std::endl;
2576  if (filetype == "png") {
2577  std::string filename = outputfilename + ".png";
2578  MyC->Print(filename.c_str());
2579  }
2580  if (filetype == "jpg") {
2581  std::string filename = outputfilename + ".jpg";
2582  MyC->Print(filename.c_str());
2583  }
2584  if (filetype == "pdf") {
2585  std::string filename = outputfilename + ".pdf";
2586  MyC->Print(filename.c_str());
2587  }
2588  std::string command = "rm " + tempfilename;
2589  command1 = command.c_str();
2590  std::cout << "Executing " << command1 << std::endl;
2591  system(command1);
2592  MyC->Clear();
2593  delete MyC;
2594  if (printflag && !saveWebInterface)
2595  delete axis;
2596  for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2597  delete (*pos1);
2598  }
2599 
2600  } //if(temporary_file)
2601  } //if(enabledFedProcessing)
2602 }
2603 
2605  bool print_total, float minval, float maxval, std::string s, int width, int height) {
2606  if (enableFedProcessing) {
2607  printflag = true;
2608  bool rangefound = true;
2610  std::vector<TPolyLine *> vp;
2611  TGaxis *axis = nullptr;
2612 
2613  size_t found = filetype.find_last_of('.');
2614  filetype = filetype.substr(found + 1);
2615  found = outputfilename.find_last_of('.');
2616  outputfilename = outputfilename.substr(0, found);
2617 
2618  temporary_file = true;
2619  if (filetype == "xml" || filetype == "svg")
2620  temporary_file = false;
2621  std::ostringstream outs;
2622  minvalue = minval;
2623  maxvalue = maxval;
2624  outs << outputfilename << ".coor";
2625  if (temporary_file)
2626  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2627  std::map<int, TmApvPair *>::iterator i_apv;
2628  std::map<int, int>::iterator i_fed;
2629  //Decide if we must use Module or ApvPair value
2630  bool useApvPairValue = false;
2631  for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2632  TmApvPair *apvPair = i_apv->second;
2633  if (apvPair != nullptr) {
2634  TmModule *apv_mod = apvPair->mod;
2635  if (apv_mod != nullptr && !apv_mod->notInUse()) {
2636  if (apvPair->count > 0 || apvPair->red != -1) {
2637  useApvPairValue = true;
2638  break;
2639  }
2640  }
2641  }
2642  }
2643  if (!print_total) {
2644  for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2645  TmApvPair *apvPair = i_apv->second;
2646  if (apvPair != nullptr) {
2647  TmModule *apv_mod = apvPair->mod;
2648  if (apv_mod != nullptr && !apv_mod->notInUse()) {
2649  if (useApvPairValue)
2650  apvPair->value = apvPair->value / apvPair->count;
2651  else if (apvPair->mpos == 0 && apv_mod->count > 0)
2652  apv_mod->value = apv_mod->value / apv_mod->count;
2653  }
2654  }
2655  }
2656  }
2657  if (minvalue >= maxvalue) {
2658  minvalue = 9999999.;
2659  maxvalue = -9999999.;
2660  rangefound = false;
2661  for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2662  TmApvPair *apvPair = i_apv->second;
2663  if (apvPair != nullptr) {
2664  TmModule *apv_mod = apvPair->mod;
2665  if (apv_mod != nullptr && !apv_mod->notInUse()) {
2666  if (useApvPairValue) {
2667  rangefound = true;
2668  if (minvalue > apvPair->value)
2669  minvalue = apvPair->value;
2670  if (maxvalue < apvPair->value)
2671  maxvalue = apvPair->value;
2672  } else {
2673  if (apv_mod->count > 0) {
2674  rangefound = true;
2675  if (minvalue > apv_mod->value)
2676  minvalue = apv_mod->value;
2677  if (maxvalue < apv_mod->value)
2678  maxvalue = apv_mod->value;
2679  }
2680  }
2681  }
2682  }
2683  }
2684  }
2685  if ((title.find("QTestAlarm") != std::string::npos) || (maxvalue == minvalue) || !rangefound)
2686  printflag = false;
2687 
2688  if (filetype == "svg") {
2689  saveAsSingleLayer = false;
2690  std::ostringstream outs;
2691  outs << outputfilename << ".svg";
2692  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2693  *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2694  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2695  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2696  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2697  *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2698  << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2699  *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2700  << std::endl;
2701  *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2702  "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2703  << std::endl;
2704  }
2705  for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
2706  if (filetype == "xml") {
2707  saveAsSingleLayer = true;
2708  std::ostringstream outs;
2709  outs << outputfilename << "crate" << crate << ".xml";
2710  savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2711  *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2712  *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2713  *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2714  *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2715  *savefile << "<script type=\"text/ecmascript\" xlink:href=\"crate.js\" />" << std::endl;
2716  *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2717  "onload=\"TrackerCrate.init()\">"
2718  << std::endl;
2719  *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2720  << std::endl;
2721  *savefile << "<g id=\"crate\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2722  }
2723  // ncrate=crate;
2724  defcwindow(crate);
2725  int numfed_incrate = 0;
2726  for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
2727  if (i_fed->second == crate) {
2728  int fedId = i_fed->first;
2729  // numfed_incrate++;
2730  numfed_incrate = slotMap[fedId];
2731  // the following piece of code is used to prepare the HTML clickable map
2732  /*
2733  double scalex=6285./6290.;
2734  double scaley=3510./3540.;
2735  double boxinitix=(NUMFED_INCOLUMN-1-(numfed_incrate-1)/NUMFED_INROW)*(NUMFEDCH_INCOLUMN+2)+NUMFEDCH_INCOLUMN+0.9;
2736  double boxinitiy=(NUMFED_INROW-1-(numfed_incrate-1)%NUMFED_INROW)*(NUMFEDCH_INROW+1)+NUMFEDCH_INROW+0.9;
2737  double boxendix=boxinitix-(NUMFEDCH_INCOLUMN-1)-0.9;
2738  double boxendiy=boxinitiy-(NUMFEDCH_INROW-1)-0.9;
2739 
2740  std::cout << "<area shape=\"rect\" coords=\" "
2741  << int(scalex*ydpixelc(boxinitiy)) << "," << int(3510-scaley*xdpixelc(boxinitix))
2742  << "," << int(scalex*ydpixelc(boxendiy)) << "," << int(3510-scaley*xdpixelc(boxendix))
2743  << "\" href=\"\" title=\"crate " << crate << " slot " << numfed_incrate << " FED " << fedId << "\" /> " << std::endl;
2744  */
2745  //
2746  for (int nconn = 0; nconn < 96; nconn++) {
2747  int key = fedId * 1000 + nconn;
2748  TmApvPair *apvPair = apvMap[key];
2749  if (apvPair != nullptr) {
2750  TmModule *apv_mod = apvPair->mod;
2751  if (apv_mod != nullptr && !apv_mod->notInUse()) {
2752  drawApvPair(crate, numfed_incrate, print_total, apvPair, savefile, useApvPairValue);
2753  }
2754  }
2755  }
2756  }
2757  }
2758  if (!temporary_file) {
2759  if (filetype == "xml") {
2760  *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2761  *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2762  *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2763  *savefile << " </text> </svg>" << std::endl;
2764  savefile->close();
2765  delete savefile;
2766  saveAsSingleLayer = false;
2767  }
2768  }
2769  }
2770  if (filetype == "svg") {
2771  *savefile << "</g> </svg> </svg> " << std::endl;
2772  savefile->close();
2773  delete savefile;
2774  }
2775  if (!print_total && !useApvPairValue) {
2776  //Restore module value
2777  for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2778  TmApvPair *apvPair = i_apv->second;
2779  if (apvPair != nullptr) {
2780  TmModule *apv_mod = apvPair->mod;
2781  if (apv_mod != nullptr && apvPair->mpos == 0 && !apv_mod->notInUse()) {
2782  apv_mod->value = apv_mod->value * apv_mod->count;
2783  }
2784  }
2785  }
2786  }
2787 
2788  int rangex = YFEDOFFSET + (YFEDCSIZE + YFEDOFFSET) * NUMFEDCRATE_INROW + 300;
2789  int rangey = XFEDOFFSET + (XFEDCSIZE + XFEDOFFSET) * NUMFEDCRATE_INCOLUMN + 300;
2790 
2791  if (temporary_file) {
2792  if (printflag && !saveWebInterface)
2793  drawPalette(savefile, rangex - 140, rangey - 100);
2794  savefile->close();
2795  delete savefile;
2796 
2797  const char *command1;
2798  std::string tempfilename = outputfilename + ".coor";
2799  int red, green, blue, npoints, colindex, ncolor;
2800  double x[4], y[4];
2801  std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2802  TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2803  gPad->SetFillColor(38);
2804 
2805  // if(saveWebInterface)gPad->Range(0,0,3750,1600); else gPad->Range(0,0,3800,1600);
2806  std::cout << " range x " << rangex << std::endl;
2807  std::cout << " range y " << rangey << std::endl;
2808  gPad->Range(0, 0, rangex, rangey);
2809 
2810  //First build palette
2811  ncolor = 0;
2812  typedef std::map<int, int> ColorList;
2813  ColorList colorList;
2814  ColorList::iterator pos;
2815  TColor *col, *c;
2816  while (!tempfile.eof()) {
2817  tempfile >> red >> green >> blue >> npoints;
2818  colindex = red + green * 1000 + blue * 1000000;
2819  pos = colorList.find(colindex);
2820  if (pos == colorList.end()) {
2821  colorList[colindex] = ncolor + 100;
2822  col = gROOT->GetColor(ncolor + 100);
2823  if (col)
2824  col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2825  else
2826  c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2827  vc.push_back(c);
2828  ncolor++;
2829  }
2830  for (int i = 0; i < npoints; i++) {
2831  tempfile >> x[i] >> y[i];
2832  }
2833  }
2834  if (ncolor > 0 && ncolor < 10000) {
2835  Int_t colors[10000];
2836  for (int i = 0; i < ncolor; i++) {
2837  colors[i] = i + 100;
2838  }
2839  gStyle->SetPalette(ncolor, colors);
2840  }
2841  tempfile.clear();
2842  tempfile.seekg(0, std::ios::beg);
2843  std::cout << "created palette with " << ncolor << " colors" << std::endl;
2844  while (!tempfile.eof()) { //create polylines
2845  tempfile >> red >> green >> blue >> npoints;
2846  for (int i = 0; i < npoints; i++) {
2847  tempfile >> x[i] >> y[i];
2848  }
2849  colindex = red + green * 1000 + blue * 1000000;
2850  pos = colorList.find(colindex);
2851  if (pos != colorList.end()) {
2852  TPolyLine *pline = new TPolyLine(npoints, y, x);
2853  vp.push_back(pline);
2854  pline->SetFillColor(colorList[colindex]);
2855  pline->SetLineWidth(0);
2856  pline->Draw("f");
2857  }
2858  }
2859  if (printflag && !saveWebInterface) {
2860  float lminvalue = minvalue;
2861  float lmaxvalue = maxvalue;
2862  if (tkMapLog) {
2863  lminvalue = log(minvalue) / log(10);
2864  lmaxvalue = log(maxvalue) / log(10);
2865  }
2866  axis = new TGaxis(rangex - 140, 34, rangex - 140, rangey - 106, lminvalue, lmaxvalue, 510, "+L");
2867  axis->SetLabelSize(0.02);
2868  axis->Draw();
2869  }
2870 
2871  if (!saveWebInterface) {
2872  TLatex l;
2873  l.SetTextSize(0.05);
2874  std::string fulltitle = title;
2875  if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2876  fulltitle += ": Log10 scale";
2877  l.DrawLatex(50, rangey - 200, fulltitle.c_str());
2878  }
2879  MyC->Update();
2880  std::cout << "Filetype " << filetype << std::endl;
2881  if (filetype == "png") {
2882  std::string filename = outputfilename + ".png";
2883  MyC->Print(filename.c_str());
2884  }
2885  if (filetype == "jpg") {
2886  std::string filename = outputfilename + ".jpg";
2887  MyC->Print(filename.c_str());
2888  }
2889  if (filetype == "pdf") {
2890  std::string filename = outputfilename + ".pdf";
2891  MyC->Print(filename.c_str());
2892  }
2893  std::string command = "rm " + tempfilename;
2894  command1 = command.c_str();
2895  std::cout << "Executing " << command1 << std::endl;
2896  system(command1);
2897  MyC->Clear();
2898  delete MyC;
2899  if (printflag && !saveWebInterface)
2900  delete axis;
2901  for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2902  delete (*pos1);
2903  }
2904 
2905  } //if(temporary_file)
2906  } //if(enabledFedProcessing)
2907 }
2908 
2909 void TrackerMap::load(std::string inputfilename) {
2910  inputfile = new std::ifstream(inputfilename.c_str(), std::ios::in);
2912  int ipos, ipos1, ipos2, id = 0, val = 0;
2913  int nline = 0;
2914  while (getline(*inputfile, line)) {
2915  ipos1 = line.find("value=\"");
2916  if (ipos1 > 0) {
2917  value = line.substr(ipos1 + 7, 10);
2918  ipos = value.find('\"');
2919  value = value.substr(0, ipos);
2920  val = atoi(value.c_str());
2921  }
2922  ipos2 = line.find("detid=\"");
2923  if (ipos2 > 0) {
2924  value = line.substr(ipos2 + 7, 10);
2925  ipos = value.find('\"');
2926  value = value.substr(0, ipos);
2927  id = atoi(value.c_str());
2928  }
2929  if (ipos1 > 0 && ipos2 > 0 && val > 0)
2930  this->fill(id, val);
2931  if (ipos1 > 0 && ipos2 > 0)
2932  nline++;
2933  //if(ipos1>0 && ipos2>0)std::cout << nline << " " << id << " " << val << std::endl;
2934  }
2935  std::cout << nline << " modules found in this svg file " << std::endl;
2936  inputfile->close();
2937  delete inputfile;
2938 }
2939 
2940 //print in svg format tracker map
2941 //print_total = true represent in color the total stored in the module
2942 //print_total = false represent in color the average
2943 void TrackerMap::print(bool print_total, float minval, float maxval, std::string outputfilename) {
2944  temporary_file = false;
2945  std::ostringstream outs;
2946  minvalue = minval;
2947  maxvalue = maxval;
2948  outs << outputfilename << ".xml";
2949  svgfile = new std::ofstream(outs.str().c_str(), std::ios::out);
2950  jsfile = new std::ifstream(edm::FileInPath(jsfilename).fullPath().c_str(), std::ios::in);
2951 
2952  //copy javascript interface from trackermap.txt file
2953  std::string line;
2954  while (getline(*jsfile, line)) {
2955  *svgfile << line << std::endl;
2956  }
2957  jsfile->close();
2958  delete jsfile;
2959  //
2960  if (!print_total) {
2961  for (int layer = 1; layer < 44; layer++) {
2962  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
2963  for (int module = 1; module < 200; module++) {
2964  int key = layer * 100000 + ring * 1000 + module;
2965  TmModule *mod = smoduleMap[key];
2966  if (mod != nullptr && !mod->notInUse()) {
2967  mod->value = mod->value / mod->count;
2968  }
2969  }
2970  }
2971  }
2972  }
2973  if (minvalue >= maxvalue) {
2974  minvalue = 9999999.;
2975  maxvalue = -9999999.;
2976  for (int layer = 1; layer < 44; layer++) {
2977  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
2978  for (int module = 1; module < 200; module++) {
2979  int key = layer * 100000 + ring * 1000 + module;
2980  TmModule *mod = smoduleMap[key];
2981  if (mod != nullptr && !mod->notInUse()) {
2982  if (minvalue > mod->value)
2983  minvalue = mod->value;
2984  if (maxvalue < mod->value)
2985  maxvalue = mod->value;
2986  }
2987  }
2988  }
2989  }
2990  }
2991  for (int layer = 1; layer < 44; layer++) {
2992  // nlay=layer;
2993  defwindow(layer);
2994  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
2995  for (int module = 1; module < 200; module++) {
2996  int key = layer * 100000 + ring * 1000 + module;
2997  TmModule *mod = smoduleMap[key];
2998  if (mod != nullptr && !mod->notInUse()) {
2999  drawModule(mod, key, layer, print_total, svgfile);
3000  }
3001  }
3002  }
3003  }
3004  *svgfile << "</svg:g></svg:svg>" << std::endl;
3005  *svgfile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">" << title << "</svg:text>" << std::endl;
3006  if (printflag)
3008  *svgfile << "</svg:svg>" << std::endl;
3009  *svgfile << "</body></html>" << std::endl;
3010  svgfile->close();
3011  delete svgfile;
3012 }
3013 
3014 void TrackerMap::drawPalette(std::ofstream *svgfile, int xoffset, int yoffset) {
3015  std::cout << "preparing the palette" << std::endl;
3016  int color, red, green, blue;
3017  float val = minvalue;
3018  int paletteLength = 250;
3019  int width = 50 * (yoffset - 40) / 1500;
3020  float dval = (maxvalue - minvalue) / (float)paletteLength;
3021  bool rtkMapLog = tkMapLog;
3022  if (tkMapLog)
3023  tkMapLog = false;
3024  float step = float(yoffset - 40) / float(paletteLength);
3025  for (int i = 1; i < paletteLength + 1; i++) {
3026  color = getcolor(val, palette);
3027  red = (color >> 16) & 0xFF;
3028  green = (color >> 8) & 0xFF;
3029  blue = (color)&0xFF;
3030  // if(!temporary_file)*svgfile <<"<svg:rect x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"6\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n";
3031  // else *svgfile << red << " " << green << " " << blue << " 4 " << (6*i)+40 << " 3010. " <<//
3032  // (6*i)+40 << " 3060. " <<//
3033  // (6*(i-1))+40 << " 3060. " <<//
3034  // (6*(i-1))+40 <<" 3010. " << std::endl; //
3035 
3036  // if(i%50 == 0){
3037  // if(!temporary_file)*svgfile <<"<svg:rect x=\"3010\" y=\""<<(1550-6*i)<<"\" width=\"50\" height=\"1\" fill=\"black\" />\n";
3038  // if(i%50==0&&!temporary_file)*svgfile << " <svg:text class=\"normalText\" x=\"3060\" y=\""<<(1560-6*i)<<"\">" <<val<<"</svg:text>"<<std::endl;
3039 
3040  if (!temporary_file)
3041  *svgfile << "<svg:rect x=\"3610\" y=\"" << (1550 - 6 * i) << "\" width=\"50\" height=\"6\" fill=\"rgb(" << red
3042  << "," << green << "," << blue << ")\" />\n";
3043  else
3044  *svgfile << red << " " << green << " " << blue << " 4 " << int(step * i) + 34 << " " << xoffset - width << ". "
3045  << //
3046  int(step * i) + 34 << " " << xoffset << ". " << //
3047  int(step * (i - 1)) + 34 << " " << xoffset << ". " << //
3048  int(step * (i - 1)) + 34 << " " << xoffset - width << ". " << std::endl; //
3049 
3050  if (i % 50 == 0) {
3051  if (!temporary_file)
3052  *svgfile << "<svg:rect x=\"3610\" y=\"" << (1550 - 6 * i)
3053  << "\" width=\"50\" height=\"1\" fill=\"black\" />\n";
3054  if (i % 50 == 0 && !temporary_file)
3055  *svgfile << " <svg:text class=\"normalText\" x=\"3660\" y=\"" << (1560 - 6 * i) << "\">" << val
3056  << "</svg:text>" << std::endl;
3057  }
3058  val = val + dval;
3059  }
3060  tkMapLog = rtkMapLog;
3061 }
3062 void TrackerMap::fillc_fed_channel(int fedId, int fedCh, int red, int green, int blue) {
3063  int key = fedId * 1000 + fedCh;
3064  TmApvPair *apvpair = apvMap[key];
3065 
3066  if (apvpair != nullptr) {
3067  apvpair->red = red;
3068  apvpair->green = green;
3069  apvpair->blue = blue;
3070  return;
3071  }
3072  std::cout << "*** error in FedTrackerMap fillc method ***";
3073 }
3074 
3075 void TrackerMap::fill_fed_channel(int idmod, float qty) {
3076  std::multimap<const int, TmApvPair *>::iterator pos;
3077  for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
3078  TmApvPair *apvpair = pos->second;
3079  if (apvpair != nullptr) {
3080  apvpair->value = apvpair->value + qty;
3081  apvpair->count++;
3082  }
3083  }
3084  return;
3085  std::cout << "*** error in FedTrackerMap fill by module method ***";
3086 }
3087 
3088 void TrackerMap::fill_current_val_fed_channel(int fedId, int fedCh, float current_val) {
3089  int key = fedId * 1000 + fedCh;
3090  TmApvPair *apvpair = apvMap[key];
3091 
3092  if (apvpair != nullptr) {
3093  apvpair->value = current_val;
3094  apvpair->count = 1;
3095  apvpair->red = -1;
3096  } else
3097  std::cout << "*** error in FedTrackerMap fill_current_val method ***";
3098 }
3099 
3100 void TrackerMap::fillc_fec_channel(int crate, int slot, int ring, int addr, int red, int green, int blue) {
3101  int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
3102 
3103  TmCcu *ccu = ccuMap[key];
3104 
3105  if (ccu != nullptr) {
3106  ccu->red = red;
3107  ccu->green = green;
3108  ccu->blue = blue;
3109  return;
3110  }
3111  std::cout << "*** error in FecTrackerMap fillc method ***";
3112 }
3113 
3114 void TrackerMap::fill_fec_channel(int crate, int slot, int ring, int addr, float qty) {
3115  int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
3116  TmCcu *ccu = ccuMap[key];
3117  if (ccu != nullptr) {
3118  ccu->count++;
3119  ccu->value = ccu->value + qty;
3120  return;
3121  }
3122 
3123  std::cout << "*** error in FecTrackerMap fill by module method ***";
3124 }
3125 
3126 void TrackerMap::fillc_lv_channel(int rack, int crate, int board, int red, int green, int blue) {
3127  int key = rack * 1000 + crate * 100 + board;
3128 
3129  TmPsu *psu = psuMap[key];
3130 
3131  if (psu != nullptr) {
3132  psu->red = red;
3133  psu->green = green;
3134  psu->blue = blue;
3135  return;
3136  }
3137  std::cout << "*** error in LVTrackerMap fillc method ***";
3138 }
3139 
3140 void TrackerMap::fill_lv_channel(int rack, int crate, int board, float qty) {
3141  int key = rack * 1000 + crate * 100 + board;
3142  TmPsu *psu = psuMap[key];
3143  if (psu != nullptr) {
3144  psu->count++;
3145  psu->value = psu->value + qty;
3146  return;
3147  }
3148 
3149  std::cout << "*** error in LVTrackerMap fill by module method ***";
3150 }
3151 
3152 void TrackerMap::fillc_hv_channel2(int rack, int crate, int board, int red, int green, int blue) {
3153  int key = rack * 1000 + crate * 100 + board;
3154 
3155  TmPsu *psu = psuMap[key];
3156 
3157  if (psu != nullptr) {
3158  psu->redHV2 = red;
3159  psu->greenHV2 = green;
3160  psu->blueHV2 = blue;
3161  return;
3162  }
3163  std::cout << "*** error in HVTrackerMap (channel 2) fillc method ***";
3164 }
3165 void TrackerMap::fillc_hv_channel3(int rack, int crate, int board, int red, int green, int blue) {
3166  int key = rack * 1000 + crate * 100 + board;
3167 
3168  TmPsu *psu = psuMap[key];
3169 
3170  if (psu != nullptr) {
3171  psu->redHV3 = red;
3172  psu->greenHV3 = green;
3173  psu->blueHV3 = blue;
3174  return;
3175  }
3176  std::cout << "*** error in HVTrackerMap (channel 3) fillc method ***";
3177 }
3178 
3179 void TrackerMap::fill_hv_channel2(int rack, int crate, int board, float qty) {
3180  int key = rack * 1000 + crate * 100 + board;
3181  TmPsu *psu = psuMap[key];
3182  if (psu != nullptr) {
3183  psu->countHV2++;
3184  psu->valueHV2 = psu->valueHV2 + qty;
3185  return;
3186  }
3187 
3188  std::cout << "*** error in HVTrackerMap fill by module method ***";
3189 }
3190 void TrackerMap::fill_hv_channel3(int rack, int crate, int board, float qty) {
3191  int key = rack * 1000 + crate * 100 + board;
3192  TmPsu *psu = psuMap[key];
3193  if (psu != nullptr) {
3194  psu->countHV3++;
3195  psu->valueHV3 = psu->valueHV3 + qty;
3196  return;
3197  }
3198 
3199  std::cout << "*** error in HVTrackerMap fill by module method ***";
3200 }
3201 
3202 int TrackerMap::module(int fedId, int fedCh) {
3203  int key = fedId * 1000 + fedCh;
3204  TmApvPair *apvpair = apvMap[key];
3205  if (apvpair != nullptr) {
3206  return (apvpair->mod->idex);
3207  }
3208  return (0);
3209  std::cout << "*** error in FedTrackerMap module method ***";
3210 }
3211 void TrackerMap::fill_fed_channel(int fedId, int fedCh, float qty) {
3212  int key = fedId * 1000 + fedCh;
3213  TmApvPair *apvpair = apvMap[key];
3214  if (apvpair != nullptr) {
3215  apvpair->value = apvpair->value + qty;
3216  apvpair->count++;
3217  return;
3218  }
3219  std::cout << "*** error inFedTrackerMap fill method ***";
3220 }
3221 
3222 void TrackerMap::fillc(int idmod, int red, int green, int blue) {
3224  if (mod != nullptr) {
3225  mod->red = red;
3226  mod->green = green;
3227  mod->blue = blue;
3228  return;
3229  }
3230  std::cout << "**************************error in fill method **************module " << idmod << std::endl;
3231 }
3232 void TrackerMap::fillc(int layer, int ring, int nmod, int red, int green, int blue) {
3233  int key = layer * 10000 + ring * 1000 + nmod;
3234  TmModule *mod = smoduleMap[key];
3235 
3236  if (mod != nullptr) {
3237  mod->red = red;
3238  mod->green = green;
3239  mod->blue = blue;
3240  return;
3241  }
3242  std::cout << "**************************error in fill method **************" << std::endl;
3243 }
3244 
3246  std::map<const int, TmModule *>::iterator imod;
3247  for (imod = imoduleMap.begin(); imod != imoduleMap.end(); imod++) {
3248  fillc(imod->first, 255, 255, 255);
3249  }
3250 }
3251 
3253  std::map<const int, TmModule *>::iterator imod;
3254  for (imod = imoduleMap.begin(); imod != imoduleMap.end(); imod++) {
3255  fill_current_val(imod->first, 0);
3256  }
3257 }
3258 
3259 void TrackerMap::fill_current_val(int idmod, float current_val) {
3261  if (mod != nullptr) {
3262  mod->value = current_val;
3263  mod->count = 1;
3264  mod->red = -1;
3265  } else
3266  std::cout << "**error in fill_current_val method ***module " << idmod << std::endl;
3267 }
3268 
3269 void TrackerMap::fill(int idmod, float qty) {
3271  if (mod != nullptr) {
3272  mod->value = mod->value + qty;
3273  mod->count++;
3274  return;
3275  } else {
3276  TmModule *mod1 = imoduleMap[idmod + 1];
3277  TmModule *mod2 = imoduleMap[idmod + 2];
3278  if (mod1 != nullptr && mod2 != nullptr) {
3279  mod1->value = mod1->value + qty;
3280  mod1->count++;
3281  mod2->value = mod2->value + qty;
3282  mod2->count++;
3283  return;
3284  }
3285  }
3286  std::cout << "**************************error in fill method **************module " << idmod << std::endl;
3287 }
3288 
3289 void TrackerMap::fill(int layer, int ring, int nmod, float qty) {
3290  int key = layer * 100000 + ring * 1000 + nmod;
3291  TmModule *mod = smoduleMap[key];
3292  if (mod != nullptr) {
3293  mod->value = mod->value + qty;
3294  mod->count++;
3295  } else
3296  std::cout << "**************************error in SvgModuleMap **************";
3297 }
3298 
3301  if (mod != nullptr) {
3302  mod->text = s;
3303  } else
3304  std::cout << "**************************error in IdModuleMap **************";
3305 }
3306 
3307 void TrackerMap::setText(int layer, int ring, int nmod, std::string s) {
3308  int key = layer * 100000 + ring * 1000 + nmod;
3309  TmModule *mod = smoduleMap[key];
3310  if (mod != nullptr) {
3311  mod->text = s;
3312  } else
3313  std::cout << "**************************error in SvgModuleMap **************";
3314 }
3315 
3317  // std::ifstream* infile;
3318 
3319  int nmods, pix_sil, fow_bar, ring, nmod, layer;
3320  unsigned int idex;
3321  float posx, posy, posz, length, width, thickness, widthAtHalfLength;
3322  int iModule = 0, old_layer = 0, ntotMod = 0;
3323  std::string name, dummys;
3324  std::ifstream infile(edm::FileInPath(infilename).fullPath().c_str(), std::ios::in);
3325  while (!infile.eof()) {
3326  infile >> nmods >> pix_sil >> fow_bar >> layer >> ring >> nmod >> posx >> posy >> posz >> length >> width >>
3327  thickness >> widthAtHalfLength >> idex;
3328  getline(infile, dummys); //necessary to reach end of record
3329  getline(infile, name);
3330  if (old_layer != layer) {
3331  old_layer = layer;
3332  iModule = 0;
3333  }
3334  iModule++;
3335  ntotMod++;
3336  int key = layer * 100000 + ring * 1000 + nmod;
3337  TmModule *mod = smoduleMap[key];
3338 
3339  imoduleMap[idex] = mod;
3340 
3341  if (mod == nullptr)
3342  std::cout << "error in module " << key << std::endl;
3343  else {
3344  mod->posx = posx;
3345  mod->posy = posy;
3346  mod->setUsed();
3347  mod->value = 0;
3348  mod->count = 0;
3349  mod->posz = posz;
3350  mod->length = length;
3351  mod->width = width;
3352  mod->thickness = thickness;
3353  mod->widthAtHalfLength = widthAtHalfLength;
3354  mod->idex = idex;
3355  mod->name = name;
3356  }
3357  }
3358  infile.close();
3359  number_modules = ntotMod - 1;
3360 }
3362  int red, green, blue;
3363  float lminvalue, lmaxvalue;
3364  lminvalue = minvalue;
3365  lmaxvalue = maxvalue;
3366  if (tkMapLog) {
3367  lminvalue = log(minvalue) / log(10);
3368  lmaxvalue = log(maxvalue) / log(10);
3369  value = log(value) / log(10);
3370  }
3371 
3372  red = 0;
3373  green = 0;
3374  blue = 0;
3375  if (palette == 1) { //palette1 1 - raibow
3376  float delta = (lmaxvalue - lminvalue);
3377  float x = (value - lminvalue);
3378  if (value < lminvalue) {
3379  red = 0;
3380  green = 0;
3381  blue = 255;
3382  }
3383  if (value > lmaxvalue) {
3384  red = 255;
3385  green = 0;
3386  blue = 0;
3387  }
3388  if (value >= lminvalue && value <= lmaxvalue) {
3389  red = (int)(x < (delta / 2) ? 0 : (x > ((3. / 4.) * delta) ? 255 : 255 / (delta / 4) * (x - (2. / 4.) * delta)));
3390  green =
3391  (int)(x < delta / 4 ? (x * 255 / (delta / 4))
3392  : (x > ((3. / 4.) * delta) ? 255 - 255 / (delta / 4) * (x - (3. / 4.) * delta) : 255));
3393  blue = (int)(x < delta / 4 ? 255
3394  : (x > ((1. / 2.) * delta) ? 0 : 255 - 255 / (delta / 4) * (x - (1. / 4.) * delta)));
3395  }
3396  }
3397  if (palette == 2) { //palette 2 yellow-green
3398  green = (int)((value - lminvalue) / (lmaxvalue - lminvalue) * 256.);
3399  if (green > 255)
3400  green = 255;
3401  red = 255;
3402  blue = 0;
3403  green = 255 - green;
3404  }
3405  // std::cout<<red<<" "<<green<<" "<<blue<<" "<<value <<" "<<lminvalue<<" "<< lmaxvalue<<std::endl;
3406  return (blue | (green << 8) | (red << 16));
3407 }
3409  //Copy interface
3410  std::ofstream *ofilename;
3411  std::ifstream *ifilename;
3412  std::ostringstream ofname;
3413  std::string ifname;
3415  std::string line;
3416  std::string outputfilename = "dqmtmap";
3417  ifilename = findfile("viewerHeader.xhtml");
3418  ofname << outputfilename << "viewer.html";
3419  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3420  while (getline(*ifilename, line)) {
3421  *ofilename << line << std::endl;
3422  }
3423  *ofilename << " var tmapname=\"" << outputfilename << "\"" << std::endl;
3424  *ofilename << " var tmaptitle=\"" << title << "\"" << std::endl;
3425  *ofilename << " var ncrates=" << ncrates << ";" << std::endl;
3426  *ofilename << " var nfeccrates=" << nfeccrates << ";" << std::endl;
3427  *ofilename << " var npsuracks=" << npsuracks << ";" << std::endl;
3428 
3429  ifilename->close();
3430  delete ifilename;
3431 
3432  ifilename = findfile("viewerTrailer.xhtml");
3433  while (getline(*ifilename, line)) {
3434  *ofilename << line << std::endl;
3435  }
3436  ofilename->close();
3437  delete ofilename;
3438  command = "sed -i \"s/XtmapnameX/" + outputfilename + "/g\" " + ofname.str();
3439  std::cout << "Executing " << command << std::endl;
3440  system(command.c_str());
3441  command = "sed -i \"s/XtmaptitleX/" + title + "/g\" " + ofname.str();
3442  std::cout << "Executing " << command << std::endl;
3443  system(command.c_str());
3444  ofname.str("");
3445  ifilename->close();
3446  delete ifilename;
3447 
3448  ifilename = findfile("jqviewer.js");
3449  ofname << "jqviewer.js";
3450  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3451  while (getline(*ifilename, line)) {
3452  *ofilename << line << std::endl;
3453  }
3454  ofname.str("");
3455  ofilename->close();
3456  delete ofilename;
3457  ifilename->close();
3458  delete ifilename;
3459 
3460  ifilename = findfile("crate.js");
3461  ofname << "crate.js";
3462  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3463  while (getline(*ifilename, line)) {
3464  *ofilename << line << std::endl;
3465  }
3466  ofname.str("");
3467  ofilename->close();
3468  delete ofilename;
3469  ifilename->close();
3470  delete ifilename;
3471 
3472  ifilename = findfile("feccrate.js");
3473  ofname << "feccrate.js";
3474  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3475  while (getline(*ifilename, line)) {
3476  *ofilename << line << std::endl;
3477  }
3478  ofname.str("");
3479  ofilename->close();
3480  delete ofilename;
3481  ifilename->close();
3482  delete ifilename;
3483 
3484  ifilename = findfile("layer.js");
3485  ofname << "layer.js";
3486  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3487  while (getline(*ifilename, line)) {
3488  *ofilename << line << std::endl;
3489  }
3490  ofname.str("");
3491  ofilename->close();
3492  delete ofilename;
3493  ifilename->close();
3494  delete ifilename;
3495 
3496  ifilename = findfile("rack.js");
3497  ofname << "rack.js";
3498  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3499  while (getline(*ifilename, line)) {
3500  *ofilename << line << std::endl;
3501  }
3502  ofname.str("");
3503  ofilename->close();
3504  delete ofilename;
3505  ifilename->close();
3506  delete ifilename;
3507  ofname.str("");
3508 
3509  ifilename = findfile("rackhv.js");
3510  ofname << "rackhv.js";
3511  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3512  while (getline(*ifilename, line)) {
3513  *ofilename << line << std::endl;
3514  }
3515  ofname.str("");
3516  ofilename->close();
3517  delete ofilename;
3518  ifilename->close();
3519  delete ifilename;
3520 
3521  std::ostringstream outs, outs1, outs2;
3522  outs << outputfilename << ".png";
3523  save(true, gminvalue, gmaxvalue, outs.str(), 3000, 1600);
3524  temporary_file = false;
3526 
3527  //Now print a text file for each layer
3528  std::ofstream *txtfile;
3529  for (int layer = 1; layer < 44; layer++) {
3530  std::ostringstream outs;
3531  outs << outputfilename << "layer" << layer << ".html";
3532  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3533  *txtfile << "<html><head></head> <body>" << std::endl;
3534  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3535  for (int module = 1; module < 200; module++) {
3536  int key = layer * 100000 + ring * 1000 + module;
3537  TmModule *mod = smoduleMap[key];
3538  if (mod != nullptr && !mod->notInUse()) {
3539  int idmod = mod->idex;
3540  int nchan = 0;
3541  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3542  std::multimap<const int, TmApvPair *>::iterator pos;
3543  for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
3544  TmApvPair *apvpair = pos->second;
3545  if (apvpair != nullptr) {
3546  nchan++;
3547  *txtfile << apvpair->text << std::endl;
3548  }
3549  }
3550  *txtfile << "</pre><h3>" << mod->name << "</h3>" << std::endl;
3551  }
3552  }
3553  }
3554  *txtfile << "</body></html>" << std::endl;
3555  txtfile->close();
3556  delete txtfile;
3557  }
3558  if (enableFedProcessing) {
3559  outs1 << outputfilename << "fed.png";
3560  save_as_fedtrackermap(true, gminvalue, gmaxvalue, outs1.str(), 6000, 3200);
3561  outs2 << outputfilename << ".xml";
3562  save_as_fedtrackermap(true, gminvalue, gmaxvalue, outs2.str(), 3000, 1600);
3563  //And a text file for each crate
3564  std::map<int, int>::iterator i_fed;
3565  std::ofstream *txtfile;
3566  for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
3567  std::ostringstream outs;
3568  outs << outputfilename << "crate" << crate << ".html";
3569  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3570  *txtfile << "<html><head></head> <body>" << std::endl;
3571  for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
3572  if (i_fed->second == crate) {
3573  int fedId = i_fed->first;
3574  for (int nconn = 0; nconn < 96; nconn++) {
3575  int key = fedId * 1000 + nconn;
3576  TmApvPair *apvPair = apvMap[key];
3577  if (apvPair != nullptr) {
3578  int idmod = apvPair->idex;
3579  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3580  *txtfile << apvPair->text << std::endl;
3581  std::ostringstream outs;
3582  outs << "fedchannel " << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connects to module "
3583  << apvPair->mod->idex;
3584  *txtfile << "</pre><h3>" << outs.str() << "</h3>" << std::endl;
3585  }
3586  }
3587  }
3588  }
3589  *txtfile << "</body></html>" << std::endl;
3590  txtfile->close();
3591  delete txtfile;
3592  }
3593  }
3594  if (enableFecProcessing) {
3595  std::ostringstream outs1, outs2;
3596  outs1 << outputfilename << "fec.png";
3597  save_as_fectrackermap(true, gminvalue, gmaxvalue, outs1.str(), 6000, 3200);
3598  outs2 << outputfilename << ".xml";
3599  save_as_fectrackermap(true, gminvalue, gmaxvalue, outs2.str(), 3000, 1600);
3600  //And a text file for each crate
3601  std::ofstream *txtfile;
3602  std::map<int, TmCcu *>::iterator i_ccu;
3603  std::multimap<TmCcu *, TmModule *>::iterator it;
3604  std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
3605  for (int crate = 1; crate < (nfeccrates + 1); crate++) {
3606  std::ostringstream outs;
3607  outs << outputfilename << "feccrate" << crate << ".html";
3608  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3609  *txtfile << "<html><head></head> <body>" << std::endl;
3610  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
3611  TmCcu *ccu = i_ccu->second;
3612  if (ccu != nullptr && ccu->getCcuCrate() == crate) {
3613  int idmod = ccu->idex;
3614  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3615  *txtfile << ccu->text << std::endl;
3616  std::ostringstream outs;
3617  if (ccu->nmod == 0)
3618  outs << "ccu is in position" << ccu->mpos << "in ring but doesn't seem to have any module connected";
3619  else {
3620  outs << "ccu is in position " << ccu->mpos << " in ring and connects " << ccu->nmod << " modules"
3621  << std::endl;
3622  ret = fecModuleMap.equal_range(ccu);
3623  for (it = ret.first; it != ret.second; ++it) {
3624  outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << "\n\n";
3625  }
3626 
3627  *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
3628  } //ifccu->nmod==0
3629  } //if ccu!=0
3630  } //for i_ccu
3631  *txtfile << "</body></html>" << std::endl;
3632  txtfile->close();
3633  delete txtfile;
3634  } //for int crate
3635  }
3636  if (enableLVProcessing) {
3637  std::ostringstream outs3, outs4;
3638  outs3 << outputfilename << "psu.png";
3639  save_as_psutrackermap(true, gminvalue, gmaxvalue, outs3.str(), 6000, 3200);
3640 
3641  outs4 << outputfilename << ".xml";
3642  save_as_psutrackermap(true, gminvalue, gmaxvalue, outs4.str(), 3000, 1600);
3643  //And a text file for each rack
3644 
3645  std::ofstream *txtfile;
3646  std::map<int, TmPsu *>::iterator ipsu;
3647  std::multimap<TmPsu *, TmModule *>::iterator it;
3648  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
3649  for (int rack = 1; rack < (npsuracks + 1); rack++) {
3650  std::ostringstream outs;
3651 
3652  outs << outputfilename << "psurack" << rack << ".html";
3653  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3654  *txtfile << "<html><head></head> <body>" << std::endl;
3655  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
3656  TmPsu *psu = ipsu->second;
3657  if (psu != nullptr && psu->getPsuRack() == rack) {
3658  *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
3659  *txtfile << psu->text << std::endl;
3660  std::ostringstream outs;
3661  if (psu->nmod == 0)
3662  outs << "Ps is in position" << psu->getPsuBoard()
3663  << "in crate but doesn't seem to have any module connected";
3664  else {
3665  outs << "PS is in position " << psu->getPsuBoard() << " in crate and connects to " << psu->nmod
3666  << " modules. " << std::endl;
3667 
3668  ret = psuModuleMap.equal_range(psu);
3669  for (it = ret.first; it != ret.second; ++it) {
3670  outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << " <br>"
3671  << std::endl;
3672  }
3673  *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
3674  }
3675  }
3676  }
3677  *txtfile << "</body></html>" << std::endl;
3678  txtfile->close();
3679  delete txtfile;
3680  }
3681  }
3682 
3683  if (enableHVProcessing) {
3684  std::ostringstream outs5, outs6;
3685  outs5 << outputfilename << "hv.png";
3686  save_as_HVtrackermap(true, gminvalue, gmaxvalue, outs5.str(), 6000, 3200);
3687 
3688  outs6 << outputfilename << ".xml";
3689  save_as_HVtrackermap(true, gminvalue, gmaxvalue, outs6.str(), 3000, 1600);
3690  //And a text file for each rack
3691 
3692  std::ofstream *txtfile;
3693  std::map<int, TmPsu *>::iterator ipsu;
3694  std::multimap<TmPsu *, TmModule *>::iterator it;
3695  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
3696  for (int rack = 1; rack < (npsuracks + 1); rack++) {
3697  std::ostringstream outs;
3698 
3699  outs << outputfilename << "HVrack" << rack << ".html";
3700  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3701  *txtfile << "<html><head></head> <body>" << std::endl;
3702  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
3703  TmPsu *psu = ipsu->second;
3704  if (psu != nullptr && psu->getPsuRack() == rack) {
3705  *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
3706  *txtfile << psu->textHV2 << std::endl;
3707  std::ostringstream outsHV2;
3708  if (psu->nmodHV2 == 0)
3709  outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()
3710  << "in crate but doesn't seem to have any module connected";
3711  else {
3712  outsHV2 << "HV Channel002 is in position " << psu->getPsuBoard() << " in crate and connects to "
3713  << psu->nmodHV2 << " modules. "
3714  << " <br>" << std::endl;
3715 
3716  ret = psuModuleMap.equal_range(psu);
3717  for (it = ret.first; it != ret.second; ++it) {
3718  if ((*it).second->HVchannel == 2) {
3719  outsHV2 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
3720  << " <br>" << std::endl;
3721  }
3722  }
3723  *txtfile << "</pre><h4>" << outsHV2.str() << "</h4>" << std::endl;
3724  }
3725 
3726  *txtfile << psu->textHV3 << std::endl;
3727  std::ostringstream outsHV3;
3728  if (psu->nmodHV3 == 0)
3729  outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()
3730  << "in crate but doesn't seem to have any module connected";
3731  else {
3732  outsHV3 << "HV Channel003 is in position " << psu->getPsuBoard() << " in crate and connects to "
3733  << psu->nmodHV3 << " modules. "
3734  << " <br>" << std::endl;
3735 
3736  ret = psuModuleMap.equal_range(psu);
3737  for (it = ret.first; it != ret.second; ++it) {
3738  if ((*it).second->HVchannel == 3) {
3739  outsHV3 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
3740  << " <br>" << std::endl;
3741  }
3742  }
3743  *txtfile << "</pre><h4>" << outsHV3.str() << "</h4>" << std::endl;
3744  }
3745  }
3746  }
3747  *txtfile << "</body></html>" << std::endl;
3748  txtfile->close();
3749  delete txtfile;
3750  }
3751  }
3752 }
3753 void TrackerMap::printall(bool print_total, float minval1, float maxval1, std::string s, int width, int height) {
3754  //Copy interface
3755  float minval, maxval;
3756  minval = minval1;
3757  maxval = maxval1;
3758  if (tkMapLog && (minval < maxval)) {
3759  minval = pow(10., minval1);
3760  maxval = pow(10., maxval1);
3761  }
3763  if (saveWebInterface) {
3764  width = 6000;
3765  height = 3200;
3766  } else {
3767  size_t found = filetype.find_last_of('.');
3768  filetype = filetype.substr(found + 1);
3769  found = outputfilename.find_last_of('.');
3770  outputfilename = outputfilename.substr(0, found);
3771  }
3772  std::ofstream *ofilename;
3773  std::ifstream *ifilename;
3774  std::ostringstream ofname;
3775  std::string ifname;
3776  std::string line;
3778  if (saveWebInterface) {
3779  ifilename = findfile("viewerHeader.xhtml");
3780  ofname << outputfilename << "viewer.html";
3781  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3782  while (getline(*ifilename, line)) {
3783  *ofilename << line << std::endl;
3784  }
3785  *ofilename << " var tmapname=\"" << outputfilename << "\"" << std::endl;
3786  *ofilename << " var tmaptitle=\"" << title << "\"" << std::endl;
3787  *ofilename << " var ncrates=" << ncrates << ";" << std::endl;
3788  *ofilename << " var nfeccrates=" << nfeccrates << ";" << std::endl;
3789  *ofilename << " var npsuracks=" << npsuracks << ";" << std::endl;
3790  ifilename->close();
3791  delete ifilename;
3792  ifilename = findfile("viewerTrailer.xhtml");
3793  while (getline(*ifilename, line)) {
3794  *ofilename << line << std::endl;
3795  }
3796  ofilename->close();
3797  delete ofilename;
3798  ifilename->close();
3799  delete ifilename;
3800  command = "sed -i \"s/XtmapnameX/" + outputfilename + "/g\" " + ofname.str();
3801  std::cout << "Executing " << command << std::endl;
3802  system(command.c_str());
3803  command = "sed -i \"s/XtmaptitleX/" + title + "/g\" " + ofname.str();
3804  std::cout << "Executing " << command << std::endl;
3805  system(command.c_str());
3806  ofname.str("");
3807 
3808  ifilename = findfile("jqviewer.js");
3809  ofname << "jqviewer.js";
3810  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3811  while (getline(*ifilename, line)) {
3812  *ofilename << line << std::endl;
3813  }
3814  ofilename->close();
3815  delete ofilename;
3816  ifilename->close();
3817  delete ifilename;
3818 
3819  ofname.str("");
3820  ifilename = findfile("crate.js");
3821  ofname << "crate.js";
3822  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3823  while (getline(*ifilename, line)) {
3824  *ofilename << line << std::endl;
3825  }
3826  ofilename->close();
3827  delete ofilename;
3828  ifilename->close();
3829  delete ifilename;
3830 
3831  ofname.str("");
3832  ifilename = findfile("feccrate.js");
3833  ofname << "feccrate.js";
3834  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3835  while (getline(*ifilename, line)) {
3836  *ofilename << line << std::endl;
3837  }
3838  ofilename->close();
3839  delete ofilename;
3840  ifilename->close();
3841  delete ifilename;
3842 
3843  ofname.str("");
3844  ifilename = findfile("rack.js");
3845  ofname << "rack.js";
3846  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3847  while (getline(*ifilename, line)) {
3848  *ofilename << line << std::endl;
3849  }
3850  ofilename->close();
3851  delete ofilename;
3852  ifilename->close();
3853  delete ifilename;
3854 
3855  ofname.str("");
3856  ifilename = findfile("rackhv.js");
3857  ofname << "rackhv.js";
3858  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3859  while (getline(*ifilename, line)) {
3860  *ofilename << line << std::endl;
3861  }
3862  ofilename->close();
3863  delete ofilename;
3864  ifilename->close();
3865  delete ifilename;
3866 
3867  ofname.str("");
3868  ifilename = findfile("layer.js");
3869  ofname << "layer.js";
3870  ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3871  while (getline(*ifilename, line)) {
3872  *ofilename << line << std::endl;
3873  }
3874  ofilename->close();
3875  delete ofilename;
3876  ifilename->close();
3877  delete ifilename;
3878 
3879  command = "scp -r ../../DQM/TrackerCommon/test/jquery/ .";
3880  std::cout << "Executing " << command << std::endl;
3881  system(command.c_str());
3882  command = "scp -r ../../CommonTools/TrackerMap/data/images/ .";
3883  std::cout << "Executing " << command << std::endl;
3884  system(command.c_str());
3885  }
3886 
3887  std::ostringstream outs;
3888  outs << outputfilename << ".png";
3889  if (saveWebInterface)
3890  save(true, minval, maxval, outs.str(), 3000, 1600);
3891  else {
3892  if (saveGeoTrackerMap)
3893  save(true, minval, maxval, s, width, height);
3894  }
3895  if (saveWebInterface) {
3896  std::ostringstream outs;
3897  outs << outputfilename << ".png";
3898  temporary_file = false;
3899  printlayers(true, minval, maxval, outputfilename);
3900 
3901  //Now print a text file for each layer
3902  std::ofstream *txtfile;
3903  for (int layer = 1; layer < 44; layer++) {
3904  std::ostringstream outs;
3905  outs << outputfilename << "layer" << layer << ".html";
3906  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3907  *txtfile << "<html><head></head> <body>" << std::endl;
3908  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3909  for (int module = 1; module < 200; module++) {
3910  int key = layer * 100000 + ring * 1000 + module;
3911  TmModule *mod = smoduleMap[key];
3912  if (mod != nullptr && !mod->notInUse()) {
3913  int idmod = mod->idex;
3914  int nchan = 0;
3915  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3916  std::multimap<const int, TmApvPair *>::iterator pos;
3917  for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
3918  TmApvPair *apvpair = pos->second;
3919  if (apvpair != nullptr) {
3920  nchan++;
3921  *txtfile << apvpair->text << std::endl;
3922  }
3923  }
3924  *txtfile << "</pre><h3>" << mod->name << "</h3>" << std::endl;
3925  }
3926  }
3927  }
3928  *txtfile << "</body></html>" << std::endl;
3929  txtfile->close();
3930  delete txtfile;
3931  }
3932  }
3933  if (enableFedProcessing) {
3934  std::ostringstream outs1, outs2;
3935  if (saveWebInterface)
3936  outs1 << outputfilename << "fed.png";
3937  else
3938  outs1 << outputfilename << "fed." << filetype;
3939  save_as_fedtrackermap(true, 0., 0., outs1.str(), width, height);
3940  if (saveWebInterface) {
3941  outs2 << outputfilename << ".xml";
3942  save_as_fedtrackermap(true, 0., 0., outs2.str(), 3000, 1600);
3943  //And a text file for each crate
3944  std::map<int, int>::iterator i_fed;
3945  std::ofstream *txtfile;
3946  for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
3947  std::ostringstream outs;
3948  outs << outputfilename << "crate" << crate << ".html";
3949  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3950  *txtfile << "<html><head></head> <body>" << std::endl;
3951  for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
3952  if (i_fed->second == crate) {
3953  int fedId = i_fed->first;
3954  for (int nconn = 0; nconn < 96; nconn++) {
3955  int key = fedId * 1000 + nconn;
3956  TmApvPair *apvPair = apvMap[key];
3957  if (apvPair != nullptr) {
3958  int idmod = apvPair->idex;
3959  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3960  *txtfile << apvPair->text << std::endl;
3961  std::ostringstream outs;
3962  outs << "fedchannel " << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connects to module "
3963  << apvPair->mod->idex;
3964  *txtfile << "</pre><h3>" << outs.str() << "</h3>" << std::endl;
3965  }
3966  }
3967  }
3968  }
3969  *txtfile << "</body></html>" << std::endl;
3970  txtfile->close();
3971  delete txtfile;
3972  }
3973  }
3974  }
3975  if (enableFecProcessing) {
3976  std::ostringstream outs1, outs2;
3977  if (saveWebInterface)
3978  outs1 << outputfilename << "fec.png";
3979  else
3980  outs1 << outputfilename << "fec." << filetype;
3981  save_as_fectrackermap(true, 0., 0., outs1.str(), width, height);
3982  if (saveWebInterface) {
3983  outs2 << outputfilename << ".xml";
3984  save_as_fectrackermap(true, 0., 0., outs2.str(), 3000, 1600);
3985  //And a text file for each crate
3986  std::ofstream *txtfile;
3987  std::map<int, TmCcu *>::iterator i_ccu;
3988  std::multimap<TmCcu *, TmModule *>::iterator it;
3989  std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
3990  for (int crate = 1; crate < (nfeccrates + 1); crate++) {
3991  std::ostringstream outs;
3992  outs << outputfilename << "feccrate" << crate << ".html";
3993  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3994  *txtfile << "<html><head></head> <body>" << std::endl;
3995  for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
3996  TmCcu *ccu = i_ccu->second;
3997  if (ccu != nullptr && ccu->getCcuCrate() == crate) {
3998  int idmod = ccu->idex;
3999  *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
4000  *txtfile << ccu->text << std::endl;
4001  std::ostringstream outs;
4002  if (ccu->nmod == 0)
4003  outs << "ccu is in position" << ccu->mpos << "in ring but doesn't seem to have any module connected";
4004  else {
4005  outs << "ccu is in position " << ccu->mpos << " in ring and connects " << ccu->nmod << " modules"
4006  << std::endl;
4007  ret = fecModuleMap.equal_range(ccu);
4008  for (it = ret.first; it != ret.second; ++it) {
4009  outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << "\n\n";
4010  }
4011 
4012  *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
4013  } //ifccu->nmod==0
4014  } //if ccu!=0
4015  } //for i_ccu
4016  *txtfile << "</body></html>" << std::endl;
4017  txtfile->close();
4018  } //for int crate
4019  }
4020  }
4021  if (enableLVProcessing) {
4022  std::ostringstream outs3, outs4;
4023  if (saveWebInterface)
4024  outs3 << outputfilename << "psu.png";
4025  else
4026  outs3 << outputfilename << "psu." << filetype;
4027  save_as_psutrackermap(true, 0., 0., outs3.str(), width, height);
4028  if (saveWebInterface) {
4029  outs4 << outputfilename << ".xml";
4030  save_as_psutrackermap(true, 0., 0., outs4.str(), 3000, 1600);
4031  //And a text file for each rack
4032 
4033  std::ofstream *txtfile;
4034  std::map<int, TmPsu *>::iterator ipsu;
4035  std::multimap<TmPsu *, TmModule *>::iterator it;
4036  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
4037  for (int rack = 1; rack < (npsuracks + 1); rack++) {
4038  std::ostringstream outs;
4039 
4040  outs << outputfilename << "psurack" << rack << ".html";
4041  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4042  *txtfile << "<html><head></head> <body>" << std::endl;
4043  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
4044  TmPsu *psu = ipsu->second;
4045  if (psu != nullptr && psu->getPsuRack() == rack) {
4046  *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
4047  *txtfile << psu->text << std::endl;
4048  std::ostringstream outs;
4049  if (psu->nmod == 0)
4050  outs << "Ps is in position" << psu->getPsuBoard()
4051  << "in crate but doesn't seem to have any module connected";
4052  else {
4053  outs << "PS is in position " << psu->getPsuBoard() << " in crate and connects to " << psu->nmod
4054  << " modules. " << std::endl;
4055 
4056  ret = psuModuleMap.equal_range(psu);
4057  for (it = ret.first; it != ret.second; ++it) {
4058  outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << " <br>"
4059  << std::endl;
4060  }
4061  *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
4062  }
4063  }
4064  }
4065  *txtfile << "</body></html>" << std::endl;
4066  txtfile->close();
4067  }
4068  }
4069  }
4070 
4071  if (enableHVProcessing) {
4072  std::ostringstream outs5, outs6;
4073  if (saveWebInterface)
4074  outs5 << outputfilename << "hv.png";
4075  else
4076  outs5 << outputfilename << "hv." << filetype;
4077  save_as_HVtrackermap(true, 0., 0., outs5.str(), width, height);
4078  if (saveWebInterface) {
4079  outs6 << outputfilename << ".xml";
4080  save_as_HVtrackermap(true, 0., 0., outs6.str(), 3000, 1600);
4081  //And a text file for each rack
4082 
4083  std::ofstream *txtfile;
4084  std::map<int, TmPsu *>::iterator ipsu;
4085  std::multimap<TmPsu *, TmModule *>::iterator it;
4086  std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
4087  for (int rack = 1; rack < (npsuracks + 1); rack++) {
4088  std::ostringstream outs;
4089 
4090  outs << outputfilename << "HVrack" << rack << ".html";
4091  txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4092  *txtfile << "<html><head></head> <body>" << std::endl;
4093  for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
4094  TmPsu *psu = ipsu->second;
4095  if (psu != nullptr && psu->getPsuRack() == rack) {
4096  *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
4097  *txtfile << psu->textHV2 << std::endl;
4098  std::ostringstream outsHV2;
4099  if (psu->nmodHV2 == 0)
4100  outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()
4101  << "in crate but doesn't seem to have any module connected";
4102  else {
4103  outsHV2 << "HV Channel002 is in position " << psu->getPsuBoard() << " in crate and connects to "
4104  << psu->nmodHV2 << " modules. "
4105  << " <br>" << std::endl;
4106 
4107  ret = psuModuleMap.equal_range(psu);
4108  for (it = ret.first; it != ret.second; ++it) {
4109  if ((*it).second->HVchannel == 2) {
4110  outsHV2 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
4111  << " <br>" << std::endl;
4112  }
4113  }
4114  *txtfile << "</pre><h4>" << outsHV2.str() << "</h4>" << std::endl;
4115  }
4116 
4117  *txtfile << psu->textHV3 << std::endl;
4118  std::ostringstream outsHV3;
4119  if (psu->nmodHV3 == 0)
4120  outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()
4121  << "in crate but doesn't seem to have any module connected";
4122  else {
4123  outsHV3 << "HV Channel003 is in position " << psu->getPsuBoard() << " in crate and connects to "
4124  << psu->nmodHV3 << " modules. "
4125  << " <br>" << std::endl;
4126 
4127  ret = psuModuleMap.equal_range(psu);
4128  for (it = ret.first; it != ret.second; ++it) {
4129  if ((*it).second->HVchannel == 3) {
4130  outsHV3 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
4131  << " <br>" << std::endl;
4132  }
4133  }
4134  *txtfile << "</pre><h4>" << outsHV3.str() << "</h4>" << std::endl;
4135  }
4136  }
4137  }
4138  *txtfile << "</body></html>" << std::endl;
4139  txtfile->close();
4140  }
4141  }
4142  }
4143 }
4144 
4146  std::ifstream *ifilename;
4147  std::string ifname;
4148  if (!jsPath.empty()) {
4149  ifname = jsPath + filename;
4150  ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4151  if (!ifilename) {
4152  ifname = "CommonTools/TrackerMap/data/" + filename;
4153  ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4154  }
4155  } else {
4156  ifname = "CommonTools/TrackerMap/data/" + filename;
4157  ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4158  }
4159  if (!ifilename)
4160  std::cout << "File " << filename << " missing" << std::endl;
4161  return ifilename;
4162 }
4163 void TrackerMap::printlayers(bool print_total, float minval, float maxval, std::string outputfilename) {
4164  std::ofstream *xmlfile;
4165  saveAsSingleLayer = true;
4166  if (!print_total) {
4167  for (int layer = 1; layer < 44; layer++) {
4168  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4169  for (int module = 1; module < 200; module++) {
4170  int key = layer * 100000 + ring * 1000 + module;
4171  TmModule *mod = smoduleMap[key];
4172  if (mod != nullptr && !mod->notInUse()) {
4173  mod->value = mod->value / mod->count;
4174  }
4175  }
4176  }
4177  }
4178  }
4179  if (minvalue >= maxvalue) {
4180  minvalue = 9999999.;
4181  maxvalue = -9999999.;
4182  for (int layer = 1; layer < 44; layer++) {
4183  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4184  for (int module = 1; module < 200; module++) {
4185  int key = layer * 100000 + ring * 1000 + module;
4186  TmModule *mod = smoduleMap[key];
4187  if (mod != nullptr && !mod->notInUse()) {
4188  if (minvalue > mod->value)
4189  minvalue = mod->value;
4190  if (maxvalue < mod->value)
4191  maxvalue = mod->value;
4192  }
4193  }
4194  }
4195  }
4196  }
4197  for (int layer = 1; layer < 44; layer++) {
4198  std::ostringstream outs;
4199  outs << outputfilename << "layer" << layer << ".xml";
4200  xmlfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4201  *xmlfile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
4202  *xmlfile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
4203  *xmlfile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
4204  *xmlfile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
4205  *xmlfile << "<script type=\"text/ecmascript\" xlink:href=\"layer.js\" />" << std::endl;
4206  *xmlfile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
4207  "onload=\"TrackerLayer.init()\">"
4208  << std::endl;
4209  if (layer < 31)
4210  *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,1.)\" > " << std::endl;
4211  else
4212  *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,0.8)\" > " << std::endl;
4213  *xmlfile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />" << std::endl;
4214  *xmlfile << "<svg:polygon id=\"fed\" mapAttribute=\"fed\" points=\"250,40 250,10 230,10 230,40\" "
4215  "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4216  "fill=\"rgb(0,127,255)\"/>"
4217  << std::endl;
4218  *xmlfile << "<svg:polygon id=\"fec\" mapAttribute=\"fec\" points=\"228,40 228,10 208,10 208,40\" "
4219  "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4220  "fill=\"rgb(0,127,255)\"/>"
4221  << std::endl;
4222  *xmlfile << "<svg:polygon id=\"lv\" mapAttribute=\"lv\" points=\"206,40 206,10 186,10 186,40\" "
4223  "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4224  "fill=\"rgb(0,127,255)\"/>"
4225  << std::endl;
4226  *xmlfile << "<svg:polygon id=\"hv\" mapAttribute=\"hv\" points=\"184,40 184,10 164,10 164,40\" "
4227  "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4228  "fill=\"rgb(0,127,255)\"/>"
4229  << std::endl;
4230  *xmlfile << "<svg:polygon id=\"plot\" mapAttribute=\"plot\" points=\"155,45 155,5 135,5 135,45\" "
4231  "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4232  "fill=\"rgb(200,0,0)\"/>"
4233  << std::endl;
4234 
4235  // nlay=layer;
4236  defwindow(layer);
4237  for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4238  for (int module = 1; module < 200; module++) {
4239  int key = layer * 100000 + ring * 1000 + module;
4240  TmModule *mod = smoduleMap[key];
4241  if (mod != nullptr && !mod->notInUse()) {
4242  drawModule(mod, key, layer, print_total, xmlfile);
4243  }
4244  }
4245  }
4246  *xmlfile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\">" << std::endl;
4247  *xmlfile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
4248  *xmlfile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
4249  *xmlfile << "<tspan id=\"line3\" x=\"40\" y=\"90\"> </tspan> " << std::endl;
4250  *xmlfile << "<tspan id=\"line4\" x=\"40\" y=\"120\"> </tspan> " << std::endl;
4251  if (layer > 33) {
4252  *xmlfile << "<tspan mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4253  "onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"228\" font-size=\"12\" font-family=\"arial\" "
4254  "fill=\"white\">FED</tspan> "
4255  << std::endl;
4256  *xmlfile << "<tspan mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4257  "onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"258\" font-size=\"12\" font-family=\"arial\" "
4258  "fill=\"white\">FEC</tspan> "
4259  << std::endl;
4260  *xmlfile << "<tspan mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4261  "onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"289\" font-size=\"12\" font-family=\"arial\" "
4262  "fill=\"white\">LV</tspan> "
4263  << std::endl;
4264  *xmlfile << "<tspan mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4265  "onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"319\" font-size=\"12\" font-family=\"arial\" "
4266  "fill=\"white\">HV</tspan> "
4267  << std::endl;
4268  *xmlfile << "<tspan mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4269  "onmouseout=\"chooseMap(evt);\" x=\"12\" y=\"360\" font-size=\"12\" font-family=\"arial\" "
4270  "fill=\"white\">PLOT</tspan> "
4271  << std::endl;
4272  } else {
4273  *xmlfile << "<tspan mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4274  "onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"228\" font-size=\"12\" font-family=\"arial\" "
4275  "fill=\"white\">FED</tspan> "
4276  << std::endl;
4277  *xmlfile << "<tspan mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4278  "onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"258\" font-size=\"12\" font-family=\"arial\" "
4279  "fill=\"white\">FEC</tspan> "
4280  << std::endl;
4281  *xmlfile << "<tspan mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4282  "onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"289\" font-size=\"12\" font-family=\"arial\" "
4283  "fill=\"white\">LV</tspan> "
4284  << std::endl;
4285  *xmlfile << "<tspan mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4286  "onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"319\" font-size=\"12\" font-family=\"arial\" "
4287  "fill=\"white\">HV</tspan> "
4288  << std::endl;
4289  *xmlfile << "<tspan mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4290  "onmouseout=\"chooseMap(evt);\" x=\"17\" y=\"360\" font-size=\"12\" font-family=\"arial\" "
4291  "fill=\"white\">PLOT</tspan> "
4292  << std::endl;
4293  }
4294  *xmlfile << " </text> </svg>" << std::endl;
4295  xmlfile->close();
4296  delete xmlfile;
4297  }
4298  saveAsSingleLayer = false;
4299 }
4300 
4302  if (legInfos_.empty()) {
4303  legInfos_.reserve(8);
4304 
4305  legInfos_.push_back(new TPolyLine(0));
4306  legInfos_.back()->SetFillColor(kGreen);
4307  legInfos_.push_back(new TPolyLine(0));
4308  legInfos_.back()->SetFillColor(kBlue - 9);
4309  legInfos_.push_back(new TPolyLine(0));
4310  legInfos_.back()->SetFillColor(kRed + 2);
4311  legInfos_.push_back(new TPolyLine(0));
4312  legInfos_.back()->SetFillColor(kPink - 9);
4313  legInfos_.push_back(new TPolyLine(0));
4314  legInfos_.back()->SetFillColor(kOrange + 2);
4315  legInfos_.push_back(new TPolyLine(0));
4316  legInfos_.back()->SetFillColor(kYellow);
4317  legInfos_.push_back(new TPolyLine(0));
4318  legInfos_.back()->SetFillColor(kRed + 1);
4319  legInfos_.push_back(new TPolyLine(0));
4320  legInfos_.back()->SetFillColor(kViolet - 5);
4321  legKeys_ = {"Good Modules",
4322  "Excluded FED",
4323  "FED errors",
4324  "# Clusters",
4325  "# Digis",
4326  "PCL bad",
4327  "# Clusters & Digis",
4328  "DCS Error"};
4329  }
4330 
4331  TLegend *myL = new TLegend(0.56, 0.87, 0.95, 0.99);
4332  myL->SetNColumns(2);
4333  myL->SetBorderSize(0);
4334  myL->SetFillColor(38);
4335  for (unsigned int i = 0; i < legInfos_.size(); i++) {
4336  myL->AddEntry((TObject *)legInfos_[i], legKeys_[i].c_str(), "f");
4337  }
4338  // myL->Draw();
4339  return myL;
4340 }
std::vector< TPolyLine * > legInfos_
Definition: TrackerMap.h:685
TmModule * mod
Definition: TmApvPair.h:16
void reset()
Definition: TrackerMap.cc:462
bool tkMapLog
Definition: TrackerMap.h:198
void fill_hv_channel2(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:3179
std::string text
Definition: TmApvPair.h:12
int getPsuBranch()
Definition: TmPsu.h:17
#define NUMFEDCRATE_INCOLUMN
Definition: TrackerMap.h:60
void build()
Definition: TrackerMap.cc:3316
float minvalue
Definition: TrackerMap.h:675
TrackerMap(std::string s=" ", int xsize1=340, int ysize1=200)
Definition: TrackerMap.cc:443
ModApvPair apvModuleMap
Definition: TrackerMap.h:178
double ydpixelc(double y)
Definition: TrackerMap.h:311
std::ifstream * findfile(std::string filename)
Definition: TrackerMap.cc:4145
int nfeccrates
Definition: TrackerMap.h:663
int redHV2
Definition: TmPsu.h:38
void fillc_all_blank()
Definition: TrackerMap.cc:3245
#define NUMPSURACK_INCOLUMN
Definition: TrackerMap.h:47
double ydpixelfec(double y)
Definition: TrackerMap.h:329
int getmoduleCount(int subdet, int partdet, int layer, int ring)
Definition: TrackerMap.h:550
float value
Definition: TmModule.h:11
MapCcu ccuMap
Definition: TrackerMap.h:183
int green
Definition: TmApvPair.h:10
int mpos
Definition: TmApvPair.h:17
std::string cmodid_HV2
Definition: TmPsu.h:50
int nmodHV3
Definition: TmPsu.h:48
void fillc_hv_channel2(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:3152
SmoduleMap smoduleMap
Definition: TrackerMap.h:172
std::ifstream * inputfile
Definition: TrackerMap.h:672
std::ofstream * savefile
Definition: TrackerMap.h:670
bool psetAvailable
Definition: TrackerMap.h:204
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
#define YFEDOFFSET
Definition: TrackerMap.h:67
int count
Definition: TmPsu.h:43
int idex
Definition: TmPsu.h:11
~TrackerMap()
default destructor
Definition: TrackerMap.cc:528
std::string cmodid
Definition: TmCcu.h:15
static const uint32_t invalid32_
Definition: Constants.h:15
bool saveGeoTrackerMap
Definition: TrackerMap.h:193
int countHV2
Definition: TmPsu.h:44
ret
prodAgent to be discontinued
int module(int fedId, int fedCh)
Definition: TrackerMap.cc:3202
bool enableFecProcessing
Definition: TrackerMap.h:195
#define XPSURSIZE
Definition: TrackerMap.h:49
int layer
Definition: TmCcu.h:16
void defwindow(int num_lay)
Definition: TrackerMap.h:397
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define NUMFEDCH_INCOLUMN
Definition: TrackerMap.h:54
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:1977
int getCcuRing()
Definition: TmCcu.h:27
double xdpixelc(double x)
Definition: TrackerMap.h:303
void defpsuwindow(int num_rack)
Definition: TrackerMap.h:384
bool addPixelFlag
Definition: TrackerMap.h:682
int number_modules
Definition: TrackerMap.h:676
bool saveWebInterface
Definition: TrackerMap.h:192
std::string infilename
Definition: TrackerMap.h:202
int getlayerCount(int subdet, int partdet)
Definition: TrackerMap.h:253
int npsuracks
Definition: TrackerMap.h:664
void fill_current_val_fed_channel(int fedId, int fedCh, float current_val)
Definition: TrackerMap.cc:3088
float value
Definition: TmPsu.h:40
#define YFEDCSIZE
Definition: TrackerMap.h:65
int getPsuBoard()
Definition: TmPsu.h:31
int red
Definition: TmPsu.h:37
int greenHV3
Definition: TmPsu.h:39
bool enableFedProcessing
Definition: TrackerMap.h:194
int layer
Definition: TmModule.h:27
ImoduleMap imoduleMap
Definition: TrackerMap.h:174
int count
Definition: TmCcu.h:11
int firstRing[43]
Definition: TrackerMap.h:655
float gminvalue
Definition: TrackerMap.h:674
int nmod
Definition: TmCcu.h:14
#define NUMFEDCRATE_INROW
Definition: TrackerMap.h:61
void fillc_fec_channel(int crate, int slot, int ring, int addr, int red, int green, int blue)
Definition: TrackerMap.cc:3100
std::string jsPath
Definition: TrackerMap.h:203
bool enableHVProcessing
Definition: TrackerMap.h:197
double xdpixelfec(double x)
Definition: TrackerMap.h:321
constexpr std::array< uint8_t, layerIndexSize > layer
bool posrel
Definition: TrackerMap.h:667
int getFedId()
Definition: TmApvPair.h:22
T getUntrackedParameter(std::string const &, T const &) const
int getPsuDcs()
Definition: TmPsu.h:13
int getCcuSlot()
Definition: TmCcu.h:22
int red
Definition: TmApvPair.h:10
double phival(double x, double y)
Definition: TrackerMap.h:205
txtfile
Delete all three files at once to make sure the user never sees stale data (e.g.
void fill_all_blank()
Definition: TrackerMap.cc:3252
void fillc_lv_channel(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:3126
std::vector< std::string > legKeys_
Definition: TrackerMap.h:686
unsigned int idex
Definition: TmModule.h:28
void save_as_psutrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="psu_svgmap.svg", int width=100+(360+100) *5+300, int height=50+(150+50) *6+300)
Definition: TrackerMap.cc:2298
int getringCount(int subdet, int partdet, int layer)
Definition: TrackerMap.h:507
int np
Definition: AMPTWrapper.h:43
double xdpixelpsu(double x)
Definition: TrackerMap.h:339
int nmod
Definition: TmPsu.h:46
void drawHV3(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:1589
std::string PsuId
Definition: TmModule.h:17
T sqrt(T t)
Definition: SSEVec.h:19
void save_as_fedtrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="fed_svgmap.svg", int width=100+(90+100) *31+300, int height=150+(2940+150) *1+300)
Definition: TrackerMap.cc:2604
#define NUMFED_INCOLUMN
Definition: TrackerMap.h:56
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:811
bool saveAsSingleLayer
Definition: TrackerMap.h:681
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int blueHV3
Definition: TmPsu.h:39
void deffecwindow(int num_crate)
Definition: TrackerMap.h:370
filetype
Definition: symbols.py:55
bool temporary_file
Definition: TrackerMap.h:677
bool onlyPixelFlag
Definition: TrackerMap.h:683
std::ofstream * svgfile
Definition: TrackerMap.h:669
void load(std::string s="tmap.svg")
Definition: TrackerMap.cc:2909
int greenHV2
Definition: TmPsu.h:38
#define XFEDCSIZE
Definition: TrackerMap.h:64
static const int npoints
Definition: value.py:1
int getCcuCrate()
Definition: TmCcu.h:18
int green
Definition: TmCcu.h:8
const std::vector< SiStripFecCrate > & crates() const
int getPsuRack()
Definition: TmPsu.h:22
int nmodHV2
Definition: TmPsu.h:47
double ydpixel(double y)
Definition: TrackerMap.h:286
void drawModule(TmModule *mod, int key, int layer, bool total, std::ofstream *file)
Definition: TrackerMap.cc:569
int green
Definition: TmPsu.h:37
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:1116
void init()
Definition: TrackerMap.cc:472
void fillc_fed_channel(int fedId, int fedCh, int red, int green, int blue)
Definition: TrackerMap.cc:3062
xmlfile
Make an XML representation of the misalignment.
int getcolor(float value, int palette)
Definition: TrackerMap.cc:3361
int count
Definition: TmModule.h:12
std::string psId
Definition: TmPsu.h:12
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:135
#define M_PI
void printlayers(bool print_total=true, float minval=0., float maxval=0., std::string s="layer")
Definition: TrackerMap.cc:4163
int psuIdex
Definition: TmModule.h:18
SvgFed slotMap
Definition: TrackerMap.h:181
int mpos
Definition: TmCcu.h:17
void drawHV2(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:1488
int redHV3
Definition: TmPsu.h:39
void drawCcu(int crate, int numfed_incrate, bool total, TmCcu *ccu, std::ofstream *file, bool useCcuValue)
Definition: TrackerMap.cc:1274
short int HVchannel
Definition: TmModule.h:19
int getKey()
Definition: TmModule.h:22
int green
Definition: TmModule.h:10
int CcuId
Definition: TmModule.h:16
int count
Definition: TmApvPair.h:13
SvgFed fedMap
Definition: TrackerMap.h:180
PsuModule psuModuleMap
Definition: TrackerMap.h:189
float value
Definition: TmCcu.h:9
#define YPSUOFFSET
Definition: TrackerMap.h:52
std::string cmodid_HV3
Definition: TmPsu.h:51
void fill_hv_channel3(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:3190
#define NUMPSUCRATE_INCOLUMN
Definition: TrackerMap.h:46
float valueHV2
Definition: TmPsu.h:42
bool printflag
Definition: TrackerMap.h:191
static const uint16_t invalid_
Definition: Constants.h:16
int crate
Definition: TmApvPair.h:15
int firstcrate
Definition: TrackerMap.h:662
TLegend * buildLegend()
Definition: TrackerMap.cc:4301
FecModule fecModuleMap
Definition: TrackerMap.h:185
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
void setRange(float min, float max)
Definition: TrackerMap.cc:774
void drawPalette(std::ofstream *file, int xoffset=3660, int yoffset=1540)
Definition: TrackerMap.cc:3014
bool notInUse()
Definition: TmModule.h:23
#define YPSURSIZE
Definition: TrackerMap.h:50
list command
Definition: mps_check.py:25
int red
Definition: TmModule.h:10
int blue
Definition: TmModule.h:10
std::string title
Definition: TrackerMap.h:201
double xdpixel(double x)
Definition: TrackerMap.h:278
int idex
Definition: TmCcu.h:12
void printonline()
Definition: TrackerMap.cc:3408
int nlayer(int det, int part, int lay)
Definition: TrackerMap.h:607
Definition: colors.py:1
std::string textHV3
Definition: TmPsu.h:54
int red
Definition: TmCcu.h:8
#define NUMFED_INROW
Definition: TrackerMap.h:57
SvgApvPair apvMap
Definition: TrackerMap.h:176
void print(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2943
col
Definition: cuy.py:1009
std::string text
Definition: TmPsu.h:52
int countHV3
Definition: TmPsu.h:45
void fill_fec_channel(int crate, int slot, int ring, int addr, float qty)
Definition: TrackerMap.cc:3114
float gmaxvalue
Definition: TrackerMap.h:674
int idex
Definition: TmApvPair.h:14
void fill_current_val(int idmod, float current_val)
Definition: TrackerMap.cc:3259
float maxvalue
Definition: TrackerMap.h:675
std::string cmodid_LV
Definition: TmPsu.h:49
float valueHV3
Definition: TmPsu.h:41
step
Definition: StallMonitor.cc:98
void setText(int idmod, std::string s)
Definition: TrackerMap.cc:3299
int blue
Definition: TmCcu.h:8
#define XFEDOFFSET
Definition: TrackerMap.h:66
bool enableLVProcessing
Definition: TrackerMap.h:196
#define NUMPSURACK_INROW
Definition: TrackerMap.h:48
bool firstcall
Definition: TrackerMap.h:668
std::string textHV2
Definition: TmPsu.h:53
int blue
Definition: TmPsu.h:37
MapPsu psuMap
Definition: TrackerMap.h:187
static bool isRingStereo(int key)
Definition: TrackerMap.h:596
Definition: TmCcu.h:4
int blueHV2
Definition: TmPsu.h:38
void defcwindow(int num_crate)
Definition: TrackerMap.h:358
std::ifstream * jsfile
Definition: TrackerMap.h:671
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::string text
Definition: TmCcu.h:10
Definition: TmPsu.h:6
FedsConstIterRange fedIds() const
#define XPSUOFFSET
Definition: TrackerMap.h:51
void fill_lv_channel(int rack, int crate, int board, float qty)
Definition: TrackerMap.cc:3140
std::vector< TColor * > vc
Definition: TrackerMap.h:169
#define NUMPSUCH_INROW
Definition: TrackerMap.h:45
float value
Definition: TmApvPair.h:11
void printall(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap", int width=6000, int height=3200)
Definition: TrackerMap.cc:3753
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
void drawPsu(int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue)
Definition: TrackerMap.cc:1377
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:3289
double ydpixelpsu(double y)
Definition: TrackerMap.h:347
ConnsConstIterRange fedConnections(uint16_t fed_id) const
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:1689
std::string name
Definition: TmModule.h:14
void fill_fed_channel(int fedId, int fedCh, float qty)
Definition: TrackerMap.cc:3211
int getFedCh()
Definition: TmApvPair.h:18
#define NUMFEDCH_INROW
Definition: TrackerMap.h:55
void fillc_hv_channel3(int rack, int crate, int board, int red, int green, int blue)
Definition: TrackerMap.cc:3165
int ntotRing[43]
Definition: TrackerMap.h:654
int getPsuCrate()
Definition: TmPsu.h:26
std::pair< float, float > getAutomaticRange()
Definition: TrackerMap.cc:783
std::string jsfilename
Definition: TrackerMap.h:202