1 |
/** @file |
2 |
* $Author: mocchiut $ |
3 |
* $Date: 2008/09/23 07:19:55 $ |
4 |
* $Revision: 1.1.1.1 $ |
5 |
* |
6 |
* Implementation of the PamelaRun class. |
7 |
*/ |
8 |
#include <iostream> |
9 |
#include <iomanip> |
10 |
#include <list> |
11 |
#include <exception> |
12 |
|
13 |
#include <TFile.h> //Substituted by Maurizio 05 Feb 2004 |
14 |
#include <TTree.h> //Substituted by Maurizio 05 Feb 2004 |
15 |
#include <TChain.h> //Substituted by Maurizio 05 Feb 2004 |
16 |
#include <TKey.h> //Substituted by Maurizio 05 Feb 2004 |
17 |
#include <TList.h> //Substituted by Maurizio 05 Feb 2004 |
18 |
|
19 |
|
20 |
#include "PamelaRun.h" |
21 |
#include "EventHeader.h" |
22 |
#include "Algorithm.h" |
23 |
#include "AlgorithmInfo.h" |
24 |
#include "Exception.h" |
25 |
#include <sys/stat.h> |
26 |
|
27 |
extern "C" { |
28 |
#include <dirent.h> |
29 |
#include "DirectoryStructure.h" |
30 |
} |
31 |
|
32 |
#include "yodaversion.h" |
33 |
//#define version 60313 |
34 |
//extern int GetYODAver(); |
35 |
|
36 |
using namespace pamela; |
37 |
|
38 |
//marco: distructor |
39 |
PamelaRun::~PamelaRun() |
40 |
{ |
41 |
delete SingleFile; SingleFile=NULL; |
42 |
} |
43 |
|
44 |
|
45 |
/** |
46 |
* Create a new Pamela run. |
47 |
* @param run Run number |
48 |
* @param path Base path name to the data |
49 |
*/ |
50 |
PamelaRun::PamelaRun(std::string fileName, std::string path, bool multiple, short compr): |
51 |
Path(path), |
52 |
Run(fileName), |
53 |
RunNumber(1),//veirificare se รจ possibilie eliminare questa variabile |
54 |
Multiple(multiple), |
55 |
SingleFile(0), |
56 |
compression(compr){ |
57 |
|
58 |
RunExists(fileName); |
59 |
info = RunInfoYoda(this); |
60 |
} |
61 |
|
62 |
|
63 |
/** |
64 |
* Get the run name according to a certain run number. |
65 |
* @param run Run number. |
66 |
* @return a string with the run name. |
67 |
*/ |
68 |
std::string PamelaRun::GetRunName(int run) { |
69 |
std::stringstream temp; |
70 |
temp.str(""); |
71 |
temp << std::setw( 4 ) << std::setfill( '0' ) << run; |
72 |
return "Run" + temp.str(); |
73 |
} |
74 |
|
75 |
/** |
76 |
* Check if the run number is already assigned |
77 |
* @param int run - Number of the run to check |
78 |
* @return int |
79 |
*/ |
80 |
void PamelaRun::RunExists(std::string input) throw (std::exception){ |
81 |
int res; |
82 |
DIR *dirp; |
83 |
std::string fileName; |
84 |
//std::string pathDir((char*)getenv("YODA_DATA")); |
85 |
std::string pathDir(GetPath()); |
86 |
std::string tempName; |
87 |
std::string::size_type pos; |
88 |
|
89 |
pos = input.find_last_of("/"); |
90 |
fileName = input.substr(pos+1); |
91 |
pos = fileName.find_last_of("."); |
92 |
fileName = fileName.substr(0,pos); |
93 |
pathDir = pathDir + "/"; |
94 |
tempName = pathDir + fileName; |
95 |
oss.str(""); |
96 |
oss << Path << "/" << fileName; |
97 |
UnpackPath = oss.str(); |
98 |
oss.str(""); |
99 |
oss << fileName; |
100 |
Run = oss.str(); |
101 |
} |
102 |
|
103 |
|
104 |
/** |
105 |
* Get the directory name that contains the files of a certain event |
106 |
* type for this run. |
107 |
* @param type the packet type. |
108 |
* @return the complete path for this event type. |
109 |
*/ |
110 |
std::string PamelaRun::GetDirName(PacketType const * type) const { |
111 |
//std::stringstream oss; |
112 |
//std::string name = type->GetName(); |
113 |
//oss.str(""); |
114 |
//oss << Path << "/" << Run << "/" << "pippo"; |
115 |
//return oss.str(); |
116 |
//return "pippo"; |
117 |
//std::string EventType = type->GetName(); |
118 |
return Path + "/" + Run + "/" + type->GetName(); |
119 |
} |
120 |
|
121 |
/** |
122 |
* Get the file name for a certain event type. |
123 |
* @param type subpacket type. |
124 |
* @param name subpacket name. |
125 |
* @return the complete path and file name. |
126 |
*/ |
127 |
std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) { |
128 |
if (type->IsDetectorSpecific()) { |
129 |
return UnpackPath + "/" + type->GetPacketType()->GetName() + "/" |
130 |
+ Run + "." + type->GetPacketType()->GetName() + "." |
131 |
+ type->GetSubDetector()->GetName() + "." |
132 |
+ name + ".root"; |
133 |
} else { |
134 |
return UnpackPath + "/" + type->GetPacketType()->GetName() + "/" |
135 |
+ Run + "." + type->GetPacketType()->GetName() + "." |
136 |
+ name + ".root"; |
137 |
/* |
138 |
return Path + "/" + type->GetPacketType()->GetName() + "/" |
139 |
+ Run + "." + type->GetPacketType()->GetName() + "." |
140 |
+ name + ".root"; */ |
141 |
} |
142 |
} |
143 |
|
144 |
/** |
145 |
* Get the file name for a certain event type. |
146 |
* @param type subpacket type. |
147 |
* @return the complete path and file name. |
148 |
*/ |
149 |
std::string PamelaRun::GetFileName(const SubPacket* type) { |
150 |
//return GetFileName(type, type->GetSubPacketName()); |
151 |
return GetFileName(type, "pippo"); |
152 |
} |
153 |
|
154 |
/** |
155 |
* Get the branch name that corresponds to a certain |
156 |
* subpacket. Usually, this is the name of the subpacket. |
157 |
* @param type subpacket type. |
158 |
* @return the corresponding branch name. |
159 |
*/ |
160 |
static std::string GetDefaultBranchName(const SubPacket* type) { |
161 |
return type->GetSubPacketName(); |
162 |
} |
163 |
|
164 |
/** |
165 |
* Get the tree name for a certain subpacket. This is the name of the |
166 |
* subdetector for detector specific subpackets, and the packet name |
167 |
* ("Physics" etc.) for common packets. |
168 |
* @param type the packet type. |
169 |
* @return the corresponding tree name. |
170 |
*/ |
171 |
static std::string GetTreeName(const SubPacket* type) { |
172 |
if (type->IsDetectorSpecific()) { |
173 |
return type->GetSubDetector()->GetName(); |
174 |
} else { |
175 |
return type->GetPacketType()->GetName(); |
176 |
} |
177 |
} |
178 |
|
179 |
/** |
180 |
* Get a list of all root files from a certain path. |
181 |
* @param path Path name to start the search. |
182 |
* @return A list of all file names. |
183 |
*/ |
184 |
static std::list<std::string> GetRootFiles(std::string path) throw (std::exception) { |
185 |
std::list<std::string> files; |
186 |
DIR *dir = opendir(path.c_str()); |
187 |
if (dir == 0) { |
188 |
//marco |
189 |
// // logger->debug("Could not open " + path); |
190 |
//throw Exception("Could not open " + path); |
191 |
} |
192 |
|
193 |
for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) { |
194 |
if ((strcmp(".",d->d_name) == 0) || (strcmp("..",d->d_name) == 0)) |
195 |
continue; |
196 |
std::string filename = path + "/" + d->d_name; |
197 |
struct stat buf; |
198 |
stat(filename.c_str(), &buf); |
199 |
if S_ISDIR(buf.st_mode) { |
200 |
std::list<std::string>toAdd = GetRootFiles(filename); |
201 |
files.insert(files.end(), toAdd.begin(), toAdd.end()); |
202 |
} else if ((filename.substr(filename.size()-5, filename.size()) |
203 |
== ".root") // correct suffix |
204 |
&& (!isdigit(filename[filename.size()-6]))) { // base file |
205 |
std::string nextfilename = filename; |
206 |
nextfilename.insert(filename.size()-5, "_1"); |
207 |
if (stat(nextfilename.c_str(), &buf) == 0) { |
208 |
filename.insert(filename.size()-5, "*"); |
209 |
} |
210 |
// // logger->debug("Using " + filename); |
211 |
files.push_back(filename); |
212 |
} |
213 |
} |
214 |
return files; |
215 |
} |
216 |
|
217 |
/** |
218 |
* Helper function to open the ROOT TTree of the header within the run |
219 |
* framework. |
220 |
* @param type The packet type. |
221 |
* @return the ROOT TTree. |
222 |
*/ |
223 |
TChain* PamelaRun::ReadHeaderTree(const PacketType *type) |
224 |
throw (std::exception) { |
225 |
EventHeader header(type); |
226 |
std::string FileName = GetFileName(&header); |
227 |
std::string TreeName = GetTreeName(&header); |
228 |
TChain *tree = new TChain(TreeName.c_str()); |
229 |
tree->Add(FileName.c_str()); |
230 |
return tree; |
231 |
} |
232 |
|
233 |
/** |
234 |
* All add trees of a file as friend to a given tree. The tree name of |
235 |
* each tree found in the file is used as the name of the friend alias. |
236 |
* @param tree The base tree to add all other as friends. |
237 |
* @param FileName The name of the file with other trees. |
238 |
*/ |
239 |
static void AddAllAsFriend(TChain* tree, std::string FileName) { |
240 |
std::string BaseFileName = FileName; |
241 |
bool HaveChain = false; |
242 |
if (BaseFileName[BaseFileName.size()-6] == '*') { |
243 |
BaseFileName.erase(BaseFileName.size()-6, 1); |
244 |
HaveChain = true; |
245 |
} |
246 |
TFile* File = new TFile(BaseFileName.c_str(), "read"); |
247 |
if (!File->IsOpen()) { |
248 |
// // logger->error("Could not open file " + BaseFileName + " for reading."); |
249 |
return; |
250 |
} |
251 |
TList* list = File->GetListOfKeys(); |
252 |
if (HaveChain) { |
253 |
for (TIter i(list); TKey* k = (TKey*)i();) { |
254 |
if (std::string(TTree::Class()->GetName()) == k->GetClassName()) { |
255 |
std::string TreeName = k->GetName(); |
256 |
TChain* FriendChain = new TChain(TreeName.c_str()); |
257 |
FriendChain->Add(FileName.c_str()); |
258 |
tree->AddFriend(FriendChain, TreeName.c_str()); |
259 |
//logger->warn("Adding chain " + TreeName + " with " + FriendChain->GetEntries() + " entries as Friend"); |
260 |
} |
261 |
} |
262 |
File->Close(); |
263 |
} else { |
264 |
for (TIter i(list); TKey* k = (TKey*)i();) { |
265 |
if (std::string(TTree::Class()->GetName()) == k->GetClassName()) { |
266 |
std::string TreeName = k->GetName(); |
267 |
TTree* FriendTree = (TTree *)File->Get(TreeName.c_str()); |
268 |
tree->AddFriend(FriendTree, TreeName.c_str()); |
269 |
//logger->debug("Adding tree " + TreeName + " with " + FriendTree->GetEntries() + " entries as Friend"); |
270 |
} |
271 |
} |
272 |
} |
273 |
} |
274 |
|
275 |
/** |
276 |
* Read all Root TTrees which belong to a certain event type and mount them |
277 |
* together as "friends". |
278 |
* @param type The packet type. |
279 |
* @return The root trees with the friends. |
280 |
*/ |
281 |
TTree* PamelaRun::ReadTTree(const PacketType* type) { |
282 |
oss.str(""); |
283 |
oss << "Getting root files of " << type->GetName(); |
284 |
//logger->debug(oss.str().c_str()); |
285 |
RootTreeMap::iterator t = TTreeMap.find(type); |
286 |
|
287 |
if (t != TTreeMap.end()) { |
288 |
return t->second; |
289 |
} else { |
290 |
oss.str(""); |
291 |
oss << "Reading root files of " << type->GetName(); |
292 |
//// logger->debug(oss.str().c_str()); |
293 |
EventHeader header(type); |
294 |
std::string HeaderFileName = GetFileName(&header); |
295 |
TChain* HeaderTree = ReadHeaderTree(type); |
296 |
std::list<std::string> rootfiles = GetRootFiles(GetDirName(type)); |
297 |
for (std::list<std::string>::iterator i = rootfiles.begin(); |
298 |
i != rootfiles.end(); i++){ |
299 |
if (*i == HeaderFileName) |
300 |
continue; // dont add the header tree itself. |
301 |
AddAllAsFriend(HeaderTree, *i); |
302 |
|
303 |
} |
304 |
TTreeMap.insert(RootTreeMap::value_type(type, HeaderTree)); |
305 |
return HeaderTree; |
306 |
} |
307 |
} |
308 |
|
309 |
/** |
310 |
* Register a certain SubPacket, identified by its name, to be read |
311 |
* from the repository. This function is made for interactive work. |
312 |
* @param subpacket A pointer to the pointer of the packet. |
313 |
* @param name The name of the subpacket |
314 |
*/ |
315 |
void PamelaRun::ReadSubPacket(void* subpacket, std::string name) { |
316 |
SubPacket *packet = *(SubPacket**)subpacket; |
317 |
|
318 |
// look into the map of subpackets if we already read it. |
319 |
std::string FullName = packet->GetPacketType()->GetName() + "." + name; |
320 |
SubPacketMap::iterator i = SubPacketAddresses.find(FullName); |
321 |
if (i != SubPacketAddresses.end()) { // it is in the map |
322 |
*(SubPacket**)subpacket = i->second; |
323 |
return; |
324 |
} else { // not found in the map of used subpackets |
325 |
TTree* tree = ReadTTree(packet->GetPacketType()); |
326 |
TBranch* branch = tree->GetBranch(name.c_str()); |
327 |
if (branch != 0) { |
328 |
branch->SetAddress(subpacket); |
329 |
SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet)); |
330 |
} else { |
331 |
oss.str(""); |
332 |
oss << "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ; |
333 |
//// logger->error(oss.str().c_str()); |
334 |
} |
335 |
} |
336 |
} |
337 |
|
338 |
/** |
339 |
* Register a certain SubPacket, identified by its default name, to be |
340 |
* read from the repository. This function is made for |
341 |
* interactive work. |
342 |
* @param subpacket A pointer to the pointer of the packet. |
343 |
*/ |
344 |
void PamelaRun::ReadSubPacket(void* subpacket) { |
345 |
SubPacket *packet = *(SubPacket**)subpacket; |
346 |
ReadSubPacket(subpacket, GetDefaultBranchName(packet)); |
347 |
} |
348 |
|
349 |
/** |
350 |
* Register a certain SubPacket with its default name, to be read from |
351 |
* the repository. This functions is for use from the algorithm. |
352 |
* @param algo Algorithm that needs this SubPacket. |
353 |
* @param subpacket A pointer to the pointer of the packet. |
354 |
*/ |
355 |
void PamelaRun::ReadSubPacket(const Algorithm* algo, void* subpacket) { |
356 |
//:TODO: store the request of the algorithm here. |
357 |
ReadSubPacket(subpacket); |
358 |
} |
359 |
|
360 |
/** |
361 |
* Register a certain SubPacket, with a custom name, to |
362 |
* be read from the repository. This functions is for use from |
363 |
* the algorithm. |
364 |
* @param algo Algorithm that needs this SubPacket. |
365 |
* @param subpacket A pointer to the pointer of the packet. |
366 |
* @param name The name of the subpacket |
367 |
*/ |
368 |
void PamelaRun::ReadSubPacket(const Algorithm* algo, void* subpacket, |
369 |
std::string name) { |
370 |
//:TODO: store the request of the algorithm here. |
371 |
ReadSubPacket(subpacket, name); |
372 |
} |
373 |
|
374 |
/** |
375 |
* Helper function to create a ROOT TTree within the run framework. |
376 |
* @param algo Algorithm that creates this SubPacket. |
377 |
* @param packet subpacket type |
378 |
* @param name the name of the subpacket |
379 |
* @return the ROOT TTree. |
380 |
*/ |
381 |
TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet, |
382 |
std::string name) |
383 |
throw (std::exception) { |
384 |
std::string FileName = ""; |
385 |
std::string EventType = packet->GetPacketType()->GetName(); |
386 |
TFile* File = 0; |
387 |
std::string TreeName = GetTreeName(packet); |
388 |
TTree *tree = 0; |
389 |
FileName = GetFileName(packet, name); |
390 |
CreateDirectoryStructure(FileName.c_str()); |
391 |
File = new TFile(FileName.c_str(), "create"); |
392 |
tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str()); |
393 |
WritingRootTrees[packet->GetPacketType()].push_back(tree); |
394 |
|
395 |
File->SetCompressionLevel(compression); |
396 |
if (!File->IsOpen()) { |
397 |
// // logger->error("Could not open file " + FileName); |
398 |
//throw Exception("Could not open file " + FileName); |
399 |
} |
400 |
//logger->debug("Creating file " + FileName + " with Tree " + TreeName); |
401 |
return tree; |
402 |
} |
403 |
|
404 |
|
405 |
/** |
406 |
* Register a certain SubPacket to be written to the repository. A |
407 |
* usual call sequence for this function ist |
408 |
* MyEvent *event = new MyEvent(); |
409 |
* run->WriteSubPacket(this, &event, event->Class() |
410 |
* @param algo Algorithm that produces this SubPacket. |
411 |
* @param subpacket A pointer to the pointer of the subpacket. |
412 |
* @param c The class the subpacket belongs to. |
413 |
* @param name The name of the packet. |
414 |
*/ |
415 |
void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket, |
416 |
const TClass *c, std::string name) { |
417 |
SubPacket *packet = *(SubPacket **)subpacket; |
418 |
oss.str(""); |
419 |
oss << "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)"; |
420 |
//logger->debug(oss.str().c_str()); |
421 |
TTree* HeaderTree = ReadTTree(packet->GetPacketType()); |
422 |
std::string FullName = packet->GetPacketType()->GetName() + "." + name; |
423 |
if (Multiple) { |
424 |
TTree* tree = CreateTTree(algo, packet, name); |
425 |
oss.str(""); |
426 |
oss << "Branch: " << name << " Class: " << c->GetName(); |
427 |
//logger->debug(oss.str().c_str()); |
428 |
tree->Branch(name.c_str(), c->GetName(), subpacket); |
429 |
HeaderTree->AddFriend(tree, tree->GetName()); |
430 |
SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet)); |
431 |
} else { |
432 |
std::string nameBranch(name); |
433 |
HeaderTree->Branch(nameBranch.c_str(), c->GetName(), subpacket); |
434 |
SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet)); |
435 |
} |
436 |
} |
437 |
|
438 |
/** |
439 |
* Register a certain SubPacket with its default name to be written to |
440 |
* the repository. A usual call sequence for this function ist |
441 |
* MyEvent *event = new MyEvent(); |
442 |
* run->WriteSubPacket(this, &event, event->Class() |
443 |
* @param algo Algorithm that produces this SubPacket. |
444 |
* @param subpacket A pointer to the pointer of the subpacket. |
445 |
* @param c The class the subpacket belongs to. |
446 |
*/ |
447 |
void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket, |
448 |
const TClass *c) { |
449 |
SubPacket *packet = *(SubPacket **)subpacket; |
450 |
WriteSubPacket(algo, subpacket, c, GetDefaultBranchName(packet)); |
451 |
} |
452 |
|
453 |
/** |
454 |
* Write the header packet to all ROOT files in the tree. Intended to |
455 |
* be used for raw data readers that create the initial event structure. |
456 |
* @param algo Algorithm that produces this SubPacket. |
457 |
* @param subpacket A pointer to the pointer of the header packet. |
458 |
*/ |
459 |
void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) { |
460 |
WriteHeader(algo, subpacket, PacketType::PhysEndRun); |
461 |
WriteHeader(algo, subpacket, PacketType::CalibCalPulse1); |
462 |
WriteHeader(algo, subpacket, PacketType::CalibCalPulse2); |
463 |
WriteHeader(algo, subpacket, PacketType::Physics); |
464 |
WriteHeader(algo, subpacket, PacketType::CalibTrkBoth); |
465 |
WriteHeader(algo, subpacket, PacketType::CalibTrk1); |
466 |
WriteHeader(algo, subpacket, PacketType::CalibTrk2); |
467 |
WriteHeader(algo, subpacket, PacketType::CalibTof); |
468 |
WriteHeader(algo, subpacket, PacketType::CalibS4); |
469 |
WriteHeader(algo, subpacket, PacketType::CalibCalPed); |
470 |
WriteHeader(algo, subpacket, PacketType::Calib1_Ac1); |
471 |
WriteHeader(algo, subpacket, PacketType::Calib1_Ac2); |
472 |
WriteHeader(algo, subpacket, PacketType::Calib2_Ac1); |
473 |
WriteHeader(algo, subpacket, PacketType::Calib2_Ac2); |
474 |
//marco: aggiunto |
475 |
WriteHeader(algo, subpacket, PacketType::CalibCal); |
476 |
WriteHeader(algo, subpacket, PacketType::RunHeader); |
477 |
WriteHeader(algo, subpacket, PacketType::RunTrailer); |
478 |
WriteHeader(algo, subpacket, PacketType::CalibHeader); |
479 |
WriteHeader(algo, subpacket, PacketType::CalibTrailer); |
480 |
WriteHeader(algo, subpacket, PacketType::InitHeader); |
481 |
WriteHeader(algo, subpacket, PacketType::InitTrailer); |
482 |
WriteHeader(algo, subpacket, PacketType::EventTrk); |
483 |
WriteHeader(algo, subpacket, PacketType::Log); |
484 |
WriteHeader(algo, subpacket, PacketType::VarDump); |
485 |
WriteHeader(algo, subpacket, PacketType::ArrDump); |
486 |
WriteHeader(algo, subpacket, PacketType::TabDump); |
487 |
WriteHeader(algo, subpacket, PacketType::Tmtc); |
488 |
WriteHeader(algo, subpacket, PacketType::Mcmd); |
489 |
WriteHeader(algo, subpacket, PacketType::ForcedFECmd); |
490 |
WriteHeader(algo, subpacket, PacketType::Ac1Init); |
491 |
WriteHeader(algo, subpacket, PacketType::CalInit); |
492 |
WriteHeader(algo, subpacket, PacketType::TrkInit); |
493 |
WriteHeader(algo, subpacket, PacketType::TofInit); |
494 |
WriteHeader(algo, subpacket, PacketType::TrgInit); |
495 |
WriteHeader(algo, subpacket, PacketType::NdInit); |
496 |
WriteHeader(algo, subpacket, PacketType::S4Init); |
497 |
WriteHeader(algo, subpacket, PacketType::Ac2Init); |
498 |
WriteHeader(algo, subpacket, PacketType::CalAlarm); |
499 |
WriteHeader(algo, subpacket, PacketType::Ac1Alarm); |
500 |
WriteHeader(algo, subpacket, PacketType::TrkAlarm); |
501 |
WriteHeader(algo, subpacket, PacketType::TrgAlarm); |
502 |
WriteHeader(algo, subpacket, PacketType::TofAlarm); |
503 |
WriteHeader(algo, subpacket, PacketType::S4Alarm); |
504 |
WriteHeader(algo, subpacket, PacketType::Ac2Alarm); |
505 |
WriteHeader(algo, subpacket, PacketType::TsbT); |
506 |
WriteHeader(algo, subpacket, PacketType::TsbB); |
507 |
|
508 |
} |
509 |
|
510 |
/** |
511 |
* Write the ROOT files to disk. |
512 |
*/ |
513 |
void PamelaRun::WriteFiles(void) { |
514 |
// Workaround: unlink all friend trees first top avoid to store |
515 |
// the links in the header tree file. |
516 |
for (RootTreeMap::iterator i = TTreeMap.begin(); i != TTreeMap.end(); i++) { |
517 |
if (i->second->GetListOfFriends() != 0) { |
518 |
i->second->GetListOfFriends()->Delete(); |
519 |
} |
520 |
} |
521 |
|
522 |
|
523 |
TTree *softinfo = 0; |
524 |
Int_t version=GetYODAver(); |
525 |
//Int_t version= 60312; |
526 |
//printf("version = %f \n",version); |
527 |
softinfo = new TTree("SoftInfo","YODA software info"); |
528 |
softinfo->Branch("SoftInfo",&version,"version/I"); |
529 |
softinfo->Fill(); |
530 |
|
531 |
for (TTreeListMap::iterator i = WritingRootTrees.begin(); |
532 |
i != WritingRootTrees.end(); i++) { |
533 |
for (TTreeList::iterator j = i->second.begin(); |
534 |
j != i->second.end(); j++) { |
535 |
(*j)->GetCurrentFile()->Write(0,TObject::kOverwrite); |
536 |
} |
537 |
} |
538 |
|
539 |
softinfo->Delete(); |
540 |
} |
541 |
|
542 |
/** |
543 |
* Fill all ROOT trees of a certain type that were opened for writing. |
544 |
* @param type the package type of the trees to fill. |
545 |
*/ |
546 |
void PamelaRun::FillTrees(const PacketType* type) { |
547 |
try{ |
548 |
for (TTreeList::iterator j = WritingRootTrees[type].begin(); |
549 |
j != WritingRootTrees[type].end(); j++) { |
550 |
(*j)->Fill(); |
551 |
} |
552 |
} catch(Exception exc){ |
553 |
// // logger->fatal("ORRORE!!!"); |
554 |
} |
555 |
} |
556 |
|
557 |
|
558 |
/** |
559 |
* Write the header packet of a specified packet type. This is mainly used |
560 |
* for the raw reader to create the base for the event structure. |
561 |
* @param algo Algorithm that produces this SubPacket. |
562 |
* @param subpacket A pointer to the pointer of the packet. |
563 |
* @param type The packet type. |
564 |
*/ |
565 |
void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket, |
566 |
const PacketType* type) { |
567 |
|
568 |
EventHeader header(type); |
569 |
std::string EventType = (&header)->GetPacketType()->GetName(); |
570 |
// std::cout<<EventType<<std::endl; |
571 |
|
572 |
std::string FileName = ""; |
573 |
TFile* File = 0; |
574 |
Long64_t maxsize = 5000000000LL; |
575 |
TTree::SetMaxTreeSize(maxsize); |
576 |
TTree *tree = 0; |
577 |
if ( Multiple ){ |
578 |
FileName = GetFileName(&header, GetDefaultBranchName(&header)); |
579 |
CreateDirectoryStructure(FileName.c_str()); |
580 |
File = new TFile(FileName.c_str(), "create"); |
581 |
File->SetCompressionLevel(compression); |
582 |
tree = new TTree("Pscu", algo->GetAlgorithmName().c_str()); |
583 |
WritingRootTrees[(&header)->GetPacketType()].push_back(tree); |
584 |
tree->GetCurrentFile()->cd(); |
585 |
tree->Branch(GetDefaultBranchName(&header).c_str(), |
586 |
(*subpacket)->Class()->GetName(), subpacket); |
587 |
TTreeMap.insert(RootTreeMap::value_type(type, tree)); |
588 |
|
589 |
} else { |
590 |
if (!Multiple && (SingleFile == NULL)){ |
591 |
//std::string pathDir((char*)getenv("YODA_DATA")); |
592 |
SingleFile = new TFile((GetPath() + "/" + Run + ".root").c_str(), "update"); |
593 |
SingleFile->SetCompressionLevel(compression); |
594 |
} |
595 |
|
596 |
tree = new TTree(EventType.c_str(), algo->GetAlgorithmName().c_str()); |
597 |
WritingRootTrees[type].push_back(tree); |
598 |
tree->GetCurrentFile()->cd(); |
599 |
tree->Branch(GetDefaultBranchName(&header).c_str(), |
600 |
(*subpacket)->Class()->GetName(), subpacket); |
601 |
TTreeMap.insert(RootTreeMap::value_type(type, tree)); |
602 |
} |
603 |
|
604 |
//marco: |
605 |
if(File){delete File; File = 0;} |
606 |
// if(tree){delete tree; tree = 0;} |
607 |
|
608 |
} |