001 // $Id: GaudiTuples.icpp,v 1.10 2008/05/15 08:50:32 marcocle Exp $
002 // ============================================================================
003 // CVS tag $Name: $, version $Revision: 1.10 $
004 // ============================================================================
005 // Include files
006 // ============================================================================
007 // Gaudi
008 // ============================================================================
009 #include "GaudiKernel/IRegistry.h"
010 #include "GaudiKernel/ToStream.h"
011 // ============================================================================
012 // GaudiAlg
013 // ============================================================================
014 #include "GaudiAlg/GaudiTuples.h"
015 #include "GaudiAlg/Tuple.h"
016 #include "GaudiAlg/TupleObj.h"
017 #include "GaudiAlg/GaudiTupleAlg.h"
018 #include "GaudiAlg/TupleDetail.h"
019 #include "GaudiAlg/Print.h"
020 // ============================================================================
021 /* @file GaudiTuples.cpp
022 *
023 * Implementation file for class : GaudiTuples
024 *
025 * @author Chris Jones Christopher.Rob.Jones@cern.ch
026 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
027 * @date 2005-08-08
028 */
029 // ============================================================================
030 // Disable warning on windows
031 #ifdef _WIN32
032 #pragma warning ( disable:4661 ) // incomplete explicit templates
033 #endif
034 // ============================================================================
035 // Destructor
036 //=============================================================================
037 template <class PBASE>
038 GaudiTuples<PBASE>::~GaudiTuples() {}
039
040 //=============================================================================
041 // Initialize ntupling
042 //=============================================================================
043 template <class PBASE>
044 StatusCode GaudiTuples<PBASE>::initialize()
045 {
046 // initialize base class
047 const StatusCode sc = PBASE::initialize();
048 if ( sc.isFailure() ) return sc;
049
050 if ( produceNTuples() )
051 {
052 // check the existance of service
053 if ( 0 == this->ntupleSvc() )
054 { return this->Error( "INTupleSvc* points to NULL!" ); }
055 // Print ntuple path
056 Print( "The N-Tuple path is set to be '" + nTuplePath() + "'",
057 StatusCode(StatusCode::SUCCESS, true) , MSG::DEBUG);
058 }
059 else
060 { this->debug() << "Production of N-Tuples is switched OFF" << endreq; }
061
062 if ( produceEvtCols() )
063 {
064 // check the existance of service
065 if ( 0 == this->evtColSvc() )
066 { return this->Error( "INTupleSvc* points to NULL!" ); }
067 // Print EvtCol path
068 Print( "The EventCol path is set to be '" + evtColPath() + "'",
069 StatusCode(StatusCode::SUCCESS, true) , MSG::DEBUG );
070 }
071 else
072 { this->debug() << "Production of Event Collections is switched OFF" << endreq; }
073
074 return sc;
075 }
076
077 //=============================================================================
078 // finalize ntupling
079 //=============================================================================
080 template <class PBASE>
081 StatusCode GaudiTuples<PBASE>::finalize()
082 {
083 if ( !( nTupleMapTitle() .empty() &&
084 nTupleMapNumID() .empty() &&
085 nTupleMapLitID() .empty() &&
086 evtColMapTitle() .empty() &&
087 evtColMapNumID() .empty() &&
088 evtColMapLitID() .empty()
089 ) )
090 {
091 const int nNtuples = nTupleMapNumID().size() + nTupleMapLitID().size();
092 const int nEvtCols = evtColMapNumID().size() + evtColMapLitID().size();
093 this->always()
094 << "Booked " << nNtuples << " N-Tuples and " << nEvtCols
095 << " Event Tag Collections" << endreq ;
096 }
097
098 if ( produceNTuples () && tuplesPrint () ) { printTuples () ; }
099 if ( produceEvtCols () && evtColsPrint () ) { printEvtCols () ; }
100
101 { // release ntuples and clear the container
102 for( TupleMapTitle::iterator itup = m_nTupleMapTitle.begin() ;
103 m_nTupleMapTitle.end() != itup ; ++itup )
104 { if( 0 != itup->second ) { itup->second->release() ; } }
105 m_nTupleMapTitle.clear() ;
106 }
107 { // release ntuples and clear the container
108 for( TupleMapNumID::iterator itup = m_nTupleMapNumID.begin() ;
109 m_nTupleMapNumID.end() != itup ; ++itup )
110 { if( 0 != itup->second ) { itup->second->release() ; } }
111 m_nTupleMapNumID.clear();
112 }
113 { // release ntuples and clear the container
114 for( TupleMapLitID::iterator itup = m_nTupleMapLitID.begin() ;
115 m_nTupleMapLitID.end() != itup ; ++itup )
116 { if( 0 != itup->second ) { itup->second->release() ; } }
117 m_nTupleMapLitID.clear();
118 }
119 { // release ntuples and clear the container
120 for( TupleMapTitle::iterator itup = m_evtColMapTitle.begin() ;
121 m_evtColMapTitle.end() != itup ; ++itup )
122 { if( 0 != itup->second ) { itup->second->release() ; } }
123 m_evtColMapTitle.clear();
124 }
125 { // release ntuples and clear the container
126 for( TupleMapNumID::iterator itup = m_evtColMapNumID.begin() ;
127 m_evtColMapNumID.end() != itup ; ++itup )
128 { if( 0 != itup->second ) { itup->second->release() ; } }
129 m_evtColMapNumID.clear() ;
130 }
131 { // release ntuples and clear the container
132 for( TupleMapLitID::iterator itup = m_evtColMapLitID.begin() ;
133 m_evtColMapLitID.end() != itup ; ++itup )
134 { if( 0 != itup->second ) { itup->second->release() ; } }
135 m_evtColMapLitID.clear() ;
136 }
137
138 // finalize base class
139 return PBASE::finalize();
140 }
141
142 // ============================================================================
143 // get N-tuple object ( book on-demand ) with unique identidier
144 // ============================================================================
145 template <class PBASE>
146 Tuples::Tuple GaudiTuples<PBASE>::nTuple
147 ( const std::string& title ,
148 const CLID& clid ) const
149 {
150 // look up in the table
151 Tuples::TupleObj* tuple = m_nTupleMapTitle[ title ] ;
152 if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
153 // Create the tuple ID
154 TupleID ID;
155 if ( this->useNumericAutoIDs() || title.empty() )
156 {
157 if ( ! this->useNumericAutoIDs() )
158 {
159 this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
160 StatusCode::SUCCESS );
161 }
162 // propose the tuple ID
163 ID = TupleID ( m_nTupleMapNumID.size() + 1 + nTupleOffSet() );
164 // adjust the proposed ID
165 while ( nTupleExists(ID) || evtColExists(ID) ) { ++ID ; }
166 }
167 else
168 {
169 // use the title to create a unique literal ID
170 ID = TupleID( this->convertTitleToID(title) );
171 // Just in case ...
172 while ( nTupleExists(ID) || evtColExists(ID) ) { ID = TupleID(ID.idAsString()+"_"); }
173 }
174 // return
175 return nTuple( ID , title , clid ) ;
176 }
177 // ============================================================================
178
179 // ============================================================================
180 // Access an Event Tag Collection object (book on-demand) with unique identifier
181 // ============================================================================
182 template <class PBASE>
183 Tuples::Tuple GaudiTuples<PBASE>::evtCol
184 ( const std::string& title ,
185 const CLID& clid ) const
186 {
187 // look up in the table
188 Tuples::TupleObj* tuple = m_evtColMapTitle[ title ] ;
189 if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
190 // Create the tuple ID
191 TupleID ID;
192 if ( this->useNumericAutoIDs() || title.empty() )
193 {
194 if ( ! this->useNumericAutoIDs() )
195 {
196 this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
197 StatusCode::SUCCESS );
198 }
199 // proposed the tuple ID
200 ID = m_evtColMapNumID.size() + 1 + evtColOffSet() ;
201 // adjust the proposed ID
202 while ( nTupleExists(ID) || evtColExists(ID) ) { ++ID ; }
203 }
204 else
205 {
206 // use the title to create a unique literal ID
207 ID = TupleID( this->convertTitleToID(title) );
208 // Just in case ...
209 while ( nTupleExists(ID) || evtColExists(ID) ) { 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>
220 Tuples::Tuple GaudiTuples<PBASE>::nTuple
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 =
231 ( ID.numeric() ? m_nTupleMapNumID[ID.numericID()] : m_nTupleMapLitID[ID.literalID()] ) ;
232 if( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
233
234 // convert ID to the string
235 const std::string tID = ID.idAsString() ;
236
237 // adjust the NTuple title
238 const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1 ;
239
240 // book new ntuple
241 if( produceNTuples() )
242 {
243 // book NTupel
244 NTuple::Tuple * tup = 0;
245 if ( ID.numeric() )
246 {
247 tup = this->ntupleSvc() -> book ( nTuplePath() , ID.numericID() , clid , title );
248 }
249 else if ( ID.literal() )
250 {
251 tup = this->ntupleSvc() -> book ( nTuplePath() , ID.literalID() , clid , title );
252 }
253 else { this->Error( "Undefined NTuple ID" ); }
254
255 // assertion
256 this->Assert( 0 != tup , "Could not book the N-Tuple='" + title + "'" ) ;
257 // some printout
258 if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
259 { this->debug() << "Booked NTuple '" << title << "' ID=" << tID
260 << "' Path='" << nTuplePath() << "' TS='"
261 << tup -> registry() -> identifier() << "'" << endreq; }
262
263 tuple = createNTuple ( title , tup , clid ) ;
264 }
265 else
266 {
267 tuple = createNTuple ( title , (NTuple::Tuple*) 0 , clid ) ;
268 }
269 // increment the reference
270 tuple -> addRef();
271 if ( ID.numeric() ) { m_nTupleMapNumID [ ID.numericID() ] = tuple ; }
272 else { m_nTupleMapLitID [ ID.literalID() ] = tuple ; }
273 tuple -> addRef();
274 m_nTupleMapTitle[ title ] = tuple ;
275 // return
276 return Tuple( tuple ) ;
277 };
278
279 // ============================================================================
280 template <class PBASE>
281 Tuples::Tuple GaudiTuples<PBASE>::evtCol
282 ( const TupleID& ID ,
283 const std::string& title1 ,
284 const CLID& clid ) const
285 {
286 // Check ID
287 if ( ID.undefined() )
288 { this->Error("Undefined NTuple ID : Title='"+title1+"'"); return Tuple(0); }
289
290 // look up in the table
291 Tuples::TupleObj* tuple =
292 ( ID.numeric() ? m_evtColMapNumID[ID.numericID()] : m_evtColMapLitID[ID.literalID()] ) ;
293 if ( 0 != tuple ) { return Tuple( tuple ) ; } // RETURN
294
295 // convert ID to the string
296 const std::string tID = ID.idAsString() ;
297
298 // adjust the NTuple title
299 const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1 ;
300
301 // book new ntuple
302 if( produceEvtCols() )
303 {
304 // book NTuple
305 NTuple::Tuple* tup = 0;
306 if ( ID.numeric() )
307 {
308 tup = this->evtColSvc()->book ( evtColPath() , ID.numericID() , clid , title ) ;
309 }
310 else if ( ID.literal() )
311 {
312 tup = this->evtColSvc()->book ( evtColPath() , ID.literalID() , clid , title ) ;
313 }
314 else { this->Error( "Undefined NTuple ID" ); }
315
316 // assertion
317 this->Assert( 0 != tup , "Could not book the EvtCol='" + title + "'" ) ;
318 // some printout
319 if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
320 { this->debug() << "Booked EvtCol '" << title << "' ID=" << tID
321 << "' Path='" << evtColPath() << "' TS='"
322 << tup -> registry() -> identifier() << "'" << endreq ; }
323
324 tuple = createEvtCol ( title , tup , clid ) ;
325 }
326 else
327 {
328 tuple = createEvtCol ( title , (NTuple::Tuple*) 0 , clid ) ;
329 }
330 // increment the reference
331 tuple -> addRef();
332 if ( ID.numeric() ) { m_evtColMapNumID [ ID.numericID() ] = tuple ; }
333 else { m_evtColMapLitID [ ID.literalID() ] = tuple ; }
334 tuple -> addRef();
335 m_evtColMapTitle[ title ] = tuple ;
336 // return
337 return Tuple( tuple ) ;
338 }
339 // ============================================================================
340
341 // ============================================================================
342 // create TupleObj
343 // ============================================================================
344 template <class PBASE>
345 Tuples::TupleObj* GaudiTuples<PBASE>::createNTuple
346 ( const std::string& name ,
347 NTuple::Tuple* tuple ,
348 const CLID& clid ) const
349 {
350 return Tuples::createTupleObj
351 ( this , "Tuple '" + name + "'" , tuple , clid , Tuples::NTUPLE ) ;
352 }
353 // ============================================================================
354
355 // ============================================================================
356 // create TupleObj for event tag collection
357 // ============================================================================
358 template <class PBASE>
359 Tuples::TupleObj* GaudiTuples<PBASE>::createEvtCol
360 ( const std::string& name ,
361 NTuple::Tuple* tuple ,
362 const CLID& clid ) const
363 {
364 return Tuples::createTupleObj
365 ( this , "EvtCol '" + name + "'" , tuple , clid , Tuples::EVTCOL ) ;
366 }
367 // ============================================================================
368
369
370 // ============================================================================
371 // perform the actual printout of N-tuples
372 // ============================================================================
373 template <class PBASE>
374 long GaudiTuples<PBASE>::printTuples () const
375 {
376
377 typedef std::set<const NTuple::Tuple*> _Tuples ;
378
379 if ( nTupleMapTitle().empty() &&
380 nTupleMapNumID().empty() &&
381 nTupleMapLitID().empty() )
382 { if (this->msgLevel(MSG::DEBUG)) this->debug() << "No N-Tuples are booked" << endreq ; }
383 else
384 { this->always() << "List of booked N-Tuples in directory "
385 << "\"" << nTuplePath() << "\"" << endreq ; }
386
387 _Tuples tuples ;
388 { // N-Tuple by Numeric ID
389 for ( TupleMapNumID::const_iterator entry = nTupleMapNumID().begin() ;
390 nTupleMapNumID().end() != entry ; ++entry )
391 {
392 if ( 0 == entry->second ) { continue ; }
393 const NTuple::Tuple* tuple = entry->second->tuple() ;
394 if ( 0 == tuple )
395 { this->error() << " NTuple::Tuple* points to NULL" << endreq ; continue ; }
396 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
397 tuples.insert ( tuple ) ;
398 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first ) << endreq ;
399 }
400 }
401 { // N-Tuple by Literal ID
402 for ( TupleMapLitID::const_iterator entry = nTupleMapLitID().begin() ;
403 nTupleMapLitID().end() != entry ; ++entry )
404 {
405 if ( 0 == entry->second ) { continue ; }
406 const NTuple::Tuple* tuple = entry->second->tuple() ;
407 if ( 0 == tuple )
408 { this->error() << " NTuple::Tuple* points to NULL" << endreq ; continue ; }
409 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
410 tuples.insert ( tuple ) ;
411 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first ) << endreq ;
412 }
413 }
414 { // N-Tuples by Title
415 for ( TupleMapTitle::const_iterator entry = nTupleMapTitle().begin() ;
416 nTupleMapTitle().end() != entry ; ++entry )
417 {
418 if ( 0 == entry->second ) { continue ; }
419 const NTuple::Tuple* tuple = entry->second->tuple() ;
420 if ( 0 == tuple )
421 { this->error() << " NTuple::Tuple* points to NULL" << endreq ; continue ; }
422 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
423 tuples.insert ( tuple ) ;
424 this->always() << GaudiAlg::PrintTuple::print ( tuple ) << endreq ;
425 }
426 }
427
428 return tuples.size() ;
429 };
430 // ============================================================================
431
432 // ============================================================================
433 // perform the actual printout of Evt Tag Collections
434 // ============================================================================
435 template <class PBASE>
436 long GaudiTuples<PBASE>::printEvtCols () const
437 {
438 typedef std::set<const NTuple::Tuple*> _Tuples ;
439
440 if ( evtColMapTitle().empty() &&
441 evtColMapNumID().empty() &&
442 evtColMapLitID().empty() )
443 { this->always() << "No Event Tag Collections are booked" << endreq ; }
444 else
445 { this->always() << "List of booked Event Tag Collections in directory "
446 << "\"" << evtColPath() << "\"" << endreq ; }
447
448 _Tuples tuples ;
449 { // EvtCols by Numeric ID
450 for ( TupleMapNumID::const_iterator entry = evtColMapNumID().begin() ;
451 evtColMapNumID().end() != entry ; ++entry )
452 {
453 if ( 0 == entry->second ) { continue ; }
454 const NTuple::Tuple* tuple = entry->second->tuple() ;
455 if ( 0 == tuple )
456 { this->error() << "NTuple::Tuple* points to NULL" << endreq ; continue ; }
457 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
458 tuples.insert ( tuple ) ;
459 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first )
460 << " Items:"
461 << Gaudi::Utils::toString ( entry->second->items() ) << endreq ;
462 }
463 }
464 { // EvtCols by literal ID
465 for ( TupleMapLitID::const_iterator entry = evtColMapLitID().begin() ;
466 evtColMapLitID().end() != entry ; ++entry )
467 {
468 if ( 0 == entry->second ) { continue ; }
469 const NTuple::Tuple* tuple = entry->second->tuple() ;
470 if ( 0 == tuple )
471 { this->error() << "NTuple::Tuple* points to NULL" << endreq ; continue ; }
472 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
473 tuples.insert ( tuple ) ;
474 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first )
475 << " Items:"
476 << Gaudi::Utils::toString ( entry->second->items() ) << endreq ;
477 }
478 }
479 { // EvtCols by Title
480 for ( TupleMapTitle::const_iterator entry = evtColMapTitle().begin() ;
481 evtColMapTitle().end() != entry ; ++entry )
482 {
483 if ( 0 == entry->second ) { continue ; }
484 const NTuple::Tuple* tuple = entry->second->tuple() ;
485 if ( 0 == tuple )
486 { this->error() << "NTuple::Tuple* points to NULL" << endreq ; continue ; }
487 if ( tuples.end() != tuples.find( tuple ) ) { continue ; }
488 tuples.insert ( tuple ) ;
489 this->always() << GaudiAlg::PrintTuple::print ( tuple )
490 << " Items:"
491 << Gaudi::Utils::toString ( entry->second->items() ) << endreq ;
492 }
493 }
494
495 return tuples.size() ;
496 }
497
498 // ============================================================================
499 // check the existence AND validity of the N-Tuple with the given ID
500 // ============================================================================
501 template <class PBASE>
502 bool GaudiTuples<PBASE>::nTupleExists ( const TupleID& ID ) const
503 {
504 bool OK(false);
505 if ( ID.numeric() )
506 {
507 TupleMapNumID::iterator found = m_nTupleMapNumID.find( ID.numericID() ) ;
508 OK = ( m_nTupleMapNumID.end() != found );
509 }
510 else
511 {
512 TupleMapLitID::iterator found = m_nTupleMapLitID.find( ID.literalID() ) ;
513 OK = ( m_nTupleMapLitID.end() != found );
514 }
515 return OK;
516 }
517
518 // ============================================================================
519 // check the existence AND validity of the Event Tag Collection with the given ID
520 // ============================================================================
521 template <class PBASE>
522 bool GaudiTuples<PBASE>::evtColExists ( const TupleID& ID ) const
523 {
524 bool OK(false);
525 if ( ID.numeric() )
526 {
527 TupleMapNumID::iterator found = m_evtColMapNumID.find( ID.numericID() ) ;
528 OK = ( m_evtColMapNumID.end() != found );
529 }
530 else
531 {
532 TupleMapLitID::iterator found = m_evtColMapLitID.find( ID.literalID() ) ;
533 OK = ( m_evtColMapLitID.end() != found );
534 }
535 return OK;
536 }
537
538 // ============================================================================
539 // The END
540 // ============================================================================
541
542
| Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems |
|
This page was automatically generated by the
LXR engine.
|
|