00001 #include "StatisticsSvc.h"
00002 #include "TObject.h"
00003 #include "TFile.h"
00004 #include "TH1F.h"
00005 #include "TH2F.h"
00006 #include "TH3F.h"
00007 #include "TTree.h"
00008 #include "TGraph.h"
00009 #include "HistMan/HistMan.h"
00010 #include "GaudiKernel/IMessageSvc.h"
00011
00012 StatisticsSvc::StatisticsSvc(const std::string& name, ISvcLocator *svc)
00013 : Service(name,svc),
00014 m_msgSvc(0)
00015 {
00016
00017 declareProperty("Input",m_input ,
00018 "List of path, input file pairs.");
00019 declareProperty("Output",m_output ,
00020 "List of path, output file pairs.");
00021 }
00022
00023 StatisticsSvc::~StatisticsSvc()
00024 {
00025 }
00026
00027
00028 static std::string xrootdify(std::string file)
00029 {
00030 if ("root:" != file.substr(0,5)) {
00031 return file;
00032 }
00033
00034 if ("?mkpath=1" == file.substr(file.size()-9)) {
00035 return file;
00036 }
00037 return file + "?mkpath=1";
00038 }
00039
00040
00041 static std::map<std::string,std::string> xrootdify_map(const std::map<std::string,std::string>& inmap)
00042 {
00043 std::map<std::string,std::string> ret;
00044 std::map<std::string,std::string>::const_iterator it, done = inmap.end();
00045 for(it = inmap.begin(); it != done; ++it) {
00046 ret[it->first] = xrootdify(it->second);
00047 }
00048 return ret;
00049 }
00050
00051
00052 StatusCode StatisticsSvc::initialize()
00053 {
00054 StatusCode sc = this->Service::initialize();
00055 if( sc.isFailure() ) return sc;
00056
00057 m_msgSvc = msgSvc();
00058 if( !m_msgSvc ) return StatusCode::FAILURE;
00059
00060 {
00061 std::ostringstream msgStr;
00062 msgStr << "initialize()";
00063 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00064 }
00065
00066 std::map<std::string, std::string> fileModeByFilename;
00067 std::vector<std::string> inHandles;
00068 std::vector<std::string> inFiles;
00069 std::vector<std::string> outHandles;
00070 std::vector<std::string> outFiles;
00071
00072 m_input = xrootdify_map(m_input);
00073 m_output = xrootdify_map(m_output);
00074
00075
00076 std::map<std::string,std::string>::const_iterator inputIter,
00077 inputEnd = m_input.end();
00078 for(inputIter=m_input.begin(); inputIter != inputEnd; inputIter++){
00079 std::string handle = inputIter->first;
00080 std::string filename = inputIter->second;
00081 sc = checkOptions(handle, filename);
00082 if( sc.isFailure() ) return sc;
00083
00084
00085 if( std::find(inHandles.begin(), inHandles.end(), handle)
00086 != inHandles.end() ){
00087 std::ostringstream msgStr;
00088 msgStr << "initialize(): File handle "
00089 << handle << " already associated with input file "
00090 << m_input[handle];
00091 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00092 return StatusCode::FAILURE;
00093 }
00094
00095 if( std::find(inFiles.begin(), inFiles.end(), filename) != inFiles.end() ){
00096 std::ostringstream msgStr;
00097 msgStr << "initialize(): Filename "
00098 << filename << " already associated with an input handle.";
00099 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00100 return StatusCode::FAILURE;
00101 }
00102
00103 inHandles.push_back(handle);
00104 inFiles.push_back(filename);
00105 m_histMan[handle] = 0;
00106
00107 fileModeByFilename[filename]="READ";
00108 }
00109
00110
00111 std::map<std::string,std::string>::const_iterator outputIter,
00112 outputEnd = m_output.end();
00113 for(outputIter=m_output.begin(); outputIter != outputEnd; outputIter++){
00114 std::string handle = outputIter->first;
00115 std::string filename = outputIter->second;
00116 sc = checkOptions(handle, filename);
00117 if( sc.isFailure() ) return sc;
00118
00119 if( std::find(outHandles.begin(), outHandles.end(), handle)
00120 != outHandles.end() ){
00121 std::ostringstream msgStr;
00122 msgStr << "initialize(): Output File handle "
00123 << handle << " already associated with file "
00124 << m_output[handle];
00125 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00126 return StatusCode::FAILURE;
00127 }
00128
00129 if( std::find(outFiles.begin(), outFiles.end(), filename)
00130 != outFiles.end() ){
00131 std::ostringstream msgStr;
00132 msgStr << "initialize(): Output Filename "
00133 << filename << " already associated with an output handle.";
00134 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00135 return StatusCode::FAILURE;
00136 }
00137
00138
00139 if( std::find(inFiles.begin(), inFiles.end(), filename) != inFiles.end()){
00140
00141 std::map<std::string, std::string>::iterator inputIter
00142 = m_input.find(handle);
00143 if( inputIter == m_input.end() || m_input[handle] != m_output[handle] ){
00144 std::ostringstream msgStr;
00145 msgStr << "initialize(): Output Filename "
00146 << filename << " already associated with separate input handle";
00147 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00148 return StatusCode::FAILURE;
00149 }
00150
00151 fileModeByFilename[filename] = "UPDATE";
00152 }else{
00153
00154 fileModeByFilename[filename]="RECREATE";
00155 m_histMan[handle] = 0;
00156 }
00157
00158
00159 outHandles.push_back(handle);
00160 outFiles.push_back(filename);
00161 }
00162
00163
00164 TDirectory* prevDirectory = gDirectory;
00165 std::map<std::string, std::string>::iterator fileIter,
00166 fileEnd = fileModeByFilename.end();
00167 for(fileIter = fileModeByFilename.begin(); fileIter != fileEnd; fileIter++){
00168 std::string filename = fileIter->first;
00169 std::string fileMode = fileIter->second;
00170
00171 TFile* file = TFile::Open(filename.c_str(), fileMode.c_str());
00172 if( !file || file->IsZombie() || !file->IsOpen() ){
00173 std::ostringstream msgStr;
00174 msgStr << "initialize(): Failed to open file "
00175 << filename << " with mode " << fileMode;
00176 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00177 return StatusCode::FAILURE;
00178 }
00179 m_files[filename] = file;
00180 }
00181
00182
00183 std::map<std::string, HistMan*>::iterator hmIter,
00184 hmEnd = m_histMan.end();
00185 for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00186 std::string handle = hmIter->first;
00187 TFile* file = 0;
00188 if(m_input.find(handle) != m_input.end()){
00189
00190 file = m_files[ m_input[handle] ];
00191 std::ostringstream msgStr;
00192 msgStr << "initialize(): Reading handle " << handle
00193 << " from file " << file->GetName() << " with mode "
00194 << fileModeByFilename[file->GetName()];
00195 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00196 }else if( m_output.find(handle) != m_output.end() ){
00197
00198 file = m_files[ m_output[handle] ];
00199 }else{
00200 std::ostringstream msgStr;
00201 msgStr << "initialize(): Error associating " << handle
00202 << " with either input or output file.";
00203 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00204 return StatusCode::FAILURE;
00205 }
00206 HistMan* histMan = new HistMan( *file, false );
00207 if(!histMan){
00208 std::ostringstream msgStr;
00209 msgStr << "initialize(): Failed to create HistMan for "
00210 << handle;
00211 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00212 return StatusCode::FAILURE;
00213 }
00214 m_histMan[ handle ] = histMan;
00215 }
00216
00217 gDirectory = prevDirectory;
00218 {
00219 std::ostringstream msgStr;
00220 msgStr << "initialize(): finished";
00221 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00222 }
00223 return sc;
00224 }
00225
00226 StatusCode StatisticsSvc::finalize()
00227 {
00228
00229 {
00230 std::ostringstream msgStr;
00231 msgStr << "finalize():";
00232 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00233 }
00234
00235
00236 this->dump();
00237
00238
00239 std::map<std::string, std::string>::iterator outputIter,
00240 outputEnd = m_output.end();
00241 for(outputIter=m_output.begin(); outputIter != outputEnd; outputIter++){
00242 std::string handle = outputIter->first;
00243 std::string filename = outputIter->second;
00244 TFile* file = m_files[filename];
00245 HistMan* histMan = m_histMan[handle];
00246 if( !file ){
00247 std::ostringstream msgStr;
00248 msgStr << "finalize(): Unexpected Err! Bad file handle: "
00249 << handle;
00250 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00251 return StatusCode::FAILURE;
00252 }
00253 if( !histMan ){
00254 std::ostringstream msgStr;
00255 msgStr << "finalize(): Unexpected Error! "
00256 << "Bad HistMan handle: " << handle;
00257 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00258 return StatusCode::FAILURE;
00259 }
00260
00261 {
00262 std::ostringstream msgStr;
00263 msgStr << "finalize(): Writing handle " << handle
00264 << " to file " << file->GetName();
00265 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00266 }
00267 histMan->WriteOut( *file );
00268 }
00269
00270
00271 std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00272 for(hmIter=m_histMan.begin(); hmIter != hmEnd; hmIter++){
00273 std::string handle = hmIter->first;
00274 HistMan* histMan = hmIter->second;
00275 delete histMan;
00276 m_histMan[handle] = 0;
00277 }
00278 m_histMan.clear();
00279
00280
00281 std::map<std::string, TFile*>::iterator fileIter, fileEnd = m_files.end();
00282 for(fileIter=m_files.begin(); fileIter != fileEnd; fileIter++){
00283 std::string filename = fileIter->first;
00284 TFile* file = fileIter->second;
00285 if( !file ){
00286 std::ostringstream msgStr;
00287 msgStr << "finalize(): Unexpected Err! Bad file: "
00288 << filename;
00289 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00290 return StatusCode::FAILURE;
00291 }
00292 file->Close();
00293 delete file;
00294 m_files[filename] = 0;
00295 }
00296 m_files.clear();
00297
00298 {
00299 std::ostringstream msgStr;
00300 msgStr << "finalize(): done";
00301 m_msgSvc->reportMessage("StatisticsSvc",MSG::INFO,msgStr.str());
00302 }
00303
00304 return this->Service::finalize();
00305 }
00306
00307 StatusCode StatisticsSvc::queryInterface(const InterfaceID& riid,
00308 void** ppvInterface)
00309 {
00310 StatusCode sc = StatusCode::FAILURE;
00311 if (ppvInterface) {
00312 *ppvInterface = 0;
00313
00314 if (IStatisticsSvc::interfaceID().versionMatch(riid)) {
00315 *ppvInterface = static_cast<IStatisticsSvc*>(this);
00316 sc = StatusCode::SUCCESS;
00317 addRef();
00318 }
00319 else sc = Service::queryInterface( riid, ppvInterface );
00320 }
00321 return sc;
00322 }
00323
00325
00326 StatusCode StatisticsSvc::put(const std::string& path, TObject* object){
00327
00328 if(!object){
00329 std::ostringstream msgStr;
00330 msgStr << "put(): Invalid object at: " << path;
00331 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00332 return StatusCode::FAILURE;
00333 }
00334
00335 std::string localPathPlusName, localPath, name;
00336 HistMan* histMan = 0;
00337 StatusCode sc = getManager(path, histMan, localPathPlusName);
00338 if( sc.isFailure() ) return sc;
00339
00340 sc = reverseParsePath(localPathPlusName, localPath, name);
00341 if( sc.isFailure() ){
00342 std::ostringstream msgStr;
00343 msgStr << "put(): Invalid path + name: " << localPathPlusName;
00344 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00345 return sc;
00346 }
00347
00348 if(name != object->GetName()){
00349 std::ostringstream msgStr;
00350 TNamed* namedObj = dynamic_cast<TNamed*>(object);
00351 if(!namedObj){
00352 msgStr << "put(): Cannot put unnamed object (" << name << ","
00353 << object->GetName() << " in statistics service.";
00354 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00355 return StatusCode::FAILURE;
00356 }else{
00357 msgStr << "put(): Changing object name: " << namedObj->GetName()
00358 << " to " << name;
00359 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00360 namedObj->SetName(name.c_str());
00361 }
00362 }
00363
00364 TObject* checkObj = histMan->Adopt(localPath.c_str(), object);
00365 if(!checkObj){
00366
00367 std::ostringstream msgStr;
00368 msgStr << "put(): Replacing object at " << path;
00369 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00370 histMan->Adopt(localPath.c_str(), object);
00371 }
00372 return StatusCode::SUCCESS;
00373 }
00374
00375 TObject* StatisticsSvc::get(const std::string& path){
00376 if(path.size()==1 && path[0]=='/') return 0;
00377 std::string localPath;
00378 HistMan* histMan = 0;
00379 StatusCode sc = this->getManager(path, histMan, localPath);
00380 if( sc.isFailure() ) return 0;
00381 TObject* obj = histMan->GetObject(localPath.c_str());
00382 if(!obj){
00383 std::ostringstream msgStr;
00384 msgStr << "get(): No entry at " << path;
00385 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00386 return 0;
00387 }
00388 return obj;
00389 }
00390
00391 bool StatisticsSvc::exists(const std::string& path){
00392 if(path.size()==1 && path[0]=='/') return true;
00393 std::string localPath;
00394 HistMan* histMan = 0;
00395 bool report = false;
00396 StatusCode sc = this->getManager(path, histMan, localPath, report);
00397 if( sc.isFailure() ) return false;
00398 TObject* obj = histMan->GetObjectOrFolder(localPath.c_str());
00399 if(!obj) return false;
00400 return true;
00401 }
00402
00403 std::vector<std::string> StatisticsSvc::getContents(const std::string& path){
00404 std::vector<std::string> empty, contents;
00405 if(path.size()==1 && path[0]=='/') return empty;
00406 std::string localPath;
00407 HistMan* histMan = 0;
00408 StatusCode sc = getManager(path, histMan, localPath);
00409 if( sc.isFailure() ) return empty;
00410
00411 std::vector<TObject*> objects = histMan->GetObjects(localPath.c_str());
00412 std::vector<TObject*>::iterator objIter, objEnd = objects.end();
00413 for(objIter=objects.begin(); objIter!=objEnd; objIter++){
00414 TObject* object = *objIter;
00415 if(!object){
00416 std::ostringstream msgStr;
00417 msgStr << "getContents(): Broken object at " << localPath;
00418 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00419 return empty;
00420 }
00421 contents.push_back( object->GetName() );
00422 }
00423 return contents;
00424 }
00425
00426 std::vector<std::string> StatisticsSvc::getSubFolders(const std::string& path){
00427 std::vector<std::string> empty, contents;
00428 if(path.size()==1 && path[0]=='/'){
00429
00430 std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00431 std::ostringstream msgStr;
00432 msgStr << "Adding root folders: ";
00433 for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00434 contents.push_back( hmIter->first );
00435 msgStr << " " << hmIter->first;
00436 }
00437 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00438 return contents;
00439 }
00440 std::string localPath;
00441 HistMan* histMan = 0;
00442 StatusCode sc = getManager(path, histMan, localPath);
00443 if( sc.isFailure() ) return empty;
00444
00445 std::vector<TFolder*> folders =
00446 histMan->GetSubFolders(localPath.c_str());
00447 std::vector<TFolder*>::iterator folderIter, folderEnd = folders.end();
00448 for(folderIter=folders.begin(); folderIter!=folderEnd; folderIter++){
00449 TFolder* folder = *folderIter;
00450 if(!folder){
00451 std::ostringstream msgStr;
00452 msgStr << "getSubFolders(): Broken folder at " << localPath;
00453 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00454 return empty;
00455 }
00456 contents.push_back( folder->GetName() );
00457 }
00458 return contents;
00459 }
00460
00461
00462 TH1F* StatisticsSvc::getTH1F(const std::string& path){
00463 TObject* obj = this->get(path);
00464 if(!obj) return 0;
00465 TH1F* hist = dynamic_cast<TH1F*>(obj);
00466 if(!hist){
00467 std::string msgStr ="Failed to cast object at "+path+" to histogram (TH1F)";
00468 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00469 return 0;
00470 }
00471 return hist;
00472 }
00473
00474 TH2F* StatisticsSvc::getTH2F(const std::string& path){
00475 TObject* obj = this->get(path);
00476 if(!obj) return 0;
00477 TH2F* hist = dynamic_cast<TH2F*>(obj);
00478 if(!hist){
00479 std::string msgStr ="Failed to cast object at "+path+" to histogram (TH2F)";
00480 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00481 return 0;
00482 }
00483 return hist;
00484 }
00485
00486 TH3F* StatisticsSvc::getTH3F(const std::string& path){
00487 TObject* obj = this->get(path);
00488 if(!obj) return 0;
00489 TH3F* hist = dynamic_cast<TH3F*>(obj);
00490 if(!hist){
00491 std::string msgStr ="Failed to cast object at "+path+" to histogram (TH3F)";
00492 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00493 return 0;
00494 }
00495 return hist;
00496 }
00497
00498 TTree* StatisticsSvc::getTree(const std::string& path){
00499 TObject* obj = this->get(path);
00500 if(!obj) return 0;
00501 TTree* tree = dynamic_cast<TTree*>(obj);
00502 if(!tree){
00503 std::string msgStr ="Failed to cast object at "+path+" to tree";
00504 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00505 return 0;
00506 }
00507 return tree;
00508 }
00509
00510 TGraph* StatisticsSvc::getGraph(const std::string& path){
00511 TObject* obj = this->get(path);
00512 if(!obj) return 0;
00513 TGraph* graph = dynamic_cast<TGraph*>(obj);
00514 if(!graph){
00515 std::string msgStr ="Failed to cast object at "+path+" to graph (TGraph)";
00516 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr);
00517 return 0;
00518 }
00519 return graph;
00520 }
00521
00523
00524 StatusCode StatisticsSvc::checkOptions(std::string& handle,
00525 std::string& filename){
00526
00527 if( filename.find("root://") == std::string::npos &&
00528 filename.find("//") != std::string::npos ) {
00529 std::ostringstream msgStr;
00530 msgStr << "checkOptions(): filename "
00531 << filename << " is not supported (cannot contain '//').";
00532 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00533 return StatusCode::FAILURE;
00534 }
00535
00536 if( handle.find('/') != std::string::npos){
00537 std::ostringstream msgStr;
00538 msgStr << "checkOptions(): handle "
00539 << handle << " is not supported (cannot contain '/').";
00540 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00541 return StatusCode::FAILURE;
00542 }
00543
00544 if( handle.size()==0 || filename.size()==0 ){
00545 std::ostringstream msgStr;
00546 msgStr << "checkOptions(): Null handle \"" << handle
00547 << "\" or filename \"" << filename << "\"";
00548 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00549 return StatusCode::FAILURE;
00550 }
00551 return StatusCode::SUCCESS;
00552 }
00553
00554 StatusCode StatisticsSvc::parsePath(const std::string& fullpath,
00555 std::string& top, std::string& rest){
00556
00557
00558
00559
00560
00561
00562 char sep = '/';
00563 if(fullpath.length()<1 || fullpath[0] != sep) return StatusCode::FAILURE;
00564 std::string::size_type pos = fullpath.find(sep, 1);
00565 if(pos == std::string::npos){
00566
00567 top = std::string(fullpath, 1, std::string::npos);
00568 rest = "";
00569 }else{
00570 top = std::string(fullpath, 1, pos-1);
00571 rest = std::string(fullpath, pos, std::string::npos);
00572 }
00573 return StatusCode::SUCCESS;
00574 }
00575
00576 StatusCode StatisticsSvc::reverseParsePath(const std::string& fullpath,
00577 std::string& rest,
00578 std::string& bottom){
00579
00580
00581
00582
00583
00584
00585 char sep = '/';
00586 if(fullpath.length()<1 || fullpath[fullpath.length()-1] == sep)
00587 return StatusCode::FAILURE;
00588 std::string::size_type pos = fullpath.rfind(sep);
00589 if(pos == std::string::npos || pos == 0
00590 || pos == (fullpath.length()-1) ) return StatusCode::FAILURE;
00591 rest = std::string(fullpath, 0, pos);
00592 bottom = std::string(fullpath, pos+1, std::string::npos);
00593 return StatusCode::SUCCESS;
00594 }
00595
00596 StatusCode StatisticsSvc::getManager(const std::string& path,
00597 HistMan*& histMan, std::string& localPath,
00598 bool report ){
00599
00600
00601 std::string handle, subPath;
00602 StatusCode sc = parsePath(path, handle, subPath);
00603 if( sc.isFailure() ){
00604 std::ostringstream msgStr;
00605 msgStr << "getManager(): Invalid path: " << path;
00606 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00607 return StatusCode::FAILURE;
00608 }
00609
00610 HistMan* hm = 0;
00611 std::map<std::string, HistMan*>::iterator hmIter = m_histMan.find(handle);
00612 if( hmIter == m_histMan.end() ){
00613 if(report){
00614 std::ostringstream msgStr;
00615 msgStr << "getManager(): Creating transient path for unknown handle "
00616 << handle
00617 << " used in full path "
00618 << path;
00619 m_msgSvc->reportMessage("StatisticsSvc",MSG::WARNING,msgStr.str());
00620 }
00621 std::string transientPath = "//root/transient_";
00622 transientPath.append( handle );
00623 TFolder* folder = new TFolder(transientPath.c_str(),
00624 "Transient Statistics Folder");
00625 hm = new HistMan(folder, false);
00626 m_histMan[handle] = hm;
00627 }else{
00628 hm = hmIter->second;
00629 if(!hm){
00630 std::ostringstream msgStr;
00631 msgStr << "getManager(): Invalid HistMan for " << handle
00632 << " used in full path " << path;
00633 m_msgSvc->reportMessage("StatisticsSvc",MSG::ERROR,msgStr.str());
00634 return StatusCode::FAILURE;
00635 }
00636 }
00637
00638 if( subPath.length() > 0 && subPath[0] == '/' )
00639 localPath = std::string(subPath, 1, std::string::npos);
00640 else
00641 localPath = subPath;
00642 histMan = hm;
00643 return StatusCode::SUCCESS;
00644 }
00645
00646 void StatisticsSvc::dump(){
00647
00648 std::ostringstream dumpStr;
00649 dumpStr << "StatisticsSvc contents:\n";
00650 std::map<std::string, HistMan*>::iterator hmIter, hmEnd = m_histMan.end();
00651 for(hmIter = m_histMan.begin(); hmIter != hmEnd; hmIter++){
00652 std::string handle = hmIter->first;
00653 std::string filename = "[TRANSIENT ONLY]";
00654 std::map<std::string, std::string>::iterator outputIter
00655 = m_output.find(handle);
00656 if( outputIter != m_output.end() )
00657 filename = outputIter->second;
00658 dumpStr << "\nPATH=" << handle << " written to: " << filename << "\n";
00659 std::string currentPath = "/"+handle;
00660 dumpStr << currentPath << "\n";
00661 this->dumpPath(currentPath, dumpStr);
00662 }
00663 m_msgSvc->reportMessage("StatisticsSvc",MSG::DEBUG,dumpStr.str());
00664 }
00665
00666 void StatisticsSvc::dumpPath(const std::string& path,
00667 std::ostringstream& dumpStr){
00668
00669 std::vector<std::string> names = this->getContents(path);
00670 std::vector<std::string>::iterator nameIter, nameEnd = names.end();
00671 for(nameIter=names.begin(); nameIter != nameEnd; nameIter++){
00672 std::string fullpath = path + "/" + (*nameIter);
00673 std::string type;
00674 TObject* obj = this->get(fullpath);
00675 if(!obj) type = "BROKEN";
00676 else type = obj->ClassName();
00677 dumpStr << fullpath << " (" << type << ")\n";
00678 }
00679
00680 names = this->getSubFolders(path);
00681 nameEnd = names.end();
00682 for(nameIter=names.begin(); nameIter != nameEnd; nameIter++){
00683 std::string fullpath = path + "/" + (*nameIter);
00684 dumpStr << fullpath << "\n";
00685 this->dumpPath(fullpath,dumpStr);
00686 }
00687 return;
00688 }