Skip to content

Commit

Permalink
Merge pull request #28618 from Dr15Jones/coreSAAllow
Browse files Browse the repository at this point in the history
Add CMS_SA_ALLOW to Core classes
  • Loading branch information
cmsbuild committed Dec 13, 2019
2 parents aa8c411 + f657eb2 commit 001ecd0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
6 changes: 4 additions & 2 deletions DataFormats/Common/interface/ProductData.h
Expand Up @@ -9,6 +9,7 @@ is the storage unit of such information.
----------------------------------------------------------------------*/

#include "DataFormats/Provenance/interface/Provenance.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"
#include <memory>

namespace edm {
Expand Down Expand Up @@ -65,8 +66,9 @@ namespace edm {
// the effort to make the Framework multithread capable ...

private:
// "non-const data" (updated every event)
mutable std::shared_ptr<WrapperBase const> wrapper_;
// "non-const data" (updated every event).
// The mutating function begin with 'unsafe_'
CMS_SA_ALLOW mutable std::shared_ptr<WrapperBase const> wrapper_;
Provenance prov_;
};

Expand Down
4 changes: 3 additions & 1 deletion DataFormats/Provenance/interface/FileIndex.h
Expand Up @@ -10,6 +10,7 @@ FileIndex.h

#include "DataFormats/Provenance/interface/RunID.h"
#include "DataFormats/Provenance/interface/EventID.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <cassert>
#include <iosfwd>
Expand Down Expand Up @@ -117,7 +118,8 @@ namespace edm {
SortState& sortState() const { return transient_.sortState_; }

std::vector<Element> entries_;
mutable Transients transient_;
//Only used within source's serial code
CMS_SA_ALLOW mutable Transients transient_;
};

bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
Expand Down
18 changes: 11 additions & 7 deletions DataFormats/Provenance/interface/IndexIntoFile.h
Expand Up @@ -200,6 +200,7 @@ The interface is too complex for general use.
#include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
#include "FWCore/Utilities/interface/propagate_const.h"
#include "FWCore/Utilities/interface/value_ptr.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <memory>

Expand Down Expand Up @@ -941,14 +942,14 @@ namespace edm {

/// The number of events needs to be set before filling the transient event vectors.
/// It is used to resize them.
void setNumberOfEvents(EntryNumber_t nevents) const { transient_.numberOfEvents_ = nevents; }
void setNumberOfEvents(EntryNumber_t nevents) { transient_.numberOfEvents_ = nevents; }

/// Calling this enables the functions that fill the event vectors to get the event numbers.
/// It needs to be called before filling the events vectors
/// This implies the client needs to define a class that inherits from
/// EventFinder and then create one. This function is used to pass in a
/// pointer to its base class.
void setEventFinder(std::shared_ptr<EventFinder> ptr) const { transient_.eventFinder_ = ptr; }
void setEventFinder(std::shared_ptr<EventFinder> ptr) { transient_.eventFinder_ = ptr; }

/// Fills a vector of event numbers.
/// Not filling it reduces the memory used by IndexIntoFile.
Expand Down Expand Up @@ -990,14 +991,15 @@ namespace edm {
/// If something external to IndexIntoFile is reading through the EventAuxiliary
/// then it could use this to fill in the event numbers so that IndexIntoFile
/// will not read through it again.
std::vector<EventNumber_t>& unsortedEventNumbers() const { return transient_.unsortedEventNumbers_; }
std::vector<EventNumber_t>& unsortedEventNumbers() { return transient_.unsortedEventNumbers_; }
std::vector<EventNumber_t> const& unsortedEventNumbers() const { return transient_.unsortedEventNumbers_; }

/// Clear some vectors and eventFinder when an input file is closed.
/// This reduces the memory used by IndexIntoFile
void inputFileClosed() const;
void inputFileClosed();

/// Clears the temporary vector of event numbers to reduce memory usage
void doneFileInitialization() const;
void doneFileInitialization();

/// Used for backward compatibility and tests.
/// RootFile::fillIndexIntoFile uses this to deal with input files created
Expand All @@ -1023,7 +1025,7 @@ namespace edm {
//*****************************************************************************
//*****************************************************************************

void initializeTransients() const { transient_.reset(); }
void initializeTransients() { transient_.reset(); }

struct Transients {
Transients();
Expand Down Expand Up @@ -1057,6 +1059,7 @@ namespace edm {
/// It depends only on the fact that the persistent data has been filled already.
void fillRunOrLumiIndexes() const;

std::vector<EventNumber_t>& unsortedEventNumbersMutable() const { return transient_.unsortedEventNumbers_; }
void fillUnsortedEventNumbers() const;
void resetEventFinder() const { transient_.eventFinder_ = nullptr; } // propagate_const<T> has no reset() function
std::vector<EventEntry>& eventEntries() const { return transient_.eventEntries_; }
Expand All @@ -1077,7 +1080,8 @@ namespace edm {
return transient_.eventFinder_->getEventNumberOfEntry(entry);
}

mutable Transients transient_;
//This class is used only by one thread at a time within the source serialized code
CMS_SA_ALLOW mutable Transients transient_;

std::vector<ProcessHistoryID> processHistoryIDs_; // of reduced process histories
std::vector<RunOrLumiEntry> runOrLumiEntries_;
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/Provenance/src/IndexIntoFile.cc
Expand Up @@ -280,7 +280,7 @@ namespace edm {
if (numberOfEvents() == 0 || !unsortedEventNumbers().empty()) {
return;
}
unsortedEventNumbers().reserve(numberOfEvents());
unsortedEventNumbersMutable().reserve(numberOfEvents());

// The main purpose for the existence of the unsortedEventNumbers
// vector is that it can easily be filled by reading through
Expand All @@ -289,21 +289,21 @@ namespace edm {
// instead of using getEventNumberOfEntry directly and reading
// the branch in a different order.
for (std::vector<EventNumber_t>::size_type entry = 0U; entry < numberOfEvents(); ++entry) {
unsortedEventNumbers().push_back(getEventNumberOfEntry(entry));
unsortedEventNumbersMutable().push_back(getEventNumberOfEntry(entry));
}
}

// We are closing the input file, but we need to keep event numbers.
// We can delete the other transient collections by using the swap trick.

void IndexIntoFile::inputFileClosed() const {
void IndexIntoFile::inputFileClosed() {
std::vector<EventEntry>().swap(eventEntries());
std::vector<RunOrLumiIndexes>().swap(runOrLumiIndexes());
std::vector<EventNumber_t>().swap(unsortedEventNumbers());
resetEventFinder();
}

void IndexIntoFile::doneFileInitialization() const { std::vector<EventNumber_t>().swap(unsortedEventNumbers()); }
void IndexIntoFile::doneFileInitialization() { std::vector<EventNumber_t>().swap(unsortedEventNumbers()); }

void IndexIntoFile::reduceProcessHistoryIDs(ProcessHistoryRegistry const& processHistoryRegistry) {
std::vector<ProcessHistoryID> reducedPHIDs;
Expand Down
4 changes: 3 additions & 1 deletion FWCore/Framework/interface/LuminosityBlock.h
Expand Up @@ -29,6 +29,7 @@ For its usage, see "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
#include "FWCore/Utilities/interface/propagate_const.h"
#include "FWCore/Utilities/interface/Likely.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -180,7 +181,8 @@ namespace edm {
PrincipalGetAdapter provRecorder_;
ProductPtrVec putProducts_;
LuminosityBlockAuxiliary const& aux_;
mutable std::optional<Run> run_;
//This class is intended to be used by only one thread
CMS_SA_ALLOW mutable std::optional<Run> run_;
ModuleCallingContext const* moduleCallingContext_;

static const std::string emptyString_;
Expand Down
7 changes: 5 additions & 2 deletions FWCore/MessageLogger/src/MessageDrop.cc
Expand Up @@ -16,6 +16,7 @@

// user include files
#include "FWCore/MessageLogger/interface/MessageDrop.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"

// Change Log
//
Expand Down Expand Up @@ -114,8 +115,10 @@ namespace edm {
std::string const* label_;
const char* phasePtr_;
unsigned int moduleID_;
mutable std::string cache_;
mutable std::map<unsigned int, std::string> idLabelMap_;

//This class is only used within a thread local object
CMS_SA_ALLOW mutable std::string cache_;
CMS_SA_ALLOW mutable std::map<unsigned int, std::string> idLabelMap_;
};

class StringProducerPath : public StringProducer {
Expand Down

0 comments on commit 001ecd0

Please sign in to comment.