Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:44:51

0001 #ifndef HcalLutManager_h
0002 #define HcalLutManager_h
0003 
0004 /**
0005 
0006    \class HcalLutManager
0007    \brief Various manipulations with trigger Lookup Tables
0008    \author Gena Kukartsev, Brown University, March 14, 2008
0009 
0010 */
0011 
0012 #include <iostream>
0013 #include <string>
0014 #include <vector>
0015 #include <map>
0016 #include "CalibCalorimetry/HcalTPGAlgos/interface/LutXml.h"
0017 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0018 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0019 #include "CondFormats/HcalObjects/interface/AllObjects.h"
0020 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0021 #include "CaloOnlineTools/HcalOnlineDb/interface/HCALConfigDB.h"
0022 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
0023 #include "CalibFormats/HcalObjects/interface/HcalTPGCoder.h"
0024 #include "CalibCalorimetry/CaloTPG/interface/CaloTPGTranscoderULUT.h"
0025 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalAssistant.h"
0026 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalChannelIterator.h"
0027 #include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h"
0028 
0029 class XMLDOMBlock;
0030 
0031 class HcalLutSet {
0032 public:
0033   std::string label;
0034   std::vector<std::string> subdet;
0035   std::vector<int> eta_min, eta_max, phi_min, phi_max, depth_min, depth_max;
0036   std::vector<std::vector<unsigned int> > lut;
0037 };
0038 
0039 class HcalLutManager {
0040 public:
0041   HcalLutManager();
0042   HcalLutManager(std::vector<HcalGenericDetId>& map);
0043   HcalLutManager(const HcalElectronicsMap* _emap,
0044                  const HcalChannelQuality* _cq = nullptr,
0045                  uint32_t _status_word_to_mask = 0x0000);
0046 
0047   HcalLutManager(const HcalDbService* conditions,
0048                  const HcalChannelQuality* _cq = nullptr,
0049                  uint32_t _status_word_to_mask = 0x0000);
0050 
0051   ~HcalLutManager();
0052 
0053   void init(void);
0054   std::string& getLutXml(std::vector<unsigned int>& _lut);
0055 
0056   // crate=-1 stands for all crates
0057   // legacy - use old LMAP. Use the xxxEmap method instead
0058   std::map<int, std::shared_ptr<LutXml> > getLutXmlFromAsciiMaster(std::string _filename,
0059                                                                    std::string _tag,
0060                                                                    int _crate = -1,
0061                                                                    bool split_by_crate = true);
0062 
0063   std::map<int, std::shared_ptr<LutXml> > getLinearizationLutXmlFromAsciiMasterEmap(std::string _filename,
0064                                                                                     std::string _tag,
0065                                                                                     int _crate,
0066                                                                                     bool split_by_crate = true);
0067 
0068   std::map<int, std::shared_ptr<LutXml> > getLinearizationLutXmlFromAsciiMasterEmap_new(std::string _filename,
0069                                                                                         std::string _tag,
0070                                                                                         int _crate,
0071                                                                                         bool split_by_crate = true);
0072 
0073   std::map<int, std::shared_ptr<LutXml> > getCompressionLutXmlFromAsciiMaster(std::string _filename,
0074                                                                               std::string _tag,
0075                                                                               int _crate = -1,
0076                                                                               bool split_by_crate = true);
0077 
0078   std::map<int, std::shared_ptr<LutXml> > getLinearizationLutXmlFromCoder(const HcalTPGCoder& _coder,
0079                                                                           std::string _tag,
0080                                                                           bool split_by_crate = true);
0081 
0082   std::map<int, std::shared_ptr<LutXml> > getMasks(int var, std::string _tag, bool split_by_crate = true);
0083 
0084   std::map<int, std::shared_ptr<LutXml> > getLinearizationLutXmlFromCoderEmap(const HcalTPGCoder& _coder,
0085                                                                               std::string _tag,
0086                                                                               bool split_by_crate = true);
0087 
0088   std::map<int, std::shared_ptr<LutXml> > getCompressionLutXmlFromCoder(std::string _tag, bool split_by_crate = true);
0089 
0090   std::map<int, std::shared_ptr<LutXml> > getCompressionLutXmlFromCoder(const CaloTPGTranscoderULUT& _coder,
0091                                                                         std::string _tag,
0092                                                                         bool split_by_crate = true);
0093 
0094   std::map<int, std::shared_ptr<LutXml> > getZdcLutXml(std::string _tag, bool split_by_crate = true);
0095 
0096   std::map<int, std::shared_ptr<LutXml> > getHEFineGrainLUTs(std::string _tag, bool split_by_crate = true);
0097 
0098   // add two std::map<s with LUTs. Designed mainly for joining compression LUTs to linearization ones.
0099   void addLutMap(std::map<int, std::shared_ptr<LutXml> >& result, const std::map<int, std::shared_ptr<LutXml> >& other);
0100 
0101   // read LUTs from ASCII master file.
0102   HcalLutSet getLutSetFromFile(std::string _filename, int _type = 1);  // _type = 1 - linearization, 2 - compression
0103 
0104   int writeLutXmlFiles(std::map<int, std::shared_ptr<LutXml> >& _xml,
0105                        std::string _tag = "default_tag",
0106                        bool split_by_crate = true);
0107 
0108   int createLinLutXmlFiles(std::string _tag, std::string _lin_file, bool split_by_crate = true);
0109   int createCompLutXmlFilesFromCoder(std::string _tag, bool split_by_crate = true);
0110   int createAllLutXmlFiles(std::string _tag, std::string _lin_file, std::string _comp_file, bool split_by_crate = true);
0111   int createAllLutXmlFilesFromCoder(const HcalTPGCoder& _coder, std::string _tag, bool split_by_crate = true);
0112   int createLutXmlFiles_HBEFFromCoder_HOFromAscii(std::string _tag,
0113                                                   const HcalTPGCoder& _coder,
0114                                                   std::string _lin_file,
0115                                                   bool split_by_crate = true);
0116   int createLutXmlFiles_HBEFFromCoder_HOFromAscii(std::string _tag,
0117                                                   const HcalTPGCoder& _coder,
0118                                                   const CaloTPGTranscoderULUT& _transcoder,
0119                                                   std::string _lin_file,
0120                                                   bool split_by_crate = true);
0121 
0122   int createLutXmlFiles_HBEFFromCoder_HOFromAscii_ZDC(std::string _tag,
0123                                                       const HcalTPGCoder& _coder,
0124                                                       const CaloTPGTranscoderULUT& _transcoder,
0125                                                       std::string _lin_file,
0126                                                       bool split_by_crate = true);
0127 
0128   int createAllLutXmlFilesLinAsciiCompCoder(std::string _tag, std::string _lin_file, bool split_by_crate = true);
0129 
0130   // tests
0131   //    reading LUTs from a local XML
0132   int test_xml_access(std::string _tag, std::string _filename);
0133   int test_direct_xml_parsing(std::string _filename);
0134   void test_emap(void);
0135 
0136   // connect to local XML file with LUTs and local ASCII file with LMAP
0137   // connection interface through protected members db and lmap
0138   int read_lmap(std::string lmap_hbef_file, std::string lmap_ho_file);
0139   int read_luts(std::string lut_xml_file);
0140   int local_connect(std::string lut_xml_file, std::string lmap_hbef_file, std::string lmap_ho_file);
0141 
0142   // hcal::ConfigurationDatabase::LinearizerLUT
0143   // hcal::ConfigurationDatabase::CompressionLUT
0144   std::vector<unsigned int> getLutFromXml_old(std::string tag,
0145                                               uint32_t _rawid,
0146                                               hcal::ConfigurationDatabase::LUTType _lt);
0147   std::vector<unsigned int> getLutFromXml(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt);
0148 
0149   std::map<int, std::shared_ptr<LutXml> > get_brickSet_from_oracle(
0150       std::string tag,
0151       const std::string _accessor =
0152           "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22");
0153 
0154   int get_xml_files_from_db(
0155       std::string tag,
0156       const std::string db_accessor =
0157           "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22",
0158       bool split_by_crate = true);
0159 
0160   int create_lut_loader(std::string file_list,
0161                         std::string _prefix,
0162                         std::string tag_name,
0163                         std::string comment = "default comment",
0164                         std::string version = "V00-01-01",
0165                         int subversion = 1);
0166 
0167   // get md5 checksums for LUTs
0168   std::string get_checksum(std::vector<unsigned int>& lut);
0169 
0170   static int getInt(std::string number);
0171   static HcalSubdetector get_subdetector(std::string _subdet);
0172   static std::string get_time_stamp(time_t _time);
0173 
0174   // gives the iterator a list of channels
0175   int initChannelIterator(std::vector<HcalGenericDetId>& map);
0176 
0177 protected:
0178   LutXml* lut_xml;
0179   XMLDOMBlock* lut_checksums_xml;
0180   HCALConfigDB* db;
0181   LMap* lmap;
0182   HcalChannelIterator _iter;
0183   HcalAssistant _ass;
0184   const HcalElectronicsMap* emap;
0185   const HcalChannelQuality* cq;
0186   const HcalDbService* conditions;
0187   uint32_t status_word_to_mask;
0188 };
0189 
0190 class HcalLutManager_test {
0191 public:
0192   static int getLutXml_test(std::vector<unsigned int>& _lut) { return 0; }
0193 
0194   static int getLutSetFromFile_test(std::string _filename);
0195 
0196   static int getInt_test(std::string number);
0197 
0198 protected:
0199   LutXml* lut_xml;
0200 };
0201 
0202 #endif