CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VParameterSetEntry.cc
Go to the documentation of this file.
5 
6 #include <cassert>
7 #include <ostream>
8 #include <sstream>
9 
10 namespace edm {
11 
12  VParameterSetEntry::VParameterSetEntry() : tracked_(false), theVPSet_(), theIDs_() {}
13 
14  VParameterSetEntry::VParameterSetEntry(std::vector<ParameterSet> const& vpset, bool isTracked)
15  : tracked_(isTracked), theVPSet_(new std::vector<ParameterSet>), theIDs_() {
16  for (std::vector<ParameterSet>::const_iterator i = vpset.begin(), e = vpset.end(); i != e; ++i) {
17  theVPSet_->push_back(*i);
18  }
19  }
20 
22  : tracked_(rep[0] == '+'), theVPSet_(), theIDs_(new std::vector<ParameterSetID>) {
23  assert(rep[0] == '+' || rep[0] == '-');
24  std::vector<std::string> temp;
25  // need a substring that starts at the '{'
26  std::string bracketedRepr(rep.begin() + 2, rep.end());
27  split(std::back_inserter(temp), bracketedRepr, '{', ',', '}');
28  theIDs_->reserve(temp.size());
29  for (std::vector<std::string>::const_iterator i = temp.begin(), e = temp.end(); i != e; ++i) {
30  theIDs_->push_back(ParameterSetID(*i));
31  }
32  }
33 
35  assert(theIDs_);
36  result += tracked_ ? "+q" : "-q";
37  result += '{';
39  std::string const between(",");
40  for (std::vector<ParameterSetID>::const_iterator i = theIDs_->begin(), e = theIDs_->end(); i != e; ++i) {
41  result += start;
42  i->toString(result);
43  start = between;
44  }
45  result += '}';
46  }
47 
49  assert(theIDs_);
50  digest.append(tracked_ ? "+q{" : "-q{", 3);
51  bool started = false;
52  for (std::vector<ParameterSetID>::const_iterator i = theIDs_->begin(), e = theIDs_->end(); i != e; ++i) {
53  if (started)
54  digest.append(",", 1);
55  i->toDigest(digest);
56  started = true;
57  }
58  digest.append("}", 1);
59  }
60 
63  toString(result);
64  return result;
65  }
66 
67  std::vector<ParameterSet> const& VParameterSetEntry::vpset() const {
68  fillVPSet();
69  return *theVPSet_;
70  }
71 
72  // NOTE: This function, and other non-const functions of this class
73  // that expose internals, may be used in a way that causes the cached
74  // "theVPSet_" and "theIDs_" to be inconsistent.
75  // THIS PROBLEM NEEDS TO BE ADDRESSED
76  std::vector<ParameterSet>& VParameterSetEntry::vpsetForUpdate() {
77  fillVPSet();
78  return *theVPSet_;
79  }
80 
82  if (nullptr == theVPSet_.load()) {
83  auto tmp = std::make_unique<std::vector<ParameterSet>>();
84  tmp->reserve(theIDs_->size());
85  for (auto const& theID : *theIDs_) {
86  tmp->push_back(getParameterSet(theID));
87  }
88  VParameterSet* expected = nullptr;
89  if (theVPSet_.compare_exchange_strong(expected, tmp.get())) {
90  // theVPSet_ was equal to nullptr and now is equal to tmp.get()
91  tmp.release();
92  }
93  }
94  }
95 
96  // NOTE: This function, and other non-const functions of this class
97  // that expose internals, may be used in a way that causes the cached
98  // "theVPSet_" and "theIDs_" to be inconsistent.
99  // THIS PROBLEM NEEDS TO BE ADDRESSED
101  assert(theVPSet_);
102  return theVPSet_->at(i);
103  }
104 
106 
108  fillVPSet();
109  theIDs_ = value_ptr<std::vector<ParameterSetID>>(new std::vector<ParameterSetID>);
110  theIDs_->resize(theVPSet_->size());
111  for (std::vector<ParameterSet>::iterator i = theVPSet_->begin(), e = theVPSet_->end(); i != e; ++i) {
112  if (!i->isRegistered()) {
113  i->registerIt();
114  }
115  theIDs_->at(i - theVPSet_->begin()) = i->id();
116  }
117  }
118 
120  std::string indentation(indent, ' ');
121  std::ostringstream os;
122  std::vector<ParameterSet> const& vps = vpset();
123  os << "VPSet " << (isTracked() ? "tracked" : "untracked") << " = ({" << std::endl;
125  std::string const between(",\n");
126  for (std::vector<ParameterSet>::const_iterator i = vps.begin(), e = vps.end(); i != e; ++i) {
127  os << start << indentation << i->dump(indent);
128  start = between;
129  }
130  if (!vps.empty()) {
131  os << std::endl;
132  }
133  os << indentation << "})";
134  return os.str();
135  }
136 
137  std::ostream& operator<<(std::ostream& os, VParameterSetEntry const& vpsetEntry) {
138  os << vpsetEntry.dump();
139  return os;
140  }
141 } // namespace edm
string rep
Definition: cuy.py:1189
std::string dump(unsigned int indent=0) const
void fillVPSet() const
reconstitutes the VPSet from the registry
Definition: Hash.h:43
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
ParameterSet const & getParameterSet(ParameterSetID const &id)
std::vector< ParameterSet > & vpsetForUpdate()
assert(be >=bs)
void toDigest(cms::Digest &digest) const
uint16_t size_type
tuple result
Definition: mps_fire.py:311
value_ptr< std::vector< ParameterSetID > > theIDs_
atomic_value_ptr< std::vector< ParameterSet > > theVPSet_
std::vector< ParameterSet > const & vpset() const
returns the VPSet
bool split(OutIter result, std::string const &string_to_split, char first, char sep, char last)
Definition: split.h:68
Hash< ParameterSetType > ParameterSetID
std::string toString() const
std::vector< ParameterSet >::size_type size() const
ParameterSet & psetInVector(int i)
tmp
align.sh
Definition: createJobs.py:716
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
void append(std::string const &s)
Definition: Digest.cc:161