CMS 3D CMS Logo

VParameterSetEntry.cc
Go to the documentation of this file.
5 
6 #include <cassert>
7 #include <ostream>
8 #include <sstream>
9 
10 namespace edm {
11 
13  tracked_(false),
14  theVPSet_(),
15  theIDs_() {
16  }
17 
18  VParameterSetEntry::VParameterSetEntry(std::vector<ParameterSet> const& vpset, bool isTracked) :
19  tracked_(isTracked),
20  theVPSet_(new std::vector<ParameterSet>),
21  theIDs_() {
22  for (std::vector<ParameterSet>::const_iterator i = vpset.begin(), e = vpset.end(); i != e; ++i) {
23  theVPSet_->push_back(*i);
24  }
25  }
26 
28  tracked_(rep[0] == '+'),
29  theVPSet_(),
30  theIDs_(new std::vector<ParameterSetID>) {
31  assert(rep[0] == '+' || rep[0] == '-');
32  std::vector<std::string> temp;
33  // need a substring that starts at the '{'
34  std::string bracketedRepr(rep.begin()+2, rep.end());
35  split(std::back_inserter(temp), bracketedRepr, '{', ',', '}');
36  theIDs_->reserve(temp.size());
37  for (std::vector<std::string>::const_iterator i = temp.begin(), e = temp.end(); i != e; ++i) {
38  theIDs_->push_back(ParameterSetID(*i));
39  }
40  }
41 
42  void
44  assert(theIDs_);
45  result += tracked_ ? "+q" : "-q";
46  result += '{';
48  std::string const between(",");
49  for (std::vector<ParameterSetID>::const_iterator i = theIDs_->begin(), e = theIDs_->end(); i != e; ++i) {
50  result += start;
51  i->toString(result);
52  start = between;
53  }
54  result += '}';
55  }
56 
57  void
59  assert(theIDs_);
60  digest.append(tracked_ ? "+q{" : "-q{", 3);
61  bool started = false;
62  for (std::vector<ParameterSetID>::const_iterator i = theIDs_->begin(), e = theIDs_->end(); i != e; ++i) {
63  if (started)
64  digest.append(",", 1);
65  i->toDigest(digest);
66  started = true;
67  }
68  digest.append("}",1);
69  }
70 
73  toString(result);
74  return result;
75  }
76 
77  std::vector<ParameterSet> const& VParameterSetEntry::vpset() const {
78  fillVPSet();
79  return *theVPSet_;
80  }
81 
82  // NOTE: This function, and other non-const functions of this class
83  // that expose internals, may be used in a way that causes the cached
84  // "theVPSet_" and "theIDs_" to be inconsistent.
85  // THIS PROBLEM NEEDS TO BE ADDRESSED
86  std::vector<ParameterSet>& VParameterSetEntry::vpsetForUpdate() {
87  fillVPSet();
88  return *theVPSet_;
89  }
90 
92  if(nullptr == theVPSet_.load()) {
93  auto tmp = std::make_unique<std::vector<ParameterSet>>();
94  tmp->reserve(theIDs_->size());
95  for (auto const& theID : *theIDs_) {
96  tmp->push_back(getParameterSet(theID));
97  }
98  VParameterSet* expected = nullptr;
99  if(theVPSet_.compare_exchange_strong(expected, tmp.get())) {
100  // theVPSet_ was equal to nullptr and now is equal to tmp.get()
101  tmp.release();
102  }
103  }
104  }
105 
106  // NOTE: This function, and other non-const functions of this class
107  // that expose internals, may be used in a way that causes the cached
108  // "theVPSet_" and "theIDs_" to be inconsistent.
109  // THIS PROBLEM NEEDS TO BE ADDRESSED
111  assert(theVPSet_);
112  return theVPSet_->at(i);
113  }
114 
116  return vpset().size();
117  }
118 
120  fillVPSet();
121  theIDs_ = value_ptr<std::vector<ParameterSetID> >(new std::vector<ParameterSetID>);
122  theIDs_->resize(theVPSet_->size());
123  for (std::vector<ParameterSet>::iterator i = theVPSet_->begin(), e = theVPSet_->end(); i != e; ++i) {
124  if (!i->isRegistered()) {
125  i->registerIt();
126  }
127  theIDs_->at(i - theVPSet_->begin()) = i->id();
128  }
129  }
130 
132  std::string indentation(indent, ' ');
133  std::ostringstream os;
134  std::vector<ParameterSet> const& vps = vpset();
135  os << "VPSet "<<(isTracked()?"tracked":"untracked")<<" = ({" << std::endl;
137  std::string const between(",\n");
138  for(std::vector<ParameterSet>::const_iterator i = vps.begin(), e = vps.end(); i != e; ++i) {
139  os << start << indentation << i->dump(indent);
140  start = between;
141  }
142  if (!vps.empty()) {
143  os << std::endl;
144  }
145  os << indentation << "})";
146  return os.str();
147  }
148 
149  std::ostream& operator<<(std::ostream& os, VParameterSetEntry const& vpsetEntry) {
150  os << vpsetEntry.dump();
151  return os;
152  }
153 }
friend std::ostream & operator<<(std::ostream &os, VParameterSetEntry const &vpsetEntry)
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:33
ParameterSet const & getParameterSet(ParameterSetID const &id)
std::vector< ParameterSet > & vpsetForUpdate()
void toDigest(cms::Digest &digest) const
uint16_t size_type
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:88
rep
Definition: cuy.py:1190
Hash< ParameterSetType > ParameterSetID
std::string toString() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
std::vector< ParameterSet >::size_type size() const
ParameterSet & psetInVector(int i)
void append(std::string const &s)
Definition: Digest.cc:182