New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed non-const static for FastSimulation/L1CaloTriggerProducer/ #1421
Fixed non-const static for FastSimulation/L1CaloTriggerProducer/ #1421
Conversation
A new Pull Request was created by @nclopezo (David Mendez) for CMSSW_7_0_X. Fixed non-const static for FastSimulation/L1CaloTriggerProducer/ It involves the following packages: FastSimulation/L1CaloTriggerProducer @cmsbuild, @nclopezo, @giamman, @lveldere can you please review it and eventually sign? Thanks. |
@@ -562,7 +562,7 @@ | |||
// rest are vetoed; 5=0101;7=0111;9=1001;10=1010;11=1011;13=1101;14=1110;15=1111 | |||
// --- Alternate patterns | |||
// --- 9=1001;15=1111 | |||
static std::vector<unsigned> vetoPatterns; | |||
std::vector<unsigned> vetoPatterns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing this to
static const std::vector<unsigned> vetoPatterns = { 5, 7, 9, 10,11,13,14,15};
vetoPatterns.push_back(5);
vetoPatterns.push_back(7);
vetoPatterns.push_back(9);
vetoPatterns.push_back(10);
vetoPatterns.push_back(11);
vetoPatterns.push_back(13);
vetoPatterns.push_back(14);
vetoPatterns.push_back(15);
};
Where you actually move the declaration of vetoPatterns
to be just before the function which uses it. This will make it a file scope static which the compiler can create and initialize outside the body of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the previous comment, remove the vetoPatterns.push_back(..);
lines. Those were a cut-n-paste error. All you want is
static const std::vector<unsigned> vetoPatterns = { 5, 7, 9, 10,11,13,14,15};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok if I do this?
static const std::vector<unsigned> vetoPatterns = { 5, 7, 9, 10,11,13,14,15};
for(std::vector<unsigned>::const_iterator i = vetoPatterns.begin();
i != vetoPatterns.end(); i++) {
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will work. However a function local static requires the compiler to add a lot of overhead code in order to initialize the value in a thread-safe manner. By moving the 'static const' outside of the function you avoid all that extra work.
+1 |
This pull request is fully signed and it will be integrated in one of the next IBs unless changes or unless it breaks tests. @ktf can you please take care of it? |
This pull request is fully signed and it will be integrated in one of the next IBs unless changes or unless it breaks tests. @ktf can you please take care of it? |
@nclopezo: Notice that in |
…ionL1CaloTriggerProducer Multithreading fixes -- Fixed non-const static for FastSimulation/L1CaloTriggerProducer
No description provided.