ATLAS Offline Software
TGCEIFICoincidenceMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 #include <string>
11 #include <iomanip>
12 
15 
16 namespace LVL1TGC {
17 
19  const SG::ReadCondHandleKey<TGCTriggerData>& readCondKey)
20  :AthMessaging("LVL1TGC::TGCEIFICoincidenceMap"),
21  m_verName("NA"),
22  m_side(0),
23  m_fullCW(false),
24  m_tgcArgs(tgcargs),
25  m_readCondKey(readCondKey)
26 {
27  setLevel(tgcArgs()->MSGLEVEL());
28 
29  // intialize map
30  ATH_MSG_DEBUG("initialising the map");
31  for (size_t sec=0; sec < kNEndcapTrigSector; sec++) {
32  for (size_t ssc=0; ssc < kNMaxSSC; ssc++) {
33  for (size_t input=0; input < N_INNER_SECTORS; input++) {
34  m_map[input][ssc][sec].setTriggerBits(true);
35  }
36  m_flagPT[ssc][sec] = std::bitset<kNThresholdsR2>(0x30); // 6b'110000
37 
38  for (size_t pos=0; pos < kNRoiInSSC; pos++){
39  m_flagROI[pos][ssc][sec] = 1;
40  }
41  }
42  }
43  ATH_MSG_DEBUG("end of initialisation");
44 
45  return;
46 }
47 
49  const SG::ReadCondHandleKey<TGCTriggerData>& readCondKey,
50  const std::string& version,
51  int sideID)
52  : AthMessaging("LVL1TGC::TGCEIFICoincidenceMap"),
53  m_verName(version),
54  m_side(sideID),
55  m_fullCW(false),
56  m_tgcArgs(tgcargs),
57  m_readCondKey(readCondKey)
58 {
59  setLevel(tgcArgs()->MSGLEVEL());
60 
61  // initialize map
62  ATH_MSG_DEBUG("initialising the map");
63  for (size_t sec=0; sec < kNEndcapTrigSector; sec++) {
64  for (size_t ssc=0; ssc < kNMaxSSC; ssc++) {
65  for (size_t input=0; input < N_INNER_SECTORS; input++) {
66  m_map[input][ssc][sec].setTriggerBits(true);
67  }
68  m_flagPT[ssc][sec] = std::bitset<kNThresholdsR2>(0x30); // 6b'110000
69 
70  for (size_t pos=0; pos < kNRoiInSSC; pos++){
71  m_flagROI[pos][ssc][sec] = 1;
72  }
73  }
74  }
75  ATH_MSG_INFO("USE_INNER = " << tgcArgs()->USE_INNER());
76 
77  if (!tgcArgs()->USE_INNER()) return;
78 
79  ATH_MSG_INFO("USE_CONDDB = " << tgcArgs()->USE_CONDDB());
80 
81  if (tgcArgs()->USE_CONDDB()) return;
82 
83  // use full CW (i.e. different maps for each side)
84  m_fullCW = (m_verName == "v07");
85 
86  // read Inner Coincidence Map
87  if (this->readMap()) {
88  ATH_MSG_INFO(" TGC EIFI CW version of " << m_verName << " is selected.");
89  } else {
90  ATH_MSG_INFO(" NOT use inner station ");
91  tgcArgs()->set_USE_INNER( false );
92  for (size_t sec=0; sec < kNEndcapTrigSector; sec++){
93  for (size_t ssc=0; ssc < kNMaxSSC; ssc++){
94  m_flagPT[ssc][sec] = std::bitset<kNThresholdsR2>(0x00); // 6b'000000
95  }
96  }
97  }
98 
99  // for debug
100  //dumpMap();
101 }
102 
103 
105  : AthMessaging("LVL1TGC::TGCEIFICoincidenceMap"),
106  m_readCondKey(right.m_readCondKey)
107 {
108  ATH_MSG_DEBUG("copy constructor");
109 
110  for (size_t sec=0; sec < kNEndcapTrigSector; sec++){
111  for (size_t ssc=0; ssc < kNMaxSSC; ssc++){
112  for (size_t input=0; input < N_INNER_SECTORS; input++){
113  m_map[input][ssc][sec] = right.m_map[input][ssc][sec];
114  }
115  m_flagPT[ssc][sec] = right.m_flagPT[ssc][sec];
116 
117  for (size_t pos=0; pos < kNRoiInSSC; pos++){
118  m_flagROI[pos][ssc][sec] = right.m_flagROI[pos][ssc][sec];
119  }
120  }
121  }
122  m_verName = right.m_verName;
123  m_side=right.m_side;
124  m_fullCW=right.m_fullCW;
125 }
126 
128 {
129  ATH_MSG_INFO("operator = ");
130 
131  if (this != &right) {
132  m_tgcArgs = right.m_tgcArgs;
133  for (size_t sec=0; sec < kNEndcapTrigSector; sec++){
134  for (size_t ssc=0; ssc < kNMaxSSC; ssc++){
135  for (size_t input=0; input< N_INNER_SECTORS; input++){
136  m_map[input][ssc][sec] = right.m_map[input][ssc][sec];
137  }
138  m_flagPT[ssc][sec] = right.m_flagPT[ssc][sec];
139 
140  for (size_t pos=0; pos < kNRoiInSSC; pos++){
141  m_flagROI[pos][ssc][sec] = right.m_flagROI[pos][ssc][sec];
142  }
143  }
144  }
145  m_verName = right.m_verName;
146  m_side=right.m_side;
147  m_fullCW=right.m_fullCW;
148  }
149  return *this;
150 }
151 
152 
154 {
155  ATH_MSG_DEBUG("readMap");
156  const std::string SideName[kNSide] = {"A","C"};
157 
158  // select right database according to a set of thresholds
159  std::string dbname="";
160  if (!m_fullCW) {
161  dbname = "InnerCoincidenceMap." + m_verName + "._12.db";
162  } else {
163  dbname = "InnerCoincidenceMap." + SideName[m_side]
164  + "." + m_verName + "._12.db";
165  }
166 
167  //-----
168 
169  std::string fullName;
170  fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/EIFI/"+dbname;
171  bool isFound =( fullName.length() > 0 );
172  if( !isFound) {
173  ATH_MSG_WARNING(" Could not found " << dbname);
174  return false ;
175  }
176 
177  std::ifstream file(fullName.c_str(),std::ios::in);
178 
179  static constexpr unsigned int BufferSize = 512;
180  char buf[BufferSize];
181  std::string tag;
182 
183  while(file.getline(buf,BufferSize)){
184  unsigned int sectorId = 999;
185  unsigned int sscId = 999;
186  int use[kNThresholdsR2] = {0, 0, 0, 0, 0, 0};
187  int roi[kNRoiInSSC] = {1, 1, 1, 1, 1, 1, 1, 1};
188  std::istringstream header(buf);
189  header >> tag;
190  if(tag == "#"){ // read header part.
191  header >> sectorId >> sscId
192  >> use[0] >> use[1] >> use[2]
193  >> use[3] >> use[4] >> use[5]
194  >> roi[0] >> roi[1] >> roi[2] >> roi[3]
195  >> roi[4] >> roi[5] >> roi[6] >> roi[7];
196  }
197  // check Id
198  if (sectorId >= kNEndcapTrigSector ||
199  sscId >= kNMaxSSC) {
200  ATH_MSG_WARNING(" illegal parameter in database header : " << header.str()
201  << " in file " << dbname);
202  file.close();
203  return false;
204  }
205  for (size_t pt=0; pt < kNThresholdsR2; pt++){
206  m_flagPT[sscId][sectorId][pt] = use[pt];
207  }
208  for (size_t pos=0; pos < kNRoiInSSC; pos++){
209  m_flagROI[pos][sscId][sectorId] = roi[pos];
210  }
211 
212  // get trigger word
213  file.getline(buf,BufferSize);
214  std::istringstream cont(buf);
215  unsigned int word;
216  for (size_t pos=0; pos < N_INNER_SECTORS; pos++) {
217  cont >> word;
218  m_map[pos][sscId][sectorId].setTriggerWord(word);
219  }
220  }
221  file.close();
222 
223  return true;
224 }
225 
226 // Debug purpose only
228 {
229  // select right database according to a set of thresholds
230  std::string fullName="InnerCoincidenceMap."+m_verName+"._12.out";
231 
232  std::ofstream file(fullName.c_str());
233 
234  for (size_t sec=0; sec < kNEndcapTrigSector; sec++){
235  for (size_t ssc=0; ssc < kNMaxSSC; ssc++){
236  file << "# " << sec << " " << ssc << " ";
237  for(int i=0; i<6; i++) file << m_flagPT[ssc][sec].test(i) << " ";
238  for(int i=0; i<8; i++) file << m_flagROI[i][ssc][sec] << " ";
239  file << std::endl;
240  file << m_map[0][ssc][sec].getTriggerWord() << " "
241  << m_map[1][ssc][sec].getTriggerWord() << " "
242  << m_map[2][ssc][sec].getTriggerWord() << " "
243  << m_map[3][ssc][sec].getTriggerWord() << " "
244  << std::endl;
245  }
246  }
247  file.close();
248 }
249 
250 int TGCEIFICoincidenceMap::getFlagPT(const unsigned int pt,
251  const unsigned int ssc,
252  const unsigned int sec) const
253 {
254  if (pt == 0 || pt > kNThresholdsR2) return -1;
255  if (ssc >= kNMaxSSC) return 0;
256  if (sec >= kNEndcapTrigSector) return -1;
257 
258  if (tgcArgs()->USE_CONDDB()) {
260  const TGCTriggerData* readCdo{*readHandle};
261  return readCdo->getFlagPtEifi(m_side,ssc,sec)>>(pt-1) & 0x1; /* only 1st bit needed (0x1) */
262  } else {
263  return m_flagPT[ssc][sec].test(pt-1);
264  }
265 }
266 
267 int TGCEIFICoincidenceMap::getFlagROI(const unsigned int roi,
268  const unsigned int ssc,
269  const unsigned int sec) const
270 {
271  if (roi >= kNRoiInSSC) return -1;
272  if (ssc >= kNMaxSSC) return 0;
273  if (sec >= kNEndcapTrigSector) return -1;
274 
275  if (tgcArgs()->USE_CONDDB()) {
277  const TGCTriggerData* readCdo{*readHandle};
278  return readCdo->getFlagRoiEifi(m_side,ssc,sec)>>roi & 0x1; /* only 1st bit needed (0x1) */
279  } else {
280  return m_flagROI[roi][ssc][sec];
281  }
282 }
283 
285  const int ssc,
286  const int sec,
287  const int reg,
288  const int read,
289  const int bit) const
290 {
291  if (tgcArgs()->USE_CONDDB()) {
293  const TGCTriggerData* readCdo{*readHandle};
294  unsigned int shift = (reg<<3) + (read<<2) + bit;
295  return readCdo->getTrigBitEifi(m_side,slot,ssc,sec)>>shift & 0x1; /* only 1st bit needed (0x1) */
296  } else {
297  return m_map[slot][ssc][sec].getTriggerBit(reg,read,bit);
298  }
299 }
300 
301 } // end of namespace
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CaloNoise_fillDB.dbname
dbname
Definition: CaloNoise_fillDB.py:43
StateLessPT_NewConfig.BufferSize
BufferSize
Definition: StateLessPT_NewConfig.py:370
header
Definition: hcg.cxx:526
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
LVL1TGC::TGCEIFICoincidenceMap::m_verName
std::string m_verName
Definition: TGCEIFICoincidenceMap.h:75
test_pyathena.pt
pt
Definition: test_pyathena.py:11
LVL1TGC::TGCEIFICoincidenceMap::getFlagPT
int getFlagPT(const unsigned int pt, const unsigned int ssc, const unsigned int sec) const
Definition: TGCEIFICoincidenceMap.cxx:250
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
TGCDatabaseManager.h
LVL1TGC::TGCEIFICoincidenceMap
Definition: TGCEIFICoincidenceMap.h:23
PathResolver::FindCalibDirectory
static std::string FindCalibDirectory(const std::string &logical_file_name)
Definition: PathResolver.h:109
TGCEIFICoincidenceMap.h
LVL1TGC::TGCEIFICoincidenceMap::m_flagPT
std::bitset< kNThresholdsR2 > m_flagPT[kNMaxSSC][kNEndcapTrigSector]
Definition: TGCEIFICoincidenceMap.h:68
AthMessaging::setLevel
void setLevel(MSG::Level lvl)
Change the current logging level.
Definition: AthMessaging.cxx:28
LVL1TGCTrigger::TGCInnerTrackletSlot::getTriggerWord
unsigned short getTriggerWord() const
Definition: TGCInnerTrackletSlot.cxx:87
LVL1TGC::TGCEIFICoincidenceMap::readMap
bool readMap()
Definition: TGCEIFICoincidenceMap.cxx:153
LVL1TGCTrigger::TGCInnerTrackletSlot::getTriggerBit
bool getTriggerBit(const unsigned int region, const unsigned int readout, const unsigned int iBit) const
Definition: TGCInnerTrackletSlot.cxx:57
LVL1TGC::TGCEIFICoincidenceMap::dumpMap
void dumpMap() const
Definition: TGCEIFICoincidenceMap.cxx:227
LVL1TGC::TGCEIFICoincidenceMap::m_flagROI
int m_flagROI[kNRoiInSSC][kNMaxSSC][kNEndcapTrigSector]
Definition: TGCEIFICoincidenceMap.h:70
lumiFormat.i
int i
Definition: lumiFormat.py:85
TGCTriggerData::getTrigBitEifi
unsigned short getTrigBitEifi(int side, int slot, int ssc, int sectorId) const
Definition: TGCTriggerData.cxx:43
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LVL1TGC::TGCEIFICoincidenceMap::m_map
LVL1TGCTrigger::TGCInnerTrackletSlot m_map[N_INNER_SECTORS][kNMaxSSC][kNEndcapTrigSector]
Definition: TGCEIFICoincidenceMap.h:73
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
LVL1TGC
Definition: BigWheelCoincidenceLUT.cxx:20
file
TFile * file
Definition: tile_monitor.h:29
LVL1TGC::TGCEIFICoincidenceMap::operator=
TGCEIFICoincidenceMap & operator=(const TGCEIFICoincidenceMap &right)
Definition: TGCEIFICoincidenceMap.cxx:127
LVL1TGC::TGCEIFICoincidenceMap::m_tgcArgs
LVL1TGCTrigger::TGCArguments * m_tgcArgs
Definition: TGCEIFICoincidenceMap.h:79
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
LVL1TGC::TGCEIFICoincidenceMap::TGCEIFICoincidenceMap
TGCEIFICoincidenceMap(LVL1TGCTrigger::TGCArguments *, const SG::ReadCondHandleKey< TGCTriggerData > &readCondKey)
Definition: TGCEIFICoincidenceMap.cxx:18
LVL1TGCTrigger::TGCInnerTrackletSlot::setTriggerBits
bool setTriggerBits(const bool val)
Definition: TGCInnerTrackletSlot.cxx:38
LVL1TGC::TGCEIFICoincidenceMap::m_side
int m_side
Definition: TGCEIFICoincidenceMap.h:76
LVL1TGC::TGCEIFICoincidenceMap::getFlagROI
int getFlagROI(const unsigned int roi, const unsigned int ssc, const unsigned int sec) const
Definition: TGCEIFICoincidenceMap.cxx:267
LVL1TGC::TGCEIFICoincidenceMap::N_INNER_SECTORS
static constexpr unsigned int N_INNER_SECTORS
Definition: TGCEIFICoincidenceMap.h:62
PathResolver.h
LVL1TGC::TGCEIFICoincidenceMap::getTriggerBit
int getTriggerBit(const int slot, const int ssc, const int sec, const int reg, const int read, const int bit) const
Definition: TGCEIFICoincidenceMap.cxx:284
LVL1TGC::TGCEIFICoincidenceMap::m_readCondKey
const SG::ReadCondHandleKey< TGCTriggerData > & m_readCondKey
Definition: TGCEIFICoincidenceMap.h:81
LVL1TGCTrigger::TGCArguments
Definition: TGCArguments.h:12
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
TGCTriggerData::getFlagPtEifi
unsigned char getFlagPtEifi(int side, int ssc, int sectorId) const
Definition: TGCTriggerData.cxx:55
SG::ReadCondHandleKey< TGCTriggerData >
get_generator_info.version
version
Definition: get_generator_info.py:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1TGCTrigger::TGCArguments::set_USE_INNER
void set_USE_INNER(bool v)
Definition: TGCArguments.cxx:30
LVL1TGC::kNSide
@ kNSide
Definition: TGCNumbering.h:16
TGCTriggerData
Definition: TGCTriggerData.h:102
LVL1TGCTrigger::TGCInnerTrackletSlot::setTriggerWord
void setTriggerWord(unsigned int word)
Definition: TGCInnerTrackletSlot.cxx:75
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
LVL1TGC::TGCEIFICoincidenceMap::tgcArgs
const LVL1TGCTrigger::TGCArguments * tgcArgs() const
Definition: TGCEIFICoincidenceMap.h:58
makeTOC.header
header
Definition: makeTOC.py:28
TGCTriggerData::getFlagRoiEifi
unsigned char getFlagRoiEifi(int side, int ssc, int sectorId) const
Definition: TGCTriggerData.cxx:66
LVL1TGC::TGCEIFICoincidenceMap::m_fullCW
bool m_fullCW
Definition: TGCEIFICoincidenceMap.h:77