00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "GaudiKernel/IRegistry.h"
00010 #include "GaudiKernel/ToStream.h"
00011
00012
00013
00014 #include "GaudiAlg/GaudiTuples.h"
00015 #include "GaudiAlg/Tuple.h"
00016 #include "GaudiAlg/TupleObj.h"
00017 #include "GaudiAlg/GaudiTupleAlg.h"
00018 #include "GaudiAlg/TupleDetail.h"
00019 #include "GaudiAlg/Print.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifdef _WIN32
00032 #pragma warning ( disable:4661 ) // incomplete explicit templates
00033 #endif
00034
00035
00036
00037 template <class PBASE>
00038 GaudiTuples<PBASE>::~GaudiTuples() {}
00039
00040
00041
00042 template <class PBASE>
00043 StatusCode GaudiTuples<PBASE>::
00044 #ifdef __ICC
00045 i_gtInitialize
00046 #else
00047 initialize
00048 #endif
00049 ()
00050 {
00051
00052 const StatusCode sc = PBASE::initialize();
00053 if ( sc.isFailure() ) return sc;
00054
00055 if ( produceNTuples() )
00056 {
00057
00058 if ( this->ntupleSvc() == 0 )
00059 { return this->Error( "INTupleSvc* points to NULL!" ); }
00060
00061 this->Print( "The N-Tuple path is set to be '" + nTuplePath() + "'",
00062 StatusCode(StatusCode::SUCCESS, true) , MSG::DEBUG);
00063 }
00064 else
00065 { this->debug() << "Production of N-Tuples is switched OFF" << endmsg; }
00066
00067 if ( produceEvtCols() )
00068 {
00069
00070 if ( 0 == this->evtColSvc() )
00071 { return this->Error( "INTupleSvc* points to NULL!" ); }
00072
00073 this->Print( "The EventCol path is set to be '" + evtColPath() + "'",
00074 StatusCode(StatusCode::SUCCESS, true) , MSG::DEBUG );
00075 }
00076 else
00077 { this->debug() << "Production of Event Collections is switched OFF" << endmsg; }
00078
00079 return sc;
00080 }
00081
00082
00083
00084
00085 template <class PBASE>
00086 StatusCode GaudiTuples<PBASE>::
00087 #ifdef __ICC
00088 i_gtFinalize
00089 #else
00090 finalize
00091 #endif
00092 ()
00093 {
00094 if ( !( nTupleMapTitle () . empty () &&
00095 nTupleMapID () . empty () &&
00096 evtColMapTitle () . empty () &&
00097 evtColMapID () . empty ()
00098 ) )
00099 {
00100 const int nNtuples = nTupleMapID () . size () ;
00101 const int nEvtCols = evtColMapID () . size ();
00102 this->always()
00103 << "Booked " << nNtuples << " N-Tuples and " << nEvtCols
00104 << " Event Tag Collections" << endmsg ;
00105 }
00106
00107 if ( produceNTuples () && tuplesPrint () ) { printTuples () ; }
00108 if ( produceEvtCols () && evtColsPrint () ) { printEvtCols () ; }
00109
00110 {
00111 for( TupleMapTitle::iterator itup = m_nTupleMapTitle.begin() ;
00112 m_nTupleMapTitle.end() != itup ; ++itup )
00113 { if( 0 != itup->second ) { itup->second->release() ; } }
00114 m_nTupleMapTitle.clear() ;
00115 }
00116 {
00117 for( TupleMapID::iterator itup = m_nTupleMapID.begin() ;
00118 m_nTupleMapID.end() != itup ; ++itup )
00119 { if( 0 != itup->second ) { itup->second->release() ; } }
00120 m_nTupleMapID.clear();
00121 }
00122 {
00123 for( TupleMapTitle::iterator itup = m_evtColMapTitle.begin() ;
00124 m_evtColMapTitle.end() != itup ; ++itup )
00125 { if( 0 != itup->second ) { itup->second->release() ; } }
00126 m_evtColMapTitle.clear();
00127 }
00128 {
00129 for( TupleMapID::iterator itup = m_evtColMapID.begin() ;
00130 m_evtColMapID.end() != itup ; ++itup )
00131 { if( 0 != itup->second ) { itup->second->release() ; } }
00132 m_evtColMapID.clear() ;
00133 }
00134
00135 return PBASE::finalize();
00136 }
00137
00138
00139
00140
00141 template <class PBASE>
00142 Tuples::Tuple GaudiTuples<PBASE>::nTuple
00143 ( const std::string& title ,
00144 const CLID& clid ) const
00145 {
00146
00147 Tuples::TupleObj* tuple = m_nTupleMapTitle[ title ] ;
00148 if ( 0 != tuple ) { return Tuple( tuple ) ; }
00149
00150 TupleID ID;
00151 if ( this->useNumericAutoIDs() || title.empty() )
00152 {
00153 if ( ! this->useNumericAutoIDs() )
00154 {
00155 this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for nTuple ID",
00156 StatusCode::SUCCESS );
00157 }
00158
00159 ID = TupleID ( m_nTupleMapID.size() + 1 + nTupleOffSet() );
00160
00161 while ( nTupleExists(ID) || evtColExists(ID) )
00162 { ID = TupleID ( ID.numeric() + 1 ) ; }
00163 }
00164 else
00165 {
00166
00167 ID = TupleID( this->convertTitleToID(title) );
00168
00169 while ( nTupleExists(ID) || evtColExists(ID) )
00170 { ID = TupleID(ID.idAsString()+"_"); }
00171 }
00172
00173 return nTuple( ID , title , clid ) ;
00174 }
00175
00176
00177
00178
00179
00180 template <class PBASE>
00181 Tuples::Tuple GaudiTuples<PBASE>::evtCol
00182 ( const std::string& title ,
00183 const CLID& clid ) const
00184 {
00185
00186 Tuples::TupleObj* tuple = m_evtColMapTitle[ title ] ;
00187 if ( 0 != tuple ) { return Tuple( tuple ) ; }
00188
00189 TupleID ID;
00190 if ( this->useNumericAutoIDs() || title.empty() )
00191 {
00192 if ( ! this->useNumericAutoIDs() )
00193 {
00194 this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for evtCol ID",
00195 StatusCode::SUCCESS );
00196 }
00197
00198 ID = TupleID ( m_evtColMapID.size() + 1 + evtColOffSet() ) ;
00199
00200 while ( nTupleExists(ID) || evtColExists(ID) )
00201 { ID = TupleID ( ID.numeric() + 1 ) ; }
00202 }
00203 else
00204 {
00205
00206 ID = TupleID( this->convertTitleToID(title) );
00207
00208 while ( nTupleExists(ID) || evtColExists(ID) )
00209 { ID = TupleID ( ID.idAsString()+"_" ) ; }
00210 }
00211
00212 return evtCol( ID , title , clid ) ;
00213 }
00214
00215
00216
00217
00218
00219 template <class PBASE>
00220 Tuples::Tuple GaudiTuples<PBASE>::nTuple
00221 ( const TupleID& ID ,
00222 const std::string& title1 ,
00223 const CLID& clid ) const
00224 {
00225
00226 if ( ID.undefined() )
00227 { this->Error("Undefined NTuple ID : Title='"+title1+"'"); return Tuple(0); }
00228
00229
00230 Tuples::TupleObj * tuple = m_nTupleMapID[ ID ] ;
00231 if( 0 != tuple ) { return Tuple( tuple ) ; }
00232
00233
00234 const std::string tID = ID.idAsString() ;
00235
00236
00237 const std::string title = title1.empty() ? ( "NTuple #" + tID ) : title1 ;
00238
00239
00240 if( produceNTuples() )
00241 {
00242
00243 NTuple::Tuple * tup = 0;
00244 if ( ID.numeric() )
00245 {
00246 tup = this->ntupleSvc() -> book ( nTuplePath() , ID.numericID() , clid , title );
00247 }
00248 else if ( ID.literal() )
00249 {
00250 tup = this->ntupleSvc() -> book ( nTuplePath() , ID.literalID() , clid , title );
00251 }
00252 else { this->Error( "Undefined NTuple ID" ); }
00253
00254
00255 this->Assert( 0 != tup , "Could not book the N-Tuple='" + title + "'" ) ;
00256
00257 if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
00258 { this->debug() << "Booked NTuple '" << title << "' ID=" << tID
00259 << "' Path='" << nTuplePath() << "' TS='"
00260 << tup -> registry() -> identifier() << "'" << endmsg; }
00261
00262 tuple = createNTuple ( title , tup , clid ) ;
00263 }
00264 else
00265 {
00266 tuple = createNTuple ( title , (NTuple::Tuple*) 0 , clid ) ;
00267 }
00268
00269 tuple -> addRef();
00270
00271 m_nTupleMapID [ ID ] = tuple ;
00272
00273 tuple -> addRef();
00274 m_nTupleMapTitle[ title ] = tuple ;
00275
00276 return Tuple( tuple ) ;
00277 }
00278
00279 template <class PBASE>
00280 Tuples::Tuple GaudiTuples<PBASE>::evtCol
00281 ( const TupleID& ID ,
00282 const std::string& title1 ,
00283 const CLID& clid ) const
00284 {
00285
00286 if ( ID.undefined() )
00287 { this->Error("Undefined NTuple ID : Title='"+title1+"'"); return Tuple(0); }
00288
00289
00290 Tuples::TupleObj* tuple = m_evtColMapID[ID] ;
00291 if ( 0 != tuple ) { return Tuple( tuple ) ; }
00292
00293
00294 const std::string tID = ID.idAsString() ;
00295
00296
00297 const std::string title = title1.empty() ? ( "EvtCol #" + tID ) : title1 ;
00298
00299
00300 if( produceEvtCols() )
00301 {
00302
00303 NTuple::Tuple* tup = 0;
00304 if ( ID.numeric() )
00305 {
00306 tup = this->evtColSvc()->book ( evtColPath() , ID.numericID() , clid , title ) ;
00307 }
00308 else if ( ID.literal() )
00309 {
00310 tup = this->evtColSvc()->book ( evtColPath() , ID.literalID() , clid , title ) ;
00311 }
00312 else { this->Error( "Undefined NTuple ID" ); }
00313
00314
00315 this->Assert( 0 != tup , "Could not book the EvtCol='" + title + "'" ) ;
00316
00317 if( 0 != tup -> registry() && this->msgLevel(MSG::DEBUG) )
00318 { this->debug() << "Booked EvtCol '" << title << "' ID=" << tID
00319 << "' Path='" << evtColPath() << "' TS='"
00320 << tup -> registry() -> identifier() << "'" << endmsg ; }
00321
00322 tuple = createEvtCol ( title , tup , clid ) ;
00323 }
00324 else
00325 {
00326 tuple = createEvtCol ( title , (NTuple::Tuple*) 0 , clid ) ;
00327 }
00328
00329 tuple -> addRef();
00330
00331 m_evtColMapID [ ID ] = tuple ;
00332
00333 tuple -> addRef();
00334 m_evtColMapTitle[ title ] = tuple ;
00335
00336 return Tuple( tuple ) ;
00337 }
00338
00339
00340
00341 template <class PBASE>
00342 Tuples::TupleObj* GaudiTuples<PBASE>::createNTuple
00343 ( const std::string& name ,
00344 NTuple::Tuple* tuple ,
00345 const CLID& clid ) const
00346 {
00347 return Tuples::createTupleObj
00348 ( this , "Tuple '" + name + "'" , tuple , clid , Tuples::NTUPLE ) ;
00349 }
00350
00351
00352
00353
00354
00355 template <class PBASE>
00356 Tuples::TupleObj* GaudiTuples<PBASE>::createEvtCol
00357 ( const std::string& name ,
00358 NTuple::Tuple* tuple ,
00359 const CLID& clid ) const
00360 {
00361 return Tuples::createTupleObj
00362 ( this , "EvtCol '" + name + "'" , tuple , clid , Tuples::EVTCOL ) ;
00363 }
00364
00365
00366
00367 template <class PBASE>
00368 long GaudiTuples<PBASE>::printTuples () const
00369 {
00370
00371 if ( nTupleMapTitle().empty() && nTupleMapID().empty() )
00372 { if (this->msgLevel(MSG::DEBUG)) this->debug() << "No N-Tuples are booked" << endmsg ; }
00373 else
00374 { this->always() << "List of booked N-Tuples in directory "
00375 << "\"" << nTuplePath() << "\"" << endmsg ; }
00376
00377
00378 typedef std::map<TupleID,const Tuples::TupleObj*> OrderedMapType;
00379 OrderedMapType OrderedMap ( nTupleMapID().begin() , nTupleMapID().end() ) ;
00380
00381 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
00382 OrderedMap.end() != entry ; ++entry )
00383 {
00384 if ( 0 == entry->second ) { continue ; }
00385 const NTuple::Tuple* tuple = entry->second->tuple() ;
00386 if ( 0 == tuple )
00387 { this->error() << " NTuple::Tuple* points to NULL" << endmsg ; continue ; }
00388 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first ) << endmsg ;
00389 }
00390
00391 return this->nTupleMapID().size() ;
00392 }
00393
00394
00395
00396 template <class PBASE>
00397 long GaudiTuples<PBASE>::printEvtCols () const
00398 {
00399 if ( evtColMapTitle().empty() && evtColMapID().empty() )
00400 { this->always() << "No Event Tag Collections are booked" << endmsg ; }
00401 else
00402 { this->always() << "List of booked Event Tag Collections in directory "
00403 << "\"" << evtColPath() << "\"" << endmsg ; }
00404
00405
00406 typedef std::map<TupleID,const Tuples::TupleObj*> OrderedMapType;
00407 OrderedMapType OrderedMap ( evtColMapID().begin() , evtColMapID().end() ) ;
00408
00409 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
00410 OrderedMap.end() != entry ; ++entry )
00411 {
00412 if ( 0 == entry->second ) { continue ; }
00413 const NTuple::Tuple* tuple = entry->second->tuple() ;
00414 if ( 0 == tuple )
00415 { this->error() << " NTuple::Tuple* points to NULL" << endmsg ; continue ; }
00416 this->always() << GaudiAlg::PrintTuple::print ( tuple , entry->first )
00417 << " Items:"
00418 << Gaudi::Utils::toString ( entry->second->items() ) << endmsg ;
00419 }
00420
00421 return this->evtColMapID().size() ;
00422 }
00423
00424
00425
00426 template <class PBASE>
00427 bool GaudiTuples<PBASE>::nTupleExists ( const TupleID& ID ) const
00428 { return m_nTupleMapID.end() != m_nTupleMapID.find ( ID ) ; }
00429
00430
00431
00432 template <class PBASE>
00433 bool GaudiTuples<PBASE>::evtColExists ( const TupleID& ID ) const
00434 { return m_evtColMapID.end() != m_evtColMapID.find ( ID ) ; }
00435
00436
00437
00438 template <class PBASE>
00439 void GaudiTuples<PBASE>::printNTupleHandler ( Property& )
00440 {
00441
00442 if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
00443 if ( this -> tuplesPrint() ) { this -> printTuples () ; }
00444 }
00445
00446
00447
00448 template <class PBASE>
00449 void GaudiTuples<PBASE>::printEvtColHandler ( Property& )
00450 {
00451
00452 if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
00453 if ( this -> evtColsPrint() ) { this -> printEvtCols () ; }
00454 }
00455
00456
00457