text:
#pragma once

#include "utils/ph_map/perfect_hash_map_builder.hpp"
#include "io/kmers/mmapped_reader.hpp"
#include "sequence/rtseq.hpp"

#include <boost/optional.hpp>

namespace debruijn_graph {

//Kmer multiplicities types: integral values
typedef uint16_t Mpl;
static const Mpl INVALID_MPL = Mpl(-1);
typedef std::size_t Offset;
typedef typename std::vector<Mpl> MplVector;

//Contig abundancies types: arbitrary values
typedef float Abundance;
typedef float Var;

struct AbVar {
    Abundance ab; Var var;
};

std::ostream& operator<<(std::ostream& str, AbVar ab_var);

template<typename T> using Profile = std::vector<T>;

class KmerProfileIndex {
private:
    typedef typename utils::InvertableStoring::trivial_inverter InverterT;
    typedef utils::KeyStoringMap<RtSeq,
        Offset,
        kmers::kmer_index_traits<RtSeq>,
        utils::InvertableStoring> IndexT;

    static size_t sample_cnt_;

public:
    static void SetSampleCount(size_t sample_cnt) { sample_cnt_ = sample_cnt; }
    static size_t SampleCount() { return sample_cnt_; }

    class KmerProfile {

    public:
        typedef Mpl value_type;

        KmerProfile(const value_type* ptr = nullptr):
            ptr_(ptr) {
        }

        KmerProfile(const MplVector& vec):
            ptr_(&vec.front()) {
        }

        size_t size() const {
            return SampleCount();
        }

        Mpl operator[](size_t i) const {
            VERIFY(i < size());
            return ptr_[i];
        }

        const value_type* begin() const {
            return ptr_;
        }

        const value_type* end() const {
            return ptr_ + size();
        }

    private:
        const value_type* ptr_;
    };

    typedef typename IndexT::KeyType KeyType;
    typedef typename IndexT::KeyWithHash KeyWithHash;

    KmerProfileIndex(unsigned k, const std::string& index_prefix);
    KmerProfileIndex(KmerProfileIndex&& other);

    KeyWithHash Construct(const KeyType& seq) const;
    boost::optional<KmerProfile> operator[](const KeyWithHash& kwh) const;

private:
    typedef MMappedRecordArrayReader<Mpl> ProfilesT;
    InverterT inverter_;
    IndexT index_;
    boost::optional<ProfilesT> profiles_;
};

using KmerProfile = KmerProfileIndex::KmerProfile;
typedef std::vector<KmerProfile> KmerProfiles;

template<class CovVecs>
Profile<Abundance> MeanVector(const CovVecs& cov_vecs) {
    VERIFY(cov_vecs.size() != 0);
    size_t sample_cnt = cov_vecs.front().size();
    Profile<Abundance> answer(sample_cnt, 0.);

    for (const auto& cov_vec : cov_vecs) {
        for (size_t i = 0; i < sample_cnt; ++i) {
            answer[i] += cov_vec[i];
        }
    }

    for (size_t i = 0; i < sample_cnt; ++i) {
        answer[i] /= float(cov_vecs.size());
    }
    return answer;
}

template<class AbVector>
std::string PrintVector(const AbVector& mpl_vector, const std::string &delim = " ") {
    std::stringstream ss;
    std::copy(mpl_vector.begin(), mpl_vector.end(),
              std::ostream_iterator<typename AbVector::value_type>(ss, delim.c_str()));
    return ss.str();
}

template<typename T>
class ClusterAnalyzer {
public:
    typedef typename boost::optional<Profile<T>> Result;
    virtual Result operator()(const KmerProfiles& kmer_mpls) const = 0;
    virtual ~ClusterAnalyzer() {};
};

template<typename T>
class TrivialClusterAnalyzer : public ClusterAnalyzer<T> {
public:
    TrivialClusterAnalyzer() {}
    virtual typename ClusterAnalyzer<T>::Result operator()(const KmerProfiles& kmer_mpls) const override;

private:
    bool var_;
    DECL_LOGGER("TrivialClusterAnalyzer");
};

/*class SingleClusterAnalyzer : public ClusterAnalyzer {
    static const uint MAX_IT = 10;

    double coord_vise_proximity_;
    double central_clust_share_;

    bool AreClose(const KmerProfile& c, const KmerProfile& v) const;
    KmerProfiles CloseKmerMpls(const KmerProfiles& kmer_mpls, const KmerProfile& center) const;

public:
    SingleClusterAnalyzer(double coord_vise_proximity = 0.7,
                          double central_clust_share = 0.7) :
        coord_vise_proximity_(coord_vise_proximity),
        central_clust_share_(central_clust_share) {
    }

    std::unique_ptr<AbundanceVector> operator()(const KmerProfiles& kmer_mpls) const override;

private:
    DECL_LOGGER("SingleClusterAnalyzer");
};*/

template<typename T>
class ProfileCounter {
    const unsigned k_;
    std::unique_ptr<ClusterAnalyzer<T>> cluster_analyzer_;
    double min_earmark_share_;

    KmerProfileIndex profile_index_;

public:
    ProfileCounter(unsigned k,
                   std::unique_ptr<ClusterAnalyzer<T>> cluster_analyzer,
                   const std::string& index_prefix,
                   double min_earmark_share = 0.7);
    ProfileCounter(ProfileCounter&& other);

    void Init(const std::string& kmer_mpl_file);

    typename ClusterAnalyzer<T>::Result operator()(const std::string& s, const std::string& /*name*/ = "") const;

private:
    DECL_LOGGER("ProfileCounter");
};

template<typename T>
ProfileCounter<T> MakeTrivial(unsigned k, const std::string& index_prefix) {
    return ProfileCounter<T>(
        k,
        std::unique_ptr<ClusterAnalyzer<T>>(new TrivialClusterAnalyzer<T>()),
        index_prefix
    );
}

}

max_stars_repo_name: STRIDES-Codes/Exploring-the-Microbiome-

max_issues_repo_name: STRIDES-Codes/Exploring-the-Microbiome-

max_forks_repo_name: STRIDES-Codes/Exploring-the-Microbiome-


text:
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/LegacyIOHelper.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/MessageLogger/interface/JobReport.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Version/interface/GetReleaseVersion.h"

#include "DQMFileSaverOnline.h"

#include <TString.h>
#include <TSystem.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

#include <openssl/md5.h>
#include <filesystem>
#include <boost/iostreams/device/mapped_file.hpp>

using namespace dqm;

DQMFileSaverOnline::DQMFileSaverOnline(const edm::ParameterSet& ps) : DQMFileSaverBase(ps) {
  backupLumiCount_ = ps.getUntrackedParameter<int>("backupLumiCount", 1);
  keepBackupLumi_ = ps.getUntrackedParameter<bool>("keepBackupLumi", false);
}

DQMFileSaverOnline::~DQMFileSaverOnline() = default;

void DQMFileSaverOnline::saveLumi(const FileParameters& fp) const {
  if (backupLumiCount_ > 0) {
    if (fp.lumi_ % backupLumiCount_ == 0) {
      // actual saving is done here
      makeSnapshot(fp, false);
    }
  }
}

void DQMFileSaverOnline::saveRun(const FileParameters& fp) const { makeSnapshot(fp, true); }

void DQMFileSaverOnline::makeSnapshot(const FileParameters& fp, bool final) const {
  int pid = getpid();
  char hostname[64];
  gethostname(hostname, 64);
  hostname[63] = 0;

  char suffix[128];
  if (!final) {
    snprintf(suffix, 127, ".ls%08ld_host%s_pid%08d", fp.lumi_, hostname, pid);
  } else {
    suffix[0] = 0;
  }

  std::string prefix = filename(fp, false);

  std::string root_fp = prefix + ".root" + suffix;
  std::string meta_fp = prefix + ".root.origin" + suffix;

  std::string tmp_root_fp = root_fp + ".tmp";
  std::string tmp_meta_fp = meta_fp + ".tmp";

  // run_ and lumi_ are ignored if dqmstore is not in multithread mode
  edm::Service<DQMStore> store;

  logFileAction("Writing DQM Root file: ", root_fp);
  // logFileAction("Writing DQM Origin file: ", meta_fp);

  //char rewrite[128];
  //snprintf(rewrite, 128, "\\1Run %ld/\\2/Run summary", fp.run_);

  //store->save(tmp_root_fp,                      /* filename      */
  //            "",                               /* path          */
  //            "^(Reference/)?([^/]+)",          /* pattern       */
  //            rewrite,                          /* rewrite       */
  //            store->mtEnabled() ? fp.run_ : 0, /* run           */
  //            0,                                /* lumi          */
  //            fp.saveReference_,                /* ref           */
  //            fp.saveReferenceQMin_,            /* ref minStatus */
  //            "RECREATE");                      /* fileupdate    */
  // TODO: some parameters prepared here are now unused, and the code should
  // eventually be removed.
  LegacyIOHelper h(&*store);
  h.save(tmp_root_fp, "", fp.run_, /* saveall */ true, "RECREATE");

  // write metadata
  // format.origin: md5:d566a34b27f48d507150a332b189398b 294835
  // /home/dqmprolocal/output/DQM_V0001_FED_R000194224.root
  std::ofstream meta_fd(tmp_meta_fp);
  meta_fd << fillOrigin(tmp_root_fp, root_fp);
  meta_fd.close();

  checkError("Rename failed: ", root_fp, ::rename(tmp_root_fp.c_str(), root_fp.c_str()));
  checkError("Rename failed: ", meta_fp, ::rename(tmp_meta_fp.c_str(), meta_fp.c_str()));

  SnapshotFiles files = {root_fp, meta_fp};
  if (final) {
    // final will never be cleared
    appendSnapshot(SnapshotFiles{});

    saveJobReport(root_fp);
  } else {
    appendSnapshot(SnapshotFiles{root_fp, meta_fp});
  }
}

void DQMFileSaverOnline::appendSnapshot(SnapshotFiles f) const {
  std::lock_guard<std::mutex> lock(snapshots_lock_);

  if (!keepBackupLumi_) {
    while (!snapshots_.empty()) {
      SnapshotFiles& x = snapshots_.front();

      // logFileAction("Deleting old snapshot (origin): ", x.meta);
      checkError("Unlink failed: ", x.meta, ::unlink(x.meta.c_str()));

      logFileAction("Deleting old snapshot (root): ", x.data);
      checkError("Unlink failed: ", x.data, ::unlink(x.data.c_str()));

      snapshots_.pop_front();
    }
  }

  if (!f.data.empty()) {
    snapshots_.push_back(f);
  }
}

void DQMFileSaverOnline::checkError(const char* msg, const std::string& file, int status) const {
  if (status != 0) {
    std::string actual_msg = msg;
    actual_msg += std::strerror(status);
    logFileAction(actual_msg, file);
  }
}

const std::string DQMFileSaverOnline::fillOrigin(const std::string& filename, const std::string& final_filename) {
  // format.origin (one line):
  //   md5:d566a34b27f48d507150a332b189398b 294835 final_filename.root

  unsigned char md5[MD5_DIGEST_LENGTH];

  boost::iostreams::mapped_file_source fp(filename);

  MD5((unsigned char*)fp.data(), fp.size(), md5);

  std::ostringstream hash;
  for (unsigned char& i : md5) {
    hash << std::hex << std::setfill('0') << std::setw(2) << (int)i;
  }

  std::ostringstream out;
  out << "md5:" << hash.str() << " " << fp.size() << " " << final_filename;
  return out.str();
}

void DQMFileSaverOnline::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  edm::ParameterSetDescription desc;
  desc.setComment("Saves histograms from DQM store, online workflow.");

  desc.addUntracked<int>("backupLumiCount", 10)
      ->setComment(
          "How often the backup file will be generated, in lumisections (-1 "
          "disables).");

  desc.addUntracked<bool>("keepBackupLumi", false)
      ->setComment(
          "Usually the backup old backup is deleted once the new file is "
          "available. Setting this to true ensures that no backup files are "
          "ever deleted. Useful for ML applications, which use backups as a "
          "'history' of what happened during the run.");

  DQMFileSaverBase::fillDescription(desc);

  // Changed to use addDefault instead of add here because previously
  // DQMFileSaverOnline and DQMFileSaverPB both used the module label
  // "saver" which caused conflicting cfi filenames to be generated.
  // add could be used if unique module labels were given.
  descriptions.addDefault(desc);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(DQMFileSaverOnline);

ext: cc

max_stars_repo_name: ckamtsikis/cmssw

max_issues_repo_name: ckamtsikis/cmssw

max_forks_repo_name: ckamtsikis/cmssw


text:
#include <string>
#include <sstream>
#include <iostream>

#include <boost/asio.hpp>

#include <odil/DataSet.h>
#include <odil/Tag.h>
#include <odil/webservices/HTTPRequest.h>
#include <odil/webservices/HTTPResponse.h>
#include <odil/webservices/QIDORSRequest.h>
#include <odil/webservices/QIDORSResponse.h>
#include <odil/webservices/Selector.h>
#include <odil/webservices/URL.h>

#include "odil/json_converter.h"

#include "odil/registry.h"
#include "list"
#include <boost/lexical_cast.hpp>
#include "odil/Exception.h"

struct Printer
{
    typedef void result_type;

    std::ostream & stream;
    std::string indent;

    Printer(std::ostream & stream, std::string const & indent="")
    : stream(stream), indent(indent)
    {
        // Nothing else
    }

    template<typename T>
    void operator()(T const & value) const
    {
        for(auto const & item: value)
        {
            this->stream << item << " ";
        }
    }

    void operator()(odil::Value::DataSets const & value) const
    {
        this->stream << "\n";

        auto const last_it = --value.end();
        for(auto it=value.begin(); it!= value.end(); ++it)
        {
            Printer const printer(this->stream, this->indent+"  ");
            printer(*it);
            if(it != last_it)
            {
                this->stream << "----\n";
            }
        }
    }

    void operator()(odil::Value::Binary const & value) const
    {
        this->stream << this->indent << "(binary)";
    }

    void operator()(odil::DataSet const & data_set) const
    {
        for(auto const & item: data_set)
        {
            this->stream << this->indent << item.first << " " << as_string(item.second.vr) << " ";
            odil::apply_visitor(*this, item.second.get_value());
            this->stream << "\n";
        }
    }
};

int main ()
{
    // orthanc local
//    odil::webservices::URL const root{
//        "http", "localhost", "/dicom-web"};
    // orthanc remote
    odil::webservices::URL const root{
        "http", "demo.orthanc-server.com", "/dicom-web"};

    odil::webservices::QIDORSRequest qido_request(root);

    //-------------------- Query DataSet creation
    odil::DataSet query_ds;
    query_ds.add(odil::Tag("PatientName"), {"KNI*"}); // Only to test the regex
    //-------------------- Wanted included fields
    query_ds.add(odil::Tag("00200035"));
    query_ds.add(odil::Tag("00200030"));

    //-------------------- Selector creation
    odil::webservices::Selector selector;
    selector.set_series("");

    qido_request.request_datasets(
        odil::webservices::Representation::DICOM_JSON,
        selector,
        query_ds
        );

    auto http_request = qido_request.get_http_request();
    // Explicitely use HTTP/1.0 to avoid chunked encoding
    http_request.set_http_version("HTTP/1.0");
    http_request.set_header("Host", root.authority);
    http_request.set_header("Connection", "close");

    // orthanc local
//    boost::asio::ip::tcp::iostream stream("localhost", "8042");
    // orthanc remote
    boost::asio::ip::tcp::iostream stream;
    stream.connect(root.authority, root.scheme);
    if(!stream)
    {
        std::cerr << "Error connecting: "
#if BOOST_VERSION >= 104700
            << stream.error().message()
#endif
            << std::endl;

        return 1;
    }

    stream << http_request;
    if(!stream)
    {
        std::cerr << "Error sending: "
#if BOOST_VERSION >= 104700
            << stream.error().message()
#endif
             << std::endl;
        return 1;
    }

    odil::webservices::HTTPResponse http_response;
    stream >> http_response;
    if(!stream)
    {
        std::cerr << "Error receiving: "
#if BOOST_VERSION >= 104700
            << stream.error().message()
#endif
            << std::endl;
        return 1;
    }

    odil::webservices::QIDORSResponse qido_response(http_response);

    std::cout << "Datasets: " << qido_response.get_data_sets().size() << std::endl;

    Printer printer(std::cout);
    for(auto const & data_set: qido_response.get_data_sets())
    {
        printer(data_set);
    }

    return 0;
}

ext: cpp

max_stars_repo_name: icryrainix/odil

max_issues_repo_name: icryrainix/odil

max_forks_repo_name: icryrainix/odil


text:
#include <Eigen/Dense>

#include <iostream>
#include <iomanip>

#include <cmath>

//! \brief Solve the autonomous IVP y' = f(y), y(0) = y0 using Rosenbrock method
//! Use semi-implicit Rosenbrock method using Jacobian evaluation. Equidistant steps of size T/N.
//! \tparam Func function type for r.h.s. f
//! \tparam DFunc function type for Jacobian df
//! \tparam StateType type of solution space y and initial data y0
//! \param[in] f r.h.s. func f
//! \param[in] df Jacobian df of f
//! \param[in] y0 initial data y(0)
//! \param[in] N number of equidistant steps
//! \param[in] T final time
//! \return vector of y_k for each step k from 0 to N
template <class Func, class DFunc, class StateType>
std::vector<StateType> solveRosenbrock(const Func & f, const DFunc & df,
                                       const StateType & y0, unsigned int N, double T) {
    const double h = T/N;
    const double a = 1. / (std::sqrt(2) + 2.);

    // Will contain all time steps
    std::vector<StateType> res(N+1);
    // Push initial data
    res.at(0) = y0;

    // Some temporary
    StateType k1, k2;
    Eigen::Matrix2d J, W;

    // Main loop: *up to N (performs N steps)*
    for(unsigned int i = 1; i <= N; ++i) {
        StateType & yprev = res.at(i-1);

        // Jacobian computation
        J = df(yprev);
        W = Eigen::Matrix2d::Identity() - a*h*J;

        // Reuse factorization for each step
        auto W_lu = W.partialPivLu();

        // Increments
        k1 = W_lu.solve(f(yprev));
        k2 = W_lu.solve(f(yprev+0.5*h*k1) - a*h*J*k1);

        // Push new step
        res.at(i) = yprev + h*k2;
    }

    return res;
}

int main() {
    // Final time
    const double T = 10;
    // All mesh sizes
    const std::vector<int> N = {16, 32, 64, 128, 256, 512, 1024, 2048, 4096};
    // Reference mesh size
    const int N_ref = 16384;
    // Initial data
    Eigen::Vector2d y0;
    y0 << 1., 1.;
    // Parameter and useful matrix for f
    const double lambda = 1;
    Eigen::Matrix2d R;
    R << 0., -1., 1., 0.;

    // Function and his Jacobian
    auto f =  [&R, &lambda] (const Eigen::Vector2d & y) { return R*y + lambda*(1. - std::pow(y.norm(),2))*y; };
    auto df = [&lambda] (const Eigen::Vector2d & y) {
        double x = 1 - std::pow(y.norm(), 2);
        Eigen::Matrix2d J;
        J << lambda*x - 2*lambda*y(0)*y(0),
        -1 - 2*lambda*y(1)*y(0),
        1 - 2*lambda*y(1)*y(0),
        lambda*x - 2*lambda*y(1)*y(1);
        return J;
    };

    // Reference solution
    auto solref = solveRosenbrock(f, df, y0, N_ref, T);

    std::cout << std::setw(15) << "n" << std::setw(15) << "maxerr" << std::setw(15) << "rate" << std::endl;
    // Used to compute rate at each step:
    double errold = 0;
    // Main loop: loop over all meshes
    for(unsigned int i = 0; i < N.size(); ++i) {
        int n = N.at(i);

        // Get solution
        auto sol = solveRosenbrock(f, df, y0, n, T);

        // Compute error
        double maxerr = 0;
        for(unsigned int j = 0; j < sol.size(); ++j) {
            maxerr = std::max(maxerr, (sol.at(j) - solref.at((j*N_ref)/n)).norm());
        }

        // Do some I/O
        std::cout << std::setw(15) << n << std::setw(15) << maxerr;
        if(i > 0) std::cout << std::setw(15) << std::log2(errold / maxerr);
        std::cout << std::endl;

        // Save old error (for rate)
        errold = maxerr;
    }
}

max_stars_repo_path: Nummerical Methods for CSE/PS14/solutions_ps14/rosenbrock.cpp

max_stars_repo_name: valentinjacot/backupETHZ

max_issues_repo_name: valentinjacot/backupETHZ

max_forks_repo_name: valentinjacot/backupETHZ


text:
//  stopclock_perf.cpp  ---------------------------------------------------//

//  Copyright 2009 Vicente J. Botet Escriba
//  Copyright 2009 Howard Hinnant

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

//  See http://www.boost.org/libs/chrono for documentation.

#ifndef BOOST_CHRONO_CLOCK_NAME_HPP
#define BOOST_CHRONO_CLOCK_NAME_HPP

#include <boost/chrono/chrono.hpp>
#include <boost/type_traits/is_same.hpp>

template <typename Clock,
          bool = boost::is_same<Clock, boost::chrono::system_clock>::value,
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
    bool = boost::is_same<Clock, boost::chrono::steady_clock>::value,
#else
    bool = false,
#endif
          bool = boost::is_same<Clock, boost::chrono::high_resolution_clock>::value
         >
struct name;

template <typename Clock>
struct name<Clock, false, false, false>  {
    static const char* apply() { return "unknown clock";}
};

template <typename Clock>
struct name<Clock, true, false, false>  {
    static const char* apply() { return "system_clock";}
};

template <typename Clock>
struct name<Clock, false, true, false>  {
    static const char* apply() { return "steady_clock";}
};

template <typename Clock>
struct name<Clock, false, false, true>  {
    static const char* apply() { return "high_resolution_clock";}
};

template <typename Clock>
struct name<Clock, false, true, true>  {
    static const char* apply() { return "steady_clock and high_resolution_clock";}
};

template <typename Clock>
struct name<Clock, true, false, true>  {
    static const char* apply() { return "system_clock and high_resolution_clock";}
};

template <typename Clock>
struct name<Clock, true, true, false>  {
    static const char* apply() { return "system_clock and steady_clock";}
};

template <typename Clock>
struct name<Clock, true, true, true>  {
    static const char* apply() { return "system_clock, steady_clock and high_resolution_clock";}
};

#endif

ext: hpp

max_stars_repo_name: randolphwong/mcsema

max_issues_repo_name: randolphwong/mcsema

max_forks_repo_name: randolphwong/mcsema


text:
#ifndef GDBPLZ_FUNCTION_CONTEXT_HPP_E066CFC4E7CD4BFCAE82237AEDB9CBD6
#define GDBPLZ_FUNCTION_CONTEXT_HPP_E066CFC4E7CD4BFCAE82237AEDB9CBD6

#include <functional>
#include <boost/utility/string_ref.hpp>
#include <wiertlo/pimpl_handle.hpp>
#include "./function_id.hpp"
#include "./expression.hpp"
#include "./source_location.hpp"

namespace gdbplz
{
	class function_context
	{
	private:
		struct impl;
		typedef wiertlo::pimpl_handle<impl> pimpl_handle_type;
		pimpl_handle_type pi;
	public:
		function_id function() const;
		source_location source_loc() const;
		std::shared_ptr<expression> evaluate_expression();

	};
}

#endif

max_stars_repo_name: milleniumbug/gdbplz

max_issues_repo_name: milleniumbug/gdbplz

max_forks_repo_name: milleniumbug/gdbplz