Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MicromegasHotChannelMapData.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MicromegasHotChannelMapData.cc
1 
7 
8 #include <cdbobjects/CDBTTree.h>
9 
10 #include <TFile.h>
11 #include <fstream>
12 #include <sstream>
13 #include <iostream>
14 
15 namespace
16 {
17  static const std::string m_total_entries_key = "total_entries";
18  static const std::string m_layer_id_key = "layer_id";
19  static const std::string m_tile_id_key = "tile_id";
20  static const std::string m_strip_id_key = "strip_id";
21 }
22 
23 //________________________________________________________________________-
24 std::ostream& operator << (std::ostream& out, const MicromegasHotChannelMapData& calib_data )
25 {
26  out << "MicromegasHotChannelMapData" << std::endl;
27 
28  out << "total entries: " << calib_data.m_hot_channel_map.size() << std::endl;
29  for( const auto& channel_id:calib_data.m_hot_channel_map )
30  { out << " " << channel_id << std::endl; }
31 
32  return out;
33 }
34 
35 //________________________________________________________________________-
37 {
38  std::cout << "MicromegasHotChannelMapData::read - filename: " << filename << std::endl;
39 
40  // clear existing data
41  m_hot_channel_map.clear();
42 
43  // make sure file exists before loading, otherwise crashes
44  if( !std::ifstream( filename.c_str() ).good() )
45  {
46  std::cout << "MicromegasHotChannelMapData::read -"
47  << " filename: " << filename << " does not exist."
48  << " No calibration loaded" << std::endl;
49  return;
50  }
51 
52  // use generic CDBTree to load
53  CDBTTree cdbttree( filename );
54  cdbttree.LoadCalibrations();
55 
56  // read total number of hot channels
57  const int m_total_entries = cdbttree.GetSingleIntValue( m_total_entries_key );
58  for( int i = 0; i < m_total_entries; ++ i )
59  {
60  // read channel id
61  const int layer_id = cdbttree.GetIntValue( i, m_layer_id_key );
62  const int tile_id = cdbttree.GetIntValue( i, m_tile_id_key );
63  const int strip_id = cdbttree.GetIntValue( i, m_strip_id_key );
64  if( std::isnan(layer_id) || std::isnan(tile_id) || std::isnan(strip_id) )
65  { continue; }
66 
67  m_hot_channel_map.emplace( layer_id, tile_id, strip_id );
68  }
69 
70  std::cout << "MicromegasHotChannelMapData::read - total entries: " << m_hot_channel_map.size() << std::endl;
71 
72 }
73 
74 //________________________________________________________________________-
76 { m_hot_channel_map.emplace( layer, tile, strip ); }
77 
78 //________________________________________________________________________-
80 {
81  std::cout << "MicromegasHotChannelMapData::write - filename: " << filename << std::endl;
82  if( m_hot_channel_map.empty() ) return;
83 
84  // use generic CDBTree to load
85  CDBTTree cdbttree( filename );
86  cdbttree.SetSingleIntValue( m_total_entries_key, m_hot_channel_map.size() );
87 
88  int index = 0;
89  for( const auto& channel_id:m_hot_channel_map )
90  {
91  cdbttree.SetIntValue( index, m_layer_id_key, channel_id.m_layer );
92  cdbttree.SetIntValue( index, m_tile_id_key, channel_id.m_tile );
93  cdbttree.SetIntValue( index, m_strip_id_key, channel_id.m_strip );
94  ++index;
95  }
96 
97  // commit and write
98  cdbttree.Commit();
99  cdbttree.CommitSingle();
100  cdbttree.WriteCDBTTree();
101 }
102 
103 //________________________________________________________________________-
104 bool MicromegasHotChannelMapData::is_hot_channel( int layer, int tile, int strip ) const
105 { return m_hot_channel_map.find({layer, tile, strip}) != m_hot_channel_map.end(); }