|
| 1 | +/// \file runHough.cxx |
| 2 | +/// \brief Implementation of a cluster loader |
| 3 | +/// \author Charis Kouzinopoulos |
| 4 | + |
| 5 | +#include "AliHLTTPCTrackGeometry.h" |
| 6 | +#include "AliHLTTPCClusterDataFormat.h" |
| 7 | +#include "AliHLTTPCSpacePointContainer.h" |
| 8 | +#include "AliHLTComponent.h" |
| 9 | + |
| 10 | +#include "boost/filesystem.hpp" |
| 11 | + |
| 12 | +#include <sstream> |
| 13 | + |
| 14 | +int processData(std::string dataFileName, std::string dataType, std::string dataOrigin) |
| 15 | +{ |
| 16 | + std::ifstream inputData(dataFileName.c_str(), std::ifstream::binary); |
| 17 | + if (!inputData) { |
| 18 | + std::cerr << "Error, cluster data file " << dataFileName << " could not be accessed" << endl; |
| 19 | + std::exit(1); |
| 20 | + } |
| 21 | + |
| 22 | + // Get length of file |
| 23 | + inputData.seekg(0, inputData.end); |
| 24 | + int dataLength = inputData.tellg(); |
| 25 | + inputData.seekg(0, inputData.beg); |
| 26 | + |
| 27 | + // Allocate memory and read file to memory |
| 28 | + char* inputBuffer = new char[dataLength]; |
| 29 | + inputData.read(inputBuffer, dataLength); |
| 30 | + inputData.close(); |
| 31 | + |
| 32 | + // Cast data to an AliHLTUInt8_t*, AliHLTComponentBlockData* and AliHLTTPCClusterData* data type |
| 33 | + AliHLTUInt8_t* pData = reinterpret_cast<AliHLTUInt8_t*>(&inputBuffer[0]); |
| 34 | + AliHLTComponentBlockData* bdTarget = reinterpret_cast<AliHLTComponentBlockData*>(&inputBuffer[0]); |
| 35 | + AliHLTTPCClusterData* pClusterData = reinterpret_cast<AliHLTTPCClusterData*>(inputBuffer); |
| 36 | + |
| 37 | + // Create a collection of all points |
| 38 | + std::auto_ptr<AliHLTTPCSpacePointContainer> spacepoints(new AliHLTTPCSpacePointContainer); |
| 39 | + if (!spacepoints.get()) { |
| 40 | + std::cerr << "Error, could not create a space point collection" << endl; |
| 41 | + std::exit(1); |
| 42 | + } |
| 43 | + |
| 44 | + // Determine the number of clusters from the header of the data file |
| 45 | + pClusterData->fSpacePointCnt = ((int)inputBuffer[1] << 8) + (int)inputBuffer[0]; |
| 46 | + |
| 47 | + AliHLTComponent::SetDataType(bdTarget->fDataType, dataType.c_str(), dataOrigin.c_str()); |
| 48 | + |
| 49 | + // AliHLTTPCDefinitions::EncodeDataSpecification(currentSlice, currentSlice, currentPartition, currentPartition); |
| 50 | + bdTarget->fSpecification = kAliHLTVoidDataSpec; |
| 51 | + bdTarget->fPtr = inputBuffer; |
| 52 | + bdTarget->fSize = sizeof(AliHLTTPCClusterData) + pClusterData->fSpacePointCnt * sizeof(AliHLTTPCSpacePointData); |
| 53 | + |
| 54 | + int numberOfClusters = spacepoints->AddInputBlock(bdTarget); |
| 55 | + |
| 56 | + // cout << *spacepoints << endl; |
| 57 | + |
| 58 | + if (inputBuffer) { |
| 59 | + delete[] inputBuffer; |
| 60 | + } |
| 61 | + inputBuffer = NULL; |
| 62 | + |
| 63 | + return numberOfClusters; |
| 64 | +} |
| 65 | + |
| 66 | +int main(int argc, char** argv) |
| 67 | +{ |
| 68 | + if (argc != 2) { |
| 69 | + std::cerr << "Usage: " << argv[0] << " <event number>" << endl; |
| 70 | + std::exit(1); |
| 71 | + } |
| 72 | + |
| 73 | + // Create data path |
| 74 | + std::string dataPath = "emulated-tpc-clusters/event"; |
| 75 | + dataPath += argv[1]; |
| 76 | + |
| 77 | + boost::filesystem::path someDir(dataPath); |
| 78 | + boost::filesystem::directory_iterator end_iter; |
| 79 | + |
| 80 | + typedef std::multimap<std::time_t, boost::filesystem::path> result_set_t; |
| 81 | + result_set_t result_set; |
| 82 | + |
| 83 | + std::string dataType = "CLUSTERS", dataOrigin = "TPC "; |
| 84 | + |
| 85 | + int totalNumberOfClusters = 0, totalNumberOfDataFiles = 0; |
| 86 | + |
| 87 | + if (boost::filesystem::exists(someDir) && boost::filesystem::is_directory(someDir)) { |
| 88 | + for (boost::filesystem::directory_iterator dir_iter(someDir); dir_iter != end_iter; ++dir_iter) { |
| 89 | + if (boost::filesystem::is_regular_file(dir_iter->status())) { |
| 90 | + totalNumberOfClusters += processData(dir_iter->path().string(), dataType, dataOrigin); |
| 91 | + totalNumberOfDataFiles++; |
| 92 | + } |
| 93 | + } |
| 94 | + } else { |
| 95 | + std::cerr << "Path " << someDir.string() << "/ could not be found or does not contain any valid data files" << endl; |
| 96 | + exit(1); |
| 97 | + } |
| 98 | + |
| 99 | + cout << "Added " << totalNumberOfClusters << " clusters from " << totalNumberOfDataFiles << " data files" << endl; |
| 100 | + return 0; |
| 101 | +} |
0 commit comments