Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiTuples.icpp
Go to the documentation of this file.
1 // $Id: GaudiTuples.icpp,v 1.10 2008/05/15 08:50:32 marcocle Exp $
2 // ============================================================================
3 // CVS tag $Name: $, version $Revision: 1.10 $
4 // ============================================================================
5 // Include files
6 // ============================================================================
7 // Gaudi
8 // ============================================================================
10 #include "GaudiKernel/ToStream.h"
11 // ============================================================================
12 // GaudiAlg
13 // ============================================================================
14 #include "GaudiAlg/GaudiTuples.h"
15 #include "GaudiAlg/Tuple.h"
16 #include "GaudiAlg/TupleObj.h"
17 #include "GaudiAlg/GaudiTupleAlg.h"
18 #include "GaudiAlg/TupleDetail.h"
19 #include "GaudiAlg/Print.h"
20 // ============================================================================
21 /* @file GaudiTuples.cpp
22  *
23  * Implementation file for class : GaudiTuples
24  *
25  * @author Chris Jones Christopher.Rob.Jones@cern.ch
26  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
27  * @date 2005-08-08
28  */
29 // ============================================================================
30 // Disable warning on windows
31 #ifdef _WIN32
32 #pragma warning ( disable:4661 ) // incomplete explicit templates
33 #endif
34 // ============================================================================
35 // Destructor
36 //=============================================================================
37 template <class PBASE>
39 //=============================================================================
40 // Initialize ntupling
41 //=============================================================================
42 template <class PBASE>
44 #ifdef __ICC
45  i_gtInitialize
46 #else
48 #endif
49  ()
50 {
51  // initialize base class
53  if ( sc.isFailure() ) return sc;
54 
55  if ( produceNTuples() )
56  {
57  // check the existance of service
58  if ( this->ntupleSvc() == 0 )
59  { return this->Error( "INTupleSvc* points to NULL!" ); }
60  // Print ntuple path
61  this->Print( "The N-Tuple path is set to be '" + nTuplePath() + "'",
63  }
64  else
65  { this->debug() << "Production of N-Tuples is switched OFF" << endmsg; }
66 
67  if ( produceEvtCols() )
68  {
69  // check the existance of service
70  if ( 0 == this->evtColSvc() )
71  { return this->Error( "INTupleSvc* points to NULL!" ); }
72  // Print EvtCol path
73  this->Print( "The EventCol path is set to be '" + evtColPath() + "'",
75  }
76  else
77  { this->debug() << "Production of Event Collections is switched OFF" << endmsg; }
78 
79  return sc;
80 }
81 
82 //=============================================================================
83 // finalize ntupling
84 //=============================================================================
85 template <class PBASE>
87 #ifdef __ICC
88  i_gtFinalize
89 #else
90  finalize
91 #endif
92  ()
93 {
94  if ( !( nTupleMapTitle () . empty () &&
95  nTupleMapID () . empty () &&
96  evtColMapTitle () . empty () &&
97  evtColMapID () . empty ()
98  ) )
99  {
100  const int nNtuples = nTupleMapID () . size () ;
101  const int nEvtCols = evtColMapID () . size ();
102  this->always()
103  << "Booked " << nNtuples << " N-Tuples and " << nEvtCols
104  << " Event Tag Collections" << endmsg ;
105  }
106 
107  if ( produceNTuples () && tuplesPrint () ) { printTuples () ; }
108  if ( produceEvtCols () && evtColsPrint () ) { printEvtCols () ; }
109 
110  { // release ntuples and clear the container
111  for( TupleMapTitle::iterator itup = m_nTupleMapTitle.begin() ;
112  m_nTupleMapTitle.end() != itup ; ++itup )
113  { if( 0 != itup->second ) { itup->second->release() ; } }
114  m_nTupleMapTitle.clear() ;
115  }
116  { // release ntuples and clear the container
117  for( TupleMapID::iterator itup = m_nTupleMapID.begin() ;
118  m_nTupleMapID.end() != itup ; ++itup )
119  { if( 0 != itup->second ) { itup->second->release() ; } }
120  m_nTupleMapID.clear();
121  }
122  { // release ntuples and clear the container
123  for( TupleMapTitle::iterator itup = m_evtColMapTitle.begin() ;
124  m_evtColMapTitle.end() != itup ; ++itup )
125  { if( 0 != itup->second ) { itup->second->release() ; } }
126  m_evtColMapTitle.clear();
127  }
128  { // release ntuples and clear the container
129  for( TupleMapID::iterator itup = m_evtColMapID.begin() ;
130  m_evtColMapID.end() != itup ; ++itup )
131  { if( 0 != itup->second ) { itup->second->release() ; } }
132  m_evtColMapID.clear() ;
133  }
134  // finalize base class
135  return PBASE::finalize();
136 }
137 
138 // ============================================================================
139 // get N-tuple object ( book on-demand ) with unique identidier
140 // ============================================================================
141 template <class PBASE>
143 ( const std::string& title ,
144  const CLID& clid ) const
145 {
146  // look up in the table
147  Tuples::TupleObj* tuple = m_nTupleMapTitle[ title ] ;
148  if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
149  // Create the tuple ID
150  TupleID ID;
151  if ( this->useNumericAutoIDs() || title.empty() )
152  {
153  if ( ! this->useNumericAutoIDs() )
154  {
155  this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
157  }
158  // propose the tuple ID
159  ID = TupleID ( m_nTupleMapID.size() + 1 + nTupleOffSet() );
160  // adjust the proposed ID
161  while ( nTupleExists(ID) || evtColExists(ID) )
162  { ID = TupleID ( ID.numeric() + 1 ) ; }
163  }
164  else
165  {
166  // use the title to create a unique literal ID
167  ID = TupleID( this->convertTitleToID(title) );
168  // Just in case ...
169  while ( nTupleExists(ID) || evtColExists(ID) )
170  { ID = TupleID(ID.idAsString()+"_"); }
171  }
172  // return
173  return nTuple( ID , title , clid ) ;
174 }
175 // ============================================================================
176 
177 // ============================================================================
178 // Access an Event Tag Collection object (book on-demand) with unique identifier
179 // ============================================================================
180 template <class PBASE>
182 ( const std::string& title ,
183  const CLID& clid ) const
184 {
185  // look up in the table
186  Tuples::TupleObj* tuple = m_evtColMapTitle[ title ] ;
187  if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
188  // Create the tuple ID
189  TupleID ID;
190  if ( this->useNumericAutoIDs() || title.empty() )
191  {
192  if ( ! this->useNumericAutoIDs() )
193  {
194  this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
196  }
197  // proposed the tuple ID
198  ID = TupleID ( m_evtColMapID.size() + 1 + evtColOffSet() ) ;
199  // adjust the proposed ID
200  while ( nTupleExists(ID) || evtColExists(ID) )
201  { ID = TupleID ( ID.numeric() + 1 ) ; }
202  }
203  else
204  {
205  // use the title to create a unique literal ID
206  ID = TupleID( this->convertTitleToID(title) );
207  // Just in case ...
208  while ( nTupleExists(ID) || evtColExists(ID) )
209  { ID = TupleID ( ID.idAsString()+"_" ) ; }
210  }
211  // return
212  return evtCol( ID , title , clid ) ;
213 }
214 // ============================================================================
215 
216 // ============================================================================
217 // get N-tuple object ( book on-demand ) with forced ID
218 // ============================================================================
219 template <class PBASE>
221 ( const TupleID& ID ,
222  const std::string& title1 ,
223  const CLID& clid ) const
224 {
225  // Check ID
226  if ( ID.undefined() )
227  { this->Error("Undefined NTuple ID : Title='"+title1+"'"); return Tuple(0); }
228 
229  // look up in the table
230  Tuples::TupleObj * tuple = m_nTupleMapID[ ID ] ;
231  if( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
232 
233  // convert ID to the string
234  const std::string tID = ID.idAsString() ;
235 
236  // adjust the NTuple title
237  const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1 ;
238 
239  // book new ntuple
240  if( produceNTuples() )
241  {
242  // book NTupel
243  NTuple::Tuple * tup = 0;
244  if ( ID.numeric() )
245  {
246  tup = this->ntupleSvc() -> book ( nTuplePath() , ID.numericID() , clid , title );
247  }
248  else if ( ID.literal() )
249  {
250  tup = this->ntupleSvc() -> book ( nTuplePath() , ID.literalID() , clid , title );
251  }
252  else { this->Error( "Undefined NTuple ID" ); }
253 
254  // assertion
255  this->Assert( 0 != tup , "Could not book the N-Tuple='" + title + "'" ) ;
256  // some printout
257  if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
258  { this->debug() << "Booked NTuple '" << title << "' ID=" << tID
259  << "' Path='" << nTuplePath() << "' TS='"
260  << tup -> registry() -> identifier() << "'" << endmsg; }
261 
262  tuple = createNTuple ( title , tup , clid ) ;
263  }
264  else
265  {
266  tuple = createNTuple ( title , (NTuple::Tuple*) 0 , clid ) ;
267  }
268  // increment the reference
269  tuple -> addRef();
270  //
271  m_nTupleMapID [ ID ] = tuple ;
272  //
273  tuple -> addRef();
274  m_nTupleMapTitle[ title ] = tuple ;
275  // return
276  return Tuple( tuple ) ;
277 }
278 // ============================================================================
279 template <class PBASE>
281 ( const TupleID& ID ,
282  const std::string& title1 ,
283  const CLID& clid ) const
284 {
285  // Check ID
286  if ( ID.undefined() )
287  { this->Error("Undefined NTuple ID : Title='"+title1+"'"); return Tuple(0); }
288 
289  // look up in the table
290  Tuples::TupleObj* tuple = m_evtColMapID[ID] ;
291  if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
292 
293  // convert ID to the string
294  const std::string tID = ID.idAsString() ;
295 
296  // adjust the NTuple title
297  const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1 ;
298 
299  // book new ntuple
300  if( produceEvtCols() )
301  {
302  // book NTuple
303  NTuple::Tuple* tup = 0;
304  if ( ID.numeric() )
305  {
306  tup = this->evtColSvc()->book ( evtColPath() , ID.numericID() , clid , title ) ;
307  }
308  else if ( ID.literal() )
309  {
310  tup = this->evtColSvc()->book ( evtColPath() , ID.literalID() , clid , title ) ;
311  }
312  else { this->Error( "Undefined NTuple ID" ); }
313 
314  // assertion
315  this->Assert( 0 != tup , "Could not book the EvtCol='" + title + "'" ) ;
316  // some printout
317  if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
318  { this->debug() << "Booked EvtCol '" << title << "' ID=" << tID
319  << "' Path='" << evtColPath() << "' TS='"
320  << tup -> registry() -> identifier() << "'" << endmsg ; }
321 
322  tuple = createEvtCol ( title , tup , clid ) ;
323  }
324  else
325  {
326  tuple = createEvtCol ( title , (NTuple::Tuple*) 0 , clid ) ;
327  }
328  // increment the reference
329  tuple -> addRef();
330  //
331  m_evtColMapID [ ID ] = tuple ;
332  //
333  tuple -> addRef();
334  m_evtColMapTitle[ title ] = tuple ;
335  // return
336  return Tuple( tuple ) ;
337 }
338 // ============================================================================
339 // create TupleObj
340 // ============================================================================
341 template <class PBASE>
343 ( const std::string& name ,
344  NTuple::Tuple* tuple ,
345  const CLID& clid ) const
346 {
348  ( this , "Tuple '" + name + "'" , tuple , clid , Tuples::NTUPLE ) ;
349 }
350 // ============================================================================
351 
352 // ============================================================================
353 // create TupleObj for event tag collection
354 // ============================================================================
355 template <class PBASE>
357 ( const std::string& name ,
358  NTuple::Tuple* tuple ,
359  const CLID& clid ) const
360 {
362  ( this , "EvtCol '" + name + "'" , tuple , clid , Tuples::EVTCOL ) ;
363 }
364 // ============================================================================
365 // perform the actual printout of N-tuples
366 // ============================================================================
367 template <class PBASE>
369 {
370 
371  if ( nTupleMapTitle().empty() && nTupleMapID().empty() )
372  { if (this->msgLevel(MSG::DEBUG)) this->debug() << "No N-Tuples are booked" << endmsg ; }
373  else
374  { this->always() << "List of booked N-Tuples in directory "
375  << "\"" << nTuplePath() << "\"" << endmsg ; }
376 
377  // helper container to sort it:
378  typedef std::map<TupleID,const Tuples::TupleObj*> OrderedMapType;
379  OrderedMapType OrderedMap ( nTupleMapID().begin() , nTupleMapID().end() ) ;
380  //
381  for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
382  OrderedMap.end() != entry ; ++entry )
383  {
384  if ( 0 == entry->second ) { continue ; }
385  const NTuple::Tuple* tuple = entry->second->tuple() ;
386  if ( 0 == tuple )
387  { this->error() << " NTuple::Tuple* points to NULL" << endmsg ; continue ; }
388  this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first ) << endmsg ;
389  }
390  //
391  return this->nTupleMapID().size() ;
392 }
393 // ============================================================================
394 // perform the actual printout of Evt Tag Collections
395 // ============================================================================
396 template <class PBASE>
398 {
399  if ( evtColMapTitle().empty() && evtColMapID().empty() )
400  { this->always() << "No Event Tag Collections are booked" << endmsg ; }
401  else
402  { this->always() << "List of booked Event Tag Collections in directory "
403  << "\"" << evtColPath() << "\"" << endmsg ; }
404 
405  // helper container to sort it:
406  typedef std::map<TupleID,const Tuples::TupleObj*> OrderedMapType;
407  OrderedMapType OrderedMap ( evtColMapID().begin() , evtColMapID().end() ) ;
408  //
409  for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
410  OrderedMap.end() != entry ; ++entry )
411  {
412  if ( 0 == entry->second ) { continue ; }
413  const NTuple::Tuple* tuple = entry->second->tuple() ;
414  if ( 0 == tuple )
415  { this->error() << " NTuple::Tuple* points to NULL" << endmsg ; continue ; }
416  this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first )
417  << " Items:"
418  << Gaudi::Utils::toString ( entry->second->items() ) << endmsg ;
419  }
420  //
421  return this->evtColMapID().size() ;
422 }
423 // ============================================================================
424 // check the existence AND validity of the N-Tuple with the given ID
425 // ============================================================================
426 template <class PBASE>
428 { return m_nTupleMapID.end() != m_nTupleMapID.find ( ID ) ; }
429 // ============================================================================
430 // check the existence AND validity of the Event Tag Collection with the given ID
431 // ============================================================================
432 template <class PBASE>
434 { return m_evtColMapID.end() != m_evtColMapID.find ( ID ) ; }
435 // ============================================================================
436 // Handle method for changes in the 'NTuplePrint' property
437 // ============================================================================
438 template <class PBASE>
440 {
441  // no action if not yet initialized
442  if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
443  if ( this -> tuplesPrint() ) { this -> printTuples () ; }
444 }
445 // ============================================================================
446 // Handle method for changes in the 'EvtColsPrint' property
447 // ============================================================================
448 template <class PBASE>
450 {
451  // no action if not yet initialized
452  if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
453  if ( this -> evtColsPrint() ) { this -> printEvtCols () ; }
454 }
455 // ============================================================================
456 // The END
457 // ============================================================================

Generated at Wed Nov 28 2012 12:17:09 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004