File indexing completed on 2025-08-06 08:17:53
0001
0002
0003
0004
0005
0006 #include "MicromegasHotChannelMapData.h"
0007
0008 #include <cdbobjects/CDBTTree.h>
0009
0010 #include <TFile.h>
0011 #include <fstream>
0012 #include <sstream>
0013 #include <iostream>
0014
0015 namespace
0016 {
0017 static const std::string m_total_entries_key = "total_entries";
0018 static const std::string m_layer_id_key = "layer_id";
0019 static const std::string m_tile_id_key = "tile_id";
0020 static const std::string m_strip_id_key = "strip_id";
0021 }
0022
0023
0024 std::ostream& operator << (std::ostream& out, const MicromegasHotChannelMapData& calib_data )
0025 {
0026 out << "MicromegasHotChannelMapData" << std::endl;
0027
0028 out << "total entries: " << calib_data.m_hot_channel_map.size() << std::endl;
0029 for( const auto& channel_id:calib_data.m_hot_channel_map )
0030 { out << " " << channel_id << std::endl; }
0031
0032 return out;
0033 }
0034
0035
0036 void MicromegasHotChannelMapData::read( const std::string& filename )
0037 {
0038 std::cout << "MicromegasHotChannelMapData::read - filename: " << filename << std::endl;
0039
0040
0041 m_hot_channel_map.clear();
0042
0043
0044 if( !std::ifstream( filename.c_str() ).good() )
0045 {
0046 std::cout << "MicromegasHotChannelMapData::read -"
0047 << " filename: " << filename << " does not exist."
0048 << " No calibration loaded" << std::endl;
0049 return;
0050 }
0051
0052
0053 CDBTTree cdbttree( filename );
0054 cdbttree.LoadCalibrations();
0055
0056
0057 const int m_total_entries = cdbttree.GetSingleIntValue( m_total_entries_key );
0058 for( int i = 0; i < m_total_entries; ++ i )
0059 {
0060
0061 const int layer_id = cdbttree.GetIntValue( i, m_layer_id_key );
0062 const int tile_id = cdbttree.GetIntValue( i, m_tile_id_key );
0063 const int strip_id = cdbttree.GetIntValue( i, m_strip_id_key );
0064 if( std::isnan(layer_id) || std::isnan(tile_id) || std::isnan(strip_id) )
0065 { continue; }
0066
0067 m_hot_channel_map.emplace( layer_id, tile_id, strip_id );
0068 }
0069
0070 std::cout << "MicromegasHotChannelMapData::read - total entries: " << m_hot_channel_map.size() << std::endl;
0071
0072 }
0073
0074
0075 void MicromegasHotChannelMapData::add_hot_channel( int layer, int tile, int strip )
0076 { m_hot_channel_map.emplace( layer, tile, strip ); }
0077
0078
0079 void MicromegasHotChannelMapData::write( const std::string& filename ) const
0080 {
0081 std::cout << "MicromegasHotChannelMapData::write - filename: " << filename << std::endl;
0082 if( m_hot_channel_map.empty() ) { return;
0083 }
0084
0085
0086 CDBTTree cdbttree( filename );
0087 cdbttree.SetSingleIntValue( m_total_entries_key, m_hot_channel_map.size() );
0088
0089 int index = 0;
0090 for( const auto& channel_id:m_hot_channel_map )
0091 {
0092 cdbttree.SetIntValue( index, m_layer_id_key, channel_id.m_layer );
0093 cdbttree.SetIntValue( index, m_tile_id_key, channel_id.m_tile );
0094 cdbttree.SetIntValue( index, m_strip_id_key, channel_id.m_strip );
0095 ++index;
0096 }
0097
0098
0099 cdbttree.Commit();
0100 cdbttree.CommitSingle();
0101 cdbttree.WriteCDBTTree();
0102 }
0103
0104
0105 bool MicromegasHotChannelMapData::is_hot_channel( int layer, int tile, int strip ) const
0106 { return m_hot_channel_map.find({layer, tile, strip}) != m_hot_channel_map.end(); }