/[PAMELA software]/yoda/event/PamelaRun.cpp
ViewVC logotype

Annotation of /yoda/event/PamelaRun.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.0 - (hide annotations) (download)
Tue Feb 7 17:11:07 2006 UTC (18 years, 9 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA6_0/00
Changes since 5.1: +3 -3 lines
Several new features in this revision:
a) all the packets are conform to the Mass Memory Format specifications (http://people.roma2.infn.it/~cpu/Mass_Memory_Format.html)
b) unpacking either using the old files structure OR the new one file unpacking.
c) parametrized root files compression factor
d) deleting of the following packet: TofTest, TrkTest, TrkEvent.
e) the Tracker routines now work without the use of temp files.

The point a) allow Yoda to unpack in the root file all the packets generated by the CPU. According to the MassMemoryFormat; that is three possible data are available:

1) almost explicit structure of the packet (like for Log, Tracker, Mcmd, etc....);
2) dummy data collection structure (InitHeader, InitTrailer, CalibHeader, CalibTrailer);
3) just the data of the packet (almost all Alarm and Init procedures). The class regarding this packets have only one parameters, a TArrayC class, which contain the data-block included in the packet (tat is the data below the packet Header).

The point b) has been implemented as a consequence of an agreement about a more compact structure of the unpacked data. Up to now the structure of each unpacked data consisted of a folder, named after the packet type, and three files: xxx.Header.root, xxx.NamePacket.root, xxx.Registry.root.
Starting from this release YODA, by default will unpack the data in a unique root file. The structure of this file will consist of:
- several TTree(s) named after the packet type;
- into each TTree are foreseen three TBranche(s):
    - 'Header'  (the old xxx.Header.root file)
    - 'NameOfThePacket' (the old xxx.Event.root file or the xxx.Event.DETECTOR.root)
    - 'Registry' (the old xxx.Registry.root file)

Anyway is still possible, but deprecated, to unpack using the old structure, passing to the "yoda" command the optional parameter "-multifile"

The point c) has been implemented because is well know that writing time in a TTree is as much fast as much lower is the compression factor for the root file; anyway for a PAMELA dat file, a compression equal to 0 will generate a root file which will be more than two times the original size. To modify the compression parameter just add the optional parameter "-c [0-9]" to the yoda command line.

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

  ViewVC Help
Powered by ViewVC 1.1.23