ATLAS Offline Software
CoWLibrary.h
Go to the documentation of this file.
1 // --*- c++ -*--
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef COWTOOLS_COWLIBRARY
8 #define COWTOOLS_COWLIBRARY
9 #include <iostream>
10 #include <unordered_map>
11 #include <string>
12 #include <memory>
13 #include "CoWTools/CoWRecord.h"
14 #include <exception>
15 namespace CoWTools{
16  class CoWLibrary{
17  public:
18  CoWLibrary(bool Summary=true):m_libName("Summary"),m_summary(Summary){};
19  CoWLibrary(const std::string &n,bool Summary=true):m_libName(n),m_ms(Summary),m_summary(Summary){};
20  std::unordered_map<std::string,std::shared_ptr<CoWRecord> > m_records;
21  void parseRecord(std::istream& in);
22  std::string m_libName;
24  static std::shared_ptr<CoWLibrary> fromRecord(std::istream &in,bool summary);
25  private:
26  bool m_summary;
27  friend std::ostream & operator<<(std::ostream &, const CoWLibrary &l);
28  public:
29 
30  friend CoWLibrary operator-(CoWLibrary lhs, const CoWLibrary& rhs){
31  if(lhs.m_libName!=rhs.m_libName){
32  std::cerr<<"Warning trying to subtract different libraries. Ignoring"<<std::endl;
33  return lhs;
34  }
35  return lhs-=rhs;
36  }
37 
38  explicit operator bool() const {
39  if(m_summary){
40  auto vals=m_ms.getValueArray();
41  for(int i=0;i<11;i++){
42  if(vals[i])return true;
43  }
44  return false;
45  }else{
46  for(auto i : m_records){
47  if(*(i.second))return true;
48  }
49  return false;
50  }
51  }
52 
53  friend CoWLibrary operator+(CoWLibrary lhs, const CoWLibrary& rhs){
54  if(lhs.m_libName!=rhs.m_libName){
55  std::cerr<<"Warning trying to add different libraries. Ignoring"<<std::endl;
56  return lhs;
57  }
58  return lhs+=rhs;
59  }
60 
62  CoWLibrary m(*this);
63  m.m_ms=-m_ms;
64  return m;
65  }
66 
67  inline CoWLibrary& operator+=(const CoWLibrary& rhs){
68  if(m_libName!=rhs.m_libName){
69  std::cerr<<"Warning trying to add different libraries. Ignoring"<<std::endl;
70  return *this;
71  }
72  for(auto i:rhs.m_records){
73  auto l=m_records.find(i.first);
74  if(l!=m_records.end()){
75  *(l->second)+=*(i.second);
76  }else{
77  m_records.insert(std::make_pair(i.first,std::make_shared<CoWRecord>(*(i.second))));
78  }
79  }
80  m_ms+=rhs.m_ms;
81  return *this;
82  }
83 
84  inline CoWLibrary& operator-=(const CoWLibrary& rhs){
85  if(m_libName!=rhs.m_libName){
86  std::cerr<<"Warning trying to subtract different libraries. Ignoring"<<std::endl;
87  return *this;
88  }
89  for(auto i:rhs.m_records){
90  auto l=m_records.find(i.first);
91  if(l!=m_records.end()){
92  *(l->second)-=*(i.second);
93  }else{
94  m_records.insert(std::make_pair(i.first,std::make_shared<CoWRecord>(-*(i.second))));
95  }
96  }
97  m_ms-=rhs.m_ms;
98  return *this;
99  }
100  };
101 
102 }//end namespace
103 
104 #endif
CoWTools::CoWRecordStats::getValueArray
long long * getValueArray()
Definition: CoWRecordStats.h:94
CoWTools::CoWLibrary::operator-
CoWLibrary operator-() const
Definition: CoWLibrary.h:61
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
CoWTools::CoWLibrary
Definition: CoWLibrary.h:16
CoWTools::CoWLibrary::parseRecord
void parseRecord(std::istream &in)
Definition: CoWLibrary.cxx:9
CoWTools::CoWLibrary::CoWLibrary
CoWLibrary(const std::string &n, bool Summary=true)
Definition: CoWLibrary.h:19
CoWTools::CoWLibrary::operator+
friend CoWLibrary operator+(CoWLibrary lhs, const CoWLibrary &rhs)
Definition: CoWLibrary.h:53
CoWTools::CoWLibrary::m_ms
CoWRecordStats m_ms
Definition: CoWLibrary.h:23
CoWTools::CoWLibrary::fromRecord
static std::shared_ptr< CoWLibrary > fromRecord(std::istream &in, bool summary)
Definition: CoWLibrary.cxx:23
CoWTools::CoWLibrary::m_summary
bool m_summary
Definition: CoWLibrary.h:26
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
MuonValidation_CreateSlides_config.Summary
list Summary
Definition: MuonValidation_CreateSlides_config.py:34
CoWTools::CoWLibrary::m_records
std::unordered_map< std::string, std::shared_ptr< CoWRecord > > m_records
Definition: CoWLibrary.h:19
CoWTools::CoWLibrary::operator-
friend CoWLibrary operator-(CoWLibrary lhs, const CoWLibrary &rhs)
Definition: CoWLibrary.h:30
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
CoWTools::CoWLibrary::CoWLibrary
CoWLibrary(bool Summary=true)
Definition: CoWLibrary.h:18
CoWTools::CoWLibrary::operator-=
CoWLibrary & operator-=(const CoWLibrary &rhs)
Definition: CoWLibrary.h:84
CoWTools::CoWRecordStats
Definition: CoWRecordStats.h:13
CoWTools
Definition: CoWLibrary.h:15
CoWTools::CoWLibrary::operator+=
CoWLibrary & operator+=(const CoWLibrary &rhs)
Definition: CoWLibrary.h:67
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CoWRecord.h
CoWTools::CoWLibrary::operator<<
friend std::ostream & operator<<(std::ostream &, const CoWLibrary &l)
Definition: CoWLibrary.cxx:54
CoWTools::CoWLibrary::m_libName
std::string m_libName
Definition: CoWLibrary.h:22
PlotCalibFromCool.vals
vals
Definition: PlotCalibFromCool.py:474
SCT_Monitoring::summary
@ summary
Definition: SCT_MonitoringNumbers.h:65