CMS 3D CMS Logo

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