Last active
October 4, 2019 10:48
-
-
Save dpiparo/812843f1cc7c65083c470336ad9653da to your computer and use it in GitHub Desktop.
Simple macro to convert to a simple TTree the on disk representation of CMS raw data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
#include <TInterpreter.h> | |
#include <ROOT/RDataFrame.hxx> | |
// http://opendata.cern.ch/record/63 | |
auto filename = "D66F223A-6A9C-E111-AF57-003048F118D4.root"; | |
class FEDRawData | |
{ | |
public: | |
vector<unsigned char> data_; // | |
}; | |
class DoNotRecordParents | |
{ | |
ClassDef(DoNotRecordParents, 128); | |
}; | |
class FEDRawDataCollection : public DoNotRecordParents | |
{ | |
public: | |
vector<FEDRawData> data_; // | |
ClassDef(FEDRawDataCollection, 128); | |
}; | |
namespace edm | |
{ | |
template <typename T0> | |
class Wrapper; | |
template <> | |
class Wrapper<FEDRawDataCollection> | |
{ | |
public: | |
bool present; | |
FEDRawDataCollection obj; | |
}; | |
} // namespace edm | |
void distil() | |
{ | |
gInterpreter->GenerateDictionary("vector<vector<unsigned char>>"); | |
gInterpreter->GenerateDictionary("DoNotRecordParents"); | |
gInterpreter->GenerateDictionary("FEDRawData"); | |
gInterpreter->GenerateDictionary("FEDRawDataCollection"); | |
ROOT::EnableImplicitMT(4); | |
TFile f(filename); | |
ROOT::RDataFrame rdf("Events", &f); | |
auto toVecOfVec = [](const FEDRawDataCollection &c) { | |
vector<vector<unsigned char>> v; | |
for (const auto &w : c.data_) | |
{ | |
v.emplace_back(w.data_); | |
} | |
return v; | |
}; | |
rdf.Define("v", toVecOfVec, {"FEDRawDataCollection_rawDataCollector__LHC.obj"}) | |
.Filter([](ULong64_t n) {if (n%1000 == 0)cout << n << endl;return true; }, {"rdfentry_"}) | |
.Snapshot<vector<vector<unsigned char>>>("Events", "rawContent.root", {"v"}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment