void TypePrinter::printTag(TagDecl *D, std::string &InnerString) {
if (Policy.SuppressTag)
return;
std::string Buffer;
bool HasKindDecoration = false;
// bool SuppressTagKeyword
// = Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword;
// We don't print tags unless this is an elaborated type.
// In C, we just assume every RecordType is an elaborated type.
if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
D->getTypedefNameForAnonDecl())) {
HasKindDecoration = true;
Buffer += D->getKindName();
Buffer += ' ';
}
// Compute the full nested-name-specifier for this type.
// In C, this will always be empty except when the type
// being printed is anonymous within other Record.
if (!Policy.SuppressScope)
AppendScope(D->getDeclContext(), Buffer);
if (const IdentifierInfo *II = D->getIdentifier())
Buffer += II->getNameStart();
else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
assert(Typedef->getIdentifier() && "Typedef without identifier?");
Buffer += Typedef->getIdentifier()->getNameStart();
} else {
// Make an unambiguous representation for anonymous types, e.g.
// <anonymous enum at /usr/include/string.h:120:9>
llvm::raw_string_ostream OS(Buffer);
OS << "<anonymous";
if (Policy.AnonymousTagLocations) {
// Suppress the redundant tag keyword if we just printed one.
// We don't have to worry about ElaboratedTypes here because you can't
// refer to an anonymous type with one.
if (!HasKindDecoration)
OS << " " << D->getKindName();
PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
D->getLocation());
if (PLoc.isValid()) {
OS << " at " << PLoc.getFilename()
<< ':' << PLoc.getLine()
<< ':' << PLoc.getColumn();
}
}
OS << '>';
}
// If this is a class template specialization, print the template
// arguments.
if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(D)) {
const TemplateArgument *Args;
unsigned NumArgs;
if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
const TemplateSpecializationType *TST =
cast<TemplateSpecializationType>(TAW->getType());
Args = TST->getArgs();
NumArgs = TST->getNumArgs();
} else {
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
Args = TemplateArgs.data();
NumArgs = TemplateArgs.size();
}
IncludeStrongLifetimeRAII Strong(Policy);
Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args,
NumArgs,
Policy);
}
if (!InnerString.empty()) {
Buffer += ' ';
Buffer += InnerString;
}
std::swap(Buffer, InnerString);
}
void TypePrinter::print(const Type *T, Qualifiers Quals, std::string &buffer) {
if (!T) {
buffer += "NULL TYPE";
return;
}
if (Policy.SuppressSpecifiers && T->isSpecifierType())
return;
// Print qualifiers as appropriate.
// CanPrefixQualifiers - We prefer to print type qualifiers before the type,
// so that we get "const int" instead of "int const", but we can't do this if
// the type is complex. For example if the type is "int*", we *must* print
// "int * const", printing "const int *" is different. Only do this when the
// type expands to a simple string.
bool CanPrefixQualifiers = false;
bool NeedARCStrongQualifier = false;
Type::TypeClass TC = T->getTypeClass();
if (const AutoType *AT = dyn_cast<AutoType>(T))
TC = AT->desugar()->getTypeClass();
if (const SubstTemplateTypeParmType *Subst
= dyn_cast<SubstTemplateTypeParmType>(T))
TC = Subst->getReplacementType()->getTypeClass();
switch (TC) {
case Type::Builtin:
case Type::Complex:
case Type::UnresolvedUsing:
case Type::Typedef:
case Type::TypeOfExpr:
case Type::TypeOf:
case Type::Decltype:
case Type::UnaryTransform:
case Type::Record:
case Type::Enum:
case Type::Elaborated:
case Type::TemplateTypeParm:
case Type::SubstTemplateTypeParmPack:
case Type::TemplateSpecialization:
case Type::InjectedClassName:
case Type::DependentName:
case Type::DependentTemplateSpecialization:
case Type::ObjCObject:
case Type::ObjCInterface:
case Type::Atomic:
CanPrefixQualifiers = true;
break;
case Type::ObjCObjectPointer:
CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() ||
T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
break;
case Type::ConstantArray:
case Type::IncompleteArray:
case Type::VariableArray:
case Type::DependentSizedArray:
NeedARCStrongQualifier = true;
// Fall through
case Type::Pointer:
case Type::BlockPointer:
case Type::LValueReference:
case Type::RValueReference:
case Type::MemberPointer:
case Type::DependentSizedExtVector:
case Type::Vector:
case Type::ExtVector:
case Type::FunctionProto:
case Type::FunctionNoProto:
case Type::Paren:
case Type::Attributed:
case Type::PackExpansion:
case Type::SubstTemplateTypeParm:
case Type::Auto:
CanPrefixQualifiers = false;
break;
}
if (!CanPrefixQualifiers && !Quals.empty()) {
std::string qualsBuffer;
if (NeedARCStrongQualifier) {
IncludeStrongLifetimeRAII Strong(Policy);
Quals.getAsStringInternal(qualsBuffer, Policy);
} else {
Quals.getAsStringInternal(qualsBuffer, Policy);
}
if (!qualsBuffer.empty()) {
if (!buffer.empty()) {
qualsBuffer += ' ';
qualsBuffer += buffer;
}
std::swap(buffer, qualsBuffer);
}
}
switch (T->getTypeClass()) {
#define ABSTRACT_TYPE(CLASS, PARENT)
//.........这里部分代码省略.........
void write_explicit_surface_opendx(const levelset<GridTraitsType, LevelSetTraitsType>& l, const std::string& filename, const DataType& Data, typename LevelSetTraitsType::value_type eps=0.) {
//this function etracts the surface using the marching cubes algorithm and writes it to the specified file using OpenDX-file format
//the parameter eps is forwarded to the surface extraction function
const int D=GridTraitsType::dimensions;
Surface<D> s;
typename GetActivePointType<typename LevelSetTraitsType::size_type, DataType>::result ActivePointList;
extract(l, s, eps, ActivePointList);
std::ofstream f(filename.c_str());
//!print positions
f<< "object \"positions\" class array type float rank 1 shape " << D << " items "<< s.Nodes.size() <<" data follows" << std::endl;
for (unsigned int i=0;i<s.Nodes.size();i++) {
for (int j=0;j<D;j++) f << static_cast<float>(s.Nodes[i][j]) << " ";
f<< std::endl;
}
//! print connections
f << "object \"connections\" class array type int rank 1 shape " << D << " items "<< s.Elements.size() <<" data follows" << std::endl;
for (unsigned int i=0;i<s.Elements.size();i++) {
for (int j=0;j<D;j++) f<< s.Elements[i][j] << " ";
f << std::endl;
}
if (D==2)
f << "attribute \"element type\" string \"lines\"" << std::endl;
else if (D==3)
f << "attribute \"element type\" string \"triangles\"" << std::endl;
f << "attribute \"ref\" string \"positions\"" << std::endl;
//output data
for (int k=0;k<Data.number_of_series();++k) {
if (Data.get_series_output(k)) {
f << "object \"" << Data.get_series_label(k) << "_data\" class array type " << Data.get_series_type(k) << " rank 0 items " << s.Nodes.size() << " data follows" << std::endl;
for (unsigned int i=0;i<s.Nodes.size();i++) {
f << Data.get_series_data(ActivePointList[i],k) << std::endl;
}
f << "attribute \"dep\" string \"positions\"" << std::endl;
}
}
//! print profile
f << "object \"profile\" class field" << std::endl;
f << " component \"positions\" value \"positions\"" << std::endl;
f << " component \"connections\" value \"connections\"" << std::endl;
for (int k=0;k<Data.number_of_series();++k) {
if (Data.get_series_output(k)) {
f << "object \""<< Data.get_series_label(k) << "\" class field" << std::endl;
f << " component \"positions\" value \"positions\"" << std::endl;
f << " component \"connections\" value \"connections\"" << std::endl;
f << " component \"data\" value \"" << Data.get_series_label(k) << "_data\"" << std::endl;
}
}
f << "end" << std::endl;
f.close();
}
void write_levelset_opendx(const levelset<GridTraitsType, LevelSetTraitsType>& l, std::string FileName, bool only_defined_grid_points, float limit, bool only_signs) {
//this functions writes all defined grid points including their level set values
// to file using the OpenDX (Open Data Explorer)-file format
//limit specifies the range of values assigned to the grid points,
// if the level set value of a grid point is
// out of this range the value is set to +/- limit
//if only_defined_grid_points is set to false then also the start and end grid points
// of undefined runs are written to file, their values are then set to +/-limit
//if only_signs is set to true then only the signs of the grid points are written to file,
// the grid point values are then set either to +1 or -1
typedef levelset<GridTraitsType, LevelSetTraitsType> LevelSetType;
// typedef typename LevelSetType::value_type value_type;
typedef typename LevelSetType::size_type size_type;
const int D=LevelSetType::dimensions;
std::ofstream f(FileName.c_str());
size_type num=0;
for (typename LevelSetType::const_iterator_runs it(l);
!it.is_finished();it.next()) {
if (only_defined_grid_points) if (!it.is_defined()) continue;
if (!l.grid().is_at_infinity(it.start_indices())) num++;
if (it.start_indices()!=it.end_indices()) if (!l.grid().is_at_infinity(it.end_indices())) num++;
}
f<< "object 1 class array type float rank 1 shape " << D << " items "<< num <<" data follows" << std::endl;
for (typename LevelSetType::const_iterator_runs it(l);
!it.is_finished();it.next()) {
if (only_defined_grid_points) if (!it.is_defined()) continue;
if (!l.grid().is_at_infinity(it.start_indices())) {
for (int j=0;j<D;j++) f << (it.start_indices()[j]) << " ";
f << std::endl;
}
if (!l.grid().is_at_infinity(it.end_indices())) {
if (it.start_indices()!=it.end_indices()) {
for (int j=0;j<D;j++) f << (it.end_indices()[j]) << " ";
f << std::endl;
}
}
}
f << "object 2 class array type float rank 0 items "<< num<<" data follows" <<std::endl;
for (typename LevelSetType::const_iterator_runs it(l);
!it.is_finished();it.next()) {
if (only_defined_grid_points) if (!it.is_defined()) continue;
float dist;
if (only_signs) {
if (it.sign()==POS_SIGN) dist=limit; else dist=-limit;
} else {
dist=static_cast<float>(it.value());
dist=std::min(limit,dist);
dist=std::max(-limit,dist);
}
if (!l.grid().is_at_infinity(it.start_indices())) f << dist << std::endl;
if (it.start_indices()!=it.end_indices()) if (!l.grid().is_at_infinity(it.end_indices())) f << dist << std::endl;
}
f << "attribute \"dep\" string \"positions\"" << std::endl;
f << "object \"data\" class field" << std::endl;
f << "component \"positions\" value 1" << std::endl;
f << "component \"data\" value 2" << std::endl;
f << "end" << std::endl;
f.close();
}
void TypePrinter::printFunctionProto(const FunctionProtoType *T,
std::string &S) {
// If needed for precedence reasons, wrap the inner part in grouping parens.
if (!S.empty())
S = "(" + S + ")";
S += "(";
std::string Tmp;
PrintingPolicy ParamPolicy(Policy);
ParamPolicy.SuppressSpecifiers = false;
for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
if (i) S += ", ";
print(T->getArgType(i), Tmp);
S += Tmp;
Tmp.clear();
}
if (T->isVariadic()) {
if (T->getNumArgs())
S += ", ";
S += "...";
} else if (T->getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) {
// Do not emit int() if we have a proto, emit 'int(void)'.
S += "void";
}
S += ")";
FunctionType::ExtInfo Info = T->getExtInfo();
switch(Info.getCC()) {
case CC_Default:
default: break;
case CC_C:
S += " __attribute__((cdecl))";
break;
case CC_X86StdCall:
S += " __attribute__((stdcall))";
break;
case CC_X86FastCall:
S += " __attribute__((fastcall))";
break;
case CC_X86ThisCall:
S += " __attribute__((thiscall))";
break;
case CC_X86Pascal:
S += " __attribute__((pascal))";
break;
case CC_AAPCS:
S += " __attribute__((pcs(\"aapcs\")))";
break;
case CC_AAPCS_VFP:
S += " __attribute__((pcs(\"aapcs-vfp\")))";
break;
}
if (Info.getNoReturn())
S += " __attribute__((noreturn))";
if (Info.getRegParm())
S += " __attribute__((regparm (" +
llvm::utostr_32(Info.getRegParm()) + ")))";
AppendTypeQualList(S, T->getTypeQuals());
switch (T->getRefQualifier()) {
case RQ_None:
break;
case RQ_LValue:
S += " &";
break;
case RQ_RValue:
S += " &&";
break;
}
if (T->hasDynamicExceptionSpec()) {
S += " throw(";
if (T->getExceptionSpecType() == EST_MSAny)
S += "...";
else
for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) {
if (I)
S += ", ";
std::string ExceptionType;
print(T->getExceptionType(I), ExceptionType);
S += ExceptionType;
}
S += ")";
} else if (isNoexceptExceptionSpec(T->getExceptionSpecType())) {
S += " noexcept";
if (T->getExceptionSpecType() == EST_ComputedNoexcept) {
S += "(";
llvm::raw_string_ostream EOut(S);
T->getNoexceptExpr()->printPretty(EOut, 0, Policy);
EOut.flush();
S += EOut.str();
S += ")";
}
}
//.........这里部分代码省略.........
void doAll() {
//
// the looper
//
gSystem->Load("libTree.so");
gSystem->Load("libPhysics.so");
gSystem->Load("libEG.so");
gSystem->Load("libMathCore.so");
gSystem->Load("/tas/dlevans/HWW2012/CMSSW_5_2_3/src/LHAPDF-5.8.92b/lib/libLHAPDF.so");
gSystem->Load("libCMS2NtupleMacrosLooper.so");
//
// create looper
//
// create a looper for a sample that was generated by using
// CTEQ6LL. Check if this is the case for your sample!
// generally, LO samples are generated with CTEQ6LL and
// NLO samples are generated with CT10. Note that in the
// CT10 case the central subset is at index 5, not 0.
MyScanChain *looper_cteq6ll = new MyScanChain("cteq6ll.LHpdf", 0);
//
// run all pdf sets
//
std::vector<std::string> pdfSets;
// CT10
pdfSets.push_back("CT10");
pdfSets.push_back("CT10as");
// MSTW
pdfSets.push_back("MSTW2008nlo68cl");
pdfSets.push_back("MSTW2008nlo68cl_asmz+68cl");
pdfSets.push_back("MSTW2008nlo68cl_asmz+68clhalf");
pdfSets.push_back("MSTW2008nlo68cl_asmz-68cl");
pdfSets.push_back("MSTW2008nlo68cl_asmz-68clhalf");
// NNPDF
pdfSets.push_back("NNPDF20_as_0116_100");
pdfSets.push_back("NNPDF20_as_0117_100");
pdfSets.push_back("NNPDF20_as_0118_100");
pdfSets.push_back("NNPDF20_100");
pdfSets.push_back("NNPDF20_as_0120_100");
pdfSets.push_back("NNPDF20_as_0121_100");
pdfSets.push_back("NNPDF20_as_0122_100");
// data sample
TChain *chain_ttbar = new TChain("Events");
chain_ttbar->Add("/tas/dlevans_data/MCNtupling/CMSSW/CMSSW_5_3_2_patch4_V05-03-23/crab/makecms2ntuple/post_processed_ntuple.root");
// do gensets
// the variation of the genset with respect to itself
// is by definition 1.0, but we'll need this number later
// stored just like all the others
looper_cteq6ll->ScanChain("ttbar", chain_ttbar, "cteq6ll");
// do other sets
for (unsigned int i = 0; i < pdfSets.size(); ++i) {
std::cout << "===== Doing =====> " << pdfSets[i] << std::endl;
looper_cteq6ll->ScanChain("ttbar", chain_ttbar, pdfSets[i]);
}
//
// write histograms
//
const std::string outFile = "results.root";
saveHist(outFile.c_str());
deleteHistos();
//
// tidy up
//
delete looper_cteq6ll;
delete chain_ttbar;
}
请发表评论