ATLAS Offline Software
Loading...
Searching...
No Matches
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>
15namespace CoWTools{
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:
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
CoWLibrary operator-() const
Definition CoWLibrary.h:61
CoWRecordStats m_ms
Definition CoWLibrary.h:23
CoWLibrary(bool Summary=true)
Definition CoWLibrary.h:18
std::unordered_map< std::string, std::shared_ptr< CoWRecord > > m_records
Definition CoWLibrary.h:20
CoWLibrary & operator-=(const CoWLibrary &rhs)
Definition CoWLibrary.h:84
CoWLibrary & operator+=(const CoWLibrary &rhs)
Definition CoWLibrary.h:67
CoWLibrary(const std::string &n, bool Summary=true)
Definition CoWLibrary.h:19
std::string m_libName
Definition CoWLibrary.h:22
static std::shared_ptr< CoWLibrary > fromRecord(std::istream &in, bool summary)
friend std::ostream & operator<<(std::ostream &, const CoWLibrary &l)
friend CoWLibrary operator+(CoWLibrary lhs, const CoWLibrary &rhs)
Definition CoWLibrary.h:53
void parseRecord(std::istream &in)
Definition CoWLibrary.cxx:9
friend CoWLibrary operator-(CoWLibrary lhs, const CoWLibrary &rhs)
Definition CoWLibrary.h:30