-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
ParameterSet.cc
2448 lines (2081 loc) · 79.7 KB
/
ParameterSet.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ----------------------------------------------------------------------
//
// definition of ParameterSet's function members
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// prerequisite source files and headers
// ----------------------------------------------------------------------
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/Registry.h"
#include "FWCore/ParameterSet/interface/split.h"
#include "FWCore/Utilities/interface/Algorithms.h"
#include "FWCore/Utilities/interface/Digest.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "DataFormats/Provenance/interface/ModuleDescription.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cassert>
// ----------------------------------------------------------------------
// class invariant checker
// ----------------------------------------------------------------------
namespace edm {
void
ParameterSet::invalidateRegistration(std::string const& nameOfTracked) {
// We have added a new parameter. Invalidate the ID.
if(isRegistered()) {
id_ = ParameterSetID();
if(!nameOfTracked.empty()) {
// Give a warning (informational for now).
LogInfo("ParameterSet") << "Warning: You have added a new tracked parameter\n"
<< "'" << nameOfTracked << "' to a previously registered parameter set.\n"
<< "This is a bad idea because the new parameter(s) will not be recorded.\n"
<< "Use the forthcoming ParameterSetDescription facility instead.\n"
<< "A warning is given only for the first such parameter in a pset.\n";
}
}
assert(!isRegistered());
}
// ----------------------------------------------------------------------
// constructors
// ----------------------------------------------------------------------
ParameterSet::ParameterSet() :
tbl_(),
psetTable_(),
vpsetTable_(),
id_() {
}
// ----------------------------------------------------------------------
// from coded string
ParameterSet::ParameterSet(std::string const& code) :
tbl_(),
psetTable_(),
vpsetTable_(),
id_() {
if(!fromString(code)) {
throw Exception(errors::Configuration, "InvalidInput")
<< "The encoded configuration string "
<< "passed to a ParameterSet during construction is invalid:\n"
<< code;
}
}
// ----------------------------------------------------------------------
// from coded string and ID.
ParameterSet::ParameterSet(std::string const& code, ParameterSetID const& id) :
tbl_(),
psetTable_(),
vpsetTable_(),
id_(id) {
if(!fromString(code)) {
throw Exception(errors::Configuration, "InvalidInput")
<< "The encoded configuration string "
<< "passed to a ParameterSet during construction is invalid:\n"
<< code;
}
}
ParameterSet::~ParameterSet() {}
void
ParameterSet::registerFromString(std::string const& rep) {
// from coded string. Will cause registration
cms::Digest dg(rep);
edm::ParameterSetID psID(dg.digest().toString());
edm::ParameterSet ps(rep, psID);
pset::Registry::instance()->insertMapped(ps);
}
ParameterSetID
ParameterSet::emptyParameterSetID() { // const
cms::Digest newDigest;
ParameterSet().toDigest(newDigest);
return ParameterSetID(newDigest.digest().toString());
}
ParameterSet::ParameterSet(ParameterSet const& other)
: tbl_(other.tbl_),
psetTable_(other.psetTable_),
vpsetTable_(other.vpsetTable_),
id_(other.id_) {
}
ParameterSet& ParameterSet::operator=(ParameterSet const& other) {
ParameterSet temp(other);
swap(temp);
return *this;
}
void ParameterSet::copyForModify(ParameterSet const& other) {
ParameterSet temp(other);
swap(temp);
id_ = ParameterSetID();
}
void ParameterSet::swap(ParameterSet& other) {
tbl_.swap(other.tbl_);
psetTable_.swap(other.psetTable_);
vpsetTable_.swap(other.vpsetTable_);
id_.swap(other.id_);
}
ParameterSet const& ParameterSet::registerIt() {
if(!isRegistered()) {
calculateID();
pset::Registry::instance()->insertMapped(*this);
}
return *this;
}
std::auto_ptr<ParameterSet> ParameterSet::popParameterSet(std::string const& name) {
assert(!isRegistered());
psettable::iterator it = psetTable_.find(name);
assert(it != psetTable_.end());
std::auto_ptr<ParameterSet> pset(new ParameterSet);
std::swap(*pset, it->second.psetForUpdate());
psetTable_.erase(it);
return pset;
}
void ParameterSet::eraseSimpleParameter(std::string const& name) {
assert(!isRegistered());
table::iterator it = tbl_.find(name);
assert(it != tbl_.end());
tbl_.erase(it);
}
void ParameterSet::eraseOrSetUntrackedParameterSet(std::string const& name) {
assert(!isRegistered());
psettable::iterator it = psetTable_.find(name);
assert(it != psetTable_.end());
ParameterSet& pset = it->second.psetForUpdate();
if (pset.isRegistered()) {
it->second.setIsTracked(false);
} else {
psetTable_.erase(it);
}
}
std::auto_ptr<std::vector<ParameterSet> > ParameterSet::popVParameterSet(std::string const& name) {
assert(!isRegistered());
vpsettable::iterator it = vpsetTable_.find(name);
assert(it != vpsetTable_.end());
std::auto_ptr<std::vector<ParameterSet> > vpset(new std::vector<ParameterSet>);
std::swap(*vpset, it->second.vpsetForUpdate());
vpsetTable_.erase(it);
return vpset;
}
void ParameterSet::calculateID() {
// make sure contained tracked psets are updated
for(auto& item : psetTable_) {
ParameterSet& pset = item.second.psetForUpdate();
if(!pset.isRegistered()) {
pset.registerIt();
}
item.second.updateID();
}
// make sure contained tracked vpsets are updated
for(vpsettable::iterator i = vpsetTable_.begin(), e = vpsetTable_.end(); i != e; ++i) {
i->second.registerPsetsAndUpdateIDs();
}
// The old, string base code is found below. Uncomment this and the assert to check whether
// there are discrepancies between old and new implementation.
// std::string stringrep;
// toString(stringrep);
// cms::Digest md5alg(stringrep);
// id_ = ParameterSetID(md5alg.digest().toString());
cms::Digest newDigest;
toDigest(newDigest);
id_ = ParameterSetID(newDigest.digest().toString());
// assert(md5alg.digest().toString() == newDigest.digest().toString());
assert(isRegistered());
}
// ----------------------------------------------------------------------
// identification
ParameterSetID
ParameterSet::id() const {
// checks if valid
if(!isRegistered()) {
throw Exception(errors::LogicError)
<< "ParameterSet::id() called prematurely\n"
<< "before ParameterSet::registerIt() has been called.\n";
}
return id_;
}
void ParameterSet::setID(ParameterSetID const& id) {
id_ = id;
}
// ----------------------------------------------------------------------
// Entry-handling
// ----------------------------------------------------------------------
Entry const*
ParameterSet::getEntryPointerOrThrow_(char const* name) const {
return getEntryPointerOrThrow_(std::string(name));
}
Entry const*
ParameterSet::getEntryPointerOrThrow_(std::string const& name) const {
Entry const* result = retrieveUntracked(name);
if(result == 0)
throw Exception(errors::Configuration, "MissingParameter:")
<< "The required parameter '" << name
<< "' was not specified.\n";
return result;
}
template<typename T, typename U> T first(std::pair<T, U> const& p) {
return p.first;
}
template<typename T, typename U> U second(std::pair<T, U> const& p) {
return p.second;
}
Entry const&
ParameterSet::retrieve(char const* name) const {
return retrieve(std::string(name));
}
Entry const&
ParameterSet::retrieve(std::string const& name) const {
table::const_iterator it = tbl_.find(name);
if(it == tbl_.end()) {
throw Exception(errors::Configuration, "MissingParameter:")
<< "Parameter '" << name
<< "' not found.";
}
if(it->second.isTracked() == false) {
if(name[0] == '@') {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Framework Error: Parameter '" << name
<< "' is incorrectly designated as tracked in the framework.";
} else {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Parameter '" << name
<< "' is designated as tracked in the code,\n"
<< "but is designated as untracked in the configuration file.\n"
<< "Please remove 'untracked' from the configuration file for parameter '"<< name << "'.";
}
}
return it->second;
} // retrieve()
Entry const*
ParameterSet::retrieveUntracked(char const* name) const {
return retrieveUntracked(std::string(name));
}
Entry const*
ParameterSet::retrieveUntracked(std::string const& name) const {
table::const_iterator it = tbl_.find(name);
if(it == tbl_.end()) return 0;
if(it->second.isTracked()) {
if(name[0] == '@') {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Framework Error: Parameter '" << name
<< "' is incorrectly designated as untracked in the framework.";
} else {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Parameter '" << name
<< "' is designated as untracked in the code,\n"
<< "but is not designated as untracked in the configuration file.\n"
<< "Please change the configuration file to 'untracked <type> " << name << "'.";
}
}
return &it->second;
} // retrieve()
ParameterSetEntry const&
ParameterSet::retrieveParameterSet(std::string const& name) const {
psettable::const_iterator it = psetTable_.find(name);
if(it == psetTable_.end()) {
throw Exception(errors::Configuration, "MissingParameter:")
<< "ParameterSet '" << name
<< "' not found.";
}
if(it->second.isTracked() == false) {
if(name[0] == '@') {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Framework Error: ParameterSet '" << name
<< "' is incorrectly designated as tracked in the framework.";
} else {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "ParameterSet '" << name
<< "' is designated as tracked in the code,\n"
<< "but is designated as untracked in the configuration file.\n"
<< "Please remove 'untracked' from the configuration file for parameter '"<< name << "'.";
}
}
return it->second;
} // retrieve()
ParameterSetEntry const*
ParameterSet::retrieveUntrackedParameterSet(std::string const& name) const {
psettable::const_iterator it = psetTable_.find(name);
if(it == psetTable_.end()) return 0;
if(it->second.isTracked()) {
if(name[0] == '@') {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "Framework Error: ParameterSet '" << name
<< "' is incorrectly designated as untracked in the framework.";
} else {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "ParameterSet '" << name
<< "' is designated as untracked in the code,\n"
<< "but is not designated as untracked in the configuration file.\n"
<< "Please change the configuration file to 'untracked <type> " << name << "'.";
}
}
return &it->second;
} // retrieve()
VParameterSetEntry const&
ParameterSet::retrieveVParameterSet(std::string const& name) const {
vpsettable::const_iterator it = vpsetTable_.find(name);
if(it == vpsetTable_.end()) {
throw Exception(errors::Configuration, "MissingParameter:")
<< "VParameterSet '" << name
<< "' not found.";
}
if(it->second.isTracked() == false) {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "VParameterSet '" << name
<< "' is designated as tracked in the code,\n"
<< "but is designated as untracked in the configuration file.\n"
<< "Please remove 'untracked' from the configuration file for parameter '"<< name << "'.";
}
return it->second;
} // retrieve()
VParameterSetEntry const*
ParameterSet::retrieveUntrackedVParameterSet(std::string const& name) const {
vpsettable::const_iterator it = vpsetTable_.find(name);
if(it == vpsetTable_.end()) return 0;
if(it->second.isTracked()) {
throw Exception(errors::Configuration, "StatusMismatch:")
<< "VParameterSet '" << name
<< "' is designated as untracked in the code,\n"
<< "but is not designated as untracked in the configuration file.\n"
<< "Please change the configuration file to 'untracked <type> " << name << "'.";
}
return &it->second;
} // retrieve()
Entry const*
ParameterSet::retrieveUnknown(char const* name) const {
return retrieveUnknown(std::string(name));
}
Entry const*
ParameterSet::retrieveUnknown(std::string const& name) const {
table::const_iterator it = tbl_.find(name);
if(it == tbl_.end()) {
return 0;
}
return &it->second;
}
ParameterSetEntry const*
ParameterSet::retrieveUnknownParameterSet(std::string const& name) const {
psettable::const_iterator it = psetTable_.find(name);
if(it == psetTable_.end()) {
return 0;
}
return &it->second;
}
VParameterSetEntry const*
ParameterSet::retrieveUnknownVParameterSet(std::string const& name) const {
vpsettable::const_iterator it = vpsetTable_.find(name);
if(it == vpsetTable_.end()) {
return 0;
}
return &it->second;
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
std::string
ParameterSet::getParameterAsString(std::string const& name) const {
if(existsAs<ParameterSet>(name)) {
return retrieveUnknownParameterSet(name)->toString();
}
else if(existsAs<std::vector<ParameterSet> >(name)) {
return retrieveUnknownVParameterSet(name)->toString();
}
else if(exists(name)) {
return retrieveUnknown(name)->toString();
}
else {
throw Exception(errors::Configuration, "getParameterAsString")
<< "Cannot find parameter " << name << " in " << *this;
}
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
void
ParameterSet::insert(bool okay_to_replace, char const* name, Entry const& value) {
insert(okay_to_replace, std::string(name), value);
}
void
ParameterSet::insert(bool okay_to_replace, std::string const& name, Entry const& value) {
// We should probably get rid of 'okay_to_replace', which will
// simplify the logic in this function.
table::iterator it = tbl_.find(name);
if(it == tbl_.end()) {
if(!tbl_.insert(std::make_pair(name, value)).second)
throw Exception(errors::Configuration, "InsertFailure")
<< "cannot insert " << name
<< " into a ParameterSet\n";
}
else if(okay_to_replace) {
it->second = value;
}
} // insert()
void ParameterSet::insertParameterSet(bool okay_to_replace, std::string const& name, ParameterSetEntry const& entry) {
// We should probably get rid of 'okay_to_replace', which will
// simplify the logic in this function.
psettable::iterator it = psetTable_.find(name);
if(it == psetTable_.end()) {
if(!psetTable_.insert(std::make_pair(name, entry)).second)
throw Exception(errors::Configuration, "InsertFailure")
<< "cannot insert " << name
<< " into a ParameterSet\n";
} else if(okay_to_replace) {
it->second = entry;
}
} // insert()
void ParameterSet::insertVParameterSet(bool okay_to_replace, std::string const& name, VParameterSetEntry const& entry) {
// We should probably get rid of 'okay_to_replace', which will
// simplify the logic in this function.
vpsettable::iterator it = vpsetTable_.find(name);
if(it == vpsetTable_.end()) {
if(!vpsetTable_.insert(std::make_pair(name, entry)).second)
throw Exception(errors::Configuration, "InsertFailure")
<< "cannot insert " << name
<< " into a VParameterSet\n";
} else if(okay_to_replace) {
it->second = entry;
}
} // insert()
void
ParameterSet::augment(ParameterSet const& from) {
// This preemptive invalidation may be more agressive than necessary.
invalidateRegistration(std::string());
if(&from == this) {
return;
}
for(table::const_iterator b = from.tbl_.begin(), e = from.tbl_.end(); b != e; ++b) {
this->insert(false, b->first, b->second);
}
for(psettable::const_iterator b = from.psetTable_.begin(), e = from.psetTable_.end(); b != e; ++b) {
this->insertParameterSet(false, b->first, b->second);
}
for(vpsettable::const_iterator b = from.vpsetTable_.begin(), e = from.vpsetTable_.end(); b != e; ++b) {
this->insertVParameterSet(false, b->first, b->second);
}
} // augment()
void ParameterSet::copyFrom(ParameterSet const& from, std::string const& name) {
invalidateRegistration(std::string());
if(from.existsAs<ParameterSet>(name)) {
this->insertParameterSet(false, name, *(from.retrieveUnknownParameterSet(name)));
}
else if(from.existsAs<std::vector<ParameterSet> >(name)) {
this->insertVParameterSet(false, name, *(from.retrieveUnknownVParameterSet(name)));
}
else if(from.exists(name)) {
this->insert(false, name, *(from.retrieveUnknown(name)));
}
else {
throw Exception(errors::Configuration, "copyFrom")
<< "Cannot find parameter " << name << " in " << from;
}
}
ParameterSet*
ParameterSet::getPSetForUpdate(std::string const& name, bool& isTracked) {
assert(!isRegistered());
isTracked = false;
psettable::iterator it = psetTable_.find(name);
if(it == psetTable_.end()) return 0;
isTracked = it->second.isTracked();
return &it->second.psetForUpdate();
}
VParameterSetEntry*
ParameterSet::getPSetVectorForUpdate(std::string const& name) {
assert(!isRegistered());
vpsettable::iterator it = vpsetTable_.find(name);
if(it == vpsetTable_.end()) return 0;
return &it->second;
}
// ----------------------------------------------------------------------
// coding
// ----------------------------------------------------------------------
void
ParameterSet::toString(std::string& rep) const {
toStringImp(rep, false);
}
void
ParameterSet::allToString(std::string& rep) const {
toStringImp(rep, true);
}
void
ParameterSet::toStringImp(std::string& rep, bool useAll) const {
// make sure the PSets get filled
if(empty()) {
rep += "<>";
return;
}
size_t size = 1;
for(table::const_iterator b = tbl_.begin(), e = tbl_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
size += 2;
size += b->first.size();
size += b->second.sizeOfString();
}
}
for(psettable::const_iterator b = psetTable_.begin(), e = psetTable_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
size += 2;
size += b->first.size();
size += b->first.size();
size += b->first.size();
size += sizeof(ParameterSetID);
}
}
for(vpsettable::const_iterator b = vpsetTable_.begin(), e = vpsetTable_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
size += 2;
size += b->first.size();
size += sizeof(ParameterSetID) * b->second.vpset().size();
}
}
rep.reserve(rep.size()+size);
rep += '<';
std::string start;
std::string const between(";");
for(table::const_iterator b = tbl_.begin(), e = tbl_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
rep += start;
rep += b->first;
rep += '=';
b->second.toString(rep);
start = between;
}
}
for(psettable::const_iterator b = psetTable_.begin(), e = psetTable_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
rep += start;
rep += b->first;
rep += '=';
b->second.toString(rep);
start = between;
}
}
for(vpsettable::const_iterator b = vpsetTable_.begin(), e = vpsetTable_.end(); b != e; ++b) {
if(useAll || b->second.isTracked()) {
rep += start;
rep += b->first;
rep += '=';
b->second.toString(rep);
start = between;
}
}
rep += '>';
} // to_string()
void
ParameterSet::toDigest(cms::Digest &digest) const {
digest.append("<", 1);
bool started = false;
for(table::const_iterator b = tbl_.begin(), e = tbl_.end(); b != e; ++b) {
if(b->second.isTracked()) {
if (started)
digest.append(";", 1);
digest.append(b->first);
digest.append("=", 1);
b->second.toDigest(digest);
started = true;
}
}
for(psettable::const_iterator b = psetTable_.begin(), e = psetTable_.end(); b != e; ++b) {
if(b->second.isTracked()) {
if (started)
digest.append(";", 1);
digest.append(b->first);
digest.append("=", 1);
b->second.toDigest(digest);
started = true;
}
}
for(vpsettable::const_iterator b = vpsetTable_.begin(), e = vpsetTable_.end(); b != e; ++b) {
if(b->second.isTracked()) {
if (started)
digest.append(";", 1);
digest.append(b->first);
digest.append("=", 1);
b->second.toDigest(digest);
}
}
digest.append(">",1);
}
std::string
ParameterSet::toString() const {
std::string result;
toString(result);
return result;
}
// ----------------------------------------------------------------------
bool
ParameterSet::fromString(std::string const& from) {
std::vector<std::string> temp;
if(!split(std::back_inserter(temp), from, '<', ';', '>'))
return false;
tbl_.clear(); // precaution
for(std::vector<std::string>::const_iterator b = temp.begin(), e = temp.end(); b != e; ++b) {
// locate required name/value separator
std::string::const_iterator q = find_in_all(*b, '=');
if(q == b->end())
return false;
// form name unique to this ParameterSet
std::string name = std::string(b->begin(), q);
if(tbl_.find(name) != tbl_.end())
return false;
std::string rep(q+1, b->end());
// entries are generically of the form tracked-type-rep
if(rep[0] == '-') {
}
if(rep[1] == 'Q') {
ParameterSetEntry psetEntry(rep);
if(!psetTable_.insert(std::make_pair(name, psetEntry)).second) {
return false;
}
} else if(rep[1] == 'q') {
VParameterSetEntry vpsetEntry(rep);
if(!vpsetTable_.insert(std::make_pair(name, vpsetEntry)).second) {
return false;
}
} else if(rep[1] == 'P') {
Entry value(name, rep);
ParameterSetEntry psetEntry(value.getPSet(), value.isTracked());
if(!psetTable_.insert(std::make_pair(name, psetEntry)).second) {
return false;
}
} else if(rep[1] == 'p') {
Entry value(name, rep);
VParameterSetEntry vpsetEntry(value.getVPSet(), value.isTracked());
if(!vpsetTable_.insert(std::make_pair(name, vpsetEntry)).second) {
return false;
}
} else {
// form value and insert name/value pair
Entry value(name, rep);
if(!tbl_.insert(std::make_pair(name, value)).second) {
return false;
}
}
}
return true;
} // from_string()
std::vector<FileInPath>::size_type
ParameterSet::getAllFileInPaths(std::vector<FileInPath>& output) const {
std::vector<FileInPath>::size_type count = 0;
table::const_iterator it = tbl_.begin();
table::const_iterator end = tbl_.end();
while (it != end) {
Entry const& e = it->second;
if(e.typeCode() == 'F') {
++count;
output.push_back(e.getFileInPath());
}
++it;
}
return count;
}
std::vector<std::string>
ParameterSet::getParameterNames() const {
using std::placeholders::_1;
std::vector<std::string> returnValue;
std::transform(tbl_.begin(), tbl_.end(), back_inserter(returnValue),
std::bind(&std::pair<std::string const, Entry>::first, _1));
std::transform(psetTable_.begin(), psetTable_.end(), back_inserter(returnValue),
std::bind(&std::pair<std::string const, ParameterSetEntry>::first, _1));
std::transform(vpsetTable_.begin(), vpsetTable_.end(), back_inserter(returnValue),
std::bind(&std::pair<std::string const, VParameterSetEntry>::first, _1));
return returnValue;
}
bool ParameterSet::exists(std::string const& parameterName) const {
return(tbl_.find(parameterName) != tbl_.end() ||
psetTable_.find(parameterName) != psetTable_.end() ||
vpsetTable_.find(parameterName) != vpsetTable_.end());
}
ParameterSet
ParameterSet::trackedPart() const {
ParameterSet result;
for(table::const_iterator tblItr = tbl_.begin(); tblItr != tbl_.end(); ++tblItr) {
if(tblItr->second.isTracked()) {
result.tbl_.insert(*tblItr);
}
}
for(psettable::const_iterator psetItr = psetTable_.begin(); psetItr != psetTable_.end(); ++psetItr) {
if(psetItr->second.isTracked()) {
result.addParameter<ParameterSet>(psetItr->first, psetItr->second.pset().trackedPart());
}
}
for(vpsettable::const_iterator vpsetItr = vpsetTable_.begin(); vpsetItr != vpsetTable_.end(); ++vpsetItr) {
if(vpsetItr->second.isTracked()) {
VParameterSet vresult;
std::vector<ParameterSet> const& this_vpset = vpsetItr->second.vpset();
typedef std::vector<ParameterSet>::const_iterator Iter;
for (Iter i = this_vpset.begin(), e = this_vpset.end(); i != e; ++i) {
vresult.push_back(i->trackedPart());
}
result.addParameter<VParameterSet>(vpsetItr->first, vresult);
}
}
return result;
}
/*
// Comment out unneeded function
size_t
ParameterSet::getAllParameterSetNames(std::vector<std::string>& output) const {
using std::placeholders::_1;
std::transform(psetTable_.begin(), psetTable_.end(), back_inserter(output),
std::bind(&std::pair<std::string const, ParameterSetEntry>::first, _1));
return output.size();
}
*/
size_t
ParameterSet::getParameterSetNames(std::vector<std::string>& output,
bool trackiness) const {
for(psettable::const_iterator psetItr = psetTable_.begin();
psetItr != psetTable_.end(); ++psetItr) {
if(psetItr->second.isTracked() == trackiness) {
output.push_back(psetItr->first);
}
}
return output.size();
}
size_t
ParameterSet::getParameterSetVectorNames(std::vector<std::string>& output,
bool trackiness) const {
for(vpsettable::const_iterator vpsetItr = vpsetTable_.begin();
vpsetItr != vpsetTable_.end(); ++vpsetItr) {
if(vpsetItr->second.isTracked() == trackiness) {
output.push_back(vpsetItr->first);
}
}
return output.size();
}
size_t
ParameterSet::getNamesByCode_(char code,
bool trackiness,
std::vector<std::string>& output) const {
size_t count = 0;
if(code == 'Q') {
return getParameterSetNames(output, trackiness);
}
if(code == 'q') {
return getParameterSetVectorNames(output, trackiness);
}
table::const_iterator it = tbl_.begin();
table::const_iterator end = tbl_.end();
while (it != end) {
Entry const& e = it->second;
if(e.typeCode() == code &&
e.isTracked() == trackiness) { // if it is a vector of ParameterSet
++count;
output.push_back(it->first); // save the name
}
++it;
}
return count;
}
template<>
std::vector<std::string> ParameterSet::getParameterNamesForType<FileInPath>(bool trackiness) const {
std::vector<std::string> result;
getNamesByCode_('F', trackiness, result);
return result;
}
bool operator==(ParameterSet const& a, ParameterSet const& b) {
if(a.isRegistered() && b.isRegistered()) {
return (a.id() == b.id());
}
return isTransientEqual(a.trackedPart(), b.trackedPart());
}
bool isTransientEqual(ParameterSet const& a, ParameterSet const& b) {
if(a.tbl().size() != b.tbl().size()) {
return false;
}
if(a.psetTable().size() != b.psetTable().size()) {
return false;
}
if(a.vpsetTable().size() != b.vpsetTable().size()) {
return false;
}
typedef ParameterSet::table::const_iterator Ti;
for (Ti i = a.tbl().begin(), e = a.tbl().end(),
j = b.tbl().begin(), f = b.tbl().end();
i != e && j != f; ++i, ++j) {
if(*i != *j) {
return false;
}
}
typedef ParameterSet::psettable::const_iterator Pi;
for (Pi i = a.psetTable().begin(), e = a.psetTable().end(),
j = b.psetTable().begin(), f = b.psetTable().end();
i != e && j != f; ++i, ++j) {
if(i->first != j->first) {
return false;
}
if(i->second.isTracked() != j->second.isTracked()) {
return false;
}
if(!isTransientEqual(i->second.pset(), j->second.pset())) {
return false;
}
}
typedef ParameterSet::vpsettable::const_iterator PVi;
for (PVi i = a.vpsetTable().begin(), e = a.vpsetTable().end(),
j = b.vpsetTable().begin(), f = b.vpsetTable().end();
i != e && j != f; ++i, ++j) {
if(i->first != j->first) {
return false;
}
if(i->second.isTracked() != j->second.isTracked()) {
return false;
}
std::vector<ParameterSet> const& iv = i->second.vpset();
std::vector<ParameterSet> const& jv = j->second.vpset();
if(iv.size() != jv.size()) {
return false;
}
for (size_t k = 0; k < iv.size(); ++k) {
if(!isTransientEqual(iv[k], jv[k])) {
return false;
}
}
}
return true;
}
std::string ParameterSet::dump(unsigned int indent) const {
std::ostringstream os;
// indent a bit
std::string indentation(indent, ' ');
os << "{" << std::endl;
for(table::const_iterator i = tbl_.begin(), e = tbl_.end(); i != e; ++i) {
os << indentation << " " << i->first << ": " << i->second << std::endl;
}
for(psettable::const_iterator i = psetTable_.begin(), e = psetTable_.end(); i != e; ++i) {
// indent a bit
std::string n = i->first;
ParameterSetEntry const& pe = i->second;
os << indentation << " " << n << ": " << pe.dump(indent + 2) << std::endl;
}
for(vpsettable::const_iterator i = vpsetTable_.begin(), e = vpsetTable_.end(); i != e; ++i) {
// indent a bit
std::string n = i->first;
VParameterSetEntry const& pe = i->second;
os << indentation << " " << n << ": " << pe.dump(indent + 2) << std::endl;
}
os << indentation << "}";
return os.str();
}
std::ostream& operator<<(std::ostream& os, ParameterSet const& pset) {
os << pset.dump();
return os;
}
// Free function to return a parameterSet given its ID.
ParameterSet const&
getParameterSet(ParameterSetID const& id) {
ParameterSet const* result = nullptr;
if(nullptr == (result = pset::Registry::instance()->getMapped(id))) {
throw Exception(errors::LogicError, "MissingParameterSet:")
<< "Parameter Set ID '" << id << "' not found.";
}
return *result;
}
ParameterSet const&
getProcessParameterSetContainingModule(ModuleDescription const& moduleDescription) {
return getParameterSet(moduleDescription.mainParameterSetID());
}
void ParameterSet::deprecatedInputTagWarning(std::string const& name,
std::string const& label) const {
LogWarning("Configuration") << "Warning:\n\tstring " << name
<< " = \"" << label
<< "\"\nis deprecated, "
<< "please update your config file to use\n\tInputTag "
<< name << " = " << label;
}
// specializations
// ----------------------------------------------------------------------
// Bool, vBool
template<>
bool
ParameterSet::getParameter<bool>(std::string const& name) const {
return retrieve(name).getBool();
}
// ----------------------------------------------------------------------
// Int32, vInt32
template<>
int
ParameterSet::getParameter<int>(std::string const& name) const {
return retrieve(name).getInt32();
}
template<>
std::vector<int>
ParameterSet::getParameter<std::vector<int> >(std::string const& name) const {
return retrieve(name).getVInt32();