7 #ifndef D3PDMAKERREADER_ROOTREADERD3PD_V2_CONSTANTS_H
8 #define D3PDMAKERREADER_ROOTREADERD3PD_V2_CONSTANTS_H
10 static const char*
const VARHANDLE_HEADER_NAME =
"VarHandle.h";
11 static const char*
const VARHANDLE_HEADER =
12 "// Dear emacs, this is -*- c++ -*-\n"
13 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
14 "#ifndef D3PDREADER_VARHANDLE_H\n"
15 "#define D3PDREADER_VARHANDLE_H\n\n"
16 "// ROOT include(s):\n"
17 "#include <TString.h>\n"
18 "#include <TDataType.h>\n\n"
19 "// Local include(s):\n"
20 "#include \"D3PDReadStats.h\"\n\n"
21 "// Forward declaration(s):\n"
24 "namespace D3PDReader {\n\n"
26 " * @short Base class for the different kind of VarHandle specializations\n"
28 " * This class is used to keep a list of all the VarHandle members of\n"
29 " * a D3PDObject class. It makes some operations much easier.\n"
31 " * $Revision: 600807 $\n"
32 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
34 " class VarHandleBase {\n\n"
36 " /// Custom enumeration describing the availability of the branch\n"
37 " enum BranchAvailability {\n"
38 " UNKNOWN = 0, ///< The input TTree has not yet been checked\n"
39 " AVAILABLE = 1, ///< The input branch is available\n"
40 " UNAVAILABLE = 2 ///< The input branch is not available\n"
43 " /// Constructor specifying all the needed parameters\n"
44 " VarHandleBase( const char* name = \"\",\n"
45 " const ::Long64_t* master = 0 );\n"
46 " /// The destructor is actually only useful in the specialized class...\n"
47 " virtual ~VarHandleBase() {}\n\n"
48 " /// Get the name of the branch handled by this class\n"
49 " const char* GetName() const;\n"
50 " /// Set the name of the branch handled by this class\n"
51 " void SetName( const char* name );\n\n"
52 " /// Get the type name of the branch handled by this object\n"
53 " const char* GetType() const;\n"
54 " /// Set the type name of the branch handled by this object\n"
55 " void SetType( const char* type );\n\n"
56 " /// Get a pointer to the master entry variable\n"
57 " const ::Long64_t* GetMaster() const;\n"
58 " /// Set the pointer to the master entry variable\n"
59 " void SetMaster( const ::Long64_t* master );\n\n"
60 " /// Connect the object to an input tree\n"
61 " virtual void ReadFrom( ::TTree* tree ) = 0;\n"
62 " /// Connect the object to an output tree\n"
63 " virtual ::TBranch* WriteTo( ::TTree* tree ) = 0;\n\n"
64 " /// Check if this variable is \"active\" at the moment\n"
65 " ::Bool_t IsActive() const;\n"
66 " /// Set the \"activity level\" of the variable\n"
67 " void SetActive( ::Bool_t active = kTRUE );\n\n"
68 " /// Check if the variable is available in the input\n"
69 " virtual ::Bool_t IsAvailable() const;\n\n"
70 " /// Read in the current entry from the branch\n"
71 " virtual void ReadCurrentEntry() const = 0;\n\n"
72 " /// \"Clear\" the variable of its contents\n"
73 " virtual void Clear() = 0;\n\n"
74 " /// Get information about the read statistics\n"
75 " virtual VariableStats GetStatistics() const;\n\n"
77 " /// Connect the variable to the branch\n"
78 " ::Bool_t ConnectVariable( void* var, ::TClass* realClass,\n"
79 " EDataType dtype, Bool_t isptr ) const;\n"
80 " /// Update the variable to the current entry in the D3PD\n"
81 " void UpdateBranch() const;\n"
82 " /// Switch to a new tree in the statistics gathering\n"
83 " void UpdateStat( ::TBranch* br ) const;\n"
84 " /// Translate the typeid() type name to something ROOT understands\n"
85 " const char* RootType( const char* typeid_type ) const;\n"
86 " /// Translate the typeid() type name to a huma-readable ROOT type name\n"
87 " const char* RootCppType( const char* typeid_type ) const;\n\n"
88 " const ::Long64_t* fMaster; ///< Pointer to the current entry number\n"
89 " ::Bool_t fFromInput; ///< Flag showing if the variable is read from an input TTree\n"
90 " ::TTree* fInTree; ///< The input TTree\n"
91 " mutable ::TBranch* fInBranch; /// The input branch belonging to this variable\n"
92 " mutable BranchAvailability fAvailable; ///< Availability of the branch\n\n"
94 " ::TString fName; ///< Name of the branch to handle\n"
95 " ::Bool_t fActive; ///< Flag telling if the variable can be written to the output\n\n"
96 " ::TString fType; ///< Variable type\n"
97 " mutable std::vector< ::Long64_t > fEntriesRead; ///< Number of read entries for each tree\n"
98 " mutable std::vector< ::Float_t > fBranchSize; ///< Unzipped entry size for each tree\n"
99 " mutable std::vector< ::Float_t > fZippedSize; ///< Zipped entry size for each tree\n\n"
100 " }; // class VarHandleBase\n\n"
102 " * @short Class responsible for reading primitive types from the D3PD\n"
104 " * This class is used by all the D3PDReader classes to physically\n"
105 " * handle the branches of the input TTree.\n"
107 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
109 " * $Revision: 600807 $\n"
110 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
112 " template< typename Type >\n"
113 " class VarHandle : public VarHandleBase {\n\n"
115 " /// Convenience typedef of the used variable\n"
116 " typedef Type& result_type;\n"
117 " /// Convenience typedef of the used variable (const version)\n"
118 " typedef const Type& const_result_type;\n\n"
119 " /// Constructor specifying all the needed parameters\n"
120 " VarHandle( const char* name = \"\",\n"
121 " const ::Long64_t* master = 0 );\n"
122 " /// The destructor is actually only useful in the specialized class...\n"
124 " /// Connect the object to an input tree\n"
125 " virtual void ReadFrom( ::TTree* tree );\n"
126 " /// Connect the object to an output tree\n"
127 " virtual ::TBranch* WriteTo( ::TTree* tree );\n\n"
128 " /// Operator used to access the branch itself\n"
129 " result_type operator()();\n"
130 " /// Operator used to access the branch itself (constant version)\n"
131 " const_result_type operator()() const;\n\n"
132 " /// Read in the current entry from the branch\n"
133 " virtual void ReadCurrentEntry() const;\n\n"
134 " /// \"Clear\" the variable of its contents\n"
135 " virtual void Clear();\n\n"
136 " /// Set the value of the variable. Used primarily from Python.\n"
137 " void Set( Type value );\n\n"
139 " mutable Type fVariable; ///< The variable in memory\n\n"
140 " }; // class VarHandle\n\n"
142 " * @short Class responsible for reading STL objects from the D3PD\n"
144 " * This specialization of the template class makes it possible to\n"
145 " * handle branches describing primitive types and branches describing\n"
146 " * STL collections a little differently.\n"
148 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
150 " * $Revision: 600807 $\n"
151 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
153 " template< typename Type >\n"
154 " class VarHandle< Type* > : public VarHandleBase {\n\n"
156 " /// Convenience typedef of the used variable\n"
157 " typedef Type* result_type;\n"
158 " /// Convenience typedef of the used variable (const version)\n"
159 " typedef const Type* const_result_type;\n\n"
160 " /// Constructor specifying all the needed parameters\n"
161 " VarHandle( const char* name = \"\",\n"
162 " const ::Long64_t* master = 0 );\n"
163 " /// This destructor actually does something...\n"
165 " /// Connect the object to an input tree\n"
166 " virtual void ReadFrom( ::TTree* tree );\n"
167 " /// Connect the object to an output tree\n"
168 " virtual ::TBranch* WriteTo( ::TTree* tree );\n\n"
169 " /// Operator used to access the branch itself\n"
170 " result_type operator()();\n"
171 " /// Operator used to access the branch itself (constant version)\n"
172 " const_result_type operator()() const;\n\n"
173 " /// Read in the current entry from the branch\n"
174 " virtual void ReadCurrentEntry() const;\n\n"
175 " /// \"Clear\" the variable of its contents\n"
176 " virtual void Clear();\n\n"
177 " /// Set the value of the variable. Used primarily from Python.\n"
178 " void Set( const_result_type value );\n\n"
180 " mutable Type* fVariable; ///< The variable in memory\n\n"
181 " }; // class VarHandle\n\n"
182 "} // namespace D3PDReader\n\n"
183 "// Include the implementation:\n"
185 "#include \"VarHandle.icc\"\n"
186 "#endif // __CINT__\n\n"
187 "#endif // D3PDREADER_VARHANDLE_H";
189 static const char*
const VARHANDLE_IMPL_NAME =
"VarHandle.icc";
190 static const char*
const VARHANDLE_IMPL =
191 "// Dear emacs, this is -*- c++ -*-\n"
192 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
193 "#ifndef D3PDREADER_VARHANDLE_ICC\n"
194 "#define D3PDREADER_VARHANDLE_ICC\n\n"
195 "// System include(s):\n"
196 "#include <string.h>\n"
197 "#include <cxxabi.h>\n"
198 "#include <cstdlib>\n\n"
199 "// ROOT include(s):\n"
200 "#include <TObject.h>\n"
201 "#include <TClass.h>\n"
202 "#include <TTree.h>\n"
203 "#include <TBranch.h>\n"
204 "#include <TError.h>\n\n"
205 "namespace D3PDReader {\n\n"
206 " template< typename Type >\n"
207 " VarHandle< Type >::VarHandle( const char* name,\n"
208 " const ::Long64_t* master )\n"
209 " : VarHandleBase( name, master ),\n"
211 " SetType( RootCppType( typeid( Type ).name() ) );\n"
213 " template< typename Type >\n"
214 " VarHandle< Type >::~VarHandle() {\n\n"
216 " template< typename Type >\n"
217 " void VarHandle< Type >::ReadFrom( ::TTree* tree ) {\n\n"
219 " fFromInput = kTRUE;\n"
222 " fAvailable = UNKNOWN;\n\n"
225 " template< typename Type >\n"
226 " ::TBranch* VarHandle< Type >::WriteTo( ::TTree* tree ) {\n\n"
227 " if( ! IsActive() ) return 0;\n\n"
228 " ::TBranch* branch = tree->GetBranch( GetName() );\n"
229 " if( branch ) return branch;\n\n"
230 " branch = tree->Branch( GetName(), &fVariable,\n"
231 " ::TString::Format( \"%s/%s\", GetName(),\n"
232 " RootType( typeid( Type ).name() ) ) );\n"
233 " if( ! branch ) {\n"
234 " ::Error( \"D3PDReader::VarHandle::WriteTo\",\n"
235 " \"Couldn't add variable %s to tree %s\",\n"
236 " GetName(), tree->GetName() );\n"
238 " for( ::Long64_t i = 0; i < tree->GetEntries(); ++i ) {\n"
244 " template< typename Type >\n"
245 " typename VarHandle< Type >::result_type VarHandle< Type >::operator()() {\n\n"
246 " if( ! fFromInput ) return fVariable;\n\n"
247 " if( ! fInBranch ) {\n"
248 " if( ! ConnectVariable( &fVariable, TClass::GetClass( typeid( Type ) ),\n"
249 " TDataType::GetType( typeid( Type ) ), kFALSE ) ) {\n"
250 " ::Error( ::TString( \"D3PDReader::VarHandle::\" ) + GetName() + \"()\",\n"
251 " \"Failed connecting to D3PD\" );\n"
252 " return fVariable;\n"
255 " UpdateBranch();\n\n"
256 " return fVariable;\n"
258 " template< typename Type >\n"
259 " typename VarHandle< Type >::const_result_type VarHandle< Type >::operator()() const {\n\n"
260 " if( ! fFromInput ) return fVariable;\n\n"
261 " if( ! fInBranch ) {\n"
262 " if( ! ConnectVariable( &fVariable, TClass::GetClass( typeid( Type ) ),\n"
263 " TDataType::GetType( typeid( Type ) ), kFALSE ) ) {\n"
264 " ::Error( ::TString( \"D3PDReader::VarHandle::\" ) + GetName() + \"()\",\n"
265 " \"Failed connecting to D3PD\" );\n"
266 " return fVariable;\n"
269 " UpdateBranch();\n\n"
270 " return fVariable;\n"
272 " template< typename Type >\n"
273 " void VarHandle< Type >::ReadCurrentEntry() const {\n\n"
274 " if( IsAvailable() ) {\n"
275 " this->operator()();\n"
281 " template< typename Type >\n"
282 " void VarHandle< Type >::Clear() {\n\n"
283 " this->operator()() = 0;\n"
286 " template< typename Type >\n"
287 " void VarHandle< Type >::Set( Type value ) {\n\n"
288 " fVariable = value;\n"
291 " template< typename Type >\n"
292 " VarHandle< Type* >::VarHandle( const char* name,\n"
293 " const ::Long64_t* master )\n"
294 " : VarHandleBase( name, master ),\n"
295 " fVariable( 0 ) {\n\n"
297 " char* type_name = abi::__cxa_demangle( typeid( Type ).name(), 0, 0, &status );\n"
298 " if( ! status ) {\n"
299 " SetType( type_name );\n"
300 " ::free( type_name );\n"
303 " template< typename Type >\n"
304 " VarHandle< Type* >::~VarHandle() {\n\n"
305 " if( fVariable ) delete fVariable;\n"
307 " template< typename Type >\n"
308 " void VarHandle< Type* >::ReadFrom( ::TTree* tree ) {\n\n"
310 " fFromInput = kTRUE;\n"
311 " if( fVariable ) fVariable->clear();\n"
313 " fAvailable = UNKNOWN;\n\n"
316 " template< typename Type >\n"
317 " ::TBranch* VarHandle< Type* >::WriteTo( ::TTree* tree ) {\n\n"
318 " if( ! IsActive() ) return 0;\n\n"
319 " ::TBranch* branch = tree->GetBranch( GetName() );\n"
320 " if( branch ) return branch;\n\n"
321 " if( ! ::strcmp( GetType(), \"\" ) ) {\n"
322 " ::Error( \"D3PDReader::VarHandle::WriteTo\",\n"
323 " \"Couldn't demangle type name: %s\",\n"
324 " typeid( Type ).name() );\n"
327 " if( ! fVariable ) {\n"
328 " fVariable = new Type();\n"
330 " branch = tree->Bronch( GetName(), GetType(), &fVariable );\n"
331 " if( ! branch ) {\n"
332 " ::Error( \"D3PDReader::VarHandle::WriteTo\",\n"
333 " \"Couldn't add variable %s to tree %s\",\n"
334 " GetName(), tree->GetName() );\n"
336 " for( ::Long64_t i = 0; i < tree->GetEntries(); ++i ) {\n"
342 " template< typename Type >\n"
343 " typename VarHandle< Type* >::result_type\n"
344 " VarHandle< Type* >::operator()() {\n\n"
345 " if( ! fFromInput ) {\n"
346 " if( ! fVariable ) fVariable = new Type();\n"
347 " return fVariable;\n"
349 " if( ! fInBranch ) {\n"
350 " if( ! ConnectVariable( &fVariable, TClass::GetClass( typeid( Type ) ),\n"
351 " TDataType::GetType( typeid( Type ) ), kTRUE ) ) {\n"
352 " ::Error( ::TString( \"D3PDReader::VarHandle::\" ) + GetName() + \"()\",\n"
353 " \"Failed connecting to D3PD\" );\n"
354 " return fVariable;\n"
357 " UpdateBranch();\n\n"
358 " return fVariable;\n"
360 " template< typename Type >\n"
361 " typename VarHandle< Type* >::const_result_type\n"
362 " VarHandle< Type* >::operator()() const {\n\n"
363 " if( ! fFromInput ) {\n"
364 " if( ! fVariable ) fVariable = new Type();\n"
365 " return fVariable;\n"
367 " if( ! fInBranch ) {\n"
368 " if( ! ConnectVariable( &fVariable, TClass::GetClass( typeid( Type ) ),\n"
369 " TDataType::GetType( typeid( Type ) ), kTRUE ) ) {\n"
370 " ::Error( ::TString( \"D3PDReader::VarHandle::\" ) + GetName() + \"()\",\n"
371 " \"Failed connecting to D3PD\" );\n"
372 " return fVariable;\n"
375 " UpdateBranch();\n\n"
376 " return fVariable;\n"
378 " template< typename Type >\n"
379 " void VarHandle< Type* >::ReadCurrentEntry() const {\n\n"
380 " if( IsAvailable() ) {\n"
381 " this->operator()();\n"
383 " if( ! fVariable ) fVariable = new Type();\n"
384 " fVariable->clear();\n"
388 " template< typename Type >\n"
389 " void VarHandle< Type* >::Clear() {\n\n"
390 " this->operator()()->clear();\n"
393 " template< typename Type >\n"
394 " void VarHandle< Type* >::Set( const_result_type value ) {\n\n"
395 " *fVariable = *value;\n"
398 "} // namespace D3PDReader\n\n"
399 "#endif // D3PDREADER_VARHANDLE_ICC";
401 static const char*
const VARHANDLE_CXX_NAME =
"VarHandle.cxx";
402 static const char*
const VARHANDLE_CXX =
403 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n\n"
404 "// ROOT include(s):\n"
405 "#include <TError.h>\n\n"
406 "// Local include(s):\n"
407 "#include \"VarHandle.h\"\n"
408 "#include \"D3PDPerfStats.h\"\n\n"
409 "namespace D3PDReader {\n\n"
410 " VarHandleBase::VarHandleBase( const char* name,\n"
411 " const ::Long64_t* master )\n"
412 " : fMaster( master ), fFromInput( kFALSE ),\n"
413 " fInTree( 0 ), fInBranch( 0 ), fAvailable( UNKNOWN ), fName( name ),\n"
414 " fActive( kFALSE ), fType( \"\" ),\n"
415 " fEntriesRead(), fBranchSize(), fZippedSize() {\n\n"
416 "#ifdef COLLECT_D3PD_READING_STATISTICS\n"
417 " D3PDPerfStats::Instance();\n"
418 "#endif // COLLECT_D3PD_READING_STATISTICS\n"
420 " const char* VarHandleBase::GetName() const {\n\n"
423 " void VarHandleBase::SetName( const char* name ) {\n\n"
427 " const char* VarHandleBase::GetType() const {\n\n"
430 " void VarHandleBase::SetType( const char* type ) {\n\n"
434 " const ::Long64_t* VarHandleBase::GetMaster() const {\n\n"
437 " void VarHandleBase::SetMaster( const ::Long64_t* master ) {\n\n"
438 " fMaster = master;\n"
441 " ::Bool_t VarHandleBase::IsActive() const {\n\n"
444 " void VarHandleBase::SetActive( ::Bool_t active ) {\n\n"
445 " fActive = active;\n"
448 " ::Bool_t VarHandleBase::IsAvailable() const {\n\n"
449 " if( ! fFromInput ) return kTRUE;\n"
450 " switch( fAvailable ) {\n\n"
454 " case UNAVAILABLE:\n"
459 " if( ! fInTree ) return kTRUE;\n"
460 " ::Bool_t temp = kFALSE;\n"
461 " fAvailable = ( temp = fInTree->GetBranch( GetName() ) ) ? AVAILABLE :\n"
467 " // This should really never be reached...\n"
470 " // It's just here to make the compiler happy:\n"
473 " VariableStats VarHandleBase::GetStatistics() const {\n\n"
474 " // Calculate the statistics:\n"
475 " ::Long64_t readEntries = 0;\n"
476 " ::Long64_t unzippedBytes = 0;\n"
477 " ::Long64_t zippedBytes = 0;\n"
478 " for( size_t i = 0; i < fEntriesRead.size(); ++i ) { \n"
479 " readEntries += fEntriesRead[ i ];\n"
480 " unzippedBytes += static_cast< ::Long64_t >( fBranchSize[ i ] *\n"
481 " fEntriesRead[ i ] );\n"
482 " zippedBytes += static_cast< ::Long64_t >( fZippedSize[ i ] *\n"
483 " fEntriesRead[ i ] );\n"
485 " // Now return the \"smart\" object:\n"
486 " return VariableStats( GetName(), GetType(),\n"
487 " fEntriesRead.size(), readEntries,\n"
488 " unzippedBytes, zippedBytes );\n"
490 " ::Bool_t VarHandleBase::ConnectVariable( void* var, ::TClass* realClass,\n"
491 " EDataType dtype, Bool_t isptr ) const {\n\n"
492 " if( ! fInTree ) {\n"
493 " ::Error( \"D3PDReader::VarHandleBase::ConnectVariable\",\n"
494 " \"Object not connected yet!\" );\n"
497 " if( ! fInTree->GetBranch( GetName() ) ) {\n"
498 " ::Error( \"D3PDReader::VarHandleBase::ConnectVariable\",\n"
499 " \"The following variable doesn't exist: %s\",\n"
503 "#ifdef ACTIVATE_BRANCHES\n"
504 " // Only call this function when the user asks for it. It's quite expensive...\n"
505 " fInTree->SetBranchStatus( ::TString( GetName() ) + \"*\", 1 );\n"
506 "#endif // ACTIVATE_BRANCHES\n"
507 " if( fInTree->SetBranchAddress( GetName(), var, &fInBranch,\n"
508 " realClass, dtype, isptr ) ) {\n"
509 " ::Error( \"D3PDReader::VarHandleBase::ConnectVariable\",\n"
510 " \"Couldn't connect variable to branch: %s\", GetName() );\n"
513 "#ifdef COLLECT_D3PD_READING_STATISTICS\n"
514 " UpdateStat( fInBranch );\n"
515 "#endif // COLLECT_D3PD_READING_STATISTICS\n\n"
518 " void VarHandleBase::UpdateBranch() const {\n\n"
519 " if( *fMaster != fInBranch->GetReadEntry() ) {\n"
520 " fInBranch->GetEntry( *fMaster );\n"
521 "#ifdef COLLECT_D3PD_READING_STATISTICS\n"
522 " ++( fEntriesRead.back() );\n"
523 "#endif // COLLECT_D3PD_READING_STATISTICS\n"
527 " void VarHandleBase::UpdateStat( ::TBranch* br ) const {\n\n"
528 " fEntriesRead.push_back( 0 );\n"
529 " fBranchSize.push_back( ( ::Float_t ) br->GetTotalSize( \"*\" ) /\n"
530 " ( ::Float_t ) br->GetEntries() );\n"
531 " fZippedSize.push_back( ( ::Float_t ) br->GetZipBytes( \"*\" ) /\n"
532 " ( ::Float_t ) br->GetEntries() );\n\n"
533 " D3PDPerfStats::Instance()->NewTreeAccessed( fInTree );\n\n"
536 " const char* VarHandleBase::RootType( const char* typeid_type ) const {\n\n"
537 " if( strlen( typeid_type ) != 1 ) {\n"
538 " ::Error( \"D3PDReader::VarHandleBase::RootType\",\n"
539 " \"Received complex object description\" );\n"
542 " switch( typeid_type[ 0 ] ) {\n\n"
577 " ::Error( \"D3PDReader::VarHandleBase::RootType\",\n"
578 " \"Unknown primitive type encountered: %s\",\n"
582 " const char* VarHandleBase::RootCppType( const char* typeid_type ) const {\n\n"
583 " if( strlen( typeid_type ) != 1 ) {\n"
584 " ::Error( \"D3PDReader::VarHandleBase::RootCppType\",\n"
585 " \"Received complex object description\" );\n"
588 " switch( typeid_type[ 0 ] ) {\n\n"
590 " return \"Char_t\";\n"
593 " return \"UChar_t\";\n"
596 " return \"Short_t\";\n"
599 " return \"UShort_t\";\n"
602 " return \"Int_t\";\n"
605 " return \"UInt_t\";\n"
608 " return \"Float_t\";\n"
611 " return \"Double_t\";\n"
614 " return \"Long64_t\";\n"
617 " return \"ULong64_t\";\n"
620 " return \"Bool_t\";\n"
623 " ::Error( \"D3PDReader::VarHandleBase::RootCppType\",\n"
624 " \"Unknown primitive type encountered: %s\",\n"
628 "} // namespace D3PDReader";
630 static const char*
const VARPROXY_HEADER_NAME =
"VarProxy.h";
631 static const char*
const VARPROXY_HEADER =
632 "// Dear emacs, this is -*- c++ -*-\n"
633 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
634 "#ifndef D3PDREADER_VARPROXY_H\n"
635 "#define D3PDREADER_VARPROXY_H\n\n"
636 "// STL include(s):\n"
637 "#include <vector>\n\n"
638 "// Local include(s):\n"
639 "#include \"VarHandle.h\"\n\n"
640 "namespace D3PDReader {\n\n"
642 " * @short Base class for the VarProxy versions\n"
644 " * This class is needed for technical reasons in order to handle\n"
645 " * user defined variables in a nice way.\n"
647 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
649 " * $Revision: 600807 $\n"
650 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
652 " class VarProxyBase {\n\n"
654 " /// Destructor, to make vtable happy\n"
655 " virtual ~VarProxyBase() {}\n\n"
656 " /// Check if the variable is available in the input\n"
657 " virtual ::Bool_t IsAvailable() const = 0;\n\n"
658 " }; // class VarProxyBase\n\n"
660 " * @short Class acting as a proxy to one element of an std::vector\n"
662 " * This class is used in the \"Element\" classes to represent one\n"
663 " * object from a collection.\n"
665 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
667 " * $Revision: 600807 $\n"
668 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
670 " template< typename Type >\n"
671 " class VarProxy : public VarProxyBase {\n\n"
673 " /// Convenience typedef of the used variable\n"
674 " typedef Type& result_type;\n"
675 " /// Convenience typedef of the used variable (const version)\n"
676 " typedef const Type& const_result_type;\n\n"
677 " /// Constructor specifying the handle object this proxy uses\n"
678 " VarProxy( const VarHandle< std::vector< Type >* >& handle, size_t i );\n"
679 " /// Copy constructor\n"
680 " VarProxy( const VarProxy< Type >& parent );\n"
681 " /// Copy operator\n"
682 " VarProxy< Type >& operator=( const VarProxy< Type >& parent );\n\n"
683 " /// Check if the variable is available in the input\n"
684 " virtual ::Bool_t IsAvailable() const;\n\n"
685 " /// Operator returning the variable belonging to this object\n"
686 " result_type operator()();\n"
687 " /// Operator returning the variable belonging to this object (constant version)\n"
688 " const_result_type operator()() const;\n\n"
690 " VarHandle< std::vector< Type >* >* fHandle; ///< Pointer to the handle object\n"
691 " size_t fIndex; ///< Index inside the handle object's vector\n"
692 " Type fDummy; ///< Object returned by default\n\n"
693 " }; // class VarProxy\n\n"
694 "} // namespace D3PDReader\n\n"
695 "// Include the implementation:\n"
697 "#include \"VarProxy.icc\"\n"
698 "#endif // __CINT__\n\n"
699 "#endif // D3PDREADER_VARPROXY_H";
701 static const char*
const VARPROXY_IMPL_NAME =
"VarProxy.icc";
702 static const char*
const VARPROXY_IMPL =
703 "// Dear emacs, this is -*- c++ -*-\n"
704 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
705 "#ifndef D3PDREADER_VARPROXY_ICC\n"
706 "#define D3PDREADER_VARPROXY_ICC\n\n"
707 "// ROOT include(s):\n"
708 "#include <TError.h>\n\n"
709 "namespace D3PDReader {\n\n"
710 " template< typename Type >\n"
711 " VarProxy< Type >::VarProxy( const VarHandle< std::vector< Type >* >& handle,\n"
713 " : fHandle( const_cast< VarHandle< std::vector< Type >* >* >( &handle ) ),\n"
714 " fIndex( i ), fDummy() {\n\n"
716 " template< typename Type >\n"
717 " VarProxy< Type >::VarProxy( const VarProxy< Type >& parent )\n"
718 " : VarProxyBase(), fHandle( parent.fHandle ), fIndex( parent.fIndex ),\n"
721 " template< typename Type >\n"
722 " VarProxy< Type >& VarProxy< Type >::operator=( const VarProxy< Type >& parent ) {\n\n"
723 " fHandle = parent.fHandle;\n"
724 " fIndex = parent.fIndex;\n\n"
727 " template< typename Type >\n"
728 " ::Bool_t VarProxy< Type >::IsAvailable() const {\n\n"
729 " return fHandle->IsAvailable();\n"
731 " template< typename Type >\n"
732 " typename VarProxy< Type >::result_type VarProxy< Type >::operator()() {\n\n"
733 " if( fHandle->IsAvailable() ) {\n"
734 " return ( ( *( *fHandle )() ) )[ fIndex ];\n"
736 " ::Warning( ::TString( \"D3PDReader::VarProxy::\" ) + fHandle->GetName() + \"()\",\n"
737 " \"Variable not available on input. Returning 0\" );\n"
741 " template< typename Type >\n"
742 " typename VarProxy< Type >::const_result_type VarProxy< Type >::operator()() const {\n\n"
743 " if( fHandle->IsAvailable() ) {\n"
744 " return ( ( *( *fHandle )() ) )[ fIndex ];\n"
746 " ::Warning( ::TString( \"D3PDReader::VarProxy::\" ) + fHandle->GetName() + \"()\",\n"
747 " \"Variable not available on input. Returning 0\" );\n"
751 "} // namespace D3PDReader\n\n"
752 "#endif // D3PDREADER_VARPROXY_ICC";
754 static const char*
const D3PDOBJECTBASE_HEADER_NAME =
"D3PDObjectBase.h";
755 static const char*
const D3PDOBJECTBASE_HEADER =
756 "// Dear emacs, this is -*- c++ -*-\n"
757 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
758 "#ifndef D3PDREADER_D3PDOBJECTBASE_H\n"
759 "#define D3PDREADER_D3PDOBJECTBASE_H\n\n"
760 "// ROOT include(s):\n"
761 "#include <TNamed.h>\n"
762 "#include <TString.h>\n\n"
763 "// Local include(s):\n"
764 "#include \"D3PDReadStats.h\"\n\n"
765 "// Forward declaration(s):\n"
767 "namespace D3PDReader {\n\n"
769 " * @short Common base class for all main D3PDReader classes\n"
771 " * To make the classes a bit easier to handle in \"smart\" code\n"
772 " * they inherit from a common base that defines all of their\n"
773 " * common features.\n"
775 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
777 " * $Revision: 600807 $\n"
778 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
780 " class D3PDObjectBase : public ::TNamed {\n\n"
782 " /// Default constructor\n"
783 " D3PDObjectBase() : ::TNamed() {}\n\n"
784 " /// Get the currently configured prefix value\n"
785 " virtual const char* GetPrefix() const = 0;\n"
786 " /// Set the prefix for the variables\n"
787 " virtual void SetPrefix( const char* prefix ) = 0;\n\n"
788 " /// Connect the object to an input TTree\n"
789 " virtual void ReadFrom( ::TTree* tree ) = 0;\n"
790 " /// Connect the object to an output TTree\n"
791 " virtual void WriteTo( ::TTree* tree ) = 0;\n\n"
792 " /// Turn (selected) branches either on or off\n"
793 " virtual void SetActive( ::Bool_t active = kTRUE,\n"
794 " const ::TString& pattern = \".*\" ) = 0;\n\n"
795 " /// Read in all the variables that we need to write out as well\n"
796 " virtual void ReadAllActive() = 0;\n\n"
797 " /// Get the D3PD reading statistics\n"
798 " virtual D3PDReadStats GetStatistics() const = 0;\n\n"
799 " ClassDef( D3PDObjectBase, 0 )\n\n"
800 " }; // class D3PDObjectBase\n\n"
801 "} // namespace D3PDReader\n\n"
802 "#endif // D3PDREADER_D3PDOBJECTBASE_H";
804 static const char*
const D3PDREADSTATS_HEADER_NAME =
"D3PDReadStats.h";
805 static const char*
const D3PDREADSTATS_HEADER =
806 "// Dear emacs, this is -*- c++ -*-\n"
807 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
808 "#ifndef D3PDREADER_D3PDREADSTATS_H\n"
809 "#define D3PDREADER_D3PDREADSTATS_H\n\n"
810 "// STL include(s):\n"
812 "#include <vector>\n\n"
813 "// ROOT include(s):\n"
814 "#include <TNamed.h>\n"
815 "#include <TString.h>\n\n"
816 "// Forward declaration(s):\n"
817 "class TCollection;\n"
820 "namespace D3PDReader {\n\n"
821 " // Forward declaration(s):\n"
822 " class D3PDPerfStats;\n\n"
824 " * @short Class describing the access statistics of one variable\n"
826 " * Objects of this class are used to describe a single D3PD variable's\n"
827 " * access pattern.\n"
829 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
831 " * $Revision: 600807 $\n"
832 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
834 " class VariableStats : public ::TNamed {\n\n"
836 " /// Constructor specifying all parameters\n"
837 " VariableStats( const char* name = \"d3pd_variable\",\n"
838 " const char* type = \"Int_t\",\n"
839 " ::Int_t nTreesAccessed = 0, ::Long64_t nReadEntries = 0,\n"
840 " ::Long64_t nUnzippedBytes = 0, ::Long64_t nZippedBytes = 0 );\n"
841 " /// Copy constructor\n"
842 " VariableStats( const VariableStats& parent );\n\n"
843 " /// Assignment operator\n"
844 " VariableStats& operator= ( const VariableStats& parent );\n\n"
845 " /// Get how many trees were accessed to read this variable\n"
846 " ::Int_t GetTreesAccessed() const;\n"
847 " /// Set how many trees were accessed to read this variable\n"
848 " void SetTreesAccessed( ::Int_t nTreesAccessed );\n\n"
849 " /// Get how many entries were read from this branch\n"
850 " ::Long64_t GetReadEntries() const;\n"
851 " /// Set how many entries were read from this branch\n"
852 " void SetReadEntries( ::Long64_t nReadEntries );\n\n"
853 " /// Get how many unzipped bytes were read from this branch in total\n"
854 " ::Long64_t GetUnzippedBytesRead() const;\n"
855 " /// Set how many unzipped bytes were read from this branch in total\n"
856 " void SetUnzippedBytesRead( ::Long64_t nUnzippedBytes );\n\n"
857 " /// Get how many zipped bytes were read from this branch in total\n"
858 " ::Long64_t GetZippedBytesRead() const;\n"
859 " /// Set how many zipped bytes were read from this branch in total\n"
860 " void SetZippedBytesRead( ::Long64_t nZippedBytes );\n\n"
861 " /// Function merging two objects\n"
862 " VariableStats& Add( const VariableStats& rh );\n"
863 " /// Operator merging two objects\n"
864 " VariableStats& operator+= ( const VariableStats& rh );\n\n"
865 " /// Function merging the information from multiple objects\n"
866 " ::Int_t Merge( ::TCollection* coll );\n\n"
867 " /// Print information about the collected statistics\n"
868 " void Print( ::Option_t* option = \"\" ) const;\n\n"
870 " ::Int_t fTreesAccessed; ///< Number of trees accessed for this variable\n"
871 " ::Long64_t fReadEntries; ///< Number of entries read from this branch\n"
872 " ::Long64_t fUnzippedBytes; ///< Number of unzipped bytes read from this branch\n"
873 " ::Long64_t fZippedBytes; ///< Number of zipped bytes read from this branch\n\n"
874 " ClassDef( VariableStats, 1 )\n\n"
875 " }; // class VariableStats\n\n"
877 " * @short Class describing the access statistics of a collection of branches\n"
879 " * Objects of this class are used to describe the access pattern of a D3PD\n"
880 " * analysis. The object can also be used to optimize the caching for the\n"
881 " * analysis in subsequent runs.\n"
883 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
885 " * $Revision: 600807 $\n"
886 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
888 " class D3PDReadStats : public ::TNamed {\n\n"
890 " /// Type of the internal object gathering information\n"
892 " * Notice that I can't write <code>::TString</code> here, because\n"
893 " * the generated dictionary would then have code with <code><::</code>\n"
894 " * in it, which is not a valid C++ operator.\n"
896 " typedef std::map< ::TString, VariableStats > Map_t;\n\n"
897 " /// Constructor just specifying the name of the object\n"
898 " D3PDReadStats( const char* name = \"D3PDReadStats\",\n"
899 " const char* title = \"D3PD reading statistics\" );\n"
900 " /// Copy constructor\n"
901 " D3PDReadStats( const D3PDReadStats& parent );\n\n"
902 " /// Assignment operator\n"
903 " D3PDReadStats& operator= ( const D3PDReadStats& parent );\n\n"
904 " /// Clear the statistics information\n"
905 " void Clear( ::Option_t* opt = \"\" );\n\n"
906 " /// Set how many bytes were read in total during the analysis\n"
907 " void SetBytesRead( ::Long64_t num );\n"
908 " /// Get how many bytes were read in total during the analysis\n"
909 " ::Long64_t GetBytesRead() const;\n\n"
910 " /// Set the total number of variables of the input\n"
911 " void SetVariableNum( ::Int_t num );\n"
912 " /// Get the total number of variables of the input\n"
913 " ::Int_t GetVariableNum() const;\n\n"
914 " /// Set the total number of file read calls\n"
915 " void SetFileReads( ::Int_t num );\n"
916 " /// Get the total number of file read calls\n"
917 " ::Int_t GetFileReads() const;\n\n"
918 " /// Set the TTreeCache size used\n"
919 " void SetCacheSize( ::Int_t size );\n"
920 " /// Get the TTreeCache size used\n"
921 " ::Int_t GetCacheSize() const;\n\n"
922 " /// Set the time spent in unzipping the data\n"
923 " void SetUnzipTime( ::Double_t time );\n"
924 " /// Get the time spent in unzipping the data\n"
925 " ::Double_t GetUnzipTime() const;\n\n"
926 " /// Set the time spent in processing events\n"
927 " void SetProcessTime( ::Double_t time );\n"
928 " /// Get the time spent in processing events\n"
929 " ::Double_t GetProcessTime() const;\n\n"
930 " /// Add information about a variable to the object\n"
931 " D3PDReadStats& AddVariable( const VariableStats& var );\n"
932 " /// Get information about a specific variable\n"
933 " const VariableStats* GetVariable( const char* name ) const;\n"
934 " /// Get all variable information\n"
935 " const Map_t& GetVariables() const;\n\n"
936 " /// Function checking if two objects are \"compatible\"\n"
937 " ::Bool_t IsCompatible( const D3PDReadStats& rh ) const;\n"
938 " /// Function merging two objects\n"
939 " D3PDReadStats& Add( const D3PDReadStats& rh );\n"
940 " /// Operator merging two objects\n"
941 " D3PDReadStats& operator+= ( const D3PDReadStats& rh );\n\n"
942 " /// Add all branches that were ever accessed, to the TTreeCache\n"
943 " void AddToTreeCache( ::TTree* tree ) const;\n"
944 " /// Add the branches accessed more than n times to the TTreeCache\n"
945 " void AddToTreeCacheByEntries( ::TTree* tree, ::Long64_t minEntries ) const;\n"
946 " /// Add the branches accessed more than a given fraction of times to the TTreeCache\n"
947 " void AddToTreeCacheByEntryFrac( ::TTree* tree,\n"
948 " ::Double_t minEvFraction ) const;\n"
949 " /// Add the branches from which more than x bytes were read, to the TTreeCache\n"
950 " void AddToTreeCacheByBytes( ::TTree* tree, ::Long64_t minBytes ) const;\n"
951 " /// Add the branches from whith more than a given fraction of the bytes were read, to the TTreeCache\n"
952 " void AddToTreeCacheByByteFrac( ::TTree* tree,\n"
953 " ::Double_t minByteFraction ) const;\n\n"
956 " /// Get the branches accessed more than n times\n"
957 " std::vector< TString > GetBranchesByEntries( ::Long64_t minEntries ) const;\n"
958 " /// Get the branches accessed more than a given fraction of times\n"
959 " std::vector< TString > GetBranchesByEntryFrac( ::Double_t minEvFraction ) const;\n"
960 " /// Get the branches from which more than x bytes were read\n"
961 " std::vector< TString > GetBranchesByBytes( ::Long64_t minBytes ) const;\n"
962 " /// Get the branches from which more than a given fraction of bytes were read\n"
963 " std::vector< TString > GetBranchesByByteFrac( ::Double_t minByteFraction ) const;\n\n"
964 " /// Get a histogram with the TTree access statistics\n"
965 " ::TH1* GetTreeAccessStat() const;\n"
966 " /// Get a histogram with the entry reading statistics\n"
967 " ::TH1* GetEntryReadStat() const;\n"
968 " /// Get a histogram with the zipped byte reading statistics\n"
969 " ::TH1* GetZippedByteReadStat() const;\n"
970 " /// Get a histogram with the unzipped byte reading statistics\n"
971 " ::TH1* GetUnzippedByteReadStat() const;\n\n"
972 " /// Function merging the information from multiple objects\n"
973 " ::Int_t Merge( ::TCollection* coll );\n\n"
974 " /// Print information about the collected statistics\n"
975 " void Print( ::Option_t* option = \"\" ) const;\n\n"
977 " /// Statistics about the variables\n"
978 " Map_t fVariables;\n"
979 " /// Total number of bytes read\n"
980 " ::Long64_t fBytesRead;\n"
981 " /// Total number of variables in the input D3PD TTree\n"
982 " ::Int_t fVariableNum;\n"
983 " /// Total number of file reading operations during the analysis\n"
984 " ::Int_t fFileReads;\n"
985 " /// Cache size used in the analysis\n"
986 " ::Int_t fCacheSize;\n"
987 " /// Time spent unzipping the events\n"
988 " ::Double_t fUnzipTime;\n"
989 " /// Time spent in processing the events\n"
990 " ::Double_t fProcessTime;\n\n"
991 " ClassDef( D3PDReadStats, 1 )\n\n"
992 " }; // class D3PDReadStats\n\n"
993 "} // namespace D3PDReader\n\n"
994 "#endif // D3PDREADER_D3PDREADSTATS_H";
996 static const char*
const D3PDREADSTATS_CXX_NAME =
"D3PDReadStats.cxx";
997 static const char*
const D3PDREADSTATS_CXX =
998 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n\n"
999 "// System include(s):\n"
1000 "#include <cstring>\n"
1001 "#include <functional>\n"
1002 "#include <algorithm>\n\n"
1003 "// ROOT include(s):\n"
1004 "#include <TCollection.h>\n"
1005 "#include <TTree.h>\n"
1006 "#include <TH1.h>\n\n"
1007 "// Local include(s):\n"
1008 "#include \"D3PDReadStats.h\"\n"
1009 "#include \"Utils.h\"\n\n"
1010 "ClassImp( D3PDReader::VariableStats )\n"
1011 "ClassImp( D3PDReader::D3PDReadStats )\n\n"
1013 " /// Strict weak ordering based on the number of trees accessed by a variable\n"
1015 " * This helper function is used together with the STL std::sort algorithm\n"
1016 " * to sort the D3PD variables based on how many trees they had to access\n"
1017 " * during an analysis.\n"
1019 " * @param v1 The first variable's access statistics\n"
1020 " * @param v2 The second variable's access statistics\n"
1021 " * @returns <code>kTRUE</code> if the first variable accessed more trees\n"
1022 " * than the second one. <code>kFALSE</code> otherwise.\n"
1024 " ::Bool_t SortByTrees( const D3PDReader::VariableStats& v1,\n"
1025 " const D3PDReader::VariableStats& v2 ) {\n\n"
1026 " return ( v1.GetTreesAccessed() > v2.GetTreesAccessed() );\n"
1028 " /// Strict weak ordering based on the number of entries read from a variable\n"
1030 " * This helper function is used together with the STL std::sort algorithm\n"
1031 " * to sort the D3PD variables based on how many events they were read in.\n"
1033 " * @param v1 The first variable's access statistics\n"
1034 " * @param v2 The second variable's access statistics\n"
1035 " * @returns <code>kTRUE</code> if the first variable was accessed more times\n"
1036 " * than the second one. <code>kFALSE</code> otherwise.\n"
1038 " ::Bool_t SortByEntries( const D3PDReader::VariableStats& v1,\n"
1039 " const D3PDReader::VariableStats& v2 ) {\n\n"
1040 " return ( v1.GetReadEntries() > v2.GetReadEntries() );\n"
1042 " /// Strict weak ordering based on the number of bytes read from a variable\n"
1044 " * This helper function is used together with the STL std::sort algorithm\n"
1045 " * to sort the D3PD variables based on how much data was read from them.\n"
1047 " * The ordering is based on the amount of compressed data read from disk.\n"
1048 " * That is usually the more interesting one for disk access optimizations.\n"
1050 " * @param v1 The first variable's access statistics\n"
1051 " * @param v2 The second variable's access statistics\n"
1052 " * @returns <code>kTRUE</code> if the first variable read more data\n"
1053 " * than the second one. <code>kFALSE</code> otherwise.\n"
1055 " ::Bool_t SortByZippedBytes( const D3PDReader::VariableStats& v1,\n"
1056 " const D3PDReader::VariableStats& v2 ) {\n\n"
1057 " return ( v1.GetZippedBytesRead() > v2.GetZippedBytesRead() );\n"
1059 " /// Strict weak ordering based on the number of bytes unpacked from a variable\n"
1061 " * This helper function is used together with the STL std::sort algorithm\n"
1062 " * to sort the D3PD variables based on how much data was unpacked from them.\n"
1064 " * @param v1 The first variable's access statistics\n"
1065 " * @param v2 The second variable's access statistics\n"
1066 " * @returns <code>kTRUE</code> if the first variable unpacked more data\n"
1067 " * than the second one. <code>kFALSE</code> otherwise.\n"
1069 " ::Bool_t SortByUnzippedBytes( const D3PDReader::VariableStats& v1,\n"
1070 " const D3PDReader::VariableStats& v2 ) {\n\n"
1071 " return ( v1.GetUnzippedBytesRead() > v2.GetUnzippedBytesRead() );\n"
1074 " * @short Smart class for selecting branches for caching\n"
1076 " * This class can be used to select branches for the cache which\n"
1077 " * were accessed more than some number of times in a previous job.\n"
1079 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
1081 " * $Revision: 600807 $\n"
1082 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
1084 " class SelectByEntries\n"
1087 " /// Constructor specifying the minimum number of entries\n"
1088 " SelectByEntries( ::Long64_t entries ) : fEntries( entries ) {}\n"
1089 " /// Constructor finding the minimum number of entries\n"
1090 " SelectByEntries( const D3PDReader::D3PDReadStats::Map_t& vars,\n"
1091 " ::Double_t minEvFrac )\n"
1092 " : fEntries( 0 ) {\n\n"
1093 " ::Long64_t maxEntries = 0;\n"
1094 " D3PDReader::D3PDReadStats::Map_t::const_iterator itr = vars.begin();\n"
1095 " D3PDReader::D3PDReadStats::Map_t::const_iterator end = vars.end();\n"
1096 " for( ; itr != end; ++itr ) {\n"
1097 " if( itr->second.GetReadEntries() > maxEntries ) {\n"
1098 " maxEntries = itr->second.GetReadEntries();\n"
1101 " fEntries = static_cast< ::Long64_t >( minEvFrac * maxEntries );\n"
1103 " /// Operator evaluating if a variable should be selected\n"
1104 " ::Bool_t operator()( const D3PDReader::VariableStats& var ) const {\n\n"
1105 " if( var.GetReadEntries() < fEntries ) {\n"
1112 " ::Long64_t fEntries; ///< Minimum number of entries for variable\n\n"
1113 " }; // class SelectByEntries\n\n"
1115 " * @short Smart class for selecting branches for caching\n"
1117 " * This class can be used to select branches for the cache from which\n"
1118 " * more than some number bytes were read in a previous job.\n"
1120 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
1122 " * $Revision: 600807 $\n"
1123 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
1125 " class SelectByBytes\n"
1128 " /// Constructor specifying the minimum number of bytes read\n"
1129 " SelectByBytes( ::Long64_t bytes ) : fBytes( bytes ) {}\n\n"
1130 " /// Constructor finding the minimum number of bytes read\n"
1131 " SelectByBytes( const D3PDReader::D3PDReadStats::Map_t& vars,\n"
1132 " ::Double_t minByteFrac )\n"
1133 " : fBytes( 0 ) {\n\n"
1134 " ::Long64_t maxBytes = 0;\n"
1135 " D3PDReader::D3PDReadStats::Map_t::const_iterator itr = vars.begin();\n"
1136 " D3PDReader::D3PDReadStats::Map_t::const_iterator end = vars.end();\n"
1137 " for( ; itr != end; ++itr ) {\n"
1138 " if( itr->second.GetZippedBytesRead() > maxBytes ) {\n"
1139 " maxBytes = itr->second.GetZippedBytesRead();\n"
1142 " fBytes = static_cast< ::Long64_t >( minByteFrac * maxBytes );\n"
1144 " /// Operator evaluating if a variable should be selected\n"
1145 " ::Bool_t operator()( const D3PDReader::VariableStats& var ) const {\n\n"
1146 " if( var.GetZippedBytesRead() < fBytes ) {\n"
1153 " ::Long64_t fBytes; ///< Minimum number of bytes read from variable\n\n"
1154 " }; // class SelectByEntries\n\n"
1155 " /// Function adding branches to the TTreeCache\n"
1157 " * The code internally uses this function to select which branches to add to the\n"
1160 " * @param tree The TTree to enable the caching for\n"
1161 " * @param vars All the D3PD variables we know about\n"
1162 " * @param selector Functor selecting the variables to cache\n"
1163 " * @returns The number of variables added to the cache\n"
1165 " template< class SELECTOR >\n"
1166 " ::Int_t AddToCache( ::TTree* tree, const D3PDReader::D3PDReadStats::Map_t& vars,\n"
1167 " const SELECTOR& selector ) {\n\n"
1168 " ::Int_t result = 0;\n\n"
1169 " D3PDReader::D3PDReadStats::Map_t::const_iterator itr = vars.begin();\n"
1170 " D3PDReader::D3PDReadStats::Map_t::const_iterator end = vars.end();\n"
1171 " for( ; itr != end; ++itr ) {\n"
1172 " if( ! selector( itr->second ) ) continue;\n"
1173 " if( tree ) tree->AddBranchToCache( itr->first, kTRUE );\n"
1178 " /// Function selecting branches with some condition\n"
1180 " * This function is used internally to select branch names.\n"
1182 " * @param vars All the D3PD variables we know about\n"
1183 " * @param selector Functor selecting the variables\n"
1184 " * @returns The selected variable names\n"
1186 " template< class SELECTOR >\n"
1187 " std::vector< ::TString >\n"
1188 " GetBranches( const D3PDReader::D3PDReadStats::Map_t& vars,\n"
1189 " const SELECTOR& selector ) {\n\n"
1190 " // The result object:\n"
1191 " std::vector< ::TString > result;\n\n"
1192 " // Iterate over all the variables:\n"
1193 " D3PDReader::D3PDReadStats::Map_t::const_iterator itr = vars.begin();\n"
1194 " D3PDReader::D3PDReadStats::Map_t::const_iterator end = vars.end();\n"
1195 " for( ; itr != end; ++itr ) {\n"
1196 " // Ignore the ones failing the selection:\n"
1197 " if( ! selector( itr->second ) ) continue;\n"
1198 " // Add this variable to the result:\n"
1199 " result.push_back( itr->first );\n"
1203 "} // private namespace\n\n"
1204 "namespace D3PDReader {\n\n"
1206 " * The constructor can specify all properties of the object in one go. All\n"
1207 " * the parameters take a default value, to make it possible to create the\n"
1208 " * object without giving the constructor any parameters. (Needed by CINT.)\n"
1210 " * @param name Name of the variable being described\n"
1211 " * @param type Full type name of the variable being described\n"
1212 " * @param nTreesAccessed Number of TTrees accessed to read this variable\n"
1213 " * @param nReadEntries Number of GetEntry(...) operations performed on this variable\n"
1214 " * @param nUnzippedBytes Number of bytes read after decompression\n"
1215 " * @param nZippedBytes Number of bytes physically read from disk\n"
1217 " VariableStats::VariableStats( const char* name, const char* type,\n"
1218 " ::Int_t nTreesAccessed, ::Long64_t nReadEntries,\n"
1219 " ::Long64_t nUnzippedBytes, ::Long64_t nZippedBytes )\n"
1220 " : TNamed( name, type ), fTreesAccessed( nTreesAccessed ),\n"
1221 " fReadEntries( nReadEntries ), fUnzippedBytes( nUnzippedBytes ),\n"
1222 " fZippedBytes( nZippedBytes ) {\n\n"
1225 " * It's probably not needed actually, but I wanted to be explicit about how the\n"
1226 " * copy constructor should behave.\n"
1228 " * @param parent The object that's being copied\n"
1230 " VariableStats::VariableStats( const VariableStats& parent )\n"
1231 " : TNamed( parent ), fTreesAccessed( parent.fTreesAccessed ),\n"
1232 " fReadEntries( parent.fReadEntries ), fUnzippedBytes( parent.fUnzippedBytes ),\n"
1233 " fZippedBytes( parent.fZippedBytes ) {\n\n"
1236 " * The assignment operator is quite an important piece of code, as it's\n"
1237 " * used all the time when using such objects in STL containers.\n"
1239 " * @param parent The object that's being copied\n"
1240 " * @returns A reference to the copied object\n"
1242 " VariableStats& VariableStats::operator= ( const VariableStats& parent ) {\n\n"
1243 " // Set the properties of TNamed:\n"
1244 " SetName( parent.GetName() );\n"
1245 " SetTitle( parent.GetTitle() );\n\n"
1246 " // Set the properties of this class:\n"
1247 " fTreesAccessed = parent.fTreesAccessed;\n"
1248 " fReadEntries = parent.fReadEntries;\n"
1249 " fUnzippedBytes = parent.fUnzippedBytes;\n"
1250 " fZippedBytes = parent.fZippedBytes;\n\n"
1253 " ::Int_t VariableStats::GetTreesAccessed() const {\n\n"
1254 " return fTreesAccessed;\n"
1256 " void VariableStats::SetTreesAccessed( ::Int_t nTreesAccessed ) {\n\n"
1257 " fTreesAccessed = nTreesAccessed;\n"
1260 " ::Long64_t VariableStats::GetReadEntries() const {\n\n"
1261 " return fReadEntries;\n"
1263 " void VariableStats::SetReadEntries( ::Long64_t nReadEntries ) {\n\n"
1264 " fReadEntries = nReadEntries;\n"
1267 " ::Long64_t VariableStats::GetUnzippedBytesRead() const {\n\n"
1268 " return fUnzippedBytes;\n"
1270 " void VariableStats::SetUnzippedBytesRead( ::Long64_t nUnzippedBytes ) {\n\n"
1271 " fUnzippedBytes = nUnzippedBytes;\n"
1274 " ::Long64_t VariableStats::GetZippedBytesRead() const {\n\n"
1275 " return fZippedBytes;\n"
1277 " void VariableStats::SetZippedBytesRead( ::Long64_t nZippedBytes ) {\n\n"
1278 " fZippedBytes = nZippedBytes;\n"
1281 " VariableStats& VariableStats::Add( const VariableStats& rh ) {\n\n"
1282 " // Set the properties of TNamed:\n"
1283 " SetName( rh.GetName() );\n"
1284 " SetTitle( rh.GetTitle() );\n\n"
1285 " // Accumulate the gathered statistics:\n"
1286 " fTreesAccessed += rh.GetTreesAccessed();\n"
1287 " fReadEntries += rh.GetReadEntries();\n"
1288 " fUnzippedBytes += rh.GetUnzippedBytesRead();\n"
1289 " fZippedBytes += rh.GetZippedBytesRead();\n\n"
1292 " VariableStats& VariableStats::operator+= ( const VariableStats& rh ) {\n\n"
1293 " return Add( rh );\n"
1296 " * This function makes it possible to properly merge objects coming from\n"
1297 " * PROOF workers.\n"
1299 " * @param coll A collection of D3PDReader::VariableStats objects\n"
1300 " * @returns <code>0</code> in case of failure, a positive number\n"
1301 " * in case of success\n"
1303 " ::Int_t VariableStats::Merge( ::TCollection* coll ) {\n\n"
1304 " // Some security checks:\n"
1305 " if( ! coll ) return 0;\n"
1306 " if( coll->IsEmpty() ) return 0;\n\n"
1307 " // Iterate over the elements of the collection:\n"
1308 " ::TIter next( coll );\n"
1309 " ::TObject* obj = 0;\n"
1310 " while( ( obj = next() ) ) {\n\n"
1311 " // Check that the element is of the right type:\n"
1312 " VariableStats* vobj = dynamic_cast< VariableStats* >( obj );\n"
1314 " Error( \"Merge\", \"Unknown object type encountered: %s\",\n"
1315 " obj->ClassName() );\n"
1318 " // Add this element to this object:\n"
1324 " * Standard ROOT printing function. It prints all information about the\n"
1325 " * statistics gathered about a single D3PD variable.\n"
1327 " * The option parameter understands the following value(s):\n"
1328 " * - \"All\": Prints the most verbose information available\n"
1330 " * @param option Possible options for the printing verbosity\n"
1332 " void VariableStats::Print( ::Option_t* option ) const {\n\n"
1333 " // Print the most basic info:\n"
1334 " Info( \"Print\", \"Variable name \\\"%s\\\", type \\\"%s\\\"\",\n"
1335 " GetName(), GetTitle() );\n\n"
1336 " // Print the access statistics only if requested:\n"
1337 " if( ! ::strcmp( option, \"All\" ) ) {\n"
1338 " Info( \"Print\", \" TTrees accessed for this variable: %i\",\n"
1339 " fTreesAccessed );\n"
1340 " Info( \"Print\", \" Number of entries read : %lli\"\n,"
1341 " fReadEntries );\n"
1342 " Info( \"Print\", \" Number of unzipped bytes read : %lli\",\n"
1343 " fUnzippedBytes );\n"
1344 " Info( \"Print\", \" Number of zipped bytes read : %lli\",\n"
1345 " fZippedBytes );\n"
1350 " * In order to be able to stream such objects, they have to have an\n"
1351 " * explicit name. It can be specified using this constructor, but\n"
1352 " * usually leaving the default is just fine.\n"
1354 " * @param name Name for the object\n"
1355 " * @param title Optional title for the object (not used for anything)\n"
1357 " D3PDReadStats::D3PDReadStats( const char* name, const char* title )\n"
1358 " : ::TNamed( name, title ), fVariables(),\n"
1359 " fBytesRead( 0 ), fVariableNum( 0 ),\n"
1360 " fFileReads( 0 ), fCacheSize( 0 ),\n"
1361 " fUnzipTime( 0.0 ), fProcessTime( 0.0 ) {\n\n"
1364 " * It's probably not needed actually, but I wanted to be explicit about how the\n"
1365 " * copy constructor should behave.\n"
1367 " * @param parent The object that's being copied\n"
1369 " D3PDReadStats::D3PDReadStats( const D3PDReadStats& parent )\n"
1370 " : ::TNamed( parent ), fVariables( parent.fVariables ),\n"
1371 " fBytesRead( parent.fBytesRead ), fVariableNum( parent.fVariableNum ),\n"
1372 " fFileReads( parent.fFileReads ), fCacheSize( parent.fCacheSize ),\n"
1373 " fUnzipTime( parent.fUnzipTime ), fProcessTime( parent.fProcessTime ) {\n\n"
1376 " * This is probably not needed either, but again, I wanted to be\n"
1379 " * @param parent The object that's being copied\n"
1380 " * @returns A reference to the copied object\n"
1382 " D3PDReadStats& D3PDReadStats::operator= ( const D3PDReadStats& parent ) {\n\n"
1383 " // Set the properties of TNamed:\n"
1384 " SetName( parent.GetName() );\n"
1385 " SetTitle( parent.GetTitle() );\n\n"
1386 " // Set the properties of this class:\n"
1387 " fVariables = parent.fVariables;\n"
1388 " fBytesRead = parent.fBytesRead;\n"
1389 " fVariableNum = parent.fVariableNum;\n"
1390 " fFileReads = parent.fFileReads;\n"
1391 " fCacheSize = parent.fCacheSize;\n"
1392 " fUnzipTime = parent.fUnzipTime;\n"
1393 " fProcessTime = parent.fProcessTime;\n\n"
1396 " void D3PDReadStats::Clear( ::Option_t* ) {\n\n"
1397 " // Clear all accumulated statistics:\n"
1398 " fVariables.clear();\n"
1399 " fBytesRead = 0;\n"
1400 " fVariableNum = 0;\n"
1401 " fFileReads = 0;\n"
1402 " fCacheSize = 0;\n"
1403 " fUnzipTime = 0.0;\n"
1404 " fProcessTime = 0.0;\n\n"
1407 " void D3PDReadStats::SetBytesRead( ::Long64_t num ) {\n\n"
1408 " fBytesRead = num;\n"
1411 " ::Long64_t D3PDReadStats::GetBytesRead() const {\n\n"
1412 " return fBytesRead;\n"
1414 " void D3PDReadStats::SetVariableNum( ::Int_t num ) {\n\n"
1415 " fVariableNum = num;\n"
1418 " ::Int_t D3PDReadStats::GetVariableNum() const {\n\n"
1419 " return fVariableNum;\n"
1421 " void D3PDReadStats::SetFileReads( ::Int_t num ) {\n\n"
1422 " fFileReads = num;\n"
1425 " ::Int_t D3PDReadStats::GetFileReads() const {\n\n"
1426 " return fFileReads;\n"
1428 " void D3PDReadStats::SetCacheSize( ::Int_t size ) {\n\n"
1429 " fCacheSize = size;\n"
1432 " ::Int_t D3PDReadStats::GetCacheSize() const {\n\n"
1433 " return fCacheSize;\n"
1435 " void D3PDReadStats::SetUnzipTime( ::Double_t time ) {\n\n"
1436 " fUnzipTime = time;\n"
1439 " ::Double_t D3PDReadStats::GetUnzipTime() const {\n\n"
1440 " return fUnzipTime;\n"
1442 " void D3PDReadStats::SetProcessTime( ::Double_t time ) {\n\n"
1443 " fProcessTime = time;\n"
1446 " ::Double_t D3PDReadStats::GetProcessTime() const {\n\n"
1447 " return fProcessTime;\n"
1450 " * Add information about a single variable to the statistics. Note that\n"
1451 " * it's perfectly valid to add multiple objects describing the same variable.\n"
1452 " * In that case the information is accumulated properly.\n"
1454 " * @param var Access statistics for a single variable\n"
1455 " * @returns A reference to the modified object\n"
1457 " D3PDReadStats& D3PDReadStats::AddVariable( const VariableStats& var ) {\n\n"
1458 " // Do the accumulation quite simply:\n"
1459 " fVariables[ var.GetName() ] += var;\n\n"
1463 " * Get the access statistics of a single D3PD variable.\n"
1465 " * @param name The name of the D3PD variable\n"
1466 " * @returns A pointer to the object describing the access statistics,\n"
1467 " * or a null pointer if the variable is unknown\n"
1469 " const VariableStats* D3PDReadStats::GetVariable( const char* name ) const {\n\n"
1470 " // Search for the variable:\n"
1471 " Map_t::const_iterator itr = fVariables.find( name );\n"
1472 " if( itr != fVariables.end() ) {\n"
1473 " return &( itr->second );\n"
1475 " // Return a null pointer if the object was not found:\n"
1478 " const D3PDReadStats::Map_t& D3PDReadStats::GetVariables() const {\n\n"
1479 " return fVariables;\n"
1482 " * This function checks whether two objects are \"compatible\" with\n"
1483 " * each other. This just means that it checks whether it appears as\n"
1484 " * if the two statistics objects would've been recorded from the same\n"
1485 " * input type or not.\n"
1487 " * @param rh Object to compare to this object\n"
1488 " * @returns <code>kTRUE</code> if the two objects are compatible,\n"
1489 " * <code>kFALSE</code> otherwise\n"
1491 " ::Bool_t D3PDReadStats::IsCompatible( const D3PDReadStats& rh ) const {\n\n"
1492 " if( ( fVariableNum == rh.GetVariableNum() ) &&\n"
1493 " ( fCacheSize == rh.GetCacheSize() ) ) {\n"
1500 " * This function is used to merge the information from two objects.\n"
1502 " * @param rh The object to be merged into this one\n"
1503 " * @returns A reference to the merged object\n"
1505 " D3PDReadStats& D3PDReadStats::Add( const D3PDReadStats& rh ) {\n\n"
1506 " // Merge the variable statistics one by one:\n"
1507 " Map_t::const_iterator itr = rh.GetVariables().begin();\n"
1508 " Map_t::const_iterator end = rh.GetVariables().end();\n"
1509 " for( ; itr != end; ++itr ) {\n"
1510 " fVariables[ itr->first ] += itr->second;\n"
1512 " // Sum up the simple statistics:\n"
1513 " fBytesRead += rh.GetBytesRead();\n"
1514 " fFileReads += rh.GetFileReads();\n"
1515 " fUnzipTime += rh.GetUnzipTime();\n"
1516 " fProcessTime += rh.GetProcessTime();\n\n"
1519 " D3PDReadStats& D3PDReadStats::operator+= ( const D3PDReadStats& rh ) {\n\n"
1520 " return Add( rh );\n"
1523 " * This function can be used to add all the branches that this object\n"
1524 " * knows about, to the cache of the TTree given to the function.\n"
1526 " * It can be useful for blankly enabling caching for all the variables\n"
1527 " * that a D3PDReader object can possibly access.\n"
1529 " * @param tree Tree for which the caching should be configured\n"
1531 " void D3PDReadStats::AddToTreeCache( ::TTree* tree ) const {\n\n"
1532 " // Add all the branches to the cache:\n"
1533 " const ::Int_t counter = AddToCache( tree, fVariables,\n"
1534 " SelectByEntries( 0 ) );\n\n"
1535 " // Let the user know what we did:\n"
1536 " Info( \"AddToTreeCache\", \"Added %i branches to the TTreeCache\",\n"
1541 " * This should be one of the most useful functions of this class. It can\n"
1542 " * be used to selectively enable the caching for the branches which were\n"
1543 " * accessed more than a specified number of times in a previous running.\n"
1545 " * @param tree Tree for which the caching should be configured\n"
1546 " * @param minEntries Minimum number of entries read from the variable to\n"
1547 " * qualify for caching\n"
1549 " void D3PDReadStats::AddToTreeCacheByEntries( ::TTree* tree,\n"
1550 " ::Long64_t minEntries ) const {\n\n"
1551 " // Add the selected branches to the cache:\n"
1552 " const ::Int_t counter = AddToCache( tree, fVariables,\n"
1553 " SelectByEntries( minEntries ) );\n\n"
1554 " // Let the user know what we did:\n"
1555 " Info( \"AddToTreeCacheByEntries\", \"Added %i branches to the TTreeCache\",\n"
1560 " * This should be one of the most useful functions of this class. It can\n"
1561 " * be used to selectively enable the caching for the branches which were\n"
1562 " * accessed more than a specified fraction of times in a previous running.\n"
1563 " * This is slightly more general than the version of this function expecting\n"
1564 " * an absolute entry number.\n"
1566 " * @param tree Tree for which the caching should be configured\n"
1567 " * @param minEvFraction Minimum fraction of entries read from the branches\n"
1568 " * that should be added to the cache\n"
1570 " void D3PDReadStats::AddToTreeCacheByEntryFrac( ::TTree* tree,\n"
1571 " ::Double_t minEvFraction ) const {\n\n"
1572 " // Add the selected branches to the cache:\n"
1573 " const ::Int_t counter = AddToCache( tree, fVariables,\n"
1574 " SelectByEntries( fVariables,\n"
1575 " minEvFraction ) );\n\n"
1576 " // Let the user know what we did:\n"
1577 " Info( \"AddToTreeCacheByEntries\", \"Added %i branches to the TTreeCache\",\n"
1582 " * This function can be used to add all the variables to the cache\n"
1583 " * from which more than some bytes were read in a previous running.\n"
1585 " * @param tree Tree for which the caching should be configured\n"
1586 " * @param minBytes Minimum number of bytes read from the variable to\n"
1587 " * qualify for caching\n"
1589 " void D3PDReadStats::AddToTreeCacheByBytes( ::TTree* tree,\n"
1590 " ::Long64_t minBytes ) const {\n\n"
1591 " // Add the selected branches to the cache:\n"
1592 " const ::Int_t counter = AddToCache( tree, fVariables,\n"
1593 " SelectByBytes( minBytes ) );\n\n"
1594 " // Let the user know what we did:\n"
1595 " Info( \"AddToTreeCacheByBytes\", \"Added %i branches to the TTreeCache\",\n"
1600 " * This function can be used to add all the variables to the cache\n"
1601 " * from which more than some fraction of the bytes were read in a\n"
1602 " * previous running.\n"
1604 " * @param tree Tree for which the caching should be configured\n"
1605 " * @param minByteFraction Minimum fraction of bytes read from the\n"
1606 " * variable to qualify for caching\n"
1608 " void D3PDReadStats::AddToTreeCacheByByteFrac( ::TTree* tree,\n"
1609 " ::Double_t minByteFraction ) const {\n\n"
1610 " // Add the selected branches to the cache:\n"
1611 " const ::Int_t counter = AddToCache( tree, fVariables,\n"
1612 " SelectByBytes( fVariables,\n"
1613 " minByteFraction ) );\n\n"
1614 " // Let the user know what we did:\n"
1615 " Info( \"AddToTreeCacheByBytes\", \"Added %i branches to the TTreeCache\",\n"
1620 " * This function can be used to get a list of branch names that were\n"
1621 " * accessed more than a specified number of times in the analysis.\n"
1623 " * @param minEntries Minimum number of entries read from the variables\n"
1624 " * @returns A list of variable names fulfilling the requirement\n"
1626 " std::vector< ::TString >\n"
1627 " D3PDReadStats::GetBranchesByEntries( ::Long64_t minEntries ) const {\n\n"
1628 " return GetBranches( fVariables, SelectByEntries( minEntries ) );\n"
1631 " * This function can be used to get a list of branch names that were\n"
1632 " * accessed more than some fraction of times in the analysis.\n"
1634 " * @param minEvFrac Minimum fraction of entries read from the variables\n"
1635 " * @returns A list of variable names fulfilling the requirement\n"
1637 " std::vector< ::TString >\n"
1638 " D3PDReadStats::GetBranchesByEntryFrac( ::Double_t minEvFrac ) const {\n\n"
1639 " return GetBranches( fVariables,\n"
1640 " SelectByEntries( fVariables, minEvFrac ) );\n"
1643 " * This function can be used to get a list of branch names from which\n"
1644 " * more than a specified number of bytes were read in the analysis.\n"
1646 " * @param minBytes Minimum number of bytes read from the variables\n"
1647 " * @returns A list of variable names fulfilling the requirement\n"
1649 " std::vector< ::TString >\n"
1650 " D3PDReadStats::GetBranchesByBytes( ::Long64_t minBytes ) const {\n\n"
1651 " return GetBranches( fVariables, SelectByBytes( minBytes ) );\n"
1654 " * This function can be used to get a list of branch names from which\n"
1655 " * more than a specified fraction of bytes were read in the analysis.\n"
1657 " * @param minByteFraction Minimum fraction of bytes read from the\n"
1659 " * @returns A list of variable names fulfilling the requirement\n"
1661 " std::vector< ::TString >\n"
1662 " D3PDReadStats::GetBranchesByByteFrac( ::Double_t minByteFraction ) const {\n\n"
1663 " return GetBranches( fVariables,\n"
1664 " SelectByBytes( fVariables, minByteFraction ) );\n"
1667 " * This function can be used to produce a nice histogram showing how many\n"
1668 " * TTrees were accessed by how many of the branches.\n"
1670 " * Note that the caller is responsible for deleting the created histogram.\n"
1672 " * @returns The histogram showing the distribution\n"
1674 " ::TH1* D3PDReadStats::GetTreeAccessStat() const {\n\n"
1675 " // Find the branch(es) which accessed the most trees:\n"
1676 " ::Long64_t maxTrees = 0;\n"
1677 " Map_t::const_iterator itr = fVariables.begin();\n"
1678 " Map_t::const_iterator end = fVariables.end();\n"
1679 " for( ; itr != end; ++itr ) {\n"
1680 " if( itr->second.GetTreesAccessed() > maxTrees ) {\n"
1681 " maxTrees = itr->second.GetTreesAccessed();\n"
1684 " // Create the histogram:\n"
1685 " ::TH1* result = new ::TH1D( \"TreeAccessStat\",\n"
1686 " \"TTree access statistics;TTrees;Branches\",\n"
1687 " 100, 0.0, ( ( ::Double_t ) maxTrees ) * 1.1 );\n\n"
1688 " // Fill the histogram by looping over the variables once more:\n"
1689 " itr = fVariables.begin();\n"
1690 " end = fVariables.end();\n"
1691 " for( ; itr != end; ++itr ) {\n"
1692 " result->Fill( ( ::Double_t ) itr->second.GetTreesAccessed() );\n"
1697 " * This function can be used to produce a nice histogram showing how many\n"
1698 " * entries were accessed by how many of the branches.\n"
1700 " * Note that the caller is responsible for deleting the created histogram.\n"
1702 " * @returns The histogram showing the distribution\n"
1704 " ::TH1* D3PDReadStats::GetEntryReadStat() const {\n\n"
1705 " // Find the branch(es) which accessed the most entries:\n"
1706 " ::Long64_t maxEntries = 0;\n"
1707 " Map_t::const_iterator itr = fVariables.begin();\n"
1708 " Map_t::const_iterator end = fVariables.end();\n"
1709 " for( ; itr != end; ++itr ) {\n"
1710 " if( itr->second.GetReadEntries() > maxEntries ) {\n"
1711 " maxEntries = itr->second.GetReadEntries();\n"
1714 " // Create the histogram:\n"
1715 " ::TH1* result = new ::TH1D( \"EntryAccessStat\",\n"
1716 " \"Entry access statistics;Entries;Branches\",\n"
1717 " 100, 0.0, ( ( ::Double_t ) maxEntries ) * 1.1 );\n\n"
1718 " // Fill the histogram by looping over the variables once more:\n"
1719 " itr = fVariables.begin();\n"
1720 " end = fVariables.end();\n"
1721 " for( ; itr != end; ++itr ) {\n"
1722 " result->Fill( ( ::Double_t ) itr->second.GetReadEntries() );\n"
1727 " * This function can be used to produce a nice histogram showing how many\n"
1728 " * raw bytes were accessed by how many of the branches.\n"
1730 " * Note that the caller is responsible for deleting the created histogram.\n"
1732 " * @returns The histogram showing the distribution\n"
1734 " ::TH1* D3PDReadStats::GetZippedByteReadStat() const {\n\n"
1735 " // Find the branch(es) which accessed the most bytes:\n"
1736 " ::Long64_t maxBytes = 0;\n"
1737 " Map_t::const_iterator itr = fVariables.begin();\n"
1738 " Map_t::const_iterator end = fVariables.end();\n"
1739 " for( ; itr != end; ++itr ) {\n"
1740 " if( itr->second.GetZippedBytesRead() > maxBytes ) {\n"
1741 " maxBytes = itr->second.GetZippedBytesRead();\n"
1744 " // Create the histogram:\n"
1745 " ::TH1* result = new ::TH1D( \"ZippedByteAccessStat\",\n"
1746 " \"Zipped byte access statistics;Bytes;Branches\",\n"
1747 " 100, 0.0, ( ( ::Double_t ) maxBytes ) * 1.1 );\n\n"
1748 " // Fill the histogram by looping over the variables once more:\n"
1749 " itr = fVariables.begin();\n"
1750 " end = fVariables.end();\n"
1751 " for( ; itr != end; ++itr ) {\n"
1752 " result->Fill( ( ::Double_t ) itr->second.GetZippedBytesRead() );\n"
1757 " * This function can be used to produce a nice histogram showing how many\n"
1758 " * uncompressed bytes were accessed by how many of the branches.\n"
1760 " * Note that the caller is responsible for deleting the created histogram.\n"
1762 " * @returns The histogram showing the distribution\n"
1764 " ::TH1* D3PDReadStats::GetUnzippedByteReadStat() const {\n\n"
1765 " // Find the branch(es) which accessed the most bytes:\n"
1766 " ::Long64_t maxBytes = 0;\n"
1767 " Map_t::const_iterator itr = fVariables.begin();\n"
1768 " Map_t::const_iterator end = fVariables.end();\n"
1769 " for( ; itr != end; ++itr ) {\n"
1770 " if( itr->second.GetUnzippedBytesRead() > maxBytes ) {\n"
1771 " maxBytes = itr->second.GetUnzippedBytesRead();\n"
1774 " // Create the histogram:\n"
1775 " ::TH1* result = new ::TH1D( \"UnzippedByteAccessStat\",\n"
1776 " \"Unzipped byte access statistics;Bytes;Branches\",\n"
1777 " 100, 0.0, ( ( ::Double_t ) maxBytes ) * 1.1 );\n\n"
1778 " // Fill the histogram by looping over the variables once more:\n"
1779 " itr = fVariables.begin();\n"
1780 " end = fVariables.end();\n"
1781 " for( ; itr != end; ++itr ) {\n"
1782 " result->Fill( ( ::Double_t ) itr->second.GetUnzippedBytesRead() );\n"
1787 " * This function makes it possible to properly merge objects coming from\n"
1788 " * PROOF workers.\n"
1790 " * @param coll A collection of D3PDReader::VariableStats objects\n"
1791 " * @returns <code>0</code> in case of failure, a positive number\n"
1792 " * in case of success\n"
1794 " ::Int_t D3PDReadStats::Merge( ::TCollection* coll ) {\n\n"
1795 " // Some security checks:\n"
1796 " if( ! coll ) return 0;\n"
1797 " if( coll->IsEmpty() ) return 0;\n\n"
1798 " // Iterate over the elements of the collection:\n"
1799 " ::TIter next( coll );\n"
1800 " ::TObject* obj = 0;\n"
1801 " while( ( obj = next() ) ) {\n\n"
1802 " // Check that the element is of the right type:\n"
1803 " D3PDReadStats* dobj = dynamic_cast< D3PDReadStats* >( obj );\n"
1805 " Error( \"Merge\", \"Unknown object type encountered: %s\",\n"
1806 " obj->ClassName() );\n"
1809 " // The compatibility of the objects is no longer checked. When\n"
1810 " // processing a large dataset, it's probable that the objects\n"
1811 " // created by the different PROOF workers will not be \"compatible\".\n\n"
1812 " // Add this element to this object:\n"
1818 " * Standard ROOT printing function. It prints the gathered information\n"
1819 " * about the variables accessed in an analysis.\n"
1821 " * The option parameter understands the following value(s):\n"
1822 " * - \"Summary\": Only the summary information is printed.\n"
1823 " * - \"ByEntries\": Order the variables by the number of entries\n"
1824 " * read from them.\n"
1825 " * - \"ByBytes\": Order the variables by the number of bytes\n"
1826 " * read from them.\n"
1828 " * @param option Possible options for the printing\n"
1830 " void D3PDReadStats::Print( ::Option_t* option ) const {\n\n"
1831 " Info( \"Print\", \"Printing D3PD usage statistics\" );\n\n"
1832 " // Calculate how many bytes were used during the analysis:\n"
1833 " ::Long64_t bytesUsed = 0;\n"
1834 " Map_t::const_iterator map_itr = fVariables.begin();\n"
1835 " Map_t::const_iterator map_end = fVariables.end();\n"
1836 " for( ; map_itr != map_end; ++map_itr ) {\n"
1837 " bytesUsed += map_itr->second.GetZippedBytesRead();\n"
1839 " // Print the summary information:\n"
1840 " Info( \"Print\", \" Number of variables in the input D3PD : %i\",\n"
1841 " fVariableNum );\n"
1842 " Info( \"Print\", \" Variables with D3PDReader objects : %i\",\n"
1843 " static_cast< Int_t >( fVariables.size() ) );\n"
1844 " Info( \"Print\", \" TTreeCache size used : %s\",\n"
1845 " SizeToString( fCacheSize ).Data() );\n"
1846 " Info( \"Print\", \" Total number of bytes read : %s\",\n"
1847 " SizeToString( fBytesRead ).Data() );\n"
1848 " Info( \"Print\", \" Total number of bytes used : %s (%g%%)\",\n"
1849 " SizeToString( bytesUsed ).Data(),\n"
1850 " ( ( ::Double_t ) bytesUsed /\n"
1851 " ( ::Double_t ) fBytesRead * 100.0 ) );\n"
1852 " Info( \"Print\", \" Data reading speed per process : %s\",\n"
1853 " SpeedToString( fBytesRead / fProcessTime ).Data() );\n"
1854 " Info( \"Print\", \" Useful data processing speed per proc.: %s\",\n"
1855 " SpeedToString( bytesUsed / fProcessTime ).Data() );\n"
1856 " Info( \"Print\", \" Total number of file read operations : %i\",\n"
1858 " Info( \"Print\", \" Data read in one go (on average) : %s\",\n"
1859 " SizeToString( ( ::Long64_t ) ( ( ::Double_t ) fBytesRead /\n"
1860 " ( ::Double_t ) fFileReads ) ).Data() );\n"
1861 " Info( \"Print\", \" Cumulative time spent processing data : %s\",\n"
1862 " TimeToString( fProcessTime ).Data() );\n"
1863 " Info( \"Print\", \" Cumulative time spent unzipping data : %s\",\n"
1864 " TimeToString( fUnzipTime ).Data() );\n\n"
1865 " // If we just needed summary information, stop here:\n"
1866 " if( ! ::strcmp( option, \"Summary\" ) ) {\n"
1869 " // Create a temporary vector of the objects, so they can be ordered\n"
1870 " // if necessary:\n"
1871 " std::vector< VariableStats > vars;\n"
1872 " map_itr = fVariables.begin();\n"
1873 " map_end = fVariables.end();\n"
1874 " for( ; map_itr != map_end; ++map_itr ) {\n"
1875 " vars.push_back( map_itr->second );\n"
1877 " // Select the kind of ordering for the variables:\n"
1878 " if( ! ::strcmp( option, \"ByEntries\" ) ) {\n"
1879 " Info( \"Print\", \"Variables, sorted by number of accesses:\" );\n"
1880 " std::sort( vars.begin(), vars.end(), SortByEntries );\n"
1881 " } else if( ! ::strcmp( option, \"ByBytes\" ) ) {\n"
1882 " Info( \"Print\", \"Variables, sorted by number of bytes read:\" );\n"
1883 " std::sort( vars.begin(), vars.end(), SortByUnzippedBytes );\n"
1885 " Info( \"Print\", \"Variables, sorted by name:\" );\n"
1887 " // Print the statistics from each variable:\n"
1888 " std::vector< VariableStats >::const_iterator vec_itr =\n"
1890 " std::vector< VariableStats >::const_iterator vec_end =\n"
1892 " for( ; vec_itr != vec_end; ++vec_itr ) {\n"
1893 " vec_itr->Print();\n"
1897 "} // namespace D3PDReader";
1899 static const char*
const D3PDPERFSTATS_HEADER_NAME =
"D3PDPerfStats.h";
1900 static const char*
const D3PDPERFSTATS_HEADER =
1901 "// Dear emacs, this is -*- c++ -*-\n"
1902 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
1903 "#ifndef D3PDREADER_D3PDPERFSTATS_H\n"
1904 "#define D3PDREADER_D3PDPERFSTATS_H\n\n"
1905 "// ROOT include(s):\n"
1906 "#include <TVirtualPerfStats.h>\n\n"
1907 "// Local include(s):\n"
1908 "#include \"D3PDReadStats.h\"\n\n"
1909 "// Forward declaration(s):\n"
1911 "namespace D3PDReader {\n\n"
1913 " * @short Specific class for collecting information about a D3PD file access pattern\n"
1915 " * This class is used for collecting the basic information about the file\n"
1916 " * access during a D3PD analysis.\n"
1918 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
1920 " * $Revision: 600807 $\n"
1921 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
1923 " class D3PDPerfStats : public ::TVirtualPerfStats {\n\n"
1925 " /// Destructor, sometimes called by PROOF\n"
1926 " ~D3PDPerfStats();\n\n"
1927 " /// Function accessing the singleton instance\n"
1928 " static D3PDPerfStats* Instance();\n\n"
1929 " /// Function for accessing the collected statistics information\n"
1930 " const D3PDReadStats& GetStats() const;\n\n"
1931 " /// Function that should be called when a new TTree is accessed\n"
1932 " void NewTreeAccessed( ::TTree* tree );\n\n"
1933 " /// Start the statistics collection\n"
1934 " void Start( ::Bool_t clear = kTRUE );\n"
1935 " /// Stop the statistics collection\n"
1938 " // Functions inherited from TVirtualPerfStats:\n"
1940 " virtual void SimpleEvent( EEventType type );\n"
1941 " virtual void PacketEvent( const char *slave, const char *slavename, const char *filename,\n"
1942 " ::Long64_t eventsprocessed, ::Double_t latency,\n"
1943 " ::Double_t proctime, ::Double_t cputime,\n"
1944 " ::Long64_t bytesRead );\n"
1945 " virtual void FileEvent( const char *slave, const char *slavename, const char *nodename,\n"
1946 " const char *filename, ::Bool_t isStart );\n"
1947 " virtual void FileOpenEvent( ::TFile *file, const char *filename, ::Double_t start );\n"
1948 " virtual void FileReadEvent( ::TFile *file, ::Int_t len, ::Double_t start );\n"
1949 " virtual void UnzipEvent( ::TObject* tree, ::Long64_t pos, ::Double_t start,\n"
1950 " ::Int_t complen, ::Int_t objlen );\n"
1951 " virtual void RateEvent( ::Double_t proctime, ::Double_t deltatime,\n"
1952 " ::Long64_t eventsprocessed, ::Long64_t bytesRead );\n"
1953 " virtual void SetBytesRead( ::Long64_t num );\n"
1954 " virtual ::Long64_t GetBytesRead() const;\n"
1955 " virtual void SetNumEvents( ::Long64_t num );\n"
1956 " virtual ::Long64_t GetNumEvents() const;\n\n"
1958 " /// The constructor is protected, as it's a singleton\n"
1959 " D3PDPerfStats();\n\n"
1961 " /// The single instance of the object\n"
1962 " static D3PDPerfStats* fInstance;\n\n"
1963 " /// Another performance monitoring object\n"
1964 " ::TVirtualPerfStats* fOtherPerfStats;\n\n"
1965 " /// Flag showing whether the statistic collection is ongoing or not\n"
1966 " ::Bool_t fRunning;\n"
1967 " /// Time when the statistics collection was started\n"
1968 " ::Double_t fStartTime;\n\n"
1969 " /// The tree we're currently investigating\n"
1970 " ::TTree* fTree;\n"
1971 " /// The currently open D3PD file\n"
1972 " ::TFile* fFile;\n\n"
1973 " /// Flag showing whether some information message has already been printed\n"
1974 " ::Bool_t fTreeWarningPrinted;\n\n"
1975 " /// Internal object for keeping track of the collected statistics\n"
1976 " D3PDReadStats fStats;\n\n"
1977 " ClassDef( D3PDPerfStats, 0 )\n\n"
1978 " }; // class D3PDPerfStats\n\n"
1979 "} // namespace D3PDReader\n\n"
1980 "#endif // D3PDREADER_D3PDPERFSTATS_H";
1982 static const char*
const D3PDPERFSTATS_CXX_NAME =
"D3PDPerfStats.cxx";
1983 static const char*
const D3PDPERFSTATS_CXX =
1984 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n\n"
1985 "// ROOT include(s):\n"
1986 "#include <TTree.h>\n"
1987 "#include <TChain.h>\n"
1988 "#include <TTimeStamp.h>\n\n"
1989 "// Local include(s):\n"
1990 "#include \"D3PDPerfStats.h\"\n"
1991 "#include \"Utils.h\"\n\n"
1992 "ClassImp( D3PDReader::D3PDPerfStats )\n\n"
1993 "namespace D3PDReader {\n\n"
1994 " // Initialize the static variable(s):\n"
1995 " D3PDPerfStats* D3PDPerfStats::fInstance = 0;\n\n"
1997 " * The destructor is a quite important function in this class.\n"
1998 " * it makes sure that the static fInstance variable gets reset,\n"
1999 " * and that all TVirtualPerfStats objects really get deleted.\n"
2001 " D3PDPerfStats::~D3PDPerfStats() {\n\n"
2002 " // Since this object can only be deleted by deleting the global\n"
2003 " // gPerfStats object, make sure that all the objects get deleted\n"
2004 " // if the user asked for it...\n"
2006 " if( fOtherPerfStats ) {\n"
2007 " delete fOtherPerfStats;\n"
2011 " * Everywhere in the code this function should be used to access\n"
2012 " * the one and only D3PDPerfStats object in memory.\n"
2014 " * @returns A pointer to the D3PDPerfStats singleton\n"
2016 " D3PDPerfStats* D3PDPerfStats::Instance() {\n\n"
2017 " // Construct the object if it is now available at the moment:\n"
2018 " if( ! fInstance ) {\n"
2019 " fInstance = new D3PDPerfStats();\n"
2021 " // Make sure that this is still the object that receives\n"
2022 " // monitoring information:\n"
2023 " gPerfStats = fInstance;\n\n"
2024 " return fInstance;\n"
2026 " const D3PDReadStats& D3PDPerfStats::GetStats() const {\n\n"
2030 " * This function is called from VarHanle::UpdateStat(...) when a new TTree\n"
2031 " * is given to the object. This way the variables get set a bit too many\n"
2032 " * times, but hopefully it's not too much of a performance problem.\n"
2034 " * @param tree The TTree that's going to be used for reading\n"
2036 " void D3PDPerfStats::NewTreeAccessed( ::TTree* tree ) {\n\n"
2037 " // Check if information extracted previously is the same\n"
2038 " // as what we see in this TTree:\n"
2039 " if( fStats.GetVariableNum() &&\n"
2040 " ( fStats.GetVariableNum() != tree->GetNbranches() ) &&\n"
2041 " ( ! fTreeWarningPrinted ) ) {\n"
2042 " Info( \"NewTreeAccessed\", \"Reading trees with varying sizes\" );\n"
2043 " Info( \"NewTreeAccessed\", \"Information about number of branches\"\n"
2044 " \" won't be reliable\" );\n"
2045 " fTreeWarningPrinted = kTRUE;\n"
2047 " // Check if the cache size has changed. This can happen when\n"
2048 " // caching is not configured explicitly:\n"
2049 " if( fStats.GetCacheSize() &&\n"
2050 " ( fStats.GetCacheSize() != tree->GetCacheSize() ) ) {\n"
2051 " Info( \"NewTreeAccessed\", \"TTreeCache size changed. Old: %s, New: %s\",\n"
2052 " SizeToString( fStats.GetCacheSize() ).Data(),\n"
2053 " SizeToString( tree->GetCacheSize() ).Data() );\n"
2055 " // Extract some information about the TTree:\n"
2056 " if( tree->GetNbranches() > fStats.GetVariableNum() ) {\n"
2057 " fStats.SetVariableNum( tree->GetNbranches() );\n"
2059 " fStats.SetCacheSize( tree->GetCacheSize() );\n\n"
2060 " // Cache some information:\n"
2062 " ::TChain* chain = dynamic_cast< ::TChain* >( tree );\n"
2064 " fFile = chain->GetFile();\n"
2066 " fFile = tree->GetCurrentFile();\n"
2071 " * The user is supposed to call this function after the initialization of his/her\n"
2072 " * analysis code finished, but before the event processing starts.\n"
2074 " * @param clear Clear the statistics gathered so far\n"
2076 " void D3PDPerfStats::Start( ::Bool_t clear ) {\n\n"
2077 " // Return right away if we are running already:\n"
2078 " if( fRunning ) return;\n\n"
2079 " // Clear the statistics collected so far if required:\n"
2080 " if( clear ) fStats.Clear();\n\n"
2081 " // Let the user know what we're doing:\n"
2082 " Info( \"Start\", \"Starting performance monitoring\" );\n\n"
2083 " // Record the starting time:\n"
2084 " fStartTime = TTimeStamp();\n"
2085 " // Remember that we are running:\n"
2086 " fRunning = kTRUE;\n\n"
2090 " * The user is supposed to call this function once his/her analysis code finished\n"
2091 " * with the event processing.\n"
2093 " void D3PDPerfStats::Stop() {\n\n"
2094 " // Return right away if we are not running:\n"
2095 " if( ! fRunning ) return;\n\n"
2096 " // Calculate the time elapsed from when the analysis started:\n"
2097 " const ::Double_t elapsed = TTimeStamp().AsDouble() -\n"
2100 " fStats.SetProcessTime( fStats.GetProcessTime() + elapsed );\n"
2101 " // Remember that we are stopped:\n"
2102 " fRunning = kFALSE;\n\n"
2103 " // Let the user know what we've done:\n"
2104 " Info( \"Stop\", \"Performance monitoring stopped after %s\",\n"
2105 " TimeToString( elapsed ).Data() );\n\n"
2108 " void D3PDPerfStats::SimpleEvent( EEventType type ) {\n\n"
2109 " // Forward the call if possible:\n"
2110 " if( fOtherPerfStats ) {\n"
2111 " fOtherPerfStats->SimpleEvent( type );\n"
2115 " void D3PDPerfStats::PacketEvent( const char* slave, const char* slavename,\n"
2116 " const char* filename,\n"
2117 " ::Long64_t eventsprocessed, ::Double_t latency,\n"
2118 " ::Double_t proctime, ::Double_t cputime,\n"
2119 " ::Long64_t bytesRead ) {\n\n"
2120 " // Forward the call if possible:\n"
2121 " if( fOtherPerfStats ) {\n"
2122 " fOtherPerfStats->PacketEvent( slave, slavename, filename, eventsprocessed,\n"
2123 " latency, proctime, cputime, bytesRead );\n"
2127 " void D3PDPerfStats::FileEvent( const char* slave, const char* slavename,\n"
2128 " const char* nodename, const char* filename,\n"
2129 " ::Bool_t isStart ) {\n\n"
2130 " // Forward the call if possible:\n"
2131 " if( fOtherPerfStats ) {\n"
2132 " fOtherPerfStats->FileEvent( slave, slavename, nodename, filename, isStart );\n"
2136 " void D3PDPerfStats::FileOpenEvent( ::TFile* file, const char* filename,\n"
2137 " ::Double_t start ) {\n\n"
2138 " // Forward the call if possible:\n"
2139 " if( fOtherPerfStats ) {\n"
2140 " fOtherPerfStats->FileOpenEvent( file, filename, start );\n"
2144 " void D3PDPerfStats::FileReadEvent( ::TFile* file, ::Int_t len, ::Double_t start ) {\n\n"
2145 " // Do nothing if we're not running:\n"
2146 " if( ( ! fRunning ) || ( file != fFile ) ) return;\n\n"
2147 " // Accumulate the amount of read data:\n"
2148 " fStats.SetBytesRead( fStats.GetBytesRead() + len );\n"
2149 " fStats.SetFileReads( fStats.GetFileReads() + 1 );\n\n"
2150 " // Forward the call if possible:\n"
2151 " if( fOtherPerfStats ) {\n"
2152 " fOtherPerfStats->FileReadEvent( file, len, start );\n"
2156 " void D3PDPerfStats::UnzipEvent( ::TObject*, ::Long64_t, ::Double_t, ::Int_t,\n"
2160 " void D3PDPerfStats::RateEvent( ::Double_t proctime, ::Double_t deltatime,\n"
2161 " ::Long64_t eventsprocessed, ::Long64_t bytesRead ) {\n\n"
2162 " // Forward the call if possible:\n"
2163 " if( fOtherPerfStats ) {\n"
2164 " fOtherPerfStats->RateEvent( proctime, deltatime, eventsprocessed, bytesRead );\n"
2169 " * In single process running this function is basically never called.\n"
2170 " * It's only active when running on PROOF, in which case we should not\n"
2171 " * care about the values given to it, but just forward it to\n"
2172 " * TPerfStats. The actual amount of data read for D3PD monitoring\n"
2173 " * is coming in through the FileReadEvent(...) function...\n"
2175 " * @param num Number of bytes read in \"some operation\"\n"
2177 " void D3PDPerfStats::SetBytesRead( ::Long64_t num ) {\n\n"
2178 " // Forward the call if possible:\n"
2179 " if( fOtherPerfStats ) {\n"
2180 " fOtherPerfStats->SetBytesRead( num );\n"
2184 " ::Long64_t D3PDPerfStats::GetBytesRead() const {\n\n"
2185 " // Forward the call if possible:\n"
2186 " if( fOtherPerfStats ) {\n"
2187 " return fOtherPerfStats->GetBytesRead();\n"
2189 " return fStats.GetBytesRead();\n"
2193 " * This function is not called with anything meaningful in standalone\n"
2194 " * ROOT analyses, so it just forwards the call to a possible other\n"
2195 " * TVirtualPerfStats object.\n"
2197 " * @param num Number of events\n"
2199 " void D3PDPerfStats::SetNumEvents( ::Long64_t num ) {\n\n"
2200 " // Forward the call if possible:\n"
2201 " if( fOtherPerfStats ) {\n"
2202 " fOtherPerfStats->SetNumEvents( num );\n"
2207 " * The function just gets the number of events from the other\n"
2208 " * TVirtualPerfStats object if it exists, otherwise it just returns\n"
2211 " * @returns The number of events\n"
2213 " ::Long64_t D3PDPerfStats::GetNumEvents() const {\n\n"
2214 " // Forward the call if possible:\n"
2215 " if( fOtherPerfStats ) {\n"
2216 " return fOtherPerfStats->GetNumEvents();\n"
2221 " * The constructor needs to do a few things. If there is already\n"
2222 " * another TVirtualPerfStats object defined under gPerfStats, then\n"
2223 " * it stores that pointer in order to be able to forward monitoring\n"
2224 " * information to that object later on. It then overwrites\n"
2225 " * gPerfStats to point to this object.\n"
2227 " D3PDPerfStats::D3PDPerfStats()\n"
2228 " : fOtherPerfStats( 0 ), fRunning( kFALSE ), fStartTime( 0.0 ),\n"
2229 " fTree( 0 ), fFile( 0 ), fTreeWarningPrinted( kFALSE ),\n"
2230 " fStats( \"D3PDReadStats\", \"D3PD reading statistics\" ) {\n\n"
2231 " // Remember a possible former performance monitoring object:\n"
2232 " if( gPerfStats && ( gPerfStats != this ) ) {\n"
2233 " fOtherPerfStats = gPerfStats;\n"
2234 " Info( \"D3PDPerfStats\",\n"
2235 " \"Will forward calls to former gPerfStats object\" );\n"
2237 " // This object is now the performance monitoring object:\n"
2238 " gPerfStats = this;\n"
2240 "} // namespace D3PDReader";
2242 static const char*
const UTILS_HEADER_NAME =
"Utils.h";
2243 static const char*
const UTILS_HEADER =
2244 "// Dear emacs, this is -*- c++ -*-\n"
2245 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
2246 "#ifndef D3PDREADER_UTILS_H\n"
2247 "#define D3PDREADER_UTILS_H\n\n"
2248 "// ROOT include(s):\n"
2249 "#include <TString.h>\n\n"
2250 "namespace D3PDReader {\n\n"
2251 " /// Function creating a human-readable elapsed time printout\n"
2252 " ::TString TimeToString( ::Double_t secs );\n\n"
2253 " /// Function for printing data sizes in human-readable format\n"
2254 " ::TString SizeToString( ::Long64_t bytes );\n\n"
2255 " /// Function for printing data processing speeds in a human-readable format\n"
2256 " ::TString SpeedToString( ::Double_t bytespersec );\n\n"
2257 "} // namespace D3PDReader\n\n"
2258 "#endif // D3PDREADER_UTILS_H";
2260 static const char*
const UTILS_CXX_NAME =
"Utils.cxx";
2261 static const char*
const UTILS_CXX =
2262 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n\n"
2263 "// STL include(s):\n"
2264 "#include <cmath>\n\n"
2265 "// Local include(s):\n"
2266 "#include \"Utils.h\"\n\n"
2269 " * @short Simple structure describing an elapsed amount of time\n"
2271 " * In order to print some elapsed times in a nice way, the\n"
2272 " * private functions of this source file use this structure.\n"
2274 " * The amount of times measured by the code should be\n"
2275 " * representable by this structure. (We shouldn't care about\n"
2276 " * sub-milisecond times, or longer running periods than a\n"
2279 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
2281 " * $Revision: 600807 $\n"
2282 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
2284 " struct TimeStruct {\n"
2285 " ::Int_t miliseconds; ///< Elapsed milisecods\n"
2286 " ::Int_t seconds; ///< Elapsed seconds\n"
2287 " ::Int_t minutes; ///< Elapsed minutes\n"
2288 " ::Int_t hours; ///< Elapsed hours\n"
2289 " ::Int_t days; ///< Elapsed days\n"
2290 " }; // struct TimeStruct\n\n"
2291 " /// Function creating a time structure\n"
2293 " * This function is used to break down a simple elapsed time expressed in\n"
2294 " * seconds into an easy-to-print structure. Shame that I couldn't find something\n"
2295 " * in standard C/C++ to do it...\n"
2297 " * @param secs The elapsed time expressed in seconds\n"
2298 " * @returns A structure describing the elapsed time\n"
2300 " TimeStruct TimeToStruct( ::Double_t secs ) {\n\n"
2301 " // Create the structure, fill its miliseconds variable,\n"
2302 " // and reset all the rest:\n"
2303 " TimeStruct result;\n"
2304 " result.miliseconds =\n"
2305 " static_cast< ::Int_t >( std::fmod( secs, 1.0 ) * 1000.0 );\n"
2306 " result.seconds = 0; result.minutes = 0; result.hours = 0;\n"
2307 " result.days = 0;\n\n"
2308 " // If the elapsed time was less than a second, finish here:\n"
2309 " secs -= ( result.miliseconds / 1000.0 );\n"
2310 " if( std::abs( secs ) < 0.5 ) return result;\n\n"
2311 " // Calculate the number of seconds passed, and finish if the\n"
2312 " // amount of time passed was less than a minute:\n"
2313 " result.seconds =\n"
2314 " static_cast< ::Int_t >( std::fmod( secs, 60.0 ) );\n"
2315 " secs -= result.seconds;\n"
2316 " if( std::abs( secs ) < 0.5 ) return result;\n\n"
2317 " // Calculate the number of minutes passed, and finish if the\n"
2318 " // amount of time passed was less than an hour:\n"
2319 " result.minutes =\n"
2320 " static_cast< ::Int_t >( std::fmod( secs, 3600.0 ) / 60.0 );\n"
2321 " secs -= result.minutes * 60.0;\n"
2322 " if( std::abs( secs ) < 0.5 ) return result;\n\n"
2323 " // Calculate the number of hours passed, and finish if the\n"
2324 " // amount of time passed was less than a day:\n"
2326 " static_cast< ::Int_t >( std::fmod( secs, 86400.0 ) / 3600.0 );\n"
2327 " secs -= result.hours * 3600.0;\n"
2328 " if( std::abs( secs ) < 0.5 ) return result;\n\n"
2329 " // Calculate the number of days passed. The function should\n"
2330 " // not expect to have to express a larger order of magnitude...\n"
2331 " result.days = static_cast< ::Int_t >( secs / 86400.0 );\n\n"
2334 "} // private namespace\n\n"
2335 "namespace D3PDReader {\n\n"
2337 " * Since I wasn't able to find a nice function printing elapsed times\n"
2338 " * in a human-readable format, I ended up writing one. This function\n"
2339 " * is used in printing the statistics about an analysis.\n"
2341 " * @param secs An amount of time passed, expressed in seconds\n"
2342 " * @returns A formatted, human-readable version of the amount of time passed\n"
2344 " ::TString TimeToString( ::Double_t secs ) {\n\n"
2345 " const TimeStruct ts = TimeToStruct( secs );\n"
2346 " ::TString result;\n"
2347 " if( ts.days ) {\n"
2348 " result += ::TString::Format( \"%id \", ts.days );\n"
2350 " if( ts.hours ) {\n"
2351 " result += ::TString::Format( \"%ih \", ts.hours );\n"
2353 " if( ts.minutes ) {\n"
2354 " result += ::TString::Format( \"%im \", ts.minutes );\n"
2356 " if( ts.seconds ) {\n"
2357 " result += ::TString::Format( \"%is \", ts.seconds );\n"
2359 " result += ::TString::Format( \"%ims\", ts.miliseconds );\n\n"
2363 " * This function is used to produce nicely readable printouts for\n"
2364 " * amounts of data.\n"
2366 " * @param bytes The amount of data expressed in bytes\n"
2367 " * @returns A human-readable printout of the data size\n"
2369 " ::TString SizeToString( ::Long64_t bytes ) {\n\n"
2370 " if( ::fabs( bytes ) > 1e12 ) {\n"
2371 " return ::TString::Format( \"%g TB\", bytes * 1e-12 );\n"
2372 " } else if( ::fabs( bytes ) > 1e9 ) {\n"
2373 " return ::TString::Format( \"%g GB\", bytes * 1e-9 );\n"
2374 " } else if( ::fabs( bytes ) > 1e6 ) {\n"
2375 " return ::TString::Format( \"%g MB\", bytes * 1e-6 );\n"
2376 " } else if( ::fabs( bytes ) > 1e3 ) {\n"
2377 " return ::TString::Format( \"%g kB\", bytes * 1e-3 );\n"
2379 " return ::TString::Format( \"%lli bytes\", bytes );\n"
2383 " * @param bytespersec The speed expressed in bytes / seconds\n"
2384 " * @returns A human-readable printout of the data processing speed\n"
2386 " ::TString SpeedToString( ::Double_t bytespersec ) {\n\n"
2387 " if( ::fabs( bytespersec ) > 1e12 ) {\n"
2388 " return ::TString::Format( \"%g TB/s\", bytespersec * 1e-12 );\n"
2389 " } else if( ::fabs( bytespersec ) > 1e9 ) {\n"
2390 " return ::TString::Format( \"%g GB/s\", bytespersec * 1e-9 );\n"
2391 " } else if( ::fabs( bytespersec ) > 1e6 ) {\n"
2392 " return ::TString::Format( \"%g MB/s\", bytespersec * 1e-6 );\n"
2393 " } else if( ::fabs( bytespersec ) > 1e3 ) {\n"
2394 " return ::TString::Format( \"%g kB/s\", bytespersec * 1e-3 );\n"
2396 " return ::TString::Format( \"%g B/s\", bytespersec );\n"
2399 "} // namespace D3PDReader";
2401 static const char*
const USERD3PDOBJECT_HEADER_NAME =
"UserD3PDObject.h";
2402 static const char*
const USERD3PDOBJECT_HEADER =
2403 "// Dear emacs, this is -*- c++ -*--\n"
2404 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
2405 "#ifndef D3PDREADER_UserD3PDObject_H\n"
2406 "#define D3PDREADER_UserD3PDObject_H\n\n"
2407 "// STL include(s):\n"
2409 "#include <vector>\n\n"
2410 "// ROOT include(s):\n"
2411 "#include <TNamed.h>\n"
2412 "#include <TString.h>\n\n"
2413 "// Local include(s):\n"
2414 "#include \"D3PDObjectBase.h\"\n"
2415 "#include \"D3PDReadStats.h\"\n"
2416 "#include \"VarHandle.h\"\n"
2417 "#include \"VarProxy.h\"\n\n"
2418 "// Forward declaration(s):\n"
2420 "namespace D3PDReader {\n\n"
2421 " // Forward declaration(s):\n"
2422 " class UserD3PDObject;\n\n"
2424 " * @short Special class for handling user variables\n"
2426 " * This proxy class can be used to handle user-defined vector\n"
2427 " * variables in a fancy way. It is also used by all of the regular\n"
2428 " * proxy classes as base class, so they could handle user defined\n"
2429 " * variables as well. (For instance for adding a new property to\n"
2430 " * electrons in the analysis.)\n"
2432 " * The class doesn't inherit from TObject on purpose, in order to\n"
2433 " * avoid ending up with a diamond in the inheritance structure.\n"
2434 " * (Python *really* doesn't like that...)\n"
2436 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
2438 " * $Revision: 600807 $\n"
2439 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
2441 " class UserD3PDObjectElement : public ::TNamed {\n\n"
2442 " friend class UserD3PDObject;\n\n"
2444 " /// Constructor only visible to children and UserD3PDObject\n"
2445 " UserD3PDObjectElement( size_t index, const UserD3PDObject& parent );\n\n"
2447 " /// Copy constructor\n"
2448 " UserD3PDObjectElement( const UserD3PDObjectElement& parent );\n"
2449 " /// Destructor, cleaning up the created objects\n"
2450 " virtual ~UserD3PDObjectElement();\n\n"
2451 " /// Index of the object inside its container\n"
2452 " virtual size_t GetIndex() const;\n\n"
2453 " /// Access a variable\n"
2454 " template< typename T >\n"
2455 " VarProxy< T >& Variable( const TString& name );\n"
2456 " /// Access a variable (constant version)\n"
2457 " template< typename T >\n"
2458 " const VarProxy< T >& Variable( const TString& name ) const;\n\n"
2460 " /// Reference to the parent of this object\n"
2461 " const UserD3PDObject* fParent;\n"
2462 " /// The index of this object inside the parent container\n"
2464 " /// Book-keeper of the VarProxy members\n"
2465 " mutable std::map< ::TString, VarProxyBase* > fProxies;\n\n"
2466 " ClassDef( UserD3PDObjectElement, 0 )\n\n"
2467 " }; // class UserD3PDObjectElement\n\n"
2469 " * @short Special class for handling user variables\n"
2471 " * This class is used to handle user defined variables. It can be\n"
2472 " * used on its own to read/write any sort of variable, but it also\n"
2473 " * acts as a base class for all the other D3PDObject classes, to\n"
2474 " * make it possible to decorate the information stored by them.\n"
2476 " * While the class fully implements the D3PDObjectBase interface,\n"
2477 " * it doesn't inherit from it, in order to avoid creating a diamond\n"
2478 " * in the inheritance structure. Python is not able to handle such\n"
2479 " * an inheritance structure correctly.\n"
2481 " * @author Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>\n"
2483 " * $Revision: 600807 $\n"
2484 " * $Date: 2014-06-08 17:26:51 +0200 (Sun, 08 Jun 2014) $\n"
2486 " class UserD3PDObject : public D3PDObjectBase {\n\n"
2488 " /// Constructor used when reading from a TTree\n"
2489 " UserD3PDObject( const ::Long64_t& master, const char* prefix = \"\" );\n"
2490 " /// Constructor when the object is only used for writing data out\n"
2491 " UserD3PDObject( const char* prefix = \"\" );\n"
2492 " /// Destructor, cleaning up the created objects\n"
2493 " virtual ~UserD3PDObject();\n\n"
2494 " /// Get the currently configured prefix value\n"
2495 " virtual const char* GetPrefix() const;\n"
2496 " /// Set the prefix for the variables\n"
2497 " virtual void SetPrefix( const char* prefix );\n\n"
2498 " /// Connect the object to an input TTree\n"
2499 " virtual void ReadFrom( ::TTree* tree );\n"
2500 " /// Connect the object to an output TTree\n"
2501 " virtual void WriteTo( ::TTree* tree );\n\n"
2502 " /// Turn (selected) branches either on or off\n"
2503 " virtual void SetActive( ::Bool_t active = kTRUE,\n"
2504 " const ::TString& pattern = \".*\" );\n"
2505 " /// Read in all the variables that we need to write out as well\n"
2506 " virtual void ReadAllActive();\n\n"
2507 " /// Get the D3PD reading statistics\n"
2508 " virtual D3PDReadStats GetStatistics() const;\n\n"
2509 " /// Set the contents of the object according to another object\n"
2510 " UserD3PDObject& Set( const UserD3PDObject& parent );\n\n"
2511 " /// Clear the container. Useful when writing new branches.\n"
2512 " void Clear( Option_t* option = \"\" );\n"
2513 " /// Add one element to an output collection\n"
2514 " UserD3PDObject& Add( const UserD3PDObjectElement& el );\n\n"
2515 " /// Access a proxy class describing one element of the container\n"
2516 " UserD3PDObjectElement& operator[]( size_t index );\n"
2517 " /// Access a proxy class describing one element of the container (constant version)\n"
2518 " const UserD3PDObjectElement& operator[]( size_t index ) const;\n"
2519 " /// Add one element to an output collection\n"
2520 " UserD3PDObject& operator+=( const UserD3PDObjectElement& el );\n\n"
2521 " /// Declare a new variable for writing\n"
2522 " template< typename T >\n"
2523 " void DeclareVariable( const TString& name );\n"
2524 " /// Access a variable\n"
2525 " template< typename T >\n"
2526 " VarHandle< T >& Variable( const TString& name );\n"
2527 " /// Access a variable (constant version)\n"
2528 " template< typename T >\n"
2529 " const VarHandle< T >& Variable( const TString& name ) const;\n\n"
2531 " const ::Long64_t* fMaster; ///< Pointer to the master entry number\n"
2532 " ::TString fPrefix; ///< Prefix to the branch names\n"
2533 " ///< Internal list of proxy objects\n"
2534 " mutable std::vector< UserD3PDObjectElement* > fProxies;\n"
2535 " /// Book-keeper of the VarHandle members\n"
2536 " mutable std::map< ::TString, VarHandleBase* > fHandles;\n"
2537 " /// Book-keeper of VarHandle objects needed for technical reasons\n"
2538 " mutable std::vector< VarHandleBase* > fExtraHandles;\n"
2539 " /// Flag specifying if object is used for D3PD reading\n"
2540 " const ::Bool_t fFromInput;\n"
2541 " /// TTree that is being read currently\n"
2542 " ::TTree* fInTree;\n\n"
2543 " ClassDef( UserD3PDObject, 0 )\n\n"
2544 " }; // class UserD3PDObject\n\n"
2545 "} // namespace D3PDReader\n\n"
2546 "// Include the template implementation:\n"
2547 "#ifndef __CINT__\n"
2548 "#include \"UserD3PDObject.icc\"\n"
2549 "#endif // __CINT__\n\n"
2550 "#endif // D3PDREADER_UserD3PDObject_H";
2552 static const char*
const USERD3PDOBJECT_IMPL_NAME =
"UserD3PDObject.icc";
2553 static const char*
const USERD3PDOBJECT_IMPL =
2554 "// Dear emacs, this is -*- c++ -*-\n"
2555 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n"
2556 "#ifndef D3PDREADER_UserD3PDObject_ICC\n"
2557 "#define D3PDREADER_UserD3PDObject_ICC\n\n"
2558 "namespace D3PDReader {\n\n"
2560 " * This function accesses a user-defined variable for modification.\n"
2561 " * The template type needs to follow the type of the underlying\n"
2562 " * TTree branch's type, without the outermost vector. So for instance\n"
2563 " * to access a <code>std::vector<float></code> variable from here, you\n"
2564 " * need to call the function with a <code>float</code> template argument.\n"
2566 " * The function also takes care of extending the underlying vector variable\n"
2567 " * to the needed size. This makes the decoration of existing objects in\n"
2568 " * a container with new variables much easier.\n"
2570 " * If you're decorating elements that you are reading from an input D3PD,\n"
2571 " * you must have already called <code>DeclareVariable(...)</code> on the\n"
2572 " * parent object before calling thig function.\n"
2574 " * @param name The name of the user variable\n"
2575 " * @returns The VarProxy object handling the requested variable\n"
2577 " template< typename T >\n"
2578 " VarProxy< T >& UserD3PDObjectElement::Variable( const TString& name ) {\n\n"
2579 " // Try to find the variable:\n"
2580 " std::map< ::TString, VarProxyBase* >::const_iterator itr =\n"
2581 " fProxies.find( name );\n"
2582 " if( itr != fProxies.end() ) {\n"
2583 " // If it's already known, let's see if it's the right type:\n"
2584 " VarProxy< T >* result =\n"
2585 " dynamic_cast< VarProxy< T >* >( itr->second );\n"
2586 " if( ! result ) {\n"
2587 " // Create a dummy object. The code will crash soon\n"
2589 " VarProxy< T >* dummy =\n"
2590 " new VarProxy< T >( fParent->Variable< std::vector< T >* >( name ),\n"
2592 " fProxies[ name ] = dummy;\n"
2593 " // Tell the user what happened:\n"
2594 " Error( \"Variable\",\n"
2595 " \"Variable with name '%s' requested with wrong type\",\n"
2599 " // Check if the underlying vector is large enough:\n"
2600 " const VarHandle< std::vector< T >* >& vh = \n"
2601 " fParent->Variable< std::vector< T >* >( name );\n"
2602 " if( vh.IsAvailable() && ( ! vh.GetMaster() ) &&\n"
2603 " ( vh()->size() <= fIndex ) ) {\n"
2604 " UserD3PDObject* ncparent = const_cast< UserD3PDObject* >( fParent );\n"
2605 " ncparent->Variable< std::vector< T >* >( name )()->resize( fIndex + 1 );\n"
2607 " // Return the proxy:\n"
2608 " return *result;\n"
2610 " // Add the new proxy variable:\n"
2611 " VarProxy< T >* result =\n"
2612 " new VarProxy< T >( fParent->Variable< std::vector< T >* >( name ),\n"
2614 " fProxies[ name ] = result;\n\n"
2615 " // Check if the underlying vector is large enough:\n"
2616 " const VarHandle< std::vector< T >* >& vh = \n"
2617 " fParent->Variable< std::vector< T >* >( name );\n"
2618 " if( vh.IsAvailable() && ( ! vh.GetMaster() ) &&\n"
2619 " ( vh()->size() <= fIndex ) ) {\n"
2620 " UserD3PDObject* ncparent = const_cast< UserD3PDObject* >( fParent );\n"
2621 " ncparent->Variable< std::vector< T >* >( name )()->resize( fIndex + 1 );\n"
2623 " // Return the proxy:\n"
2624 " return *result;\n"
2627 " * This function accesses a user-defined variable for reading.\n"
2628 " * The template type needs to follow the type of the underlying\n"
2629 " * TTree branch's type, without the outermost vector. So for instance\n"
2630 " * to access a <code>std::vector<float></code> variable from here, you\n"
2631 " * need to call the function with a <code>float</code> template argument.\n"
2633 " * If you're decorating elements that you are reading from an input D3PD,\n"
2634 " * you must have already called <code>DeclareVariable(...)</code> on the\n"
2635 " * parent object before calling thig function.\n"
2637 " * @param name The name of the user variable\n"
2638 " * @returns The VarProxy object handling the requested variable\n"
2640 " template< typename T >\n"
2641 " const VarProxy< T >& UserD3PDObjectElement::Variable( const TString& name ) const {\n\n"
2642 " // Try to find the variable:\n"
2643 " std::map< ::TString, VarProxyBase* >::const_iterator itr =\n"
2644 " fProxies.find( name );\n"
2645 " if( itr != fProxies.end() ) {\n"
2646 " // If it's already known, let's see if it's the right type:\n"
2647 " VarProxy< T >* result =\n"
2648 " dynamic_cast< VarProxy< T >* >( itr->second );\n"
2649 " if( ! result ) {\n"
2650 " // Create a dummy object. The code will crash soon\n"
2652 " VarProxy< T >* dummy =\n"
2653 " new VarProxy< T >( fParent->Variable< std::vector< T >* >( name ),\n"
2655 " fProxies[ name ] = dummy;\n"
2656 " // Tell the user what happened:\n"
2657 " Error( \"Variable\",\n"
2658 " \"Variable with name '%s' requested with wrong type\",\n"
2662 " // Return the proxy:\n"
2663 " return *result;\n"
2665 " // Add the new proxy variable:\n"
2666 " VarProxy< T >* result =\n"
2667 " new VarProxy< T >( fParent->Variable< std::vector< T >* >( name ),\n"
2669 " fProxies[ name ] = result;\n\n"
2670 " // Return the proxy:\n"
2671 " return *result;\n"
2674 " * This function can be used to add a new variable to an output D3PD.\n"
2675 " * When reading an input D3PD that the user wants to write out a part of,\n"
2676 " * extended with some additional variables, this function should be used.\n"
2678 " * @param name The name of the new variable to create\n"
2680 " template< typename T >\n"
2681 " void UserD3PDObject::DeclareVariable( const TString& name ) {\n\n"
2682 " // Check if the variable with this name is already in place:\n"
2683 " std::map< ::TString, VarHandleBase* >::const_iterator itr =\n"
2684 " fHandles.find( name );\n"
2685 " if( itr != fHandles.end() ) {\n"
2686 " Warning( \"DeclareVariable\",\n"
2687 " \"Variable with name '%s' already declared\",\n"
2688 " ( fPrefix + name ).Data() );\n"
2691 " // Declare the new variable:\n"
2692 " fHandles[ name ] = new VarHandle< T >( fPrefix + name, 0 );\n\n"
2696 " * This function can be used to access a user-defined variable for\n"
2697 " * modification. It should mostly be used when writing a D3PD with the\n"
2698 " * additional user variable.\n"
2700 " * @param name The name of the user-defined variable\n"
2701 " * @returns The VarHandle object handling the user variable\n"
2703 " template< typename T >\n"
2704 " VarHandle< T >& UserD3PDObject::Variable( const TString& name ) {\n\n"
2705 " // Try to find the variable:\n"
2706 " std::map< ::TString, VarHandleBase* >::const_iterator itr =\n"
2707 " fHandles.find( name );\n"
2708 " if( itr != fHandles.end() ) {\n"
2709 " // It's already known, so let's see if it's of the right type:\n"
2710 " VarHandle< T >* result =\n"
2711 " dynamic_cast< VarHandle< T >* >( itr->second );\n"
2712 " if( ! result ) {\n"
2713 " // Add a dummy object for technical reasons. The user code\n"
2714 " // will anyway probably die after this.\n"
2715 " VarHandle< T >* dummy = new VarHandle< T >();\n"
2716 " fExtraHandles.push_back( dummy );\n"
2717 " // Tell the user what happened:\n"
2718 " Error( \"Variable\",\n"
2719 " \"Variable with name '%s' is of type '%s', \"\n"
2720 " \"not of type '%s'\",\n"
2721 " ( fPrefix + name ).Data(), itr->second->GetType(),\n"
2722 " dummy->GetType() );\n"
2723 " // Return the dummy:\n"
2726 " // Return the object:\n"
2727 " return *result;\n"
2729 " // If it doesn't exist yet, let's add it:\n"
2730 " VarHandle< T >* result = new VarHandle< T >( fPrefix + name, fMaster );\n"
2731 " if( fInTree ) result->ReadFrom( fInTree );\n"
2732 " fHandles[ name ] = result;\n"
2733 " return *result;\n"
2736 " * This function can be used to access a user-defined variable for\n"
2737 " * reading. It can be used both when reading or writing a D3PD.\n"
2739 " * @param name The name of the user-defined variable\n"
2740 " * @returns The VarHandle object handling the user variable\n"
2742 " template< typename T >\n"
2743 " const VarHandle< T >& UserD3PDObject::Variable( const TString& name ) const {\n\n"
2744 " // Try to find the variable:\n"
2745 " std::map< ::TString, VarHandleBase* >::const_iterator itr =\n"
2746 " fHandles.find( name );\n"
2747 " if( itr != fHandles.end() ) {\n"
2748 " // It's already known, so let's see if it's of the right type:\n"
2749 " VarHandle< T >* result =\n"
2750 " dynamic_cast< VarHandle< T >* >( itr->second );\n"
2751 " if( ! result ) {\n"
2752 " // Add a dummy object for technical reasons. The user code\n"
2753 " // will anyway probably die after this.\n"
2754 " VarHandle< T >* dummy = new VarHandle< T >();\n"
2755 " fExtraHandles.push_back( dummy );\n"
2756 " // Tell the user what happened:\n"
2757 " Error( \"Variable\",\n"
2758 " \"Variable with name '%s' is of type '%s', \"\n"
2759 " \"not of type '%s'\",\n"
2760 " ( fPrefix + name ).Data(), itr->second->GetType(),\n"
2761 " dummy->GetType() );\n"
2762 " // Return the dummy:\n"
2765 " // Return the object:\n"
2766 " return *result;\n"
2768 " // If it doesn't exist yet, let's add it:\n"
2769 " VarHandle< T >* result = new VarHandle< T >( fPrefix + name, fMaster );\n"
2770 " if( fInTree ) result->ReadFrom( fInTree );\n"
2771 " fHandles[ name ] = result;\n"
2772 " return *result;\n"
2774 "} // namespace D3PDReader\n\n"
2775 "#endif // D3PDREADER_UserD3PDObject_ICC";
2777 static const char*
const USERD3PDOBJECT_CXX_NAME =
"UserD3PDObject.cxx";
2778 static const char*
const USERD3PDOBJECT_CXX =
2779 "// $Id: CodeGenerator_v2_constants.h 600807 2014-06-08 15:26:51Z krasznaa $\n\n"
2780 "// ROOT include(s):\n"
2781 "#include <TPRegexp.h>\n\n"
2782 "// Local include(s):\n"
2783 "#include \"UserD3PDObject.h\"\n\n"
2784 "namespace D3PDReader {\n\n"
2785 " UserD3PDObjectElement::UserD3PDObjectElement( size_t index,\n"
2786 " const UserD3PDObject& parent )\n"
2787 " : ::TNamed(), fParent( &parent ), fIndex( index ), fProxies() {\n\n"
2789 " UserD3PDObjectElement::\n"
2790 " UserD3PDObjectElement( const UserD3PDObjectElement& parent )\n"
2791 " : TNamed( parent ), fParent( parent.fParent ), fIndex( parent.fIndex ),\n"
2794 " UserD3PDObjectElement::~UserD3PDObjectElement() {\n\n"
2795 " // Delete the allocated objects:\n"
2796 " std::map< ::TString, VarProxyBase* >::iterator itr = fProxies.begin();\n"
2797 " std::map< ::TString, VarProxyBase* >::iterator end = fProxies.end();\n"
2798 " for( ; itr != end; ++itr ) {\n"
2799 " delete itr->second;\n"
2802 " size_t UserD3PDObjectElement::GetIndex() const {\n\n"
2805 " UserD3PDObject::UserD3PDObject( const ::Long64_t& master,\n"
2806 " const char* prefix )\n"
2807 " : D3PDObjectBase(), fMaster( &master ), fPrefix( prefix ), fProxies(),\n"
2808 " fHandles(), fExtraHandles(), fFromInput( kTRUE ),\n"
2809 " fInTree( 0 ) {\n\n"
2811 " UserD3PDObject::UserD3PDObject( const char* prefix )\n"
2812 " : D3PDObjectBase(), fMaster( 0 ), fPrefix( prefix ), fProxies(),\n"
2813 " fHandles(), fExtraHandles(), fFromInput( kFALSE ),\n"
2814 " fInTree( 0 ) {\n\n"
2816 " UserD3PDObject::~UserD3PDObject() {\n\n"
2817 " // Delete the allocated objects:\n"
2818 " std::map< ::TString, VarHandleBase* >::iterator itr = fHandles.begin();\n"
2819 " std::map< ::TString, VarHandleBase* >::iterator end = fHandles.end();\n"
2820 " for( ; itr != end; ++itr ) {\n"
2821 " delete itr->second;\n"
2823 " // Although the code almost certainly crashes when such dummy objects\n"
2824 " // are created, there's still some chance that they need to be cleaned:\n"
2825 " std::vector< VarHandleBase* >::iterator eitr = fExtraHandles.begin();\n"
2826 " std::vector< VarHandleBase* >::iterator eend = fExtraHandles.end();\n"
2827 " for( ; eitr != eend; ++eitr ) {\n"
2832 " * @returns The branch name prefix used by the object\n"
2834 " const char* UserD3PDObject::GetPrefix() const {\n\n"
2835 " return fPrefix;\n"
2838 " * @param prefix The prefix that should be used for the variables\n"
2840 " void UserD3PDObject::SetPrefix( const char* prefix ) {\n\n"
2841 " fPrefix = prefix;\n\n"
2842 " // Set all the variable names:\n"
2843 " std::map< TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2844 " std::map< TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2845 " for( ; itr != end; ++itr ) {\n"
2846 " itr->second->SetName( ::TString( prefix ) + itr->first );\n"
2851 " * This function should be called every time a new TFile is opened\n"
2852 " * by your analysis code.\n"
2854 " * @param tree Pointer to the TTree with the variables\n"
2856 " void UserD3PDObject::ReadFrom( TTree* tree ) {\n\n"
2857 " // Check if the object will be able to read from the TTree:\n"
2858 " if( ! fFromInput ) {\n"
2859 " Error( \"ReadFrom\",\n"
2860 " \"The object was not created with the correct\" );\n"
2861 " Error( \"ReadFrom\",\n"
2862 " \"constructor to read data from a D3PD!\" );\n"
2865 " // Call ReadFrom(...) on all the variables:\n"
2866 " std::map< TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2867 " std::map< TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2868 " for( ; itr != end; ++itr ) {\n"
2869 " // Ignore the variables that are created only now:\n"
2870 " if( ! itr->second->GetMaster() ) continue;\n"
2871 " itr->second->ReadFrom( tree );\n"
2873 " // Remember the pointer:\n"
2874 " fInTree = tree;\n\n"
2878 " * This function can be called to connect the active variables of the object\n"
2879 " * to an output TTree. It can be called multiple times, then the variables\n"
2880 " * will be written to multiple TTrees.\n"
2882 " * @param tree Pointer to the TTree where the variables should be written\n"
2884 " void UserD3PDObject::WriteTo( TTree* tree ) {\n\n"
2885 " // Call WriteTo(...) on all the variables:\n"
2886 " std::map< TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2887 " std::map< TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2888 " for( ; itr != end; ++itr ) {\n"
2889 " itr->second->WriteTo( tree );\n"
2894 " * This is a convenience function for turning the branches active or\n"
2895 " * inactive conveniently. If the parameter is set to <code>kTRUE</code>\n"
2896 " * then the branches available from the input which match the given\n"
2897 " * pattern are turned active.\n"
2898 " * When it's set to <code>kFALSE</code> then all the variables matching\n"
2899 " * the pattern are turned inactive.\n"
2901 " * @param active Flag behaving as explained above\n"
2902 " * @param pattern Regular expression specifying which branches to modify\n"
2904 " void UserD3PDObject::SetActive( ::Bool_t active, const ::TString& pattern ) {\n\n"
2905 " ::TPRegexp re( pattern );\n\n"
2906 " std::map< TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2907 " std::map< TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2908 " for( ; itr != end; ++itr ) {\n"
2909 " if( ! re.Match( fPrefix + itr->first ) ) continue;\n"
2911 " if( itr->second->IsAvailable() ) itr->second->SetActive( active );\n"
2913 " itr->second->SetActive( active );\n"
2919 " * This function can be used to read in all the branches from the input\n"
2920 " * TTree which are set active for writing out. This can simplify writing\n"
2921 " * event selector codes immensely. Remember to set the desired variable\n"
2922 " * active before calling this function.\n"
2924 " void UserD3PDObject::ReadAllActive() {\n\n"
2925 " // Check if it makes sense to call this function:\n"
2926 " if( ! fFromInput ) {\n"
2927 " static ::Bool_t wPrinted = kFALSE;\n"
2928 " if( ! wPrinted ) {\n"
2929 " Warning( \"ReadAllActive\",\n"
2930 " \"Function only meaningful when used on objects\" );\n"
2931 " Warning( \"ReadAllActive\",\n"
2932 " \"which are used to read information from a D3PD\" );\n"
2933 " wPrinted = kTRUE;\n"
2936 " // Read in the current entry for each active variable:\n"
2937 " std::map< TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2938 " std::map< TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2939 " for( ; itr != end; ++itr ) {\n"
2940 " if( ! itr->second->IsActive() ) continue;\n"
2941 " itr->second->ReadCurrentEntry();\n"
2946 " * This function can be used to get information about the access\n"
2947 " * pattern/statistics of the job. It should be called at the end of\n"
2948 " * an analysis job to get the information about the performance of the\n"
2951 " * @returns An object describing the D3PD access statistics\n"
2953 " D3PDReadStats UserD3PDObject::GetStatistics() const {\n\n"
2954 " // The result object:\n"
2955 " D3PDReadStats result;\n\n"
2956 " // Add the statistics from each variable to the result:\n"
2957 " std::map< ::TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2958 " std::map< ::TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2959 " for( ; itr != end; ++itr ) {\n"
2960 " result.AddVariable( itr->second->GetStatistics() );\n"
2965 " * User variables can't be copied like this at the moment.\n"
2967 " UserD3PDObject& UserD3PDObject::Set( const UserD3PDObject& parent ) {\n\n"
2968 " if( parent.fHandles.size() ) {\n"
2969 " Error( \"Set\",\n"
2970 " \"User variables can not be copied usig this function!\" );\n"
2975 " * This function makes it easier to clear out the object completely.\n"
2976 " * It cleares all the vector variables, and sets the element number\n"
2977 " * variable to 0. Very useful when performing object selection.\n"
2978 " * The option argument is not used at the moment for anything.\n"
2979 " * It's only there because the <code>Clear</code> function defined in\n"
2980 " * TObject has this parameter as well.\n"
2982 " * @param option Ignored at the moment\n"
2984 " void UserD3PDObject::Clear( Option_t* ) {\n\n"
2985 " // Clear each variable:\n"
2986 " std::map< ::TString, VarHandleBase* >::const_iterator itr = fHandles.begin();\n"
2987 " std::map< ::TString, VarHandleBase* >::const_iterator end = fHandles.end();\n"
2988 " for( ; itr != end; ++itr ) {\n"
2989 " itr->second->Clear();\n"
2994 " * User variables can't be copied like this at the moment.\n"
2996 " UserD3PDObject& UserD3PDObject::Add( const UserD3PDObjectElement& el ) {\n\n"
2997 " if( el.fProxies.size() ) {\n"
2998 " Error( \"Add\",\n"
2999 " \"User variables can not be copied usig this function!\" );\n"
3004 " * This operator can be used to get access to one element in the\n"
3005 " * collection. This element can then be passed around between parts\n"
3006 " * of the analysis code easily.\n"
3008 " * This version is useful when modifying the variable contents through\n"
3009 " * the proxy objects.\n"
3011 " * @param index Index of the element inside the collection\n"
3013 " UserD3PDObjectElement& UserD3PDObject::operator[]( size_t index ) {\n\n"
3014 " while( fProxies.size() <= index ) {\n"
3015 " fProxies.push_back( new UserD3PDObjectElement( fProxies.size(), *this ) );\n"
3017 " return *fProxies[ index ];\n"
3020 " * This operator can be used to get access to one element in the\n"
3021 " * collection. This element can then be passed around between parts\n"
3022 " * of the analysis code easily.\n"
3024 " * This version is useful when only reading the variables.\n"
3026 " * @param index Index of the element inside the collection\n"
3028 " const UserD3PDObjectElement& UserD3PDObject::operator[]( size_t index ) const {\n\n"
3029 " while( fProxies.size() <= index ) {\n"
3030 " fProxies.push_back( new UserD3PDObjectElement( fProxies.size(), *this ) );\n"
3032 " return *fProxies[ index ];\n"
3035 " * A convenience operator for adding an 'element' to this collection.\n"
3038 " * @param el The 'element' that should be added to the collection\n"
3040 " UserD3PDObject& UserD3PDObject::operator+=( const UserD3PDObjectElement& el ) {\n\n"
3041 " return this->Add( el );\n"
3043 "} // namespace D3PDReader";
3045 #endif // D3PDMAKERREADER_ROOTREADERD3PD_V2_CONSTANTS_H