19 using namespace Diana;
29 if(filename == fRWCommon->fReaderCurrentFileName)
30 Panic(
"Output filename is equal to input filename");
35 std::string treeDescription = GetString(
"Description",
"Diana tree",
false);
37 fRootOutput =
new TFile(filename.c_str(),
"RECREATE");
39 Panic(
"cannot open file: %s",filename.c_str());
42 int FilePermissions = strtol(GetString(
"FilePermissions",
"0644",
false).c_str(),NULL,8);
43 chmod(filename.c_str(),FilePermissions);
59 for(
size_t s = 0; s <
vec.size(); s++) {
65 std::string diana_install =
"";
70 std::string AliasFileName =
71 GetString(
"AliasFileName",diana_install+
"cfg/aliases.txt");
72 std::string CustomAliasFileName = GetString(
"CustomAliasFileName",
"",
false);
73 if(AliasFileName !=
"") {
74 Debug(
"Adding aliases from %s",AliasFileName.c_str());
77 std::stringstream str;
79 Error(
"%s",str.str().c_str());
82 if(CustomAliasFileName !=
"") {
83 Debug(
"Adding aliases from %s",CustomAliasFileName.c_str());
86 std::stringstream str;
88 Error(
"%s",str.str().c_str());
93 std::vector<QEventLabel>::const_iterator evLabelIter = evDataLabels.begin();
94 bool inclusive = GetBool(
"InclusiveMode",
true,
false);
95 while(evLabelIter != evDataLabels.end()) {
97 QObject** peventData = evi.
Get(label.
owner.c_str(),label.
name.c_str());
98 QObject* eventData = (*peventData);
102 std::string newOwner = GetString(label.
GetStringLabel() +
":NewOwner",
"",
106 newLabel.
owner = newOwner;
107 Warn(
"Changed owner of %s into %s, this is a dangerous action",
112 std::string brnamestr = labelstr +
".";
113 Debug(
"Adding branch %s of type %s",
114 brnamestr.c_str(),eventData->GetName());
115 fTree->Branch(brnamestr.c_str(),eventData->GetName(),peventData);
117 std::map<std::string, std::string> aliasMap = aliases.
Find(label);
118 std::map<std::string, std::string>::const_iterator iter =
122 while(iter != aliasMap.end()) {
124 if(iter->second ==
"") {
127 path = labelstr+std::string(
".")+iter->second;
130 const char* al = iter->first.c_str();
131 const char*
ap = path.c_str();
132 Debug(
"Adding alias %s for %s",al,
ap);
168 std::map<std::string,std::string>::iterator iter =
171 remove(iter->second.c_str());
179 std::map<std::string,std::string>::const_iterator iter =
182 std::string input =
"", output =
"";
183 Long64_t inputEntries = 0, outputEntries = 0;
186 output = iter->second;
187 Debug(
"Reader file \"%s\"; writer file \"%s\"",input.c_str(),
190 TFile* ifile =
new TFile(input.c_str());
191 if(!ifile || ifile->IsZombie() || access(input.c_str(),W_OK)) {
192 Error(
"Input file %s is not writable! Merge with input failed. Input "
193 "files not touched. Output saved on specified files.",
200 inputEntries = itree->GetEntries();
201 TFile* ofile =
new TFile(output.c_str());
203 outputEntries = otree->GetEntries();
204 if(inputEntries > 0 && inputEntries == outputEntries) match =
true;
210 Error(
"Input file %s has %llu entries while output file %s has %llu "
211 "entries: merge with input failed. Input files not touched. Output"
212 " saved on specified files.",input.c_str(),inputEntries,
213 output.c_str(),outputEntries);
222 output = iter->second;
223 Info(
"Merging %s into %s",output.c_str(),input.c_str());
243 const char *toFile)
const {
245 TFile ofile(fromFile);
247 TFile* ifile =
new TFile (toFile,
"UPDATE");
252 TString friendname =
"qtree";
254 friendname += GetSequence().GetName();
257 if(ifile->FindObject(friendname.Data()) &&
259 !GetBool(
"OverWriteEvent",
false,
false)
261 Panic(
"AppendToInput: Input file already contains a QTree with name %s. You may want to set the OverWriteEvent=true option to this module or run diana with the option -O or remove the QTree manually with diana-rootfilehandler. Best regards.",friendname.Data());
263 ifile->Delete(friendname+
";*");
266 TList* flist = itree->GetListOfFriends();
267 if(flist) fele = flist->FindObject(friendname.Data());
268 if(fele) itree->GetListOfFriends()->Remove(fele);
272 QTree* otree2 =
dynamic_cast<QTree *
>(otree->CloneTree(-1,
"fast"));
273 otree2->SetName(friendname);
274 itree->AddFriend(otree2);
275 ifile->Write(
"",TObject::kOverwrite);
279 TList* list = dir->GetListOfKeys();
280 if(list && list->GetSize() > 0) {
282 if(rootGlobalDir == 0)
288 while (TKey* key = (TKey *) nextobj()) {
291 fullPath += key->GetName();
292 TString thisKey = key->GetName();
293 rootGlobalDir->Delete(thisKey+
";*");
294 ofile.Get(fullPath)->Write(key->GetName());
299 ifile->Write(
"",TObject::kOverwrite);
QError FillFromFile(const std::string &filename)
std::map< std::string, std::string > Find(const QEventLabel &label) const
QTreeInfo & GetTreeInfo()
bool wrapped into a QObject
error class with error type and description
Visitor class to inspect the QEvent content.
QEvent & GetEvent()
Get the event.
std::vector< QEventLabel > GetWriteLabels() const
Get labels of QObjects to be written.
QObject ** Get(const char *owner, const char *name) const
Get reference of a QObject (can be used with TTree::SetBranchAddress).
const QAliases & GetAliases() const
get aliases (const version)
label for QObject in the QEvent
std::string GetStringLabel() const
get string in the format "owner@name"
std::string owner
owner of the QObject
std::string name
name of the QObject
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
virtual void Done()
Done method called by the framework.
QGlobalWriter * GetWriter(const std::string &filename, QError &err)
get writer
static QGlobalWriterDispatcher & GetInstance()
QError Set(const std::string &name, const Q &obj, const std::string &descr="")
Set QObject, owned by the caller, - leave it undeclared if you can't implement it.
static QOptions & GetInstance()
QGlobalWriter * fGlobalWriter
The current global writer for the file.
void AppendToInput()
Append the output files to the input files.
std::map< std::string, std::string > fReaderWriterFiles
Map of output files and the input files they are synced to.
void Close()
Close any open files.
QTFilePointer fRootOutputAddress
Pointer to the output file.
TFile * fRootOutput
The current file being written.
QRootFileWriterBase()
Default ctor.
void Dump(const Diana::QEventInspector &evi)
Write the event to the output tree.
bool fSkipGenerated
Option to skip events that are generated by the reader.
void Done()
Done run at the end of the event loop.
virtual void Open(const std::string &filename, const Diana::QEventInspector &evi)
Open a file.
bool fAppendToInput
Flag to specify append to input.
virtual void AppendFileToFile(const char *fromFile, const char *toFile) const
Merge an individual file into another.
QTree * fTree
The current tree being written.
std::string fSoftwareRevision
std::map< std::string, std::string > fExtSWVersion
std::vector< QVdt > QVdt_vector
const std::string & GetString() const
std::string GetName() const
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...