Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:00:06

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(const HcalTPGCoder& _coder,
0095                                                        std::string _tag,
0096                                                        bool split_by_crate = true,
0097                                                        bool ootpu_lut = false);
0098 
0099   std::map<int, std::shared_ptr<LutXml> > getHEFineGrainLUTs(std::string _tag, bool split_by_crate = true);
0100 
0101   // add two std::map<s with LUTs. Designed mainly for joining compression LUTs to linearization ones.
0102   void addLutMap(std::map<int, std::shared_ptr<LutXml> >& result, const std::map<int, std::shared_ptr<LutXml> >& other);
0103 
0104   // read LUTs from ASCII master file.
0105   HcalLutSet getLutSetFromFile(std::string _filename, int _type = 1);  // _type = 1 - linearization, 2 - compression
0106 
0107   int writeLutXmlFiles(std::map<int, std::shared_ptr<LutXml> >& _xml,
0108                        std::string _tag = "default_tag",
0109                        bool split_by_crate = true);
0110 
0111   int createLinLutXmlFiles(std::string _tag, std::string _lin_file, bool split_by_crate = true);
0112   int createCompLutXmlFilesFromCoder(std::string _tag, bool split_by_crate = true);
0113   int createAllLutXmlFiles(std::string _tag, std::string _lin_file, std::string _comp_file, bool split_by_crate = true);
0114   int createAllLutXmlFilesFromCoder(const HcalTPGCoder& _coder, std::string _tag, bool split_by_crate = true);
0115   int createLutXmlFiles_HBEFFromCoder_HOFromAscii(std::string _tag,
0116                                                   const HcalTPGCoder& _coder,
0117                                                   std::string _lin_file,
0118                                                   bool split_by_crate = true);
0119   int createLutXmlFiles_HBEFFromCoder_HOFromAscii(std::string _tag,
0120                                                   const HcalTPGCoder& _coder,
0121                                                   const CaloTPGTranscoderULUT& _transcoder,
0122                                                   std::string _lin_file,
0123                                                   bool split_by_crate = true);
0124 
0125   int createLutXmlFiles_HBEFFromCoder_HOFromAscii_ZDC(std::string _tag,
0126                                                       const HcalTPGCoder& _coder,
0127                                                       const CaloTPGTranscoderULUT& _transcoder,
0128                                                       std::string _lin_file,
0129                                                       bool split_by_crate = true);
0130 
0131   int createAllLutXmlFilesLinAsciiCompCoder(std::string _tag, std::string _lin_file, bool split_by_crate = true);
0132 
0133   // tests
0134   //    reading LUTs from a local XML
0135   int test_xml_access(std::string _tag, std::string _filename);
0136   int test_direct_xml_parsing(std::string _filename);
0137   void test_emap(void);
0138 
0139   // connect to local XML file with LUTs and local ASCII file with LMAP
0140   // connection interface through protected members db and lmap
0141   int read_lmap(std::string lmap_hbef_file, std::string lmap_ho_file);
0142   int read_luts(std::string lut_xml_file);
0143   int local_connect(std::string lut_xml_file, std::string lmap_hbef_file, std::string lmap_ho_file);
0144 
0145   // hcal::ConfigurationDatabase::LinearizerLUT
0146   // hcal::ConfigurationDatabase::CompressionLUT
0147   std::vector<unsigned int> getLutFromXml_old(std::string tag,
0148                                               uint32_t _rawid,
0149                                               hcal::ConfigurationDatabase::LUTType _lt);
0150   std::vector<unsigned int> getLutFromXml(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt);
0151 
0152   std::map<int, std::shared_ptr<LutXml> > get_brickSet_from_oracle(
0153       std::string tag,
0154       const std::string _accessor =
0155           "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22");
0156 
0157   int get_xml_files_from_db(
0158       std::string tag,
0159       const std::string db_accessor =
0160           "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22",
0161       bool split_by_crate = true);
0162 
0163   int create_lut_loader(std::string file_list,
0164                         std::string _prefix,
0165                         std::string tag_name,
0166                         std::string comment = "default comment",
0167                         std::string version = "V00-01-01",
0168                         int subversion = 1);
0169 
0170   // get md5 checksums for LUTs
0171   std::string get_checksum(std::vector<unsigned int>& lut);
0172 
0173   static int getInt(std::string number);
0174   static HcalSubdetector get_subdetector(std::string _subdet);
0175   static std::string get_time_stamp(time_t _time);
0176 
0177   // gives the iterator a list of channels
0178   int initChannelIterator(std::vector<HcalGenericDetId>& map);
0179 
0180 protected:
0181   LutXml* lut_xml;
0182   XMLDOMBlock* lut_checksums_xml;
0183   HCALConfigDB* db;
0184   LMap* lmap;
0185   HcalChannelIterator _iter;
0186   HcalAssistant _ass;
0187   const HcalElectronicsMap* emap;
0188   const HcalChannelQuality* cq;
0189   const HcalDbService* conditions;
0190   uint32_t status_word_to_mask;
0191 };
0192 
0193 class HcalLutManager_test {
0194 public:
0195   static int getLutXml_test(std::vector<unsigned int>& _lut) { return 0; }
0196 
0197   static int getLutSetFromFile_test(std::string _filename);
0198 
0199   static int getInt_test(std::string number);
0200 
0201 protected:
0202   LutXml* lut_xml;
0203 };
0204 
0205 #endif