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