//------------------------------------------------------------------------------ StatusCode HistogramSvc::connectInput(CSTR ident) { MsgStream log (msgSvc(), name()); DataObject* pO = 0; StatusCode status = this->findObject(m_rootName, pO); if (status.isSuccess()) { Tokenizer tok(true); std::string::size_type loc = ident.find(" "); std::string filename, auth, svc = "", typ = ""; std::string logname = ident.substr(0,loc); tok.analyse(ident.substr(loc+1,ident.length()), " ", "", "", "=", "'", "'"); for (Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++) { CSTR tag = (*i).tag(); switch(::toupper(tag[0])) { case 'F': // FILE='<file name>' case 'D': // DATAFILE='<file name>' filename = (*i).value(); break; case 'T': // TYP='<HBOOK,ROOT,OBJY,...>' typ = (*i).value(); break; default: break; } } if (typ.length() > 0) { // Now add the registry entry to the store std::string entryname = m_rootName; entryname += '/'; entryname += logname; GenericAddress* pA = 0; switch(::toupper(typ[0])) { case 'H': pA=new GenericAddress(HBOOK_StorageType,CLID_StatisticsFile, filename,entryname,0,'O'); break; case 'R': pA=new GenericAddress(ROOT_StorageType,CLID_StatisticsFile, filename,entryname,0,'O'); break; } if (0 != pA) { status = registerAddress(pO, logname, pA); if (status.isSuccess()) { log << MSG::INFO << "Added stream file:" << filename << " as " << logname << endmsg; return status; } pA->release(); } } } log << MSG::ERROR << "Cannot add " << ident << " invalid filename!" << endmsg; return StatusCode::FAILURE; }
//------------------------------------------------------------------------------ StatusCode HistogramSvc::registerObject (DataObject* pPar,CSTR obj,IBaseHistogram* hObj) { // Set the histogram id if (obj[0] == SEPARATOR) { // hObj->setTitle(obj.substr(1) + "|" + hObj->title()); if (!hObj->annotation().addItem("id", obj.substr(1))) hObj->annotation().setValue("id", obj.substr(1)); } else { // hObj->setTitle(obj + "|" + hObj->title()); if (!hObj->annotation().addItem("id", obj)) hObj->annotation().setValue("id", obj); } // Register the histogram in the histogram data store return DataSvc::registerObject(pPar,obj,__cast(hObj)); }
///////////////////////////////////////////////////////////////////////////// // Read all data for Elo calculation ///////////////////////////////////////////////////////////////////////////// void EloDataFromFile(CPGNLex &pgnlex, CResultSet &rs, std::vector<std::string> &vNames) { int Players = 0; int Ignored = 0; // // Add current players to the name map // std::map<std::string, int> NameMap; for (int i = vNames.size(); --i >= 0;) { std::pair<const std::string, int> Pair(vNames[i], i); NameMap.insert(Pair); Players++; } // // Loop over games // while (1) { CSTR str; int fTheEnd = CPGN::ReadSTR(str, pgnlex); SkipGame(pgnlex); if (!fTheEnd) { // // Ignore unknown results // int r = str.GetResult(); if (r < 0 || r > 2) { Ignored++; } else { std::string sWhite(str.GetWhite()); std::string sBlack(str.GetBlack()); { std::pair<const std::string, int> Pair(sWhite, Players); if (NameMap.insert(Pair).second) { Players++; vNames.push_back(sWhite); } } { std::pair<const std::string, int> Pair(sBlack, Players); if (NameMap.insert(Pair).second) { Players++; vNames.push_back(sBlack); } } int WhitePlayer = NameMap.find(sWhite)->second; int BlackPlayer = NameMap.find(sBlack)->second; rs.Append(WhitePlayer, BlackPlayer, r); } } if (rs.GetGames() % 1000 == 0 || fTheEnd) { std::cerr << rs.GetGames() << " game(s) loaded, "; std::cerr << Ignored << " game(s) with unknown result ignored.\r"; } if (fTheEnd) { std::cerr << '\n'; break; } } }
StatusCode StagedIODataManager::connectDataIO(int typ, IoType rw, CSTR dataset, CSTR technology,bool keep_open,Connection* connection) { MsgStream log(msgSvc(),name()); std::string dsn = dataset; try { StatusCode sc(StatusCode::SUCCESS,true); if ( ::strncasecmp(dsn.c_str(),"FID:",4)==0 ) dsn = dataset.substr(4), typ = FID; else if ( ::strncasecmp(dsn.c_str(),"LFN:",4)==0 ) dsn = dataset.substr(4), typ = LFN; else if ( ::strncasecmp(dsn.c_str(),"PFN:",4)==0 ) dsn = dataset.substr(4), typ = PFN; else if ( typ == UNKNOWN ) return connectDataIO(PFN, rw, dsn, technology, keep_open, connection); log << MSG::INFO << "Inside StagedIODataManager::connectDataIO(" <<dsn<<","<<dataset<<","<<technology<<")"<< endmsg; std::string dataset_local; if(m_stager.isValid()) { sc = m_stager->getLocalDataset(dataset, dataset_local); if (sc.isSuccess()) { dsn = dataset_local; typ = PFN; log << MSG::INFO << " StagedIODataManager: dsn: "<<dsn << endmsg; // for ETCs, no EndInputFile event is fired by the EventSelector when the previous file is finished with reading. //Only FILE_OPEN_READ is fired from ROOT, but then it is too late: if the file is not fully staged, it will result in an error // m_incSvc->fireIncident(Incident(dsn,"ATTEMPT_OPEN_FILE")); } else { log << MSG::ERROR << "Local URL not available for staged/replicated copy of " <<dataset<<", using original file descriptor." << endmsg; } } if(std::find(s_badFiles.begin(),s_badFiles.end(),dsn) != s_badFiles.end()) { m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); return IDataConnection::BAD_DATA_CONNECTION; } if ( typ == FID ) { ConnectionMap::iterator fi = m_connectionMap.find(dsn); if ( fi == m_connectionMap.end() ) { IFileCatalog::Files files; m_catalog->getPFN(dsn,files); log<<MSG::INFO<<"inside StagedIODataManager: connectDataIO (FID) args:dataset:" <<dataset<<" dsn"<<dsn<<endmsg; if ( files.size() == 0 ) { if ( !m_useGFAL ) { if ( m_quarantine ) s_badFiles.insert(dsn); m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); error("connectDataIO> failed to resolve FID:"+dsn,false).ignore(); return IDataConnection::BAD_DATA_CONNECTION; } else if ( dsn.length() == 36 && dsn[8]=='-' && dsn[13]=='-' ) { std::string gfal_name = "gfal:guid:" + dsn; m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[gfal_name] = dsn; sc = connectDataIO(PFN, rw, gfal_name, technology, keep_open, connection); if ( sc.isSuccess() ) return sc; if ( m_quarantine ) s_badFiles.insert(dsn); } if ( m_quarantine ) s_badFiles.insert(dsn); m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); error("connectDataIO> Failed to resolve FID:"+dsn,false).ignore(); return IDataConnection::BAD_DATA_CONNECTION; } std::string pfn = files[0].first; m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn; sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection); if ( !sc.isSuccess() ) { if ( m_quarantine ) s_badFiles.insert(pfn); m_incSvc->fireIncident(Incident(pfn,IncidentType::FailInputFile)); return IDataConnection::BAD_DATA_CONNECTION; } return sc; } return S_ERROR; } std::string fid; FidMap::iterator j = m_fidMap.find(dsn); if ( j == m_fidMap.end() ) { IFileCatalog::Files files; switch(typ) { case LFN: fid = m_catalog->lookupLFN(dsn); if ( fid.empty() ) { m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); log << MSG::ERROR << "Failed to resolve LFN:" << dsn << " Cannot access this dataset." << endmsg; return IDataConnection::BAD_DATA_CONNECTION; } break; case PFN: fid = m_catalog->lookupPFN(dsn); if ( !fid.empty() ) m_catalog->getPFN(fid, files); if ( files.empty() ) { if ( rw == Connection::CREATE || rw == Connection::RECREATE ) { if ( fid.empty() ) fid = m_catalog->createFID(); m_catalog->registerPFN(fid,dsn,technology); log << MSG::INFO << "Referring to dataset " << dsn << " by its file ID:" << fid << endmsg; } else { fid = dsn; } } break; } } else { fid = (*j).second; } if ( typ == PFN ) { ConnectionMap::iterator fi = m_connectionMap.find(fid); if ( fi == m_connectionMap.end() ) { connection->setFID(fid); connection->setPFN(dsn); Entry* e = new Entry(technology, keep_open, rw, connection); // Here we open the file! log<<MSG::INFO<<"From StagedIODataManager: connectDataIO(PFN) args:dataset:"<<dataset<<" dsn:"<<dsn<<endmsg; if ( !reconnect(e).isSuccess() ) { delete e; if ( m_quarantine ) s_badFiles.insert(dsn); m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore(); return IDataConnection::BAD_DATA_CONNECTION; } fid = connection->fid(); m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid; if ( !(rw==Connection::CREATE || rw==Connection::RECREATE) ) { if ( strcasecmp(dsn.c_str(),fid.c_str()) == 0 ) { log << MSG::ERROR << "Referring to existing dataset " << dsn << " by its physical name." << endmsg; log << "You may not be able to navigate back to the input file" << " -- processing continues" << endmsg; } } m_connectionMap.insert(std::make_pair(fid,e)).first; return S_OK; } // Here we open the file! if ( !reconnect((*fi).second).isSuccess() ) { if ( m_quarantine ) s_badFiles.insert(dsn); m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore(); return IDataConnection::BAD_DATA_CONNECTION; } return S_OK; } sc = connectDataIO(FID, rw, fid, technology, keep_open, connection); if ( !sc.isSuccess() && m_quarantine ) { s_badFiles.insert(fid); } else if ( typ == LFN ) { m_fidMap[dataset] = fid; } return sc; } catch (std::exception& e) { error(std::string("connectDataIO> Caught exception:")+e.what(), false).ignore(); } catch(...) { error(std::string("connectDataIO> Caught unknown exception"), false).ignore(); } m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile)); error("connectDataIO> The dataset "+dsn+" cannot be opened.",false).ignore(); s_badFiles.insert(dsn); return IDataConnection::BAD_DATA_CONNECTION; }