ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/ReducedSample.cpp
Revision: 1.3
Committed: Wed Jul 24 11:48:55 2013 UTC (11 years, 9 months ago) by grimes
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -47 lines
Log Message:
Big commit of lots of changes before migrating to Git.

File Contents

# User Rev Content
1 grimes 1.1 #include "l1menu/ReducedSample.h"
2    
3     #include <vector>
4     #include <stdexcept>
5     #include <fcntl.h>
6     #include <algorithm>
7     #include <iostream>
8     #include <sstream>
9     #include "l1menu/ReducedEvent.h"
10     #include "l1menu/FullSample.h"
11     #include "l1menu/TriggerMenu.h"
12     #include "l1menu/ITrigger.h"
13     #include "l1menu/ICachedTrigger.h"
14     #include "l1menu/L1TriggerDPGEvent.h"
15     #include "l1menu/IEvent.h"
16     #include "l1menu/IMenuRate.h"
17     #include "l1menu/ITriggerRate.h"
18     #include "l1menu/tools/tools.h"
19     #include "l1menu/implementation/MenuRateImplementation.h"
20     #include "protobuf/l1menu.pb.h"
21     #include <google/protobuf/io/zero_copy_stream_impl.h>
22     #include <google/protobuf/io/gzip_stream.h>
23    
24     namespace // unnamed namespace
25     {
26     /** @brief Sentry that closes a Unix file descriptor when it goes out of scope.
27     * @author Mark Grimes (mark.grimes@bristol.ac.uk)
28     * @date 07/Jun/2013
29     */
30     class UnixFileSentry
31     {
32     public:
33     UnixFileSentry( int fileDescriptor ) : fileDescriptor_(fileDescriptor) {}
34     ~UnixFileSentry() { close(fileDescriptor_); }
35     private:
36     int fileDescriptor_;
37     };
38    
39     /** @brief An object that stores pointers to trigger parameters to avoid costly string comparisons.
40     *
41     * @author Mark Grimes (mark.grimes@bristol.ac.uk)
42     * @date 26/Jun/2013
43     */
44     class CachedTriggerImplementation : public l1menu::ICachedTrigger
45     {
46     public:
47     CachedTriggerImplementation( const l1menu::ReducedSample& sample, const l1menu::ITrigger& trigger )
48     {
49     const auto& parameterIdentifiers=sample.getTriggerParameterIdentifiers(trigger);
50    
51     for( const auto& identifier : parameterIdentifiers )
52     {
53     identifiers_.push_back( std::make_pair( identifier.second, &trigger.parameter(identifier.first) ) );
54     }
55     }
56     virtual bool apply( const l1menu::IEvent& event )
57     {
58     // Not happy using a static_cast, but this method is called in many, many loops.
59     // I should probably find out how much faster this is than a dynamic_cast, maybe
60     // it's not even worth it. Anyway, I'm banking that no one will ever pass an
61     // event that wasn't created with the same sample that this proxy was created
62     // with.
63     const l1menu::ReducedEvent* pEvent=static_cast<const l1menu::ReducedEvent*>(&event);
64     for( const auto& identifier : identifiers_ )
65     {
66     if( pEvent->parameterValue(identifier.first) < *identifier.second ) return false;
67     }
68    
69     // If control got this far then all of the thresholds passed, and
70     // I can pass the event.
71     return true;
72     }
73     protected:
74     std::vector< std::pair<l1menu::ReducedEvent::ParameterID,const float*> > identifiers_;
75     }; // end of class ReducedSampleCachedTrigger
76    
77     float sumWeights( const l1menuprotobuf::Run& run )
78     {
79     float returnValue=0;
80     for( const auto& event : run.event() )
81     {
82     if( event.has_weight() ) returnValue+=event.weight();
83     else returnValue+=1;
84     }
85     return returnValue;
86     }
87     }
88    
89     namespace l1menu
90     {
91     /** @brief Private members for the ReducedSample class
92     *
93     * @author Mark Grimes (mark.grimes@bristol.ac.uk)
94     * @date 28/May/2013
95     */
96     class ReducedSamplePrivateMembers
97     {
98     private:
99     l1menu::TriggerMenu mutableTriggerMenu_;
100     public:
101     ReducedSamplePrivateMembers( const l1menu::ReducedSample& thisObject, const l1menu::TriggerMenu& newTriggerMenu );
102     ReducedSamplePrivateMembers( const l1menu::ReducedSample& thisObject, const std::string& filename );
103     //void copyMenuToProtobufSample();
104     l1menu::ReducedEvent event;
105     const l1menu::TriggerMenu& triggerMenu; // External const access to mutableTriggerMenu_
106     float eventRate;
107     float sumOfWeights;
108     l1menuprotobuf::SampleHeader protobufSampleHeader;
109     // Protobuf doesn't implement move semantics so I'll use pointers
110     std::vector<std::unique_ptr<l1menuprotobuf::Run> > protobufRuns;
111     const static int EVENTS_PER_RUN;
112     const static char PROTOBUF_MESSAGE_DELIMETER;
113     const static std::string FILE_FORMAT_MAGIC_NUMBER;
114     };
115    
116     const int ReducedSamplePrivateMembers::EVENTS_PER_RUN=20000;
117     const char ReducedSamplePrivateMembers::PROTOBUF_MESSAGE_DELIMETER='\n';
118     const std::string ReducedSamplePrivateMembers::FILE_FORMAT_MAGIC_NUMBER="l1menuReducedSample";
119     }
120    
121     l1menu::ReducedSamplePrivateMembers::ReducedSamplePrivateMembers( const l1menu::ReducedSample& thisObject, const l1menu::TriggerMenu& newTriggerMenu )
122     : mutableTriggerMenu_( newTriggerMenu ), event(thisObject), triggerMenu( mutableTriggerMenu_ ), eventRate(1), sumOfWeights(0)
123     {
124     GOOGLE_PROTOBUF_VERIFY_VERSION;
125    
126     // I need to copy the details of the trigger menu into the protobuf storage.
127     // This means I'm holding a duplicate, but I need it to write the sample to a
128     // protobuf file, so I might as well do it now.
129     for( size_t triggerNumber=0; triggerNumber<triggerMenu.numberOfTriggers(); ++triggerNumber )
130     {
131     const l1menu::ITrigger& trigger=triggerMenu.getTrigger(triggerNumber);
132    
133     l1menuprotobuf::Trigger* pProtobufTrigger=protobufSampleHeader.add_trigger();
134     pProtobufTrigger->set_name( trigger.name() );
135     pProtobufTrigger->set_version( trigger.version() );
136    
137     // Record all of the parameters. It's not strictly necessary to record the values
138     // of the parameters that are recorded for each event, but I might as well so that
139     // the trigger menu is loaded exactly as it was saved.
140     const auto parameterNames=trigger.parameterNames();
141     for( const auto& parameterName : parameterNames )
142     {
143     l1menuprotobuf::Trigger_TriggerParameter* pProtobufParameter=pProtobufTrigger->add_parameter();
144     pProtobufParameter->set_name(parameterName);
145     pProtobufParameter->set_value( trigger.parameter(parameterName) );
146     }
147    
148     // Make a note of the names of the parameters that are recorded for each event. For this
149     // I'm just recording the parameters that refer to the thresholds.
150     const auto thresholdNames=l1menu::tools::getThresholdNames(trigger);
151     for( const auto& thresholdName : thresholdNames ) pProtobufTrigger->add_varying_parameter(thresholdName);
152    
153     } // end of loop over triggers
154    
155     // Always make sure there is at least one Run ready to be added to
156     std::unique_ptr<l1menuprotobuf::Run> pNewRun( new l1menuprotobuf::Run );
157     protobufRuns.push_back( std::move( pNewRun ) );
158    
159     }
160    
161     l1menu::ReducedSamplePrivateMembers::ReducedSamplePrivateMembers( const l1menu::ReducedSample& thisObject, const std::string& filename )
162     : event(thisObject), triggerMenu(mutableTriggerMenu_), eventRate(1), sumOfWeights(0)
163     {
164     GOOGLE_PROTOBUF_VERIFY_VERSION;
165    
166     // Open the file with read ability
167     int fileDescriptor = open( filename.c_str(), O_RDONLY );
168     if( fileDescriptor==0 ) throw std::runtime_error( "ReducedSample initialise from file - couldn't open file" );
169     ::UnixFileSentry fileSentry( fileDescriptor ); // Use this as an exception safe way of closing the input file
170     google::protobuf::io::FileInputStream fileInput( fileDescriptor );
171    
172     // First read the magic number at the start of the file and make sure it
173     // matches what I expect. This is uncompressed so I'll wrap it in a block
174     // to make sure the CodedInputStream is destructed before creating a new
175     // one with gzip input.
176     {
177     google::protobuf::io::CodedInputStream codedInput( &fileInput );
178    
179     // As a read buffer, I'll create a string the correct size (filled with an arbitrary
180     // character) and read straight into that.
181     std::string readMagicNumber;
182     if( !codedInput.ReadString( &readMagicNumber, FILE_FORMAT_MAGIC_NUMBER.size() ) ) throw std::runtime_error( "ReducedSample initialise from file - error reading magic number" );
183     if( readMagicNumber!=FILE_FORMAT_MAGIC_NUMBER ) throw std::runtime_error( "ReducedSample - tried to initialise with a file that is not the correct format" );
184    
185     google::protobuf::uint32 fileformatVersion;
186     if( !codedInput.ReadVarint32( &fileformatVersion ) ) throw std::runtime_error( "ReducedSample initialise from file - error reading file format version" );
187     // So far I only have (and ever expect to have) one version of the file
188     // format, imaginatively versioned "1". You never know though...
189     if( fileformatVersion>1 ) std::cerr << "Warning: Attempting to read a ReducedSample with version " << fileformatVersion << " with code that only knows up to version 1." << std::endl;
190     }
191    
192     google::protobuf::io::GzipInputStream gzipInput( &fileInput );
193     google::protobuf::io::CodedInputStream codedInput( &gzipInput );
194    
195     // Disable warnings on this input stream (second parameter, -1). The
196     // first parameter is the default. I'll change this if necessary in
197     // the loop later.
198     size_t totalBytesLimit=67108864;
199     codedInput.SetTotalBytesLimit( totalBytesLimit, -1 );
200    
201     google::protobuf::uint64 messageSize;
202    
203     // Read the size of the header message
204     if( !codedInput.ReadVarint64( &messageSize ) ) throw std::runtime_error( "ReducedSample initialise from file - error reading message size for header" );
205     google::protobuf::io::CodedInputStream::Limit readLimit=codedInput.PushLimit(messageSize);
206     if( !protobufSampleHeader.ParseFromCodedStream( &codedInput ) ) throw std::runtime_error( "ReducedSample initialise from file - some unknown error while reading header" );
207     codedInput.PopLimit(readLimit);
208    
209     // Keep looping until there is nothing more to be read from the file.
210     while( codedInput.ReadVarint64( &messageSize ) )
211     {
212     readLimit=codedInput.PushLimit(messageSize);
213    
214     // Make sure the CodedInputStream doesn't refuse to read the message because it's
215     // read too much already. I'll also add an arbitrary 50 on to always make sure
216     // I can read the next messageSize if there is one.
217     if( gzipInput.ByteCount()+messageSize+50 > totalBytesLimit )
218     {
219     totalBytesLimit+=messageSize*5; // Might as well set it a little higher than necessary while I'm at it.
220     codedInput.SetTotalBytesLimit( totalBytesLimit, -1 );
221     }
222     std::unique_ptr<l1menuprotobuf::Run> pNewRun( new l1menuprotobuf::Run );
223     if( !pNewRun->ParseFromCodedStream( &codedInput ) ) throw std::runtime_error( "ReducedSample initialise from file - some unknown error while reading run" );
224     protobufRuns.push_back( std::move( pNewRun ) );
225    
226     codedInput.PopLimit(readLimit);
227     }
228    
229    
230     // Always make sure there is at least one Run ready to be added to. Later
231     // code assumes there is already a run there.
232     if( protobufRuns.empty() )
233     {
234     std::unique_ptr<l1menuprotobuf::Run> pNewRun( new l1menuprotobuf::Run );
235     protobufRuns.push_back( std::move( pNewRun ) );
236     }
237    
238     // Count up the sum of the weights of all events
239     for( const auto& pRun : protobufRuns )
240     {
241     sumOfWeights+=sumWeights( *pRun );
242     }
243    
244     // I have all of the information in the protobuf members, but I also need the trigger information
245     // in the form of l1menu::TriggerMenu. Copy out the required information.
246     for( int triggerNumber=0; triggerNumber<protobufSampleHeader.trigger_size(); ++triggerNumber )
247     {
248     const l1menuprotobuf::Trigger& inputTrigger=protobufSampleHeader.trigger(triggerNumber);
249    
250     mutableTriggerMenu_.addTrigger( inputTrigger.name(), inputTrigger.version() );
251     // Get a reference to the trigger I just created
252     l1menu::ITrigger& trigger=mutableTriggerMenu_.getTrigger(triggerNumber);
253    
254     // Run through all of the parameters and set them to what they were
255     // when the sample was made.
256     for( int parameterNumber=0; parameterNumber<inputTrigger.parameter_size(); ++parameterNumber )
257     {
258     const auto& inputParameter=inputTrigger.parameter(parameterNumber);
259     trigger.parameter(inputParameter.name())=inputParameter.value();
260     }
261    
262     // I should probably check the threshold names exist. I'll do it another time.
263     }
264    
265     }
266    
267     l1menu::ReducedSample::ReducedSample( const l1menu::FullSample& originalSample, const l1menu::TriggerMenu& triggerMenu )
268     : pImple_( new l1menu::ReducedSamplePrivateMembers( *this, triggerMenu ) )
269     {
270     addSample( originalSample );
271 grimes 1.2 setEventRate( originalSample.eventRate() );
272 grimes 1.1 }
273    
274     l1menu::ReducedSample::ReducedSample( const l1menu::TriggerMenu& triggerMenu )
275     : pImple_( new l1menu::ReducedSamplePrivateMembers( *this, triggerMenu ) )
276     {
277     // No operation besides the initialiser list
278     }
279    
280     l1menu::ReducedSample::ReducedSample( const std::string& filename )
281     : pImple_( new l1menu::ReducedSamplePrivateMembers( *this, filename ) )
282     {
283     // No operation except the initialiser list
284     }
285    
286     l1menu::ReducedSample::~ReducedSample()
287     {
288     // No operation. Just need one defined otherwise the default one messes up
289     // the unique_ptr deletion because ReducedSamplePrivateMembers isn't
290     // defined elsewhere.
291     }
292    
293     void l1menu::ReducedSample::addSample( const l1menu::FullSample& originalSample )
294     {
295     l1menuprotobuf::Run* pCurrentRun=pImple_->protobufRuns.back().get();
296    
297     for( size_t eventNumber=0; eventNumber<originalSample.numberOfEvents(); ++eventNumber )
298     {
299     // Split the events up into groups in arbitrary numbers. This is to get around
300     // a protobuf aversion to long messages.
301     if( pCurrentRun->event_size() >= pImple_->EVENTS_PER_RUN )
302     {
303     // Gone over the arbitrary limit, so create a new protobuf Run and start
304     // using that instead.
305     std::unique_ptr<l1menuprotobuf::Run> pNewRun( new l1menuprotobuf::Run );
306     pImple_->protobufRuns.push_back( std::move( pNewRun ) );
307     pCurrentRun=pImple_->protobufRuns.back().get();
308     }
309    
310     const l1menu::L1TriggerDPGEvent& event=originalSample.getFullEvent( eventNumber );
311     l1menuprotobuf::Event* pProtobufEvent=pCurrentRun->add_event();
312     if( event.weight()!=1 ) pProtobufEvent->set_weight( event.weight() );
313    
314     // Loop over all of the triggers
315     for( size_t triggerNumber=0; triggerNumber<pImple_->triggerMenu.numberOfTriggers(); ++triggerNumber )
316     {
317     std::unique_ptr<l1menu::ITrigger> pTrigger=pImple_->triggerMenu.getTriggerCopy(triggerNumber);
318     std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(*pTrigger);
319    
320     try
321     {
322     l1menu::tools::setTriggerThresholdsAsTightAsPossible( event, *pTrigger, 0.001 );
323     // Set all of the parameters to match the thresholds in the trigger
324     for( const auto& thresholdName : thresholdNames )
325     {
326     pProtobufEvent->add_threshold( pTrigger->parameter(thresholdName) );
327     }
328     }
329     catch( std::exception& error )
330     {
331     // setTriggerThresholdsAsTightAsPossible() couldn't find thresholds so record
332     // -1 for everything.
333     // Range based for loop gives me a warning because I don't use the thresholdName.
334     for( size_t index=0; index<thresholdNames.size(); ++index ) pProtobufEvent->add_threshold(-1);
335     } // end of try block that sets the trigger thresholds
336    
337     } // end of loop over triggers
338    
339     pImple_->sumOfWeights+=event.weight();
340     } // end of loop over events
341     }
342    
343     void l1menu::ReducedSample::saveToFile( const std::string& filename ) const
344     {
345     // Open the file. Parameters are filename, write ability and create, rw-r--r-- permissions.
346     int fileDescriptor = open( filename.c_str(), O_WRONLY | O_CREAT, 0644 );
347     if( fileDescriptor==0 ) throw std::runtime_error( "ReducedSample save to file - couldn't open file" );
348     ::UnixFileSentry fileSentry( fileDescriptor ); // Use this as an exception safe way of closing the output file
349    
350     // Setup the protobuf file handlers
351     google::protobuf::io::FileOutputStream fileOutput( fileDescriptor );
352    
353     // I want the magic number and file format identifier uncompressed, so
354     // I'll write those before switching to using gzipped output.
355     { // Block to make sure codedOutput is destructed before the gzip version is created
356     google::protobuf::io::CodedOutputStream codedOutput( &fileOutput );
357    
358     // Write a magic number at the start of all files
359     codedOutput.WriteString( pImple_->FILE_FORMAT_MAGIC_NUMBER );
360     // Write an integer that specifies what version of the file format I'm using. I
361     // have no intention of changing the format but I might as well keep the option
362     // open.
363     codedOutput.WriteVarint32( 1 );
364     }
365    
366     google::protobuf::io::GzipOutputStream gzipOutput( &fileOutput );
367     google::protobuf::io::CodedOutputStream codedOutput( &gzipOutput );
368    
369     // Write the size of the header message into the file...
370     codedOutput.WriteVarint64( pImple_->protobufSampleHeader.ByteSize() );
371     // ...and then write the header
372     pImple_->protobufSampleHeader.SerializeToCodedStream( &codedOutput );
373    
374     // Now go through each of the runs and do the same for those
375     for( const auto& pRun : pImple_->protobufRuns )
376     {
377     codedOutput.WriteVarint64( pRun->ByteSize() );
378     pRun->SerializeToCodedStream( &codedOutput );
379     }
380    
381     }
382    
383     size_t l1menu::ReducedSample::numberOfEvents() const
384     {
385     size_t numberOfEvents=0;
386     for( const auto& pRun : pImple_->protobufRuns ) numberOfEvents+=pRun->event_size();
387     return numberOfEvents;
388     }
389    
390     const l1menu::TriggerMenu& l1menu::ReducedSample::getTriggerMenu() const
391     {
392     return pImple_->triggerMenu;
393     }
394    
395     bool l1menu::ReducedSample::containsTrigger( const l1menu::ITrigger& trigger, bool allowOlderVersion ) const
396     {
397     // Loop over all of the triggers in the menu, and see if there is one
398     // where the name and version match.
399     for( size_t triggerNumber=0; triggerNumber<pImple_->triggerMenu.numberOfTriggers(); ++triggerNumber )
400     {
401     const l1menu::ITrigger& triggerInMenu=pImple_->triggerMenu.getTrigger(triggerNumber);
402     if( triggerInMenu.name()!=trigger.name() ) continue;
403     if( allowOlderVersion )
404     {
405     if( triggerInMenu.version()>trigger.version() ) continue;
406     }
407     else
408     {
409     if( triggerInMenu.version()!=trigger.version() ) continue;
410     }
411    
412     // If control got this far then there is a trigger with the required name
413     // and sufficient version. I now need to check all of the non threshold parameters
414     // to make sure they match, i.e. make sure the ReducedSample was made with the same
415     // eta cuts or whatever.
416     // I don't care if the thresholds don't match because that's what's stored in the
417     // ReducedSample.
418     std::vector<std::string> parameterNames=l1menu::tools::getNonThresholdParameterNames( trigger );
419     bool allParametersMatch=true;
420     for( const auto& parameterName : parameterNames )
421     {
422     if( trigger.parameter(parameterName)!=triggerInMenu.parameter(parameterName) ) allParametersMatch=false;
423     }
424    
425     if( allParametersMatch ) return true;
426     } // end of loop over triggers
427    
428     // If control got this far then no trigger was found that matched
429     return false;
430     }
431    
432     const std::map<std::string,size_t> l1menu::ReducedSample::getTriggerParameterIdentifiers( const l1menu::ITrigger& trigger, bool allowOlderVersion ) const
433     {
434     std::map<std::string,size_t> returnValue;
435    
436     // Need to find out how many parameters there are for each event. Basically the sum
437     // of the number of thresholds for all triggers.
438     size_t parameterNumber=0;
439     bool triggerWasFound=true;
440     for( size_t triggerNumber=0; triggerNumber<pImple_->triggerMenu.numberOfTriggers(); ++triggerNumber )
441     {
442     const l1menu::ITrigger& triggerInMenu=pImple_->triggerMenu.getTrigger(triggerNumber);
443    
444     triggerWasFound=true; // Set to true, then back to false if any of the tests fail
445     // See if this trigger in the menu is the same as the one passed as a parameter
446     if( triggerInMenu.name()!=trigger.name() ) triggerWasFound=false;
447     if( allowOlderVersion )
448     {
449     if( triggerInMenu.version()>trigger.version() ) triggerWasFound=false;
450     }
451     else
452     {
453     if( triggerInMenu.version()!=trigger.version() ) triggerWasFound=false;
454     }
455    
456     // If control got this far then there is a trigger with the required name
457     // and sufficient version. I now need to check all of the non threshold parameters
458     // to make sure they match, i.e. make sure the ReducedSample was made with the same
459     // eta cuts or whatever.
460     // I don't care if the thresholds don't match because that's what's stored in the
461     // ReducedSample.
462     if( triggerWasFound ) // Trigger can still fail, but no point doing this check if it already has
463     {
464     std::vector<std::string> parameterNames=l1menu::tools::getNonThresholdParameterNames( trigger );
465     for( const auto& parameterName : parameterNames )
466     {
467     if( trigger.parameter(parameterName)!=triggerInMenu.parameter(parameterName) ) triggerWasFound=false;
468     }
469     }
470    
471     std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(triggerInMenu);
472     if( triggerWasFound )
473     {
474     for( const auto& thresholdName : thresholdNames )
475     {
476     returnValue[thresholdName]=parameterNumber;
477     ++parameterNumber;
478     }
479     break;
480     }
481     else parameterNumber+=thresholdNames.size();
482     }
483    
484     // There could conceivably be a trigger that was found but has no thresholds
485     // (I guess - it would be a pretty pointless trigger though). To indicate the
486     // difference between that and a trigger that wasn't found I'll respectively
487     // return the empty vector or throw an exception.
488     if( !triggerWasFound ) throw std::runtime_error( "l1menu::ReducedSample::getTriggerParameterIdentifiers() called for a trigger that was not used to create the sample - "+trigger.name() );
489    
490     return returnValue;
491     }
492    
493     const l1menu::IEvent& l1menu::ReducedSample::getEvent( size_t eventNumber ) const
494     {
495     for( const auto& pRun : pImple_->protobufRuns )
496     {
497     if( eventNumber<static_cast<size_t>(pRun->event_size()) )
498     {
499     pImple_->event.pProtobufEvent_=pRun->mutable_event(eventNumber);
500     return pImple_->event;
501     }
502     // Event must be in a later run, so reduce the number by how many events
503     // were in this run and look again.
504     eventNumber-=pRun->event_size();
505     }
506    
507     // Should always find the event before getting to this point, so throw an
508     // exception if this happens.
509     throw std::runtime_error( "ReducedSample::getEvent(eventNumber) was asked for an invalid eventNumber" );
510     }
511    
512     std::unique_ptr<l1menu::ICachedTrigger> l1menu::ReducedSample::createCachedTrigger( const l1menu::ITrigger& trigger ) const
513     {
514     return std::unique_ptr<l1menu::ICachedTrigger>( new CachedTriggerImplementation(*this,trigger) );
515     }
516    
517     float l1menu::ReducedSample::eventRate() const
518     {
519     return pImple_->eventRate;
520     }
521    
522     void l1menu::ReducedSample::setEventRate( float rate )
523     {
524     pImple_->eventRate=rate;
525     }
526    
527     float l1menu::ReducedSample::sumOfWeights() const
528     {
529     return pImple_->sumOfWeights;
530     }
531    
532     std::unique_ptr<const l1menu::IMenuRate> l1menu::ReducedSample::rate( const l1menu::TriggerMenu& menu ) const
533     {
534     // TODO make sure the TriggerMenu is valid for this sample
535 grimes 1.3 return std::unique_ptr<const l1menu::IMenuRate>( new l1menu::implementation::MenuRateImplementation( menu, *this ) );
536 grimes 1.1 }