Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:42

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiStripCommon
0004 // Class  :     SiStripFolderOrganizer
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  dkcira
0010 //         Created:  Thu Jan 26 23:52:43 CET 2006
0011 
0012 //
0013 
0014 #include <iostream>
0015 #include <sstream>
0016 
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 
0019 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0020 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0021 
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025 
0026 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0027 #define CONTROL_FOLDER_NAME "ControlView"
0028 #define MECHANICAL_FOLDER_NAME "MechanicalView"
0029 #define SEP "/"
0030 
0031 #include <cstring>
0032 
0033 SiStripFolderOrganizer::SiStripFolderOrganizer() {
0034   TopFolderName = "SiStrip";
0035   // get a pointer to DQMStore
0036   dbe_ = edm::Service<DQMStore>().operator->();
0037 }
0038 
0039 SiStripFolderOrganizer::~SiStripFolderOrganizer() {}
0040 
0041 void SiStripFolderOrganizer::setSiStripFolderName(std::string name) { TopFolderName = name; }
0042 
0043 std::string SiStripFolderOrganizer::getSiStripFolder() { return TopFolderName; }
0044 
0045 void SiStripFolderOrganizer::setSiStripFolder() {
0046   dbe_->setCurrentFolder(TopFolderName);
0047   return;
0048 }
0049 
0050 std::string SiStripFolderOrganizer::getSiStripTopControlFolder() {
0051   std::string lokal_folder = TopFolderName + CONTROL_FOLDER_NAME;
0052   return lokal_folder;
0053 }
0054 
0055 void SiStripFolderOrganizer::setSiStripTopControlFolder() {
0056   std::string lokal_folder = TopFolderName + CONTROL_FOLDER_NAME;
0057   dbe_->setCurrentFolder(lokal_folder);
0058   return;
0059 }
0060 
0061 std::string SiStripFolderOrganizer::getSiStripControlFolder(
0062     // unsigned short crate,
0063     unsigned short slot,
0064     unsigned short ring,
0065     unsigned short addr,
0066     unsigned short chan
0067     // unsigned short i2c
0068 ) {
0069   std::stringstream lokal_folder;
0070   lokal_folder << getSiStripTopControlFolder();
0071   //   if ( crate != all_ ) {// if ==all_ then remain in top control folder
0072   //     lokal_folder << SEP << "FecCrate" << crate;
0073   if (slot != all_) {
0074     lokal_folder << SEP << "FecSlot" << slot;
0075     if (ring != all_) {
0076       lokal_folder << SEP << "FecRing" << ring;
0077       if (addr != all_) {
0078         lokal_folder << SEP << "CcuAddr" << addr;
0079         if (chan != all_) {
0080           lokal_folder << SEP << "CcuChan" << chan;
0081           //        if ( i2c != all_ ) {
0082           //          lokal_folder << SEP << "I2cAddr" << i2c;
0083           //        }
0084         }
0085       }
0086     }
0087   }
0088   //   }
0089   std::string folder_name = lokal_folder.str();
0090   return folder_name;
0091 }
0092 
0093 void SiStripFolderOrganizer::setSiStripControlFolder(
0094     // unsigned short crate,
0095     unsigned short slot,
0096     unsigned short ring,
0097     unsigned short addr,
0098     unsigned short chan
0099     // unsigned short i2c
0100 ) {
0101   std::string lokal_folder = getSiStripControlFolder(slot, ring, addr, chan);
0102   dbe_->setCurrentFolder(lokal_folder);
0103   return;
0104 }
0105 
0106 std::pair<std::string, int32_t> SiStripFolderOrganizer::GetSubDetAndLayer(const uint32_t& detid,
0107                                                                           const TrackerTopology* tTopo,
0108                                                                           bool ring_flag) {
0109   std::string cSubDet;
0110   int32_t layer = 0;
0111   switch (StripSubdetector::SubDetector(StripSubdetector(detid).subdetId())) {
0112     case StripSubdetector::TIB:
0113       cSubDet = "TIB";
0114       layer = tTopo->tibLayer(detid);
0115       break;
0116     case StripSubdetector::TOB:
0117       cSubDet = "TOB";
0118       layer = tTopo->tobLayer(detid);
0119       break;
0120     case StripSubdetector::TID:
0121       cSubDet = "TID";
0122       if (ring_flag)
0123         layer = tTopo->tidRing(detid) * (tTopo->tidSide(detid) == 1 ? -1 : +1);
0124       else
0125         layer = tTopo->tidWheel(detid) * (tTopo->tidSide(detid) == 1 ? -1 : +1);
0126       break;
0127     case StripSubdetector::TEC:
0128       cSubDet = "TEC";
0129       if (ring_flag)
0130         layer = tTopo->tecRing(detid) * (tTopo->tecSide(detid) == 1 ? -1 : +1);
0131       else
0132         layer = tTopo->tecWheel(detid) * (tTopo->tecSide(detid) == 1 ? -1 : +1);
0133       break;
0134     default:
0135       edm::LogWarning("SiStripMonitorTrack") << "WARNING!!! this detid does not belong to tracker" << std::endl;
0136   }
0137   return std::make_pair(cSubDet, layer);
0138 }
0139 
0140 std::pair<std::string, int32_t> SiStripFolderOrganizer::GetSubDetAndLayerThickness(const uint32_t& detid,
0141                                                                                    const TrackerTopology* tTopo,
0142                                                                                    std::string& cThickness) {
0143   std::string cSubDet;
0144   int32_t layer = 0;
0145   int32_t ring = 0;
0146   switch (StripSubdetector::SubDetector(StripSubdetector(detid).subdetId())) {
0147     case StripSubdetector::TIB:
0148       cSubDet = "TIB";
0149       layer = tTopo->tibLayer(detid);
0150       cThickness = "THIN";
0151       break;
0152     case StripSubdetector::TOB:
0153       cSubDet = "TOB";
0154       layer = tTopo->tobLayer(detid);
0155       cThickness = "THICK";
0156       break;
0157     case StripSubdetector::TID:
0158       cSubDet = "TID";
0159       layer = tTopo->tidWheel(detid) * (tTopo->tidSide(detid) == 1 ? -1 : +1);
0160       cThickness = "THIN";
0161       break;
0162     case StripSubdetector::TEC:
0163       cSubDet = "TEC";
0164       layer = tTopo->tecWheel(detid) * (tTopo->tecSide(detid) == 1 ? -1 : +1);
0165       ring = tTopo->tecRing(detid) * (tTopo->tecSide(detid) == 1 ? -1 : +1);
0166       if (ring >= 1 && ring <= 4)
0167         cThickness = "THIN";
0168       else
0169         cThickness = "THICK";
0170       break;
0171     default:
0172       edm::LogWarning("SiStripMonitorTrack") << "WARNING!!! this detid does not belong to tracker" << std::endl;
0173   }
0174   return std::make_pair(cSubDet, layer);
0175 }
0176 
0177 std::pair<std::string, int32_t> SiStripFolderOrganizer::GetSubDetAndRing(const uint32_t& detid,
0178                                                                          const TrackerTopology* tTopo) {
0179   std::string cSubDet;
0180   int32_t ring = 0;
0181   switch (StripSubdetector::SubDetector(StripSubdetector(detid).subdetId())) {
0182     case StripSubdetector::TIB:
0183       cSubDet = "TIB";
0184       break;
0185     case StripSubdetector::TOB:
0186       cSubDet = "TOB";
0187       break;
0188     case StripSubdetector::TID:
0189       cSubDet = "TID";
0190       ring = tTopo->tidRing(detid) * (tTopo->tidSide(detid) == 1 ? -1 : +1);
0191       break;
0192     case StripSubdetector::TEC:
0193       cSubDet = "TEC";
0194       ring = tTopo->tecRing(detid) * (tTopo->tecSide(detid) == 1 ? -1 : +1);
0195       break;
0196     default:
0197       edm::LogWarning("SiStripMonitorTrack") << "WARNING!!! this detid does not belong to tracker" << std::endl;
0198   }
0199   return std::make_pair(cSubDet, ring);
0200 }
0201 
0202 void SiStripFolderOrganizer::setDetectorFolder(uint32_t rawdetid, const TrackerTopology* tTopo) {
0203   std::string folder_name;
0204   getFolderName(rawdetid, tTopo, folder_name);
0205   dbe_->setCurrentFolder(folder_name);
0206 }
0207 
0208 void SiStripFolderOrganizer::getSubDetLayerFolderName(std::stringstream& ss,
0209                                                       SiStripDetId::SubDetector subDet,
0210                                                       uint32_t layer,
0211                                                       uint32_t side) {
0212   //  std::cout << "[SiStripFolderOrganizer::getSubDetLayerFolderName] TopFolderName: " << TopFolderName << std::endl;
0213   ss << TopFolderName << SEP << MECHANICAL_FOLDER_NAME;
0214 
0215   std::stringstream sside;
0216   if (side == 1) {
0217     sside << "MINUS";
0218   } else if (side == 2) {
0219     sside << "PLUS";
0220   }
0221 
0222   if (subDet == SiStripDetId::TIB) {
0223     ss << SEP << "TIB" << SEP << "layer_" << layer << SEP;
0224   } else if (subDet == SiStripDetId::TID) {
0225     ss << SEP << "TID" << SEP << sside.str() << SEP << "wheel_" << layer << SEP;
0226   } else if (subDet == SiStripDetId::TOB) {
0227     ss << SEP << "TOB" << SEP << "layer_" << layer << SEP;
0228   } else if (subDet == SiStripDetId::TEC) {
0229     ss << SEP << "TEC" << SEP << sside.str() << SEP << "wheel_" << layer << SEP;
0230   } else {
0231     // ---------------------------  ???  --------------------------- //
0232     edm::LogWarning("SiStripTkDQM|WrongInput") << "no such SubDet :" << subDet << " no folder set!" << std::endl;
0233   }
0234 }
0235 
0236 void SiStripFolderOrganizer::getFolderName(int32_t rawdetid, const TrackerTopology* tTopo, std::string& lokal_folder) {
0237   lokal_folder = "";
0238   if (rawdetid == 0) {  // just top MechanicalFolder if rawdetid==0;
0239     return;
0240   }
0241   std::stringstream rest;
0242   SiStripDetId stripdet = SiStripDetId(rawdetid);
0243 
0244   if (stripdet.subDetector() == SiStripDetId::TIB) {
0245     // ---------------------------  TIB  --------------------------- //
0246 
0247     getSubDetLayerFolderName(rest, stripdet.subDetector(), tTopo->tibLayer(rawdetid));
0248 
0249     if (tTopo->tibIsZMinusSide(rawdetid))
0250       rest << "backward_strings" << SEP;
0251     else
0252       rest << "forward_strings" << SEP;
0253     if (tTopo->tibIsExternalString(rawdetid))
0254       rest << "external_strings" << SEP;
0255     else
0256       rest << "internal_strings" << SEP;
0257     rest << "string_" << tTopo->tibString(rawdetid) << SEP << "module_" << rawdetid;
0258   } else if (stripdet.subDetector() == SiStripDetId::TID) {
0259     // ---------------------------  TID  --------------------------- //
0260 
0261     getSubDetLayerFolderName(rest, stripdet.subDetector(), tTopo->tidWheel(rawdetid), tTopo->tidSide(rawdetid));
0262     rest << "ring_" << tTopo->tidRing(rawdetid) << SEP;
0263 
0264     if (tTopo->tidIsStereo(rawdetid))
0265       rest << "stereo_modules" << SEP;
0266     else
0267       rest << "mono_modules" << SEP;
0268     rest << "module_" << rawdetid;
0269   } else if (stripdet.subDetector() == SiStripDetId::TOB) {
0270     // ---------------------------  TOB  --------------------------- //
0271 
0272     getSubDetLayerFolderName(rest, stripdet.subDetector(), tTopo->tobLayer(rawdetid));
0273     if (tTopo->tobIsZMinusSide(rawdetid))
0274       rest << "backward_rods" << SEP;
0275     else
0276       rest << "forward_rods" << SEP;
0277     rest << "rod_" << tTopo->tobRod(rawdetid) << SEP << "module_" << rawdetid;
0278   } else if (stripdet.subDetector() == SiStripDetId::TEC) {
0279     // ---------------------------  TEC  --------------------------- //
0280 
0281     getSubDetLayerFolderName(rest, stripdet.subDetector(), tTopo->tecWheel(rawdetid), tTopo->tecSide(rawdetid));
0282     if (tTopo->tecIsBackPetal(rawdetid))
0283       rest << "backward_petals" << SEP;
0284     else
0285       rest << "forward_petals" << SEP;
0286 
0287     rest << "petal_" << tTopo->tecPetalNumber(rawdetid) << SEP << "ring_" << tTopo->tecRing(rawdetid) << SEP;
0288 
0289     if (tTopo->tecIsStereo(rawdetid))
0290       rest << "stereo_modules" << SEP;
0291     else
0292       rest << "mono_modules" << SEP;
0293 
0294     rest << "module_" << rawdetid;
0295   } else {
0296     // ---------------------------  ???  --------------------------- //
0297     edm::LogWarning("SiStripTkDQM|WrongInput")
0298         << "no such subdetector type :" << stripdet.subDetector() << " no folder set!" << std::endl;
0299     return;
0300   }
0301   lokal_folder += rest.str();
0302 }
0303 
0304 void SiStripFolderOrganizer::setLayerFolder(uint32_t rawdetid,
0305                                             const TrackerTopology* tTopo,
0306                                             int32_t layer,
0307                                             bool ring_flag) {
0308   std::string lokal_folder = TopFolderName + SEP + MECHANICAL_FOLDER_NAME;
0309   if (rawdetid == 0) {  // just top MechanicalFolder if rawdetid==0;
0310     dbe_->setCurrentFolder(lokal_folder);
0311     return;
0312   }
0313 
0314   std::ostringstream rest;
0315   SiStripDetId stripdet = SiStripDetId(rawdetid);
0316   if (stripdet.subDetector() == SiStripDetId::TIB) {
0317     // ---------------------------  TIB  --------------------------- //
0318 
0319     int tib_layer = tTopo->tibLayer(rawdetid);
0320     if (abs(layer) != tib_layer) {
0321       edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0322           << " expect " << abs(layer) << " but getting " << tTopo->tibLayer(rawdetid) << std::endl;
0323       return;
0324     }
0325     rest << SEP << "TIB" << SEP << "layer_" << tTopo->tibLayer(rawdetid);
0326   } else if (stripdet.subDetector() == SiStripDetId::TID) {
0327     // ---------------------------  TID  --------------------------- //
0328 
0329     int tid_ring = tTopo->tidRing(rawdetid);
0330 
0331     // side
0332     uint32_t side = tTopo->tidSide(rawdetid);
0333     std::stringstream sside;
0334     if (side == 1) {
0335       sside << "MINUS";
0336     } else if (side == 2) {
0337       sside << "PLUS";
0338     }
0339 
0340     if (ring_flag) {
0341       if (abs(layer) != tid_ring) {
0342         edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0343             << " expect " << abs(layer) << " but getting " << tTopo->tidRing(rawdetid) << std::endl;
0344         return;
0345       }
0346       rest << SEP << "TID" << SEP << sside.str() << SEP << "ring_" << tTopo->tidRing(rawdetid);
0347     } else {
0348       int tid_wheel = tTopo->tidWheel(rawdetid);
0349       if (abs(layer) != tid_wheel) {
0350         edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0351             << " expect " << abs(layer) << " but getting " << tTopo->tidWheel(rawdetid) << std::endl;
0352         return;
0353       }
0354       rest << SEP << "TID" << SEP << sside.str() << SEP << "wheel_" << tTopo->tidWheel(rawdetid);
0355     }
0356   } else if (stripdet.subDetector() == SiStripDetId::TOB) {
0357     // ---------------------------  TOB  --------------------------- //
0358 
0359     int tob_layer = tTopo->tobLayer(rawdetid);
0360     if (abs(layer) != tob_layer) {
0361       edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0362           << " expect " << abs(layer) << " but getting " << tTopo->tobLayer(rawdetid) << std::endl;
0363       return;
0364     }
0365     rest << SEP << "TOB" << SEP << "layer_" << tTopo->tobLayer(rawdetid);
0366   } else if (stripdet.subDetector() == SiStripDetId::TEC) {
0367     // ---------------------------  TEC  --------------------------- //
0368 
0369     // side
0370     uint32_t side = tTopo->tecSide(rawdetid);
0371     std::stringstream sside;
0372     if (side == 1) {
0373       sside << "MINUS";
0374     } else if (side == 2) {
0375       sside << "PLUS";
0376     }
0377 
0378     if (ring_flag) {
0379       int tec_ring = tTopo->tecRing(rawdetid);
0380       if (abs(layer) != tec_ring) {
0381         edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0382             << " expect " << abs(layer) << " but getting " << tTopo->tecRing(rawdetid) << std::endl;
0383         return;
0384       }
0385       rest << SEP << "TEC" << SEP << sside.str() << SEP << "ring_" << tTopo->tecRing(rawdetid);
0386     } else {
0387       int tec_wheel = tTopo->tecWheel(rawdetid);
0388       if (abs(layer) != tec_wheel) {
0389         edm::LogWarning("SiStripTkDQM|Layer mismatch!!!")
0390             << " expect " << abs(layer) << " but getting " << tTopo->tecWheel(rawdetid) << std::endl;
0391         return;
0392       }
0393       rest << SEP << "TEC" << SEP << sside.str() << SEP << "wheel_" << tTopo->tecWheel(rawdetid);
0394     }
0395   } else {
0396     // ---------------------------  ???  --------------------------- //
0397     edm::LogWarning("SiStripTkDQM|WrongInput")
0398         << "no such subdetector type :" << stripdet.subDetector() << " no folder set!" << std::endl;
0399     return;
0400   }
0401 
0402   lokal_folder += rest.str();
0403   dbe_->setCurrentFolder(lokal_folder);
0404 }
0405 
0406 void SiStripFolderOrganizer::getSubDetFolder(const uint32_t& detid,
0407                                              const TrackerTopology* tTopo,
0408                                              std::string& folder_name) {
0409   std::pair<std::string, std::string> subdet_and_tag = getSubDetFolderAndTag(detid, tTopo);
0410   folder_name = subdet_and_tag.first;
0411 }
0412 //
0413 // -- Get the name of Subdetector Layer folder
0414 //
0415 void SiStripFolderOrganizer::getLayerFolderName(std::stringstream& ss,
0416                                                 uint32_t rawdetid,
0417                                                 const TrackerTopology* tTopo,
0418                                                 bool ring_flag) {
0419   ss << TopFolderName + SEP + MECHANICAL_FOLDER_NAME;
0420   if (rawdetid == 0) {  // just top MechanicalFolder if rawdetid==0;
0421     return;
0422   }
0423 
0424   SiStripDetId stripdet = SiStripDetId(rawdetid);
0425   if (stripdet.subDetector() == SiStripDetId::TIB) {
0426     // ---------------------------  TIB  --------------------------- //
0427 
0428     ss << SEP << "TIB" << SEP << "layer_" << tTopo->tibLayer(rawdetid);
0429   } else if (stripdet.subDetector() == SiStripDetId::TID) {
0430     // ---------------------------  TID  --------------------------- //
0431 
0432     uint32_t side = tTopo->tidSide(rawdetid);
0433     std::stringstream sside;
0434     if (side == 1) {
0435       sside << "MINUS";
0436     } else if (side == 2) {
0437       sside << "PLUS";
0438     }
0439 
0440     if (ring_flag) {
0441       ss << SEP << "TID" << SEP << sside.str() << SEP << "ring_" << tTopo->tidRing(rawdetid);
0442     } else {
0443       ss << SEP << "TID" << SEP << sside.str() << SEP << "wheel_" << tTopo->tidWheel(rawdetid);
0444     }
0445   } else if (stripdet.subDetector() == SiStripDetId::TOB) {
0446     // ---------------------------  TOB  --------------------------- //
0447 
0448     ss << SEP << "TOB" << SEP << "layer_" << tTopo->tobLayer(rawdetid);
0449   } else if (stripdet.subDetector() == SiStripDetId::TEC) {
0450     // ---------------------------  TEC  --------------------------- //
0451 
0452     uint32_t side = tTopo->tecSide(rawdetid);
0453     std::stringstream sside;
0454     if (side == 1) {
0455       sside << "MINUS";
0456     } else if (side == 2) {
0457       sside << "PLUS";
0458     }
0459 
0460     if (ring_flag) {
0461       ss << SEP << "TEC" << SEP << sside.str() << SEP << "ring_" << tTopo->tecRing(rawdetid);
0462     } else {
0463       ss << SEP << "TEC" << SEP << sside.str() << SEP << "wheel_" << tTopo->tecWheel(rawdetid);
0464     }
0465   } else {
0466     // ---------------------------  ???  --------------------------- //
0467     edm::LogWarning("SiStripTkDQM|WrongInput")
0468         << "no such subdetector type :" << stripdet.subDetector() << " no folder set!" << std::endl;
0469     return;
0470   }
0471 }
0472 //
0473 // -- Get Subdetector Folder name and the Tag
0474 //
0475 std::pair<const std::string, const char*> SiStripFolderOrganizer::getSubDetFolderAndTag(const uint32_t& detid,
0476                                                                                         const TrackerTopology* tTopo) {
0477   const char* subdet_folder = "";
0478   const char* tag = "";
0479   switch (StripSubdetector::SubDetector(StripSubdetector(detid).subdetId())) {
0480     case StripSubdetector::TIB:
0481       subdet_folder = "TIB";
0482       tag = subdet_folder;
0483       break;
0484     case StripSubdetector::TOB:
0485       subdet_folder = "TOB";
0486       tag = subdet_folder;
0487       break;
0488     case StripSubdetector::TID:
0489       if (tTopo->tidSide(detid) == 2) {
0490         subdet_folder = "TID/PLUS";
0491         tag = "TID__PLUS";
0492       } else if (tTopo->tidSide(detid) == 1) {
0493         subdet_folder = "TID/MINUS";
0494         tag = "TID__MINUS";
0495       }
0496       break;
0497     case StripSubdetector::TEC:
0498       if (tTopo->tecSide(detid) == 2) {
0499         subdet_folder = "TEC/PLUS";
0500         tag = "TEC__PLUS";
0501       } else if (tTopo->tecSide(detid) == 1) {
0502         subdet_folder = "TEC/MINUS";
0503         tag = "TEC__MINUS";
0504       }
0505       break;
0506     default: {
0507       edm::LogWarning("SiStripCommon") << "WARNING!!! this detid does not belong to tracker" << std::endl;
0508       subdet_folder = "";
0509     }
0510   }
0511 
0512   std::string folder;
0513   folder.reserve(TopFolderName.size() + strlen(SEP MECHANICAL_FOLDER_NAME SEP) + strlen(subdet_folder) + 1);
0514   folder = TopFolderName + SEP MECHANICAL_FOLDER_NAME SEP + subdet_folder;
0515 
0516   return std::pair<const std::string, const char*>(folder, tag);
0517 }