Public Types |
Static Public Member Functions |
Private Types |
Private Member Functions |
Private Attributes |
Friends
ProjectionHandler Class Reference The projection handler is a central repository for projections to be used in a Rivet analysis run. More...
Detailed DescriptionThe projection handler is a central repository for projections to be used in a Rivet analysis run. Without centralised projections, it can be hard to know which of an equivalent set of projections will be run on a particular event. In turn, this may mean that certain projections in the chain can go out of scope unexpectedly. There were originally also the issues that projections may need to be held as member pointers to an abstract base class, since post-construction setup is needed; that projections contained pointers to their own dependency chain, which could go out of scope; and that projection members could be modified after being applied to an event which, due to the caching model, would have unpredictable consequences. By centralising all the projections, these issues are eliminated, as well as allowing analysis classes to contain fewer data members (since projections are now better accessed by name than by storing a data member reference or pointer). The core of the ProjectionHandler design is that it is a singleton class, essentially a wrapper around a map of Definition at line 39 of file ProjectionHandler.hh. Member Typedef Documentation
Typedef for the structure used to contain named projections for a particular containing Analysis or Projection. Definition at line 50 of file ProjectionHandler.hh.
Structure used to map a containing Analysis or Projection to its set of contained projections. Definition at line 60 of file ProjectionHandler.hh.
Typedef for a vector of Projection pointers. Definition at line 46 of file ProjectionHandler.hh. Member Enumeration Documentation
Enum to specify depth of projection search. Definition at line 53 of file ProjectionHandler.hh. Constructor & Destructor Documentation
Private destructor means no inheritance from this class.
The copy constructor is hidden.
The standard constructor. Member Function Documentation
Check that this parent projection doesn't already use this name. Definition at line 159 of file ProjectionHandler.cc. { auto listedParent = _namedprojs.find(&parent); if (listedParent != _namedprojs.end()) { const NamedProjs pnps = listedParent->second; const NamedProjs::const_iterator ipph = pnps.find(name); if (ipph != pnps.end()) { const ProjHandle pph = ipph->second; getLog() << Log::ERROR << "Projection clash! " << parent.name() << " (" << &parent << ") " << "is trying to overwrite its registered '" << name << "' " << "projection (" << pph << "=" << pph->name() << ") with a non-equivalent projection " << "(" << &proj << "=" << proj.name() << ")" << endl; getLog() << Log::ERROR << _getStatus(); return false; } } return true; }
Make a clone of proj, copying across child references from the original. Definition at line 51 of file ProjectionHandler.cc. { // Clone a new copy of the passed projection on the heap getLog() << Log::TRACE << "Cloning projection " << proj.name() << " from " << &proj << "..." << endl; unique_ptr<Projection> newproj = proj.clone(); getLog() << Log::TRACE << "...cloned to " << proj.name() << " at " << newproj.get() << endl; // Copy all the child ProjHandles when cloning, since otherwise links to "stack parents" // will be generated by their children, without any connection to the cloned parent if (&proj != newproj.get()) { auto nps = _namedprojs.find(&proj); if (nps != _namedprojs.end()) { getLog() << Log::TRACE << "Cloning registered projections list: " << &proj << " -> " << newproj.get() << endl; getLog() << Log::TRACE << "** creates " << newproj.get() << " -> (map from " << nps->first << ")\n"; _namedprojs[newproj.get()] = nps->second; } } return newproj; }
Try to get an equivalent projection from the system
Definition at line 106 of file ProjectionHandler.cc. { // Get class type using RTTI const std::type_info& newtype = typeid(proj); getLog() << Log::TRACE << "RTTI type of " << &proj << " is " << newtype.name() << endl; // Compare to ALL projections via _projs collection getLog() << Log::TRACE << "Comparing " << &proj << " with " << _projs.size() << " registered projection" << (_projs.size() == 1 ? "" : "s") << endl; foreach (const ProjHandle& ph, _projs) { // Make sure the concrete types match, using RTTI. const std::type_info& regtype = typeid(*ph); getLog() << Log::TRACE << " RTTI type comparison with " << ph << ": " << newtype.name() << " vs. " << regtype.name() << endl; if (newtype != regtype) continue; getLog() << Log::TRACE << " RTTI type matches with " << ph << endl; // Test for semantic match if (pcmp(*ph, proj) != EQUIVALENT) { getLog() << Log::TRACE << " Projections at " << &proj << " and " << ph << " are not equivalent" << endl; } else { getLog() << Log::TRACE << " MATCH! Projections at " << &proj << " and " << ph << " are equivalent" << endl; return ph; } } getLog() << Log::TRACE << " Nothing matches." << endl; // If no match, just return a null pointer return nullptr; }
Get a string dump of the current ProjHandler structure. Definition at line 141 of file ProjectionHandler.cc. { ostringstream msg; msg << "Current projection hierarchy:" << endl; foreach (const NamedProjsMap::value_type& nps, _namedprojs) { //const string parentname = nps.first->name(); msg << nps.first << endl; //"(" << parentname << ")" << endl; foreach (const NamedProjs::value_type& np, nps.second) { msg << " " << np.second << " (" << np.second->name() << ", locally called '" << np.first << "')" << endl; } msg << endl; } return msg.str(); }
Internal function to do the registering. Definition at line 76 of file ProjectionHandler.cc. { // here we take ownership of the projection getLog() << Log::TRACE << "Registering new projection at " << p.get() << ". Starting refcount: " << p.use_count() << endl; // Add the passed Projection to _projs _projs.insert(p); getLog() << Log::TRACE << "** inserted " << p.get() << " to lookup. Refcount: " << p.use_count() << endl; // Add the ProjApplier* => name location to the associative container _namedprojs[&parent][name] = p; getLog() << Log::TRACE << "** created " << &parent << " -> (" << name << ',' << p.get() << "). Refcount: " << p.use_count() << endl; p->markAsOwned(); return *p; }
Get child projections for the given parent. By default this will just return the projections directly contained by the parent, but the depth argument can be changed to do a deep retrieval, which will recurse through the whole projection chain. In this case, there is no protection against getting stuck in a circular projection dependency loop. Definition at line 209 of file ProjectionHandler.cc. { set<const Projection*> toplevel; NamedProjs nps = _namedprojs.find(&parent)->second; foreach (NamedProjs::value_type& np, nps) { toplevel.insert(np.second.get()); } if (depth == SHALLOW) { // Only return the projections directly contained within the top level return toplevel; } else { // Return recursively built projection list set<const Projection*> alllevels = toplevel; foreach (const Projection* p, toplevel) { set<const Projection*> allsublevels = getChildProjections(*p, DEEP); alllevels.insert(allsublevels.begin(), allsublevels.end()); } return alllevels; } }
Singleton creation function. Definition at line 94 of file ProjectionHandler.hh. { static ProjectionHandler _instance; return _instance; }
Retrieve a named projection for the given parent. Returning as a reference is partly to discourage ProjectionApplier classes from storing pointer members to the registered projections, since that can lead to problems and there is no need to do so. Definition at line 234 of file ProjectionHandler.cc. { //getLog() << Log::TRACE << "Searching for child projection '" // << name << "' of " << &parent << endl; NamedProjsMap::const_iterator nps = _namedprojs.find(&parent); if (nps == _namedprojs.end()) { ostringstream msg; msg << "No projections registered for parent " << &parent; throw Error(msg.str()); } NamedProjs::const_iterator np = nps->second.find(name); if (np == nps->second.end()) { ostringstream msg; msg << "No projection '" << name << "' found for parent " << &parent; throw Error(msg.str()); } // If it's registered with the projection handler, we must be able to safely // dereference the Projection pointer to a reference... return *(np->second); }
The assignment operator is hidden.
Attach and retrieve a projection as a reference. Definition at line 20 of file ProjectionHandler.cc. { getLog() << Log::TRACE << "Trying to register" << " projection " << &proj << " (" << proj.name() << ")" << " for parent " << &parent << " (" << parent.name() << ")" << " with name '" << name << "'" << endl; // Check for duplicate use of "name" on "parent" const bool dupOk = _checkDuplicate(parent, proj, name); if (!dupOk) { cerr << "Duplicate name '" << name << "' in parent '" << parent.name() << "'." << endl; exit(1); } // Choose which version of the projection to register with this parent and name ProjHandle ph = _getEquiv(proj); if ( ph ) { const Projection & ret = _register(parent, ph, name); return ret; } else { unique_ptr<Projection> p = _clone(proj); const Projection & ret = _register(parent, move(p), name); // Return registered proj return ret; } }
Remove a ProjectionApplier: designed to only be called by ~ProjectionApplier (as a friend) Definition at line 185 of file ProjectionHandler.cc. { auto npi = _namedprojs.find(&parent); if (npi != _namedprojs.end()) { getLog() << Log::TRACE << "REMOVE Projection at " << &parent << " from map" << endl; _namedprojs.erase(npi); } // auto pAsProj = dynamic_cast<Projection*>(&parent); if (pAsProj) { auto pi = find_if(_projs.begin(), _projs.end(), [pAsProj](ProjHandle h)->bool { return h.get() == pAsProj; } ); if (pi != _projs.end()) { getLog() << Log::TRACE << "REMOVE Projection at " << pAsProj << " from lookup" << endl; _projs.erase(pi); } } } Friends And Related Function Documentation
ProjectionApplier's destructor needs to trigger cleaning up the proj handler repo. Definition at line 43 of file ProjectionHandler.hh. Member Data Documentation
Core data member, associating a given containing class (via a ProjectionApplier pointer) to its contained projections. Definition at line 64 of file ProjectionHandler.hh.
Cache of Projections for reverse lookup, to speed up registering new projections as Definition at line 68 of file ProjectionHandler.hh. The documentation for this class was generated from the following files: Generated on Tue Dec 13 2016 16:32:46 for The Rivet MC analysis system by ![]() |